X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc%2Fmiddle%2Fdead.rs;h=18e19e802e889da4d40f4276d4716e2e89fb516c;hb=fff08cb04389497d254fb40948674cbbee402908;hp=2a9928567f4dcfa2fed79a3dd44afba6ed765089;hpb=5a08ca38deb7c363aa5078681b4ea90a6276c931;p=rust.git diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 2a9928567f4..18e19e802e8 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -26,8 +26,7 @@ // explored. For example, if it's a live Node::Item that is a // function, then we should explore its block to check for codes that // may need to be marked as live. -fn should_explore<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - hir_id: hir::HirId) -> bool { +fn should_explore<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, hir_id: hir::HirId) -> bool { match tcx.hir().find_by_hir_id(hir_id) { Some(Node::Item(..)) | Some(Node::ImplItem(..)) | @@ -41,7 +40,7 @@ fn should_explore<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, struct MarkSymbolVisitor<'a, 'tcx: 'a> { worklist: Vec, - tcx: TyCtxt<'a, 'tcx, 'tcx>, + tcx: TyCtxt<'tcx, 'tcx>, tables: &'a ty::TypeckTables<'tcx>, live_symbols: FxHashSet, repr_has_repr_c: bool, @@ -72,13 +71,13 @@ fn insert_def_id(&mut self, def_id: DefId) { fn handle_res(&mut self, res: Res) { match res { Res::Def(DefKind::Const, _) - | Res::Def(DefKind::AssociatedConst, _) + | Res::Def(DefKind::AssocConst, _) | Res::Def(DefKind::TyAlias, _) => { self.check_def_id(res.def_id()); } _ if self.in_pat => {}, Res::PrimTy(..) | Res::SelfTy(..) | Res::SelfCtor(..) | - Res::Local(..) | Res::Upvar(..) => {} + Res::Local(..) => {} Res::Def(DefKind::Ctor(CtorOf::Variant, ..), ctor_def_id) => { let variant_id = self.tcx.parent(ctor_def_id).unwrap(); let enum_id = self.tcx.parent(variant_id).unwrap(); @@ -302,9 +301,11 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty) { } } -fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_, '_>, - id: hir::HirId, - attrs: &[ast::Attribute]) -> bool { +fn has_allow_dead_code_or_lang_attr( + tcx: TyCtxt<'_, '_>, + id: hir::HirId, + attrs: &[ast::Attribute], +) -> bool { if attr::contains_name(attrs, sym::lang) { return true; } @@ -353,7 +354,7 @@ fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_, '_>, struct LifeSeeder<'k, 'tcx: 'k> { worklist: Vec, krate: &'k hir::Crate, - tcx: TyCtxt<'k, 'tcx, 'tcx>, + tcx: TyCtxt<'tcx, 'tcx>, // see `MarkSymbolVisitor::struct_constructors` struct_constructors: FxHashMap, } @@ -423,8 +424,8 @@ fn visit_impl_item(&mut self, _item: &hir::ImplItem) { } } -fn create_and_seed_worklist<'a, 'tcx>( - tcx: TyCtxt<'a, 'tcx, 'tcx>, +fn create_and_seed_worklist<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, access_levels: &privacy::AccessLevels, krate: &hir::Crate, ) -> (Vec, FxHashMap) { @@ -451,10 +452,11 @@ fn create_and_seed_worklist<'a, 'tcx>( (life_seeder.worklist, life_seeder.struct_constructors) } -fn find_live<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - access_levels: &privacy::AccessLevels, - krate: &hir::Crate) - -> FxHashSet { +fn find_live<'tcx>( + tcx: TyCtxt<'tcx, 'tcx>, + access_levels: &privacy::AccessLevels, + krate: &hir::Crate, +) -> FxHashSet { let (worklist, struct_constructors) = create_and_seed_worklist(tcx, access_levels, krate); let mut symbol_visitor = MarkSymbolVisitor { worklist, @@ -471,12 +473,12 @@ fn find_live<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, symbol_visitor.live_symbols } -struct DeadVisitor<'a, 'tcx: 'a> { - tcx: TyCtxt<'a, 'tcx, 'tcx>, +struct DeadVisitor<'tcx> { + tcx: TyCtxt<'tcx, 'tcx>, live_symbols: FxHashSet, } -impl<'a, 'tcx> DeadVisitor<'a, 'tcx> { +impl DeadVisitor<'tcx> { fn should_warn_about_item(&mut self, item: &hir::Item) -> bool { let should_warn = match item.node { hir::ItemKind::Static(..) @@ -554,7 +556,7 @@ fn warn_dead_code(&mut self, } } -impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> { +impl Visitor<'tcx> for DeadVisitor<'tcx> { /// Walk nested items in place so that we don't report dead-code /// on inner functions when the outer function is already getting /// an error. We could do this also by checking the parents, but @@ -660,7 +662,7 @@ fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { } } -pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { +pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx, 'tcx>) { let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE); let krate = tcx.hir().krate(); let live_symbols = find_live(tcx, access_levels, krate);