Skip to content

Commit b70a98f

Browse files
authored
Rollup merge of rust-lang#59129 - sanxiyn:visit-impl-trait, r=varkor
Visit impl Trait for dead_code lint Fix rust-lang#59085.
2 parents f3dc046 + 2027459 commit b70a98f

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

src/librustc/middle/dead.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// from live codes are live, and everything else is dead.
44

55
use crate::hir::Node;
6-
use crate::hir::{self, PatKind};
6+
use crate::hir::{self, PatKind, TyKind};
77
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
88
use crate::hir::itemlikevisit::ItemLikeVisitor;
99

@@ -282,6 +282,17 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
282282
self.handle_definition(path.def);
283283
intravisit::walk_path(self, path);
284284
}
285+
286+
fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
287+
match ty.node {
288+
TyKind::Def(item_id, _) => {
289+
let item = self.tcx.hir().expect_item(item_id.id);
290+
intravisit::walk_item(self, item);
291+
}
292+
_ => ()
293+
}
294+
intravisit::walk_ty(self, ty);
295+
}
285296
}
286297

287298
fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_, '_>,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![deny(dead_code)]
2+
3+
trait Trait {
4+
type Type;
5+
}
6+
7+
impl Trait for () {
8+
type Type = ();
9+
}
10+
11+
type Used = ();
12+
type Unused = (); //~ ERROR type alias is never used
13+
14+
fn foo() -> impl Trait<Type = Used> {}
15+
16+
fn main() {
17+
foo();
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: type alias is never used: `Unused`
2+
--> $DIR/lint-dead-code-impl-trait.rs:12:1
3+
|
4+
LL | type Unused = ();
5+
| ^^^^^^^^^^^^^^^^^
6+
|
7+
note: lint level defined here
8+
--> $DIR/lint-dead-code-impl-trait.rs:1:9
9+
|
10+
LL | #![deny(dead_code)]
11+
| ^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)