Rollup merge of #59129 - sanxiyn:visit-impl-trait, r=varkor
Visit impl Trait for dead_code lint Fix #59085.
This commit is contained in:
commit
b70a98f261
@ -3,7 +3,7 @@
|
||||
// from live codes are live, and everything else is dead.
|
||||
|
||||
use crate::hir::Node;
|
||||
use crate::hir::{self, PatKind};
|
||||
use crate::hir::{self, PatKind, TyKind};
|
||||
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||
use crate::hir::itemlikevisit::ItemLikeVisitor;
|
||||
|
||||
@ -282,6 +282,17 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
|
||||
self.handle_definition(path.def);
|
||||
intravisit::walk_path(self, path);
|
||||
}
|
||||
|
||||
fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
|
||||
match ty.node {
|
||||
TyKind::Def(item_id, _) => {
|
||||
let item = self.tcx.hir().expect_item(item_id.id);
|
||||
intravisit::walk_item(self, item);
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
intravisit::walk_ty(self, ty);
|
||||
}
|
||||
}
|
||||
|
||||
fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_, '_>,
|
||||
|
18
src/test/ui/lint/lint-dead-code-impl-trait.rs
Normal file
18
src/test/ui/lint/lint-dead-code-impl-trait.rs
Normal file
@ -0,0 +1,18 @@
|
||||
#![deny(dead_code)]
|
||||
|
||||
trait Trait {
|
||||
type Type;
|
||||
}
|
||||
|
||||
impl Trait for () {
|
||||
type Type = ();
|
||||
}
|
||||
|
||||
type Used = ();
|
||||
type Unused = (); //~ ERROR type alias is never used
|
||||
|
||||
fn foo() -> impl Trait<Type = Used> {}
|
||||
|
||||
fn main() {
|
||||
foo();
|
||||
}
|
14
src/test/ui/lint/lint-dead-code-impl-trait.stderr
Normal file
14
src/test/ui/lint/lint-dead-code-impl-trait.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error: type alias is never used: `Unused`
|
||||
--> $DIR/lint-dead-code-impl-trait.rs:12:1
|
||||
|
|
||||
LL | type Unused = ();
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/lint-dead-code-impl-trait.rs:1:9
|
||||
|
|
||||
LL | #![deny(dead_code)]
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user