mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
Do not complain about unused code when used in impl
Self
type
This commit is contained in:
parent
7b0085a613
commit
053afa7aec
@ -30,10 +30,11 @@ fn should_explore(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
|
||||
Some(Node::Item(..)) |
|
||||
Some(Node::ImplItem(..)) |
|
||||
Some(Node::ForeignItem(..)) |
|
||||
Some(Node::TraitItem(..)) =>
|
||||
true,
|
||||
_ =>
|
||||
false
|
||||
Some(Node::TraitItem(..)) |
|
||||
Some(Node::Variant(..)) |
|
||||
Some(Node::AnonConst(..)) |
|
||||
Some(Node::Pat(..)) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,7 +76,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
||||
self.check_def_id(res.def_id());
|
||||
}
|
||||
_ if self.in_pat => {},
|
||||
Res::PrimTy(..) | Res::SelfTy(..) | Res::SelfCtor(..) |
|
||||
Res::PrimTy(..) | Res::SelfCtor(..) |
|
||||
Res::Local(..) => {}
|
||||
Res::Def(DefKind::Ctor(CtorOf::Variant, ..), ctor_def_id) => {
|
||||
let variant_id = self.tcx.parent(ctor_def_id).unwrap();
|
||||
@ -92,6 +93,14 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
||||
self.check_def_id(variant_id);
|
||||
}
|
||||
}
|
||||
Res::SelfTy(t, i) => {
|
||||
if let Some(t) = t {
|
||||
self.check_def_id(t);
|
||||
}
|
||||
if let Some(i) = i {
|
||||
self.check_def_id(i);
|
||||
}
|
||||
}
|
||||
Res::ToolMod | Res::NonMacroAttr(..) | Res::Err => {}
|
||||
_ => {
|
||||
self.check_def_id(res.def_id());
|
||||
@ -271,7 +280,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
|
||||
let res = self.tables.qpath_res(path, pat.hir_id);
|
||||
self.handle_field_pattern_match(pat, res, fields);
|
||||
}
|
||||
PatKind::Path(ref qpath @ hir::QPath::TypeRelative(..)) => {
|
||||
PatKind::Path(ref qpath) => {
|
||||
let res = self.tables.qpath_res(qpath, pat.hir_id);
|
||||
self.handle_res(res);
|
||||
}
|
||||
@ -298,6 +307,11 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
|
||||
}
|
||||
intravisit::walk_ty(self, ty);
|
||||
}
|
||||
|
||||
fn visit_anon_const(&mut self, c: &'tcx hir::AnonConst) {
|
||||
self.live_symbols.insert(c.hir_id);
|
||||
intravisit::walk_anon_const(self, c);
|
||||
}
|
||||
}
|
||||
|
||||
fn has_allow_dead_code_or_lang_attr(
|
||||
|
@ -5,12 +5,15 @@
|
||||
// when deriving Debug on an empty enum
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Void {} //~ WARN never used
|
||||
enum Void {}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Foo { //~ WARN never used
|
||||
enum Foo {
|
||||
Bar(u8),
|
||||
Void(Void),
|
||||
Void(Void), //~ WARN never used
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
fn main() {
|
||||
let x = Foo::Bar(42);
|
||||
println!("{:?}", x);
|
||||
}
|
||||
|
@ -1,14 +1,8 @@
|
||||
warning: enum is never used: `Void`
|
||||
--> $DIR/derive-uninhabited-enum-38885.rs:8:1
|
||||
warning: variant is never constructed: `Void`
|
||||
--> $DIR/derive-uninhabited-enum-38885.rs:13:5
|
||||
|
|
||||
LL | enum Void {}
|
||||
| ^^^^^^^^^
|
||||
LL | Void(Void),
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: `-W dead-code` implied by `-W unused`
|
||||
|
||||
warning: enum is never used: `Foo`
|
||||
--> $DIR/derive-uninhabited-enum-38885.rs:11:1
|
||||
|
|
||||
LL | enum Foo {
|
||||
| ^^^^^^^^
|
||||
|
||||
|
35
src/test/ui/lint/lint-dead-code-const-and-self.rs
Normal file
35
src/test/ui/lint/lint-dead-code-const-and-self.rs
Normal file
@ -0,0 +1,35 @@
|
||||
// check-pass
|
||||
|
||||
#![deny(dead_code)]
|
||||
|
||||
const TLC: usize = 4;
|
||||
|
||||
trait Tr { fn doit(&self); }
|
||||
|
||||
impl Tr for [usize; TLC] {
|
||||
fn doit(&self) {
|
||||
println!("called 4");
|
||||
}
|
||||
}
|
||||
|
||||
struct X;
|
||||
struct Y;
|
||||
struct Z;
|
||||
|
||||
trait Foo<T> {
|
||||
type Ty;
|
||||
fn foo() -> Self::Ty;
|
||||
}
|
||||
|
||||
impl Foo<Y> for X {
|
||||
type Ty = Z;
|
||||
fn foo() -> Self::Ty {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let s = [0,1,2,3];
|
||||
s.doit();
|
||||
X::foo();
|
||||
}
|
Loading…
Reference in New Issue
Block a user