未验证 提交 b70a98f2 编写于 作者: M Mazdak Farrokhzad 提交者: GitHub

Rollup merge of #59129 - sanxiyn:visit-impl-trait, r=varkor

Visit impl Trait for dead_code lint

Fix #59085.
......@@ -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 @@ fn visit_path(&mut self, path: &'tcx hir::Path, _: hir::HirId) {
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<'_, '_, '_>,
......
#![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();
}
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册