diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-26 23:55:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-26 23:55:42 +0200 |
| commit | 44cfa7823d25ca52e42e23aad7dec22e4626f892 (patch) | |
| tree | aac345103a9fa061d9927a55dd728cd875ca769f /src/librustc | |
| parent | 9b91b9c10e3c87ed333a1e34c4f46ed68f1eee06 (diff) | |
| parent | 7def99af8a311139c43c961e13872ff27dd235c7 (diff) | |
| download | rust-44cfa7823d25ca52e42e23aad7dec22e4626f892.tar.gz rust-44cfa7823d25ca52e42e23aad7dec22e4626f892.zip | |
Rollup merge of #63317 - estebank:dead-code, r=matthewjasper
Do not complain about unused code when used in `impl` `Self` type Fix https://github.com/rust-lang/rust/issues/18290.
Diffstat (limited to 'src/librustc')
| -rw-r--r-- | src/librustc/middle/dead.rs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 8ce8bb52566..d4805a7c783 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -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( |
