diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 3ea782b62f1..f87f3cdde4c 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -39,10 +39,10 @@ type Res = def::Res; -impl<'a, Id: Into> ToNameBinding<'a> - for (Module<'a>, ty::Visibility, Span, LocalExpnId) +impl<'ra, Id: Into> ToNameBinding<'ra> + for (Module<'ra>, ty::Visibility, Span, LocalExpnId) { - fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> NameBinding<'a> { + fn to_name_binding(self, arenas: &'ra ResolverArenas<'ra>) -> NameBinding<'ra> { arenas.alloc_name_binding(NameBindingData { kind: NameBindingKind::Module(self.0), ambiguity: None, @@ -54,8 +54,8 @@ fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> NameBinding<'a> { } } -impl<'a, Id: Into> ToNameBinding<'a> for (Res, ty::Visibility, Span, LocalExpnId) { - fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> NameBinding<'a> { +impl<'ra, Id: Into> ToNameBinding<'ra> for (Res, ty::Visibility, Span, LocalExpnId) { + fn to_name_binding(self, arenas: &'ra ResolverArenas<'ra>) -> NameBinding<'ra> { arenas.alloc_name_binding(NameBindingData { kind: NameBindingKind::Res(self.0), ambiguity: None, @@ -67,12 +67,12 @@ fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> NameBinding<'a> { } } -impl<'a, 'tcx> Resolver<'a, 'tcx> { +impl<'ra, 'tcx> Resolver<'ra, 'tcx> { /// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined; /// otherwise, reports an error. - pub(crate) fn define(&mut self, parent: Module<'a>, ident: Ident, ns: Namespace, def: T) + pub(crate) fn define(&mut self, parent: Module<'ra>, ident: Ident, ns: Namespace, def: T) where - T: ToNameBinding<'a>, + T: ToNameBinding<'ra>, { let binding = def.to_name_binding(self.arenas); let key = self.new_disambiguated_key(ident, ns); @@ -97,7 +97,7 @@ pub(crate) fn define(&mut self, parent: Module<'a>, ident: Ident, ns: Namespa /// Reachable macros with block module parents exist due to `#[macro_export] macro_rules!`, /// but they cannot use def-site hygiene, so the assumption holds /// (). - pub(crate) fn get_nearest_non_block_module(&mut self, mut def_id: DefId) -> Module<'a> { + pub(crate) fn get_nearest_non_block_module(&mut self, mut def_id: DefId) -> Module<'ra> { loop { match self.get_module(def_id) { Some(module) => return module, @@ -106,14 +106,14 @@ pub(crate) fn get_nearest_non_block_module(&mut self, mut def_id: DefId) -> Modu } } - pub(crate) fn expect_module(&mut self, def_id: DefId) -> Module<'a> { + pub(crate) fn expect_module(&mut self, def_id: DefId) -> Module<'ra> { self.get_module(def_id).expect("argument `DefId` is not a module") } /// If `def_id` refers to a module (in resolver's sense, i.e. a module item, crate root, enum, /// or trait), then this function returns that module's resolver representation, otherwise it /// returns `None`. - pub(crate) fn get_module(&mut self, def_id: DefId) -> Option> { + pub(crate) fn get_module(&mut self, def_id: DefId) -> Option> { if let module @ Some(..) = self.module_map.get(&def_id) { return module.copied(); } @@ -143,7 +143,7 @@ pub(crate) fn get_module(&mut self, def_id: DefId) -> Option> { None } - pub(crate) fn expn_def_scope(&mut self, expn_id: ExpnId) -> Module<'a> { + pub(crate) fn expn_def_scope(&mut self, expn_id: ExpnId) -> Module<'ra> { match expn_id.expn_data().macro_def_id { Some(def_id) => self.macro_def_scope(def_id), None => expn_id @@ -153,7 +153,7 @@ pub(crate) fn expn_def_scope(&mut self, expn_id: ExpnId) -> Module<'a> { } } - pub(crate) fn macro_def_scope(&mut self, def_id: DefId) -> Module<'a> { + pub(crate) fn macro_def_scope(&mut self, def_id: DefId) -> Module<'ra> { if let Some(id) = def_id.as_local() { self.local_macro_def_scopes[&id] } else { @@ -186,15 +186,15 @@ pub(crate) fn get_macro_by_def_id(&mut self, def_id: DefId) -> &MacroData { pub(crate) fn build_reduced_graph( &mut self, fragment: &AstFragment, - parent_scope: ParentScope<'a>, - ) -> MacroRulesScopeRef<'a> { + parent_scope: ParentScope<'ra>, + ) -> MacroRulesScopeRef<'ra> { collect_definitions(self, fragment, parent_scope.expansion); let mut visitor = BuildReducedGraphVisitor { r: self, parent_scope }; fragment.visit_with(&mut visitor); visitor.parent_scope.macro_rules } - pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) { + pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'ra>) { for child in self.tcx.module_children(module.def_id()) { let parent_scope = ParentScope::module(module, self); self.build_reduced_graph_for_external_crate_res(child, parent_scope) @@ -205,7 +205,7 @@ pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) { fn build_reduced_graph_for_external_crate_res( &mut self, child: &ModChild, - parent_scope: ParentScope<'a>, + parent_scope: ParentScope<'ra>, ) { let parent = parent_scope.module; let ModChild { ident, res, vis, ref reexport_chain } = *child; @@ -273,18 +273,18 @@ fn build_reduced_graph_for_external_crate_res( } } -struct BuildReducedGraphVisitor<'a, 'b, 'tcx> { - r: &'b mut Resolver<'a, 'tcx>, - parent_scope: ParentScope<'a>, +struct BuildReducedGraphVisitor<'a, 'ra, 'tcx> { + r: &'a mut Resolver<'ra, 'tcx>, + parent_scope: ParentScope<'ra>, } -impl<'a, 'tcx> AsMut> for BuildReducedGraphVisitor<'a, '_, 'tcx> { - fn as_mut(&mut self) -> &mut Resolver<'a, 'tcx> { +impl<'ra, 'tcx> AsMut> for BuildReducedGraphVisitor<'_, 'ra, 'tcx> { + fn as_mut(&mut self) -> &mut Resolver<'ra, 'tcx> { self.r } } -impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { +impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { fn res(&self, def_id: impl Into) -> Res { let def_id = def_id.into(); Res::Def(self.r.tcx.def_kind(def_id), def_id) @@ -424,7 +424,7 @@ fn block_needs_anonymous_module(&mut self, block: &Block) -> bool { fn add_import( &mut self, module_path: Vec, - kind: ImportKind<'a>, + kind: ImportKind<'ra>, span: Span, item: &ast::Item, root_span: Span, @@ -752,7 +752,7 @@ fn build_reduced_graph_for_struct_variant( } /// Constructs the reduced graph for one item. - fn build_reduced_graph_for_item(&mut self, item: &'b Item) { + fn build_reduced_graph_for_item(&mut self, item: &'a Item) { let parent_scope = &self.parent_scope; let parent = parent_scope.module; let expansion = parent_scope.expansion; @@ -918,7 +918,7 @@ fn build_reduced_graph_for_extern_crate( item: &Item, local_def_id: LocalDefId, vis: ty::Visibility, - parent: Module<'a>, + parent: Module<'ra>, ) { let ident = item.ident; let sp = item.span; @@ -1040,7 +1040,7 @@ fn build_reduced_graph_for_block(&mut self, block: &Block) { fn add_macro_use_binding( &mut self, name: Symbol, - binding: NameBinding<'a>, + binding: NameBinding<'ra>, span: Span, allow_shadowing: bool, ) { @@ -1050,7 +1050,7 @@ fn add_macro_use_binding( } /// Returns `true` if we should consider the underlying `extern crate` to be used. - fn process_macro_use_imports(&mut self, item: &Item, module: Module<'a>) -> bool { + fn process_macro_use_imports(&mut self, item: &Item, module: Module<'ra>) -> bool { let mut import_all = None; let mut single_imports = Vec::new(); for attr in &item.attrs { @@ -1188,7 +1188,7 @@ fn visit_invoc(&mut self, id: NodeId) -> LocalExpnId { /// Visit invocation in context in which it can emit a named item (possibly `macro_rules`) /// directly into its parent scope's module. - fn visit_invoc_in_module(&mut self, id: NodeId) -> MacroRulesScopeRef<'a> { + fn visit_invoc_in_module(&mut self, id: NodeId) -> MacroRulesScopeRef<'ra> { let invoc_id = self.visit_invoc(id); self.parent_scope.module.unexpanded_invocations.borrow_mut().insert(invoc_id); self.r.arenas.alloc_macro_rules_scope(MacroRulesScope::Invocation(invoc_id)) @@ -1221,7 +1221,7 @@ fn insert_unused_macro(&mut self, ident: Ident, def_id: LocalDefId, node_id: Nod } } - fn define_macro(&mut self, item: &ast::Item) -> MacroRulesScopeRef<'a> { + fn define_macro(&mut self, item: &ast::Item) -> MacroRulesScopeRef<'ra> { let parent_scope = self.parent_scope; let expansion = parent_scope.expansion; let feed = self.r.feed(item.id); @@ -1308,7 +1308,7 @@ fn define_macro(&mut self, item: &ast::Item) -> MacroRulesScopeRef<'a> { macro_rules! method { ($visit:ident: $ty:ty, $invoc:path, $walk:ident) => { - fn $visit(&mut self, node: &'b $ty) { + fn $visit(&mut self, node: &'a $ty) { if let $invoc(..) = node.kind { self.visit_invoc(node.id); } else { @@ -1318,12 +1318,12 @@ fn $visit(&mut self, node: &'b $ty) { }; } -impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> { +impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> { method!(visit_expr: ast::Expr, ast::ExprKind::MacCall, walk_expr); method!(visit_pat: ast::Pat, ast::PatKind::MacCall, walk_pat); method!(visit_ty: ast::Ty, ast::TyKind::MacCall, walk_ty); - fn visit_item(&mut self, item: &'b Item) { + fn visit_item(&mut self, item: &'a Item) { let orig_module_scope = self.parent_scope.module; self.parent_scope.macro_rules = match item.kind { ItemKind::MacroDef(..) => { @@ -1357,7 +1357,7 @@ fn visit_item(&mut self, item: &'b Item) { self.parent_scope.module = orig_module_scope; } - fn visit_stmt(&mut self, stmt: &'b ast::Stmt) { + fn visit_stmt(&mut self, stmt: &'a ast::Stmt) { if let ast::StmtKind::MacCall(..) = stmt.kind { self.parent_scope.macro_rules = self.visit_invoc_in_module(stmt.id); } else { @@ -1365,7 +1365,7 @@ fn visit_stmt(&mut self, stmt: &'b ast::Stmt) { } } - fn visit_foreign_item(&mut self, foreign_item: &'b ForeignItem) { + fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) { if let ForeignItemKind::MacCall(_) = foreign_item.kind { self.visit_invoc_in_module(foreign_item.id); return; @@ -1375,7 +1375,7 @@ fn visit_foreign_item(&mut self, foreign_item: &'b ForeignItem) { visit::walk_item(self, foreign_item); } - fn visit_block(&mut self, block: &'b Block) { + fn visit_block(&mut self, block: &'a Block) { let orig_current_module = self.parent_scope.module; let orig_current_macro_rules_scope = self.parent_scope.macro_rules; self.build_reduced_graph_for_block(block); @@ -1384,7 +1384,7 @@ fn visit_block(&mut self, block: &'b Block) { self.parent_scope.macro_rules = orig_current_macro_rules_scope; } - fn visit_assoc_item(&mut self, item: &'b AssocItem, ctxt: AssocCtxt) { + fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) { if let AssocItemKind::MacCall(_) = item.kind { match ctxt { AssocCtxt::Trait => { @@ -1440,7 +1440,7 @@ fn visit_assoc_item(&mut self, item: &'b AssocItem, ctxt: AssocCtxt) { visit::walk_assoc_item(self, item, ctxt); } - fn visit_attribute(&mut self, attr: &'b ast::Attribute) { + fn visit_attribute(&mut self, attr: &'a ast::Attribute) { if !attr.is_doc_comment() && attr::is_builtin_attr(attr) { self.r .builtin_attrs @@ -1449,7 +1449,7 @@ fn visit_attribute(&mut self, attr: &'b ast::Attribute) { visit::walk_attribute(self, attr); } - fn visit_arm(&mut self, arm: &'b ast::Arm) { + fn visit_arm(&mut self, arm: &'a ast::Arm) { if arm.is_placeholder { self.visit_invoc(arm.id); } else { @@ -1457,7 +1457,7 @@ fn visit_arm(&mut self, arm: &'b ast::Arm) { } } - fn visit_expr_field(&mut self, f: &'b ast::ExprField) { + fn visit_expr_field(&mut self, f: &'a ast::ExprField) { if f.is_placeholder { self.visit_invoc(f.id); } else { @@ -1465,7 +1465,7 @@ fn visit_expr_field(&mut self, f: &'b ast::ExprField) { } } - fn visit_pat_field(&mut self, fp: &'b ast::PatField) { + fn visit_pat_field(&mut self, fp: &'a ast::PatField) { if fp.is_placeholder { self.visit_invoc(fp.id); } else { @@ -1473,7 +1473,7 @@ fn visit_pat_field(&mut self, fp: &'b ast::PatField) { } } - fn visit_generic_param(&mut self, param: &'b ast::GenericParam) { + fn visit_generic_param(&mut self, param: &'a ast::GenericParam) { if param.is_placeholder { self.visit_invoc(param.id); } else { @@ -1481,7 +1481,7 @@ fn visit_generic_param(&mut self, param: &'b ast::GenericParam) { } } - fn visit_param(&mut self, p: &'b ast::Param) { + fn visit_param(&mut self, p: &'a ast::Param) { if p.is_placeholder { self.visit_invoc(p.id); } else { @@ -1489,7 +1489,7 @@ fn visit_param(&mut self, p: &'b ast::Param) { } } - fn visit_field_def(&mut self, sf: &'b ast::FieldDef) { + fn visit_field_def(&mut self, sf: &'a ast::FieldDef) { if sf.is_placeholder { self.visit_invoc(sf.id); } else { @@ -1501,7 +1501,7 @@ fn visit_field_def(&mut self, sf: &'b ast::FieldDef) { // Constructs the reduced graph for one variant. Variants exist in the // type and value namespaces. - fn visit_variant(&mut self, variant: &'b ast::Variant) { + fn visit_variant(&mut self, variant: &'a ast::Variant) { if variant.is_placeholder { self.visit_invoc_in_module(variant.id); return; @@ -1542,7 +1542,7 @@ fn visit_variant(&mut self, variant: &'b ast::Variant) { visit::walk_variant(self, variant); } - fn visit_crate(&mut self, krate: &'b ast::Crate) { + fn visit_crate(&mut self, krate: &'a ast::Crate) { if krate.is_placeholder { self.visit_invoc_in_module(krate.id); } else { diff --git a/compiler/rustc_resolve/src/check_unused.rs b/compiler/rustc_resolve/src/check_unused.rs index 1cee876b80f..8c434007f2c 100644 --- a/compiler/rustc_resolve/src/check_unused.rs +++ b/compiler/rustc_resolve/src/check_unused.rs @@ -52,8 +52,8 @@ fn add(&mut self, id: ast::NodeId) { } } -struct UnusedImportCheckVisitor<'a, 'b, 'tcx> { - r: &'a mut Resolver<'b, 'tcx>, +struct UnusedImportCheckVisitor<'a, 'ra, 'tcx> { + r: &'a mut Resolver<'ra, 'tcx>, /// All the (so far) unused imports, grouped path list unused_imports: FxIndexMap, extern_crate_items: Vec, @@ -78,7 +78,7 @@ struct ExternCrateToLint { renames: bool, } -impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> { +impl<'a, 'ra, 'tcx> UnusedImportCheckVisitor<'a, 'ra, 'tcx> { // We have information about whether `use` (import) items are actually // used now. If an import is not used at all, we signal a lint error. fn check_import(&mut self, id: ast::NodeId) { @@ -212,7 +212,7 @@ fn report_unused_extern_crate_items( } } -impl<'a, 'b, 'tcx> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b, 'tcx> { +impl<'a, 'ra, 'tcx> Visitor<'a> for UnusedImportCheckVisitor<'a, 'ra, 'tcx> { fn visit_item(&mut self, item: &'a ast::Item) { match item.kind { // Ignore is_public import statements because there's no way to be sure diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index 0fedb998463..87054dd04f5 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -25,15 +25,15 @@ pub(crate) fn collect_definitions( } /// Creates `DefId`s for nodes in the AST. -struct DefCollector<'a, 'b, 'tcx> { - resolver: &'a mut Resolver<'b, 'tcx>, +struct DefCollector<'a, 'ra, 'tcx> { + resolver: &'a mut Resolver<'ra, 'tcx>, parent_def: LocalDefId, impl_trait_context: ImplTraitContext, in_attr: bool, expansion: LocalExpnId, } -impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> { +impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { fn create_def( &mut self, node_id: NodeId, @@ -119,7 +119,7 @@ fn visit_macro_invoc(&mut self, id: NodeId) { } } -impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> { +impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> { fn visit_item(&mut self, i: &'a Item) { // Pick the def data. This need not be unique, but the more // information we encapsulate into, the better diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 6f4cb9b4cc6..3b69ecee357 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -123,7 +123,7 @@ fn reduce_impl_span_to_impl_keyword(sm: &SourceMap, impl_span: Span) -> Span { sm.span_until_whitespace(impl_span) } -impl<'a, 'tcx> Resolver<'a, 'tcx> { +impl<'ra, 'tcx> Resolver<'ra, 'tcx> { pub(crate) fn dcx(&self) -> DiagCtxtHandle<'tcx> { self.tcx.dcx() } @@ -208,8 +208,8 @@ pub(crate) fn report_conflict( parent: Module<'_>, ident: Ident, ns: Namespace, - new_binding: NameBinding<'a>, - old_binding: NameBinding<'a>, + new_binding: NameBinding<'ra>, + old_binding: NameBinding<'ra>, ) { // Error on the second of two conflicting names if old_binding.span.lo() > new_binding.span.lo() { @@ -531,7 +531,7 @@ pub(crate) fn lint_if_path_starts_with_module( pub(crate) fn add_module_candidates( &mut self, - module: Module<'a>, + module: Module<'ra>, names: &mut Vec, filter_fn: &impl Fn(Res) -> bool, ctxt: Option, @@ -553,7 +553,7 @@ pub(crate) fn add_module_candidates( pub(crate) fn report_error( &mut self, span: Span, - resolution_error: ResolutionError<'a>, + resolution_error: ResolutionError<'ra>, ) -> ErrorGuaranteed { self.into_struct_error(span, resolution_error).emit() } @@ -561,7 +561,7 @@ pub(crate) fn report_error( pub(crate) fn into_struct_error( &mut self, span: Span, - resolution_error: ResolutionError<'a>, + resolution_error: ResolutionError<'ra>, ) -> Diag<'_> { match resolution_error { ResolutionError::GenericParamsFromOuterItem( @@ -1020,8 +1020,8 @@ pub(crate) fn report_vis_error( /// Lookup typo candidate in scope for a macro or import. fn early_lookup_typo_candidate( &mut self, - scope_set: ScopeSet<'a>, - parent_scope: &ParentScope<'a>, + scope_set: ScopeSet<'ra>, + parent_scope: &ParentScope<'ra>, ident: Ident, filter_fn: &impl Fn(Res) -> bool, ) -> Option { @@ -1156,8 +1156,8 @@ fn lookup_import_candidates_from_module( &mut self, lookup_ident: Ident, namespace: Namespace, - parent_scope: &ParentScope<'a>, - start_module: Module<'a>, + parent_scope: &ParentScope<'ra>, + start_module: Module<'ra>, crate_path: ThinVec, filter_fn: FilterFn, ) -> Vec @@ -1342,7 +1342,7 @@ pub(crate) fn lookup_import_candidates( &mut self, lookup_ident: Ident, namespace: Namespace, - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, filter_fn: FilterFn, ) -> Vec where @@ -1420,7 +1420,7 @@ pub(crate) fn unresolved_macro_suggestions( &mut self, err: &mut Diag<'_>, macro_kind: MacroKind, - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, ident: Ident, krate: &Crate, ) { @@ -1748,7 +1748,7 @@ fn ctor_fields_span(&self, binding: NameBinding<'_>) -> Option { None } - fn report_privacy_error(&mut self, privacy_error: &PrivacyError<'a>) { + fn report_privacy_error(&mut self, privacy_error: &PrivacyError<'ra>) { let PrivacyError { ident, binding, outermost_res, parent_scope, single_nested, dedup_span } = *privacy_error; @@ -1953,7 +1953,7 @@ fn report_privacy_error(&mut self, privacy_error: &PrivacyError<'a>) { pub(crate) fn find_similarly_named_module_or_crate( &mut self, ident: Symbol, - current_module: Module<'a>, + current_module: Module<'ra>, ) -> Option { let mut candidates = self .extern_prelude @@ -1981,11 +1981,11 @@ pub(crate) fn report_path_resolution_error( &mut self, path: &[Segment], opt_ns: Option, // `None` indicates a module path in import - parent_scope: &ParentScope<'a>, - ribs: Option<&PerNS>>>, - ignore_binding: Option>, - ignore_import: Option>, - module: Option>, + parent_scope: &ParentScope<'ra>, + ribs: Option<&PerNS>>>, + ignore_binding: Option>, + ignore_import: Option>, + module: Option>, failed_segment_idx: usize, ident: Ident, ) -> (String, Option) { @@ -2227,7 +2227,7 @@ pub(crate) fn make_path_suggestion( &mut self, span: Span, mut path: Vec, - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, ) -> Option<(Vec, Option)> { debug!("make_path_suggestion: span={:?} path={:?}", span, path); @@ -2262,7 +2262,7 @@ pub(crate) fn make_path_suggestion( fn make_missing_self_suggestion( &mut self, mut path: Vec, - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, ) -> Option<(Vec, Option)> { // Replace first ident with `self` and check if that is valid. path[0].ident.name = kw::SelfLower; @@ -2281,7 +2281,7 @@ fn make_missing_self_suggestion( fn make_missing_crate_suggestion( &mut self, mut path: Vec, - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, ) -> Option<(Vec, Option)> { // Replace first ident with `crate` and check if that is valid. path[0].ident.name = kw::Crate; @@ -2312,7 +2312,7 @@ fn make_missing_crate_suggestion( fn make_missing_super_suggestion( &mut self, mut path: Vec, - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, ) -> Option<(Vec, Option)> { // Replace first ident with `crate` and check if that is valid. path[0].ident.name = kw::Super; @@ -2334,7 +2334,7 @@ fn make_missing_super_suggestion( fn make_external_crate_suggestion( &mut self, mut path: Vec, - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, ) -> Option<(Vec, Option)> { if path[1].ident.span.is_rust_2015() { return None; @@ -2377,8 +2377,8 @@ fn make_external_crate_suggestion( /// ``` pub(crate) fn check_for_module_export_macro( &mut self, - import: Import<'a>, - module: ModuleOrUniformRoot<'a>, + import: Import<'ra>, + module: ModuleOrUniformRoot<'ra>, ident: Ident, ) -> Option<(Option, Option)> { let ModuleOrUniformRoot::Module(mut crate_module) = module else { diff --git a/compiler/rustc_resolve/src/effective_visibilities.rs b/compiler/rustc_resolve/src/effective_visibilities.rs index 5ee495da2d9..c91eed0e39b 100644 --- a/compiler/rustc_resolve/src/effective_visibilities.rs +++ b/compiler/rustc_resolve/src/effective_visibilities.rs @@ -11,9 +11,9 @@ use crate::{NameBinding, NameBindingKind, Resolver}; #[derive(Clone, Copy)] -enum ParentId<'a> { +enum ParentId<'ra> { Def(LocalDefId), - Import(NameBinding<'a>), + Import(NameBinding<'ra>), } impl ParentId<'_> { @@ -25,13 +25,13 @@ fn level(self) -> Level { } } -pub(crate) struct EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> { - r: &'r mut Resolver<'a, 'tcx>, +pub(crate) struct EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> { + r: &'a mut Resolver<'ra, 'tcx>, def_effective_visibilities: EffectiveVisibilities, /// While walking import chains we need to track effective visibilities per-binding, and def id /// keys in `Resolver::effective_visibilities` are not enough for that, because multiple /// bindings can correspond to a single def id in imports. So we keep a separate table. - import_effective_visibilities: EffectiveVisibilities>, + import_effective_visibilities: EffectiveVisibilities>, // It's possible to recalculate this at any point, but it's relatively expensive. current_private_vis: Visibility, changed: bool, @@ -63,14 +63,14 @@ fn private_vis_def(&mut self, def_id: LocalDefId) -> Visibility { } } -impl<'r, 'a, 'tcx> EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> { +impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> { /// Fills the `Resolver::effective_visibilities` table with public & exported items /// For now, this doesn't resolve macros (FIXME) and cannot resolve Impl, as we /// need access to a TyCtxt for that. Returns the set of ambiguous re-exports. pub(crate) fn compute_effective_visibilities<'c>( - r: &'r mut Resolver<'a, 'tcx>, + r: &'a mut Resolver<'ra, 'tcx>, krate: &'c Crate, - ) -> FxHashSet> { + ) -> FxHashSet> { let mut visitor = EffectiveVisibilitiesVisitor { r, def_effective_visibilities: Default::default(), @@ -127,7 +127,7 @@ fn set_bindings_effective_visibilities(&mut self, module_id: LocalDefId) { // leading to it into the table. They are used by the `ambiguous_glob_reexports` // lint. For all bindings added to the table this way `is_ambiguity` returns true. let is_ambiguity = - |binding: NameBinding<'a>, warn: bool| binding.ambiguity.is_some() && !warn; + |binding: NameBinding<'ra>, warn: bool| binding.ambiguity.is_some() && !warn; let mut parent_id = ParentId::Def(module_id); let mut warn_ambiguity = binding.warn_ambiguity; while let NameBindingKind::Import { binding: nested_binding, .. } = binding.kind { @@ -153,7 +153,7 @@ fn set_bindings_effective_visibilities(&mut self, module_id: LocalDefId) { } } - fn effective_vis_or_private(&mut self, parent_id: ParentId<'a>) -> EffectiveVisibility { + fn effective_vis_or_private(&mut self, parent_id: ParentId<'ra>) -> EffectiveVisibility { // Private nodes are only added to the table for caching, they could be added or removed at // any moment without consequences, so we don't set `changed` to true when adding them. *match parent_id { @@ -190,7 +190,7 @@ fn may_update( } } - fn update_import(&mut self, binding: NameBinding<'a>, parent_id: ParentId<'a>) { + fn update_import(&mut self, binding: NameBinding<'ra>, parent_id: ParentId<'ra>) { let nominal_vis = binding.vis.expect_local(); let Some(cheap_private_vis) = self.may_update(nominal_vis, parent_id) else { return }; let inherited_eff_vis = self.effective_vis_or_private(parent_id); @@ -205,7 +205,12 @@ fn update_import(&mut self, binding: NameBinding<'a>, parent_id: ParentId<'a>) { ); } - fn update_def(&mut self, def_id: LocalDefId, nominal_vis: Visibility, parent_id: ParentId<'a>) { + fn update_def( + &mut self, + def_id: LocalDefId, + nominal_vis: Visibility, + parent_id: ParentId<'ra>, + ) { let Some(cheap_private_vis) = self.may_update(nominal_vis, parent_id) else { return }; let inherited_eff_vis = self.effective_vis_or_private(parent_id); let tcx = self.r.tcx; @@ -224,8 +229,8 @@ fn update_field(&mut self, def_id: LocalDefId, parent_id: LocalDefId) { } } -impl<'r, 'ast, 'tcx> Visitor<'ast> for EffectiveVisibilitiesVisitor<'ast, 'r, 'tcx> { - fn visit_item(&mut self, item: &'ast ast::Item) { +impl<'a, 'ra, 'tcx> Visitor<'a> for EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> { + fn visit_item(&mut self, item: &'a ast::Item) { let def_id = self.r.local_def_id(item.id); // Update effective visibilities of nested items. // If it's a mod, also make the visitor walk all of its items diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 7f2bf03bcd1..61df051ec1e 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -38,16 +38,16 @@ fn from(up: UsePrelude) -> bool { } } -impl<'a, 'tcx> Resolver<'a, 'tcx> { +impl<'ra, 'tcx> Resolver<'ra, 'tcx> { /// A generic scope visitor. /// Visits scopes in order to resolve some identifier in them or perform other actions. /// If the callback returns `Some` result, we stop visiting scopes and return it. pub(crate) fn visit_scopes( &mut self, - scope_set: ScopeSet<'a>, - parent_scope: &ParentScope<'a>, + scope_set: ScopeSet<'ra>, + parent_scope: &ParentScope<'ra>, ctxt: SyntaxContext, - mut visitor: impl FnMut(&mut Self, Scope<'a>, UsePrelude, SyntaxContext) -> Option, + mut visitor: impl FnMut(&mut Self, Scope<'ra>, UsePrelude, SyntaxContext) -> Option, ) -> Option { // General principles: // 1. Not controlled (user-defined) names should have higher priority than controlled names @@ -218,10 +218,10 @@ pub(crate) fn visit_scopes( fn hygienic_lexical_parent( &mut self, - module: Module<'a>, + module: Module<'ra>, ctxt: &mut SyntaxContext, derive_fallback_lint_id: Option, - ) -> Option<(Module<'a>, Option)> { + ) -> Option<(Module<'ra>, Option)> { if !module.expansion.outer_expn_is_descendant_of(*ctxt) { return Some((self.expn_def_scope(ctxt.remove_mark()), None)); } @@ -286,11 +286,11 @@ pub(crate) fn resolve_ident_in_lexical_scope( &mut self, mut ident: Ident, ns: Namespace, - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, finalize: Option, - ribs: &[Rib<'a>], - ignore_binding: Option>, - ) -> Option> { + ribs: &[Rib<'ra>], + ignore_binding: Option>, + ) -> Option> { assert!(ns == TypeNS || ns == ValueNS); let orig_ident = ident; if ident.name == kw::Empty { @@ -381,13 +381,13 @@ pub(crate) fn resolve_ident_in_lexical_scope( pub(crate) fn early_resolve_ident_in_lexical_scope( &mut self, orig_ident: Ident, - scope_set: ScopeSet<'a>, - parent_scope: &ParentScope<'a>, + scope_set: ScopeSet<'ra>, + parent_scope: &ParentScope<'ra>, finalize: Option, force: bool, - ignore_binding: Option>, - ignore_import: Option>, - ) -> Result, Determinacy> { + ignore_binding: Option>, + ignore_import: Option>, + ) -> Result, Determinacy> { bitflags::bitflags! { #[derive(Clone, Copy)] struct Flags: u8 { @@ -742,12 +742,12 @@ struct Flags: u8 { #[instrument(level = "debug", skip(self))] pub(crate) fn maybe_resolve_ident_in_module( &mut self, - module: ModuleOrUniformRoot<'a>, + module: ModuleOrUniformRoot<'ra>, ident: Ident, ns: Namespace, - parent_scope: &ParentScope<'a>, - ignore_import: Option>, - ) -> Result, Determinacy> { + parent_scope: &ParentScope<'ra>, + ignore_import: Option>, + ) -> Result, Determinacy> { self.resolve_ident_in_module_ext(module, ident, ns, parent_scope, None, None, ignore_import) .map_err(|(determinacy, _)| determinacy) } @@ -755,14 +755,14 @@ pub(crate) fn maybe_resolve_ident_in_module( #[instrument(level = "debug", skip(self))] pub(crate) fn resolve_ident_in_module( &mut self, - module: ModuleOrUniformRoot<'a>, + module: ModuleOrUniformRoot<'ra>, ident: Ident, ns: Namespace, - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, finalize: Option, - ignore_binding: Option>, - ignore_import: Option>, - ) -> Result, Determinacy> { + ignore_binding: Option>, + ignore_import: Option>, + ) -> Result, Determinacy> { self.resolve_ident_in_module_ext( module, ident, @@ -778,14 +778,14 @@ pub(crate) fn resolve_ident_in_module( #[instrument(level = "debug", skip(self))] fn resolve_ident_in_module_ext( &mut self, - module: ModuleOrUniformRoot<'a>, + module: ModuleOrUniformRoot<'ra>, mut ident: Ident, ns: Namespace, - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, finalize: Option, - ignore_binding: Option>, - ignore_import: Option>, - ) -> Result, (Determinacy, Weak)> { + ignore_binding: Option>, + ignore_import: Option>, + ) -> Result, (Determinacy, Weak)> { let tmp_parent_scope; let mut adjusted_parent_scope = parent_scope; match module { @@ -818,14 +818,14 @@ fn resolve_ident_in_module_ext( #[instrument(level = "debug", skip(self))] fn resolve_ident_in_module_unadjusted( &mut self, - module: ModuleOrUniformRoot<'a>, + module: ModuleOrUniformRoot<'ra>, ident: Ident, ns: Namespace, - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, finalize: Option, - ignore_binding: Option>, - ignore_import: Option>, - ) -> Result, Determinacy> { + ignore_binding: Option>, + ignore_import: Option>, + ) -> Result, Determinacy> { self.resolve_ident_in_module_unadjusted_ext( module, ident, @@ -844,17 +844,17 @@ fn resolve_ident_in_module_unadjusted( #[instrument(level = "debug", skip(self))] fn resolve_ident_in_module_unadjusted_ext( &mut self, - module: ModuleOrUniformRoot<'a>, + module: ModuleOrUniformRoot<'ra>, ident: Ident, ns: Namespace, - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, restricted_shadowing: bool, finalize: Option, // This binding should be ignored during in-module resolution, so that we don't get // "self-confirming" import resolutions during import validation and checking. - ignore_binding: Option>, - ignore_import: Option>, - ) -> Result, (Determinacy, Weak)> { + ignore_binding: Option>, + ignore_import: Option>, + ) -> Result, (Determinacy, Weak)> { let module = match module { ModuleOrUniformRoot::Module(module) => module, ModuleOrUniformRoot::CrateRootAndExternPrelude => { @@ -970,7 +970,7 @@ fn resolve_ident_in_module_unadjusted_ext( return Ok(binding); } - let check_usable = |this: &mut Self, binding: NameBinding<'a>| { + let check_usable = |this: &mut Self, binding: NameBinding<'ra>| { let usable = this.is_accessible_from(binding.vis, parent_scope.module); if usable { Ok(binding) } else { Err((Determined, Weak::No)) } }; @@ -1151,7 +1151,7 @@ fn validate_res_from_ribs( mut res: Res, finalize: Option, original_rib_ident_def: Ident, - all_ribs: &[Rib<'a>], + all_ribs: &[Rib<'ra>], ) -> Res { debug!("validate_res_from_ribs({:?})", res); let ribs = &all_ribs[rib_index + 1..]; @@ -1436,9 +1436,9 @@ pub(crate) fn maybe_resolve_path( &mut self, path: &[Segment], opt_ns: Option, // `None` indicates a module path in import - parent_scope: &ParentScope<'a>, - ignore_import: Option>, - ) -> PathResult<'a> { + parent_scope: &ParentScope<'ra>, + ignore_import: Option>, + ) -> PathResult<'ra> { self.resolve_path_with_ribs(path, opt_ns, parent_scope, None, None, None, ignore_import) } @@ -1447,11 +1447,11 @@ pub(crate) fn resolve_path( &mut self, path: &[Segment], opt_ns: Option, // `None` indicates a module path in import - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, finalize: Option, - ignore_binding: Option>, - ignore_import: Option>, - ) -> PathResult<'a> { + ignore_binding: Option>, + ignore_import: Option>, + ) -> PathResult<'ra> { self.resolve_path_with_ribs( path, opt_ns, @@ -1467,12 +1467,12 @@ pub(crate) fn resolve_path_with_ribs( &mut self, path: &[Segment], opt_ns: Option, // `None` indicates a module path in import - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, finalize: Option, - ribs: Option<&PerNS>>>, - ignore_binding: Option>, - ignore_import: Option>, - ) -> PathResult<'a> { + ribs: Option<&PerNS>>>, + ignore_binding: Option>, + ignore_import: Option>, + ) -> PathResult<'ra> { let mut module = None; let mut allow_super = true; let mut second_binding = None; diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 1c8ccd2321f..67ee377fd54 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -43,7 +43,7 @@ /// Contains data for specific kinds of imports. #[derive(Clone)] -pub(crate) enum ImportKind<'a> { +pub(crate) enum ImportKind<'ra> { Single { /// `source` in `use prefix::source as target`. source: Ident, @@ -51,9 +51,9 @@ pub(crate) enum ImportKind<'a> { /// It will directly use `source` when the format is `use prefix::source`. target: Ident, /// Bindings to which `source` refers to. - source_bindings: PerNS, Determinacy>>>, + source_bindings: PerNS, Determinacy>>>, /// Bindings introduced by `target`. - target_bindings: PerNS>>>, + target_bindings: PerNS>>>, /// `true` for `...::{self [as target]}` imports, `false` otherwise. type_ns_only: bool, /// Did this import result from a nested import? ie. `use foo::{bar, baz};` @@ -93,7 +93,7 @@ pub(crate) enum ImportKind<'a> { /// Manually implement `Debug` for `ImportKind` because the `source/target_bindings` /// contain `Cell`s which can introduce infinite loops while printing. -impl<'a> std::fmt::Debug for ImportKind<'a> { +impl<'ra> std::fmt::Debug for ImportKind<'ra> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { use ImportKind::*; match self { @@ -142,8 +142,8 @@ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { /// One import. #[derive(Debug, Clone)] -pub(crate) struct ImportData<'a> { - pub kind: ImportKind<'a>, +pub(crate) struct ImportData<'ra> { + pub kind: ImportKind<'ra>, /// Node ID of the "root" use item -- this is always the same as `ImportKind`'s `id` /// (if it exists) except in the case of "nested" use trees, in which case @@ -171,18 +171,18 @@ pub(crate) struct ImportData<'a> { /// Span of the *root* use tree (see `root_id`). pub root_span: Span, - pub parent_scope: ParentScope<'a>, + pub parent_scope: ParentScope<'ra>, pub module_path: Vec, /// The resolution of `module_path`. - pub imported_module: Cell>>, + pub imported_module: Cell>>, pub vis: ty::Visibility, } /// All imports are unique and allocated on a same arena, /// so we can use referential equality to compare them. -pub(crate) type Import<'a> = Interned<'a, ImportData<'a>>; +pub(crate) type Import<'ra> = Interned<'ra, ImportData<'ra>>; -impl<'a> ImportData<'a> { +impl<'ra> ImportData<'ra> { pub(crate) fn is_glob(&self) -> bool { matches!(self.kind, ImportKind::Glob { .. }) } @@ -217,18 +217,18 @@ fn simplify(&self, r: &Resolver<'_, '_>) -> Reexport { /// Records information about the resolution of a name in a namespace of a module. #[derive(Clone, Default, Debug)] -pub(crate) struct NameResolution<'a> { +pub(crate) struct NameResolution<'ra> { /// Single imports that may define the name in the namespace. /// Imports are arena-allocated, so it's ok to use pointers as keys. - pub single_imports: FxHashSet>, + pub single_imports: FxHashSet>, /// The least shadowable known binding for this name, or None if there are no known bindings. - pub binding: Option>, - pub shadowed_glob: Option>, + pub binding: Option>, + pub shadowed_glob: Option>, } -impl<'a> NameResolution<'a> { +impl<'ra> NameResolution<'ra> { /// Returns the binding for the name if it is known or None if it not known. - pub(crate) fn binding(&self) -> Option> { + pub(crate) fn binding(&self) -> Option> { self.binding.and_then(|binding| { if !binding.is_glob_import() || self.single_imports.is_empty() { Some(binding) @@ -270,10 +270,14 @@ fn pub_use_of_private_extern_crate_hack( } } -impl<'a, 'tcx> Resolver<'a, 'tcx> { +impl<'ra, 'tcx> Resolver<'ra, 'tcx> { /// Given a binding and an import that resolves to it, /// return the corresponding binding defined by the import. - pub(crate) fn import(&self, binding: NameBinding<'a>, import: Import<'a>) -> NameBinding<'a> { + pub(crate) fn import( + &self, + binding: NameBinding<'ra>, + import: Import<'ra>, + ) -> NameBinding<'ra> { let import_vis = import.vis.to_def_id(); let vis = if binding.vis.is_at_least(import_vis, self.tcx) || pub_use_of_private_extern_crate_hack(import, binding).is_some() @@ -305,11 +309,11 @@ pub(crate) fn import(&self, binding: NameBinding<'a>, import: Import<'a>) -> Nam /// `update` indicates if the definition is a redefinition of an existing binding. pub(crate) fn try_define( &mut self, - module: Module<'a>, + module: Module<'ra>, key: BindingKey, - binding: NameBinding<'a>, + binding: NameBinding<'ra>, warn_ambiguity: bool, - ) -> Result<(), NameBinding<'a>> { + ) -> Result<(), NameBinding<'ra>> { let res = binding.res(); self.check_reserved_macro_name(key.ident, res); self.set_binding_parent_module(binding, module); @@ -394,16 +398,16 @@ pub(crate) fn try_define( fn new_ambiguity_binding( &self, ambiguity_kind: AmbiguityKind, - primary_binding: NameBinding<'a>, - secondary_binding: NameBinding<'a>, + primary_binding: NameBinding<'ra>, + secondary_binding: NameBinding<'ra>, warn_ambiguity: bool, - ) -> NameBinding<'a> { + ) -> NameBinding<'ra> { let ambiguity = Some((secondary_binding, ambiguity_kind)); let data = NameBindingData { ambiguity, warn_ambiguity, ..*primary_binding }; self.arenas.alloc_name_binding(data) } - fn new_warn_ambiguity_binding(&self, binding: NameBinding<'a>) -> NameBinding<'a> { + fn new_warn_ambiguity_binding(&self, binding: NameBinding<'ra>) -> NameBinding<'ra> { assert!(binding.is_ambiguity_recursive()); self.arenas.alloc_name_binding(NameBindingData { warn_ambiguity: true, ..*binding }) } @@ -412,13 +416,13 @@ fn new_warn_ambiguity_binding(&self, binding: NameBinding<'a>) -> NameBinding<'a // If the resolution becomes a success, define it in the module's glob importers. fn update_resolution( &mut self, - module: Module<'a>, + module: Module<'ra>, key: BindingKey, warn_ambiguity: bool, f: F, ) -> T where - F: FnOnce(&mut Resolver<'a, 'tcx>, &mut NameResolution<'a>) -> T, + F: FnOnce(&mut Resolver<'ra, 'tcx>, &mut NameResolution<'ra>) -> T, { // Ensure that `resolution` isn't borrowed when defining in the module's glob importers, // during which the resolution might end up getting re-defined via a glob cycle. @@ -466,7 +470,7 @@ fn update_resolution( // Define a dummy resolution containing a `Res::Err` as a placeholder for a failed // or indeterminate resolution, also mark such failed imports as used to avoid duplicate diagnostics. - fn import_dummy_binding(&mut self, import: Import<'a>, is_indeterminate: bool) { + fn import_dummy_binding(&mut self, import: Import<'ra>, is_indeterminate: bool) { if let ImportKind::Single { target, ref target_bindings, .. } = import.kind { if !(is_indeterminate || target_bindings.iter().all(|binding| binding.get().is_none())) { @@ -599,7 +603,7 @@ pub(crate) fn finalize_imports(&mut self) { pub(crate) fn check_hidden_glob_reexports( &mut self, - exported_ambiguities: FxHashSet>, + exported_ambiguities: FxHashSet>, ) { for module in self.arenas.local_modules().iter() { for (key, resolution) in self.resolutions(*module).borrow().iter() { @@ -759,7 +763,7 @@ fn throw_unresolved_import_error( /// /// Meanwhile, if resolve successful, the resolved bindings are written /// into the module. - fn resolve_import(&mut self, import: Import<'a>) -> usize { + fn resolve_import(&mut self, import: Import<'ra>) -> usize { debug!( "(resolving import for module) resolving import `{}::...` in `{}`", Segment::names_to_string(&import.module_path), @@ -847,7 +851,7 @@ fn resolve_import(&mut self, import: Import<'a>) -> usize { /// /// Optionally returns an unresolved import error. This error is buffered and used to /// consolidate multiple unresolved import errors into a single diagnostic. - fn finalize_import(&mut self, import: Import<'a>) -> Option { + fn finalize_import(&mut self, import: Import<'ra>) -> Option { let ignore_binding = match &import.kind { ImportKind::Single { target_bindings, .. } => target_bindings[TypeNS].get(), _ => None, @@ -1317,7 +1321,7 @@ fn finalize_import(&mut self, import: Import<'a>) -> Option) -> bool { + pub(crate) fn check_for_redundant_imports(&mut self, import: Import<'ra>) -> bool { // This function is only called for single imports. let ImportKind::Single { source, target, ref source_bindings, ref target_bindings, id, .. @@ -1392,7 +1396,7 @@ pub(crate) fn check_for_redundant_imports(&mut self, import: Import<'a>) -> bool false } - fn resolve_glob_import(&mut self, import: Import<'a>) { + fn resolve_glob_import(&mut self, import: Import<'ra>) { // This function is only called for glob imports. let ImportKind::Glob { id, is_prelude, .. } = import.kind else { unreachable!() }; @@ -1452,7 +1456,7 @@ fn resolve_glob_import(&mut self, import: Import<'a>) { // Miscellaneous post-processing, including recording re-exports, // reporting conflicts, and reporting unresolved imports. - fn finalize_resolutions_in(&mut self, module: Module<'a>) { + fn finalize_resolutions_in(&mut self, module: Module<'ra>) { // Since import resolution is finished, globs will not define any more names. *module.globs.borrow_mut() = Vec::new(); diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 11dd98a331f..0aa351cad40 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -172,7 +172,7 @@ enum RecordPartialRes { /// The rib kind restricts certain accesses, /// e.g. to a `Res::Local` of an outer item. #[derive(Copy, Clone, Debug)] -pub(crate) enum RibKind<'a> { +pub(crate) enum RibKind<'ra> { /// No restriction needs to be applied. Normal, @@ -195,7 +195,7 @@ pub(crate) enum RibKind<'a> { ConstantItem(ConstantHasGenerics, Option<(Ident, ConstantItemKind)>), /// We passed through a module. - Module(Module<'a>), + Module(Module<'ra>), /// We passed through a `macro_rules!` statement MacroDefinition(DefId), @@ -260,13 +260,13 @@ fn is_label_barrier(self) -> bool { /// The resolution keeps a separate stack of ribs as it traverses the AST for each namespace. When /// resolving, the name is looked up from inside out. #[derive(Debug)] -pub(crate) struct Rib<'a, R = Res> { +pub(crate) struct Rib<'ra, R = Res> { pub bindings: IdentMap, - pub kind: RibKind<'a>, + pub kind: RibKind<'ra>, } -impl<'a, R> Rib<'a, R> { - fn new(kind: RibKind<'a>) -> Rib<'a, R> { +impl<'ra, R> Rib<'ra, R> { + fn new(kind: RibKind<'ra>) -> Rib<'ra, R> { Rib { bindings: Default::default(), kind } } } @@ -584,8 +584,8 @@ fn eval(self, r: &Resolver<'_, '_>) -> bool { /// Used for recording UnnecessaryQualification. #[derive(Debug)] -pub(crate) struct UnnecessaryQualification<'a> { - pub binding: LexicalScopeBinding<'a>, +pub(crate) struct UnnecessaryQualification<'ra> { + pub binding: LexicalScopeBinding<'ra>, pub node_id: NodeId, pub path_span: Span, pub removal_span: Span, @@ -659,20 +659,20 @@ struct DiagMetadata<'ast> { current_elision_failures: Vec, } -struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { - r: &'b mut Resolver<'a, 'tcx>, +struct LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { + r: &'a mut Resolver<'ra, 'tcx>, /// The module that represents the current item scope. - parent_scope: ParentScope<'a>, + parent_scope: ParentScope<'ra>, /// The current set of local scopes for types and values. - ribs: PerNS>>, + ribs: PerNS>>, /// Previous popped `rib`, only used for diagnostic. - last_block_rib: Option>, + last_block_rib: Option>, /// The current set of local scopes, for labels. - label_ribs: Vec>, + label_ribs: Vec>, /// The current set of local scopes for lifetimes. lifetime_ribs: Vec, @@ -685,7 +685,7 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { lifetime_elision_candidates: Option>, /// The trait that the current context can refer to. - current_trait_ref: Option<(Module<'a>, TraitRef)>, + current_trait_ref: Option<(Module<'ra>, TraitRef)>, /// Fields used to add information to diagnostic errors. diag_metadata: Box>, @@ -702,7 +702,7 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { } /// Walks the whole crate in DFS order, visiting each item, resolving names as it goes. -impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, 'tcx> { +impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn visit_attribute(&mut self, _: &'ast Attribute) { // We do not want to resolve expressions that appear in attributes, // as they do not correspond to actual code. @@ -1316,8 +1316,8 @@ fn visit_field_def(&mut self, f: &'ast FieldDef) { } } -impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { - fn new(resolver: &'b mut Resolver<'a, 'tcx>) -> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { +impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { + fn new(resolver: &'a mut Resolver<'ra, 'tcx>) -> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { // During late resolution we only track the module component of the parent scope, // although it may be useful to track other components as well for diagnostics. let graph_root = resolver.graph_root; @@ -1347,7 +1347,7 @@ fn maybe_resolve_ident_in_lexical_scope( &mut self, ident: Ident, ns: Namespace, - ) -> Option> { + ) -> Option> { self.r.resolve_ident_in_lexical_scope( ident, ns, @@ -1363,8 +1363,8 @@ fn resolve_ident_in_lexical_scope( ident: Ident, ns: Namespace, finalize: Option, - ignore_binding: Option>, - ) -> Option> { + ignore_binding: Option>, + ) -> Option> { self.r.resolve_ident_in_lexical_scope( ident, ns, @@ -1380,7 +1380,7 @@ fn resolve_path( path: &[Segment], opt_ns: Option, // `None` indicates a module path in import finalize: Option, - ) -> PathResult<'a> { + ) -> PathResult<'ra> { self.r.resolve_path_with_ribs( path, opt_ns, @@ -1414,7 +1414,7 @@ fn resolve_path( fn with_rib( &mut self, ns: Namespace, - kind: RibKind<'a>, + kind: RibKind<'ra>, work: impl FnOnce(&mut Self) -> T, ) -> T { self.ribs[ns].push(Rib::new(kind)); @@ -2266,14 +2266,14 @@ fn find_lifetime_for_self(&self, ty: &'ast Ty) -> Set1 { /// Visits a type to find all the &references, and determines the /// set of lifetimes for all of those references where the referent /// contains Self. - struct FindReferenceVisitor<'r, 'a, 'tcx> { - r: &'r Resolver<'a, 'tcx>, + struct FindReferenceVisitor<'a, 'ra, 'tcx> { + r: &'a Resolver<'ra, 'tcx>, impl_self: Option, lifetime: Set1, } - impl<'a> Visitor<'a> for FindReferenceVisitor<'_, '_, '_> { - fn visit_ty(&mut self, ty: &'a Ty) { + impl<'ra> Visitor<'ra> for FindReferenceVisitor<'_, '_, '_> { + fn visit_ty(&mut self, ty: &'ra Ty) { trace!("FindReferenceVisitor considering ty={:?}", ty); if let TyKind::Ref(lt, _) = ty.kind { // See if anything inside the &thing contains Self @@ -2299,13 +2299,13 @@ fn visit_ty(&mut self, ty: &'a Ty) { // A type may have an expression as a const generic argument. // We do not want to recurse into those. - fn visit_expr(&mut self, _: &'a Expr) {} + fn visit_expr(&mut self, _: &'ra Expr) {} } /// Visitor which checks the referent of a &Thing to see if the /// Thing contains Self - struct SelfVisitor<'r, 'a, 'tcx> { - r: &'r Resolver<'a, 'tcx>, + struct SelfVisitor<'a, 'ra, 'tcx> { + r: &'a Resolver<'ra, 'tcx>, impl_self: Option, self_found: bool, } @@ -2327,8 +2327,8 @@ fn is_self_ty(&self, ty: &Ty) -> bool { } } - impl<'a> Visitor<'a> for SelfVisitor<'_, '_, '_> { - fn visit_ty(&mut self, ty: &'a Ty) { + impl<'ra> Visitor<'ra> for SelfVisitor<'_, '_, '_> { + fn visit_ty(&mut self, ty: &'ra Ty) { trace!("SelfVisitor considering ty={:?}", ty); if self.is_self_ty(ty) { trace!("SelfVisitor found Self"); @@ -2339,7 +2339,7 @@ fn visit_ty(&mut self, ty: &'a Ty) { // A type may have an expression as a const generic argument. // We do not want to recurse into those. - fn visit_expr(&mut self, _: &'a Expr) {} + fn visit_expr(&mut self, _: &'ra Expr) {} } let impl_self = self @@ -2371,7 +2371,7 @@ fn visit_expr(&mut self, _: &'a Expr) {} /// Searches the current set of local scopes for labels. Returns the `NodeId` of the resolved /// label and reports an error if the label is not found or is unreachable. - fn resolve_label(&mut self, mut label: Ident) -> Result<(NodeId, Span), ResolutionError<'a>> { + fn resolve_label(&mut self, mut label: Ident) -> Result<(NodeId, Span), ResolutionError<'ra>> { let mut suggestion = None; for i in (0..self.label_ribs.len()).rev() { @@ -2712,7 +2712,7 @@ fn resolve_item(&mut self, item: &'ast Item) { fn with_generic_param_rib<'c, F>( &'c mut self, params: &'c [GenericParam], - kind: RibKind<'a>, + kind: RibKind<'ra>, lifetime_kind: LifetimeRibKind, f: F, ) where @@ -2878,7 +2878,7 @@ fn with_generic_param_rib<'c, F>( } } - fn with_label_rib(&mut self, kind: RibKind<'a>, f: impl FnOnce(&mut Self)) { + fn with_label_rib(&mut self, kind: RibKind<'ra>, f: impl FnOnce(&mut Self)) { self.label_ribs.push(Rib::new(kind)); f(self); self.label_ribs.pop(); @@ -3306,7 +3306,7 @@ fn check_trait_item( seen_trait_items: &mut FxHashMap, err: F, ) where - F: FnOnce(Ident, String, Option) -> ResolutionError<'a>, + F: FnOnce(Ident, String, Option) -> ResolutionError<'ra>, { // If there is a TraitRef in scope for an impl, then the method must be in the trait. let Some((module, _)) = self.current_trait_ref else { @@ -4010,101 +4010,102 @@ fn smart_resolve_path_fragment( // about possible missing imports. // // Similar thing, for types, happens in `report_errors` above. - let report_errors_for_call = |this: &mut Self, parent_err: Spanned>| { - // Before we start looking for candidates, we have to get our hands - // on the type user is trying to perform invocation on; basically: - // we're transforming `HashMap::new` into just `HashMap`. - let (following_seg, prefix_path) = match path.split_last() { - Some((last, path)) if !path.is_empty() => (Some(last), path), - _ => return Some(parent_err), - }; - - let (mut err, candidates) = this.smart_resolve_report_errors( - prefix_path, - following_seg, - path_span, - PathSource::Type, - None, - ); - - // There are two different error messages user might receive at - // this point: - // - E0412 cannot find type `{}` in this scope - // - E0433 failed to resolve: use of undeclared type or module `{}` - // - // The first one is emitted for paths in type-position, and the - // latter one - for paths in expression-position. - // - // Thus (since we're in expression-position at this point), not to - // confuse the user, we want to keep the *message* from E0433 (so - // `parent_err`), but we want *hints* from E0412 (so `err`). - // - // And that's what happens below - we're just mixing both messages - // into a single one. - let mut parent_err = this.r.into_struct_error(parent_err.span, parent_err.node); - - // overwrite all properties with the parent's error message - err.messages = take(&mut parent_err.messages); - err.code = take(&mut parent_err.code); - swap(&mut err.span, &mut parent_err.span); - err.children = take(&mut parent_err.children); - err.sort_span = parent_err.sort_span; - err.is_lint = parent_err.is_lint.clone(); - - // merge the parent's suggestions with the typo suggestions - fn append_result(res1: &mut Result, E>, res2: Result, E>) { - match res1 { - Ok(vec1) => match res2 { - Ok(mut vec2) => vec1.append(&mut vec2), - Err(e) => *res1 = Err(e), - }, - Err(_) => (), + let report_errors_for_call = + |this: &mut Self, parent_err: Spanned>| { + // Before we start looking for candidates, we have to get our hands + // on the type user is trying to perform invocation on; basically: + // we're transforming `HashMap::new` into just `HashMap`. + let (following_seg, prefix_path) = match path.split_last() { + Some((last, path)) if !path.is_empty() => (Some(last), path), + _ => return Some(parent_err), }; - } - append_result(&mut err.suggestions, parent_err.suggestions.clone()); - parent_err.cancel(); + let (mut err, candidates) = this.smart_resolve_report_errors( + prefix_path, + following_seg, + path_span, + PathSource::Type, + None, + ); - let def_id = this.parent_scope.module.nearest_parent_mod(); + // There are two different error messages user might receive at + // this point: + // - E0412 cannot find type `{}` in this scope + // - E0433 failed to resolve: use of undeclared type or module `{}` + // + // The first one is emitted for paths in type-position, and the + // latter one - for paths in expression-position. + // + // Thus (since we're in expression-position at this point), not to + // confuse the user, we want to keep the *message* from E0433 (so + // `parent_err`), but we want *hints* from E0412 (so `err`). + // + // And that's what happens below - we're just mixing both messages + // into a single one. + let mut parent_err = this.r.into_struct_error(parent_err.span, parent_err.node); - if this.should_report_errs() { - if candidates.is_empty() { - if path.len() == 2 - && let [segment] = prefix_path - { - // Delay to check whether methond name is an associated function or not - // ``` - // let foo = Foo {}; - // foo::bar(); // possibly suggest to foo.bar(); - //``` - err.stash(segment.ident.span, rustc_errors::StashKey::CallAssocMethod); + // overwrite all properties with the parent's error message + err.messages = take(&mut parent_err.messages); + err.code = take(&mut parent_err.code); + swap(&mut err.span, &mut parent_err.span); + err.children = take(&mut parent_err.children); + err.sort_span = parent_err.sort_span; + err.is_lint = parent_err.is_lint.clone(); + + // merge the parent's suggestions with the typo suggestions + fn append_result(res1: &mut Result, E>, res2: Result, E>) { + match res1 { + Ok(vec1) => match res2 { + Ok(mut vec2) => vec1.append(&mut vec2), + Err(e) => *res1 = Err(e), + }, + Err(_) => (), + }; + } + append_result(&mut err.suggestions, parent_err.suggestions.clone()); + + parent_err.cancel(); + + let def_id = this.parent_scope.module.nearest_parent_mod(); + + if this.should_report_errs() { + if candidates.is_empty() { + if path.len() == 2 + && let [segment] = prefix_path + { + // Delay to check whether methond name is an associated function or not + // ``` + // let foo = Foo {}; + // foo::bar(); // possibly suggest to foo.bar(); + //``` + err.stash(segment.ident.span, rustc_errors::StashKey::CallAssocMethod); + } else { + // When there is no suggested imports, we can just emit the error + // and suggestions immediately. Note that we bypass the usually error + // reporting routine (ie via `self.r.report_error`) because we need + // to post-process the `ResolutionError` above. + err.emit(); + } } else { - // When there is no suggested imports, we can just emit the error - // and suggestions immediately. Note that we bypass the usually error - // reporting routine (ie via `self.r.report_error`) because we need - // to post-process the `ResolutionError` above. - err.emit(); + // If there are suggested imports, the error reporting is delayed + this.r.use_injections.push(UseError { + err, + candidates, + def_id, + instead: false, + suggestion: None, + path: prefix_path.into(), + is_call: source.is_call(), + }); } } else { - // If there are suggested imports, the error reporting is delayed - this.r.use_injections.push(UseError { - err, - candidates, - def_id, - instead: false, - suggestion: None, - path: prefix_path.into(), - is_call: source.is_call(), - }); + err.cancel(); } - } else { - err.cancel(); - } - // We don't return `Some(parent_err)` here, because the error will - // be already printed either immediately or as part of the `use` injections - None - }; + // We don't return `Some(parent_err)` here, because the error will + // be already printed either immediately or as part of the `use` injections + None + }; let partial_res = match self.resolve_qpath_anywhere( qself, @@ -4205,7 +4206,7 @@ fn self_value_is_available(&mut self, self_span: Span) -> bool { /// A wrapper around [`Resolver::report_error`]. /// /// This doesn't emit errors for function bodies if this is rustdoc. - fn report_error(&mut self, span: Span, resolution_error: ResolutionError<'a>) { + fn report_error(&mut self, span: Span, resolution_error: ResolutionError<'ra>) { if self.should_report_errs() { self.r.report_error(span, resolution_error); } @@ -4229,7 +4230,7 @@ fn resolve_qpath_anywhere( span: Span, defer_to_typeck: bool, finalize: Finalize, - ) -> Result, Spanned>> { + ) -> Result, Spanned>> { let mut fin_res = None; for (i, &ns) in [primary_ns, TypeNS, ValueNS].iter().enumerate() { @@ -4271,7 +4272,7 @@ fn resolve_qpath( path: &[Segment], ns: Namespace, finalize: Finalize, - ) -> Result, Spanned>> { + ) -> Result, Spanned>> { debug!( "resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})", qself, path, ns, finalize, @@ -4920,8 +4921,8 @@ fn lint_unused_qualifications(&mut self, path: &[Segment], ns: Namespace, finali /// Walks the whole crate in DFS order, visiting each item, counting the declared number of /// lifetime generic parameters and function parameters. -struct ItemInfoCollector<'a, 'b, 'tcx> { - r: &'b mut Resolver<'a, 'tcx>, +struct ItemInfoCollector<'a, 'ra, 'tcx> { + r: &'a mut Resolver<'ra, 'tcx>, } impl ItemInfoCollector<'_, '_, '_> { @@ -4988,7 +4989,7 @@ fn visit_assoc_item(&mut self, item: &'ast AssocItem, ctxt: AssocCtxt) { } } -impl<'a, 'tcx> Resolver<'a, 'tcx> { +impl<'ra, 'tcx> Resolver<'ra, 'tcx> { pub(crate) fn late_resolve_crate(&mut self, krate: &Crate) { visit::walk_crate(&mut ItemInfoCollector { r: self }, krate); let mut late_resolution_visitor = LateResolutionVisitor::new(self); diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 202c0e5f9c5..1c584bf8338 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -170,7 +170,7 @@ fn to_opt_suggestion(self) -> Option { } } -impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { +impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn make_base_error( &mut self, path: &[Segment], @@ -2277,7 +2277,7 @@ fn let_binding_suggestion(&mut self, err: &mut Diag<'_>, ident_span: Span) -> bo false } - fn find_module(&mut self, def_id: DefId) -> Option<(Module<'a>, ImportSuggestion)> { + fn find_module(&mut self, def_id: DefId) -> Option<(Module<'ra>, ImportSuggestion)> { let mut result = None; let mut seen_modules = FxHashSet::default(); let root_did = self.r.graph_root.def_id(); diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 8ffd00d1b2e..872535627a5 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -113,14 +113,14 @@ fn determined(determined: bool) -> Determinacy { /// This enum is currently used only for early resolution (imports and macros), /// but not for late resolution yet. #[derive(Clone, Copy, Debug)] -enum Scope<'a> { +enum Scope<'ra> { DeriveHelpers(LocalExpnId), DeriveHelpersCompat, - MacroRules(MacroRulesScopeRef<'a>), + MacroRules(MacroRulesScopeRef<'ra>), CrateRoot, // The node ID is for reporting the `PROC_MACRO_DERIVE_RESOLUTION_FALLBACK` // lint if it should be reported. - Module(Module<'a>, Option), + Module(Module<'ra>, Option), MacroUsePrelude, BuiltinAttrs, ExternPrelude, @@ -134,7 +134,7 @@ enum Scope<'a> { /// This enum is currently used only for early resolution (imports and macros), /// but not for late resolution yet. #[derive(Clone, Copy, Debug)] -enum ScopeSet<'a> { +enum ScopeSet<'ra> { /// All scopes with the given namespace. All(Namespace), /// Crate root, then extern prelude (used for mixed 2015-2018 mode in macros). @@ -143,7 +143,7 @@ enum ScopeSet<'a> { Macro(MacroKind), /// All scopes with the given namespace, used for partially performing late resolution. /// The node id enables lints and is used for reporting them. - Late(Namespace, Module<'a>, Option), + Late(Namespace, Module<'ra>, Option), } /// Everything you need to know about a name's location to resolve it. @@ -151,17 +151,17 @@ enum ScopeSet<'a> { /// This struct is currently used only for early resolution (imports and macros), /// but not for late resolution yet. #[derive(Clone, Copy, Debug)] -struct ParentScope<'a> { - module: Module<'a>, +struct ParentScope<'ra> { + module: Module<'ra>, expansion: LocalExpnId, - macro_rules: MacroRulesScopeRef<'a>, - derives: &'a [ast::Path], + macro_rules: MacroRulesScopeRef<'ra>, + derives: &'ra [ast::Path], } -impl<'a> ParentScope<'a> { +impl<'ra> ParentScope<'ra> { /// Creates a parent scope with the passed argument used as the module scope component, /// and other scope components set to default empty values. - fn module(module: Module<'a>, resolver: &Resolver<'a, '_>) -> ParentScope<'a> { + fn module(module: Module<'ra>, resolver: &Resolver<'ra, '_>) -> ParentScope<'ra> { ParentScope { module, expansion: LocalExpnId::ROOT, @@ -203,7 +203,7 @@ struct BindingError { } #[derive(Debug)] -enum ResolutionError<'a> { +enum ResolutionError<'ra> { /// Error E0401: can't use type or const parameters from outer item. GenericParamsFromOuterItem(Res, HasGenericParams, DefKind), /// Error E0403: the name is already used for a type or const parameter in this generic @@ -216,7 +216,7 @@ enum ResolutionError<'a> { /// Error E0438: const is not a member of trait. ConstNotMemberOfTrait(Ident, String, Option), /// Error E0408: variable `{}` is not bound in all patterns. - VariableNotBoundInPattern(BindingError, ParentScope<'a>), + VariableNotBoundInPattern(BindingError, ParentScope<'ra>), /// Error E0409: variable `{}` is bound in inconsistent ways within the same match arm. VariableBoundWithDifferentMode(Symbol, Span), /// Error E0415: identifier is bound more than once in this parameter list. @@ -236,7 +236,7 @@ enum ResolutionError<'a> { segment: Option, label: String, suggestion: Option, - module: Option>, + module: Option>, }, /// Error E0434: can't capture dynamic environment in a fn item. CannotCaptureDynamicEnvironmentInFnItem, @@ -377,12 +377,12 @@ fn from(seg: &'a ast::PathSegment) -> Segment { /// items are visible in their whole block, while `Res`es only from the place they are defined /// forward. #[derive(Debug, Copy, Clone)] -enum LexicalScopeBinding<'a> { - Item(NameBinding<'a>), +enum LexicalScopeBinding<'ra> { + Item(NameBinding<'ra>), Res(Res), } -impl<'a> LexicalScopeBinding<'a> { +impl<'ra> LexicalScopeBinding<'ra> { fn res(self) -> Res { match self { LexicalScopeBinding::Item(binding) => binding.res(), @@ -392,9 +392,9 @@ fn res(self) -> Res { } #[derive(Copy, Clone, PartialEq, Debug)] -enum ModuleOrUniformRoot<'a> { +enum ModuleOrUniformRoot<'ra> { /// Regular module. - Module(Module<'a>), + Module(Module<'ra>), /// Virtual module that denotes resolution in crate root with fallback to extern prelude. CrateRootAndExternPrelude, @@ -410,8 +410,8 @@ enum ModuleOrUniformRoot<'a> { } #[derive(Debug)] -enum PathResult<'a> { - Module(ModuleOrUniformRoot<'a>), +enum PathResult<'ra> { + Module(ModuleOrUniformRoot<'ra>), NonModule(PartialRes), Indeterminate, Failed { @@ -432,20 +432,20 @@ enum PathResult<'a> { /// ``` /// /// In this case, `module` will point to `a`. - module: Option>, + module: Option>, /// The segment name of target segment_name: Symbol, }, } -impl<'a> PathResult<'a> { +impl<'ra> PathResult<'ra> { fn failed( ident: Ident, is_error_from_last_segment: bool, finalize: bool, - module: Option>, + module: Option>, label_and_suggestion: impl FnOnce() -> (String, Option), - ) -> PathResult<'a> { + ) -> PathResult<'ra> { let (label, suggestion) = if finalize { label_and_suggestion() } else { (String::new(), None) }; PathResult::Failed { @@ -518,7 +518,7 @@ fn new(ident: Ident, ns: Namespace) -> Self { } } -type Resolutions<'a> = RefCell>>>; +type Resolutions<'ra> = RefCell>>>; /// One node in the tree of modules. /// @@ -531,15 +531,15 @@ fn new(ident: Ident, ns: Namespace) -> Self { /// * curly-braced block with statements /// /// You can use [`ModuleData::kind`] to determine the kind of module this is. -struct ModuleData<'a> { +struct ModuleData<'ra> { /// The direct parent module (it may not be a `mod`, however). - parent: Option>, + parent: Option>, /// What kind of module this is, because this may not be a `mod`. kind: ModuleKind, /// Mapping between names and their (possibly in-progress) resolutions in this module. /// Resolutions in modules from other crates are not populated until accessed. - lazy_resolutions: Resolutions<'a>, + lazy_resolutions: Resolutions<'ra>, /// True if this is a module from other crate that needs to be populated on access. populate_on_access: Cell, @@ -549,11 +549,11 @@ struct ModuleData<'a> { /// Whether `#[no_implicit_prelude]` is active. no_implicit_prelude: bool, - glob_importers: RefCell>>, - globs: RefCell>>, + glob_importers: RefCell>>, + globs: RefCell>>, /// Used to memoize the traits in this module for faster searches through all traits in scope. - traits: RefCell)]>>>, + traits: RefCell)]>>>, /// Span of the module itself. Used for error reporting. span: Span, @@ -565,11 +565,11 @@ struct ModuleData<'a> { /// so we can use referential equality to compare them. #[derive(Clone, Copy, PartialEq, Eq, Hash)] #[rustc_pass_by_value] -struct Module<'a>(Interned<'a, ModuleData<'a>>); +struct Module<'ra>(Interned<'ra, ModuleData<'ra>>); -impl<'a> ModuleData<'a> { +impl<'ra> ModuleData<'ra> { fn new( - parent: Option>, + parent: Option>, kind: ModuleKind, expansion: ExpnId, span: Span, @@ -595,11 +595,11 @@ fn new( } } -impl<'a> Module<'a> { +impl<'ra> Module<'ra> { fn for_each_child<'tcx, R, F>(self, resolver: &mut R, mut f: F) where - R: AsMut>, - F: FnMut(&mut R, Ident, Namespace, NameBinding<'a>), + R: AsMut>, + F: FnMut(&mut R, Ident, Namespace, NameBinding<'ra>), { for (key, name_resolution) in resolver.as_mut().resolutions(self).borrow().iter() { if let Some(binding) = name_resolution.borrow().binding { @@ -611,7 +611,7 @@ fn for_each_child<'tcx, R, F>(self, resolver: &mut R, mut f: F) /// This modifies `self` in place. The traits will be stored in `self.traits`. fn ensure_traits<'tcx, R>(self, resolver: &mut R) where - R: AsMut>, + R: AsMut>, { let mut traits = self.traits.borrow_mut(); if traits.is_none() { @@ -656,7 +656,7 @@ fn is_trait(self) -> bool { matches!(self.kind, ModuleKind::Def(DefKind::Trait, _, _)) } - fn nearest_item_scope(self) -> Module<'a> { + fn nearest_item_scope(self) -> Module<'ra> { match self.kind { ModuleKind::Def(DefKind::Enum | DefKind::Trait, ..) => { self.parent.expect("enum or trait module without a parent") @@ -686,15 +686,15 @@ fn is_ancestor_of(self, mut other: Self) -> bool { } } -impl<'a> std::ops::Deref for Module<'a> { - type Target = ModuleData<'a>; +impl<'ra> std::ops::Deref for Module<'ra> { + type Target = ModuleData<'ra>; fn deref(&self) -> &Self::Target { &self.0 } } -impl<'a> fmt::Debug for Module<'a> { +impl<'ra> fmt::Debug for Module<'ra> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self.res()) } @@ -702,9 +702,9 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { /// Records a possibly-private value, type, or module definition. #[derive(Clone, Copy, Debug)] -struct NameBindingData<'a> { - kind: NameBindingKind<'a>, - ambiguity: Option<(NameBinding<'a>, AmbiguityKind)>, +struct NameBindingData<'ra> { + kind: NameBindingKind<'ra>, + ambiguity: Option<(NameBinding<'ra>, AmbiguityKind)>, /// Produce a warning instead of an error when reporting ambiguities inside this binding. /// May apply to indirect ambiguities under imports, so `ambiguity.is_some()` is not required. warn_ambiguity: bool, @@ -715,26 +715,26 @@ struct NameBindingData<'a> { /// All name bindings are unique and allocated on a same arena, /// so we can use referential equality to compare them. -type NameBinding<'a> = Interned<'a, NameBindingData<'a>>; +type NameBinding<'ra> = Interned<'ra, NameBindingData<'ra>>; -trait ToNameBinding<'a> { - fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> NameBinding<'a>; +trait ToNameBinding<'ra> { + fn to_name_binding(self, arenas: &'ra ResolverArenas<'ra>) -> NameBinding<'ra>; } -impl<'a> ToNameBinding<'a> for NameBinding<'a> { - fn to_name_binding(self, _: &'a ResolverArenas<'a>) -> NameBinding<'a> { +impl<'ra> ToNameBinding<'ra> for NameBinding<'ra> { + fn to_name_binding(self, _: &'ra ResolverArenas<'ra>) -> NameBinding<'ra> { self } } #[derive(Clone, Copy, Debug)] -enum NameBindingKind<'a> { +enum NameBindingKind<'ra> { Res(Res), - Module(Module<'a>), - Import { binding: NameBinding<'a>, import: Import<'a> }, + Module(Module<'ra>), + Import { binding: NameBinding<'ra>, import: Import<'ra> }, } -impl<'a> NameBindingKind<'a> { +impl<'ra> NameBindingKind<'ra> { /// Is this a name binding of an import? fn is_import(&self) -> bool { matches!(*self, NameBindingKind::Import { .. }) @@ -742,12 +742,12 @@ fn is_import(&self) -> bool { } #[derive(Debug)] -struct PrivacyError<'a> { +struct PrivacyError<'ra> { ident: Ident, - binding: NameBinding<'a>, + binding: NameBinding<'ra>, dedup_span: Span, outermost_res: Option<(Res, Ident)>, - parent_scope: ParentScope<'a>, + parent_scope: ParentScope<'ra>, /// Is the format `use a::{b,c}`? single_nested: bool, } @@ -812,18 +812,18 @@ enum AmbiguityErrorMisc { None, } -struct AmbiguityError<'a> { +struct AmbiguityError<'ra> { kind: AmbiguityKind, ident: Ident, - b1: NameBinding<'a>, - b2: NameBinding<'a>, + b1: NameBinding<'ra>, + b2: NameBinding<'ra>, misc1: AmbiguityErrorMisc, misc2: AmbiguityErrorMisc, warning: bool, } -impl<'a> NameBindingData<'a> { - fn module(&self) -> Option> { +impl<'ra> NameBindingData<'ra> { + fn module(&self) -> Option> { match self.kind { NameBindingKind::Module(module) => Some(module), NameBindingKind::Import { binding, .. } => binding.module(), @@ -947,8 +947,8 @@ fn determined(&self) -> bool { } #[derive(Default, Clone)] -struct ExternPreludeEntry<'a> { - binding: Option>, +struct ExternPreludeEntry<'ra> { + binding: Option>, introduced_by_item: bool, } @@ -985,16 +985,16 @@ fn new(ext: Lrc) -> MacroData { /// The main resolver class. /// /// This is the visitor that walks the whole crate. -pub struct Resolver<'a, 'tcx> { +pub struct Resolver<'ra, 'tcx> { tcx: TyCtxt<'tcx>, /// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`. expn_that_defined: FxHashMap, - graph_root: Module<'a>, + graph_root: Module<'ra>, - prelude: Option>, - extern_prelude: FxHashMap>, + prelude: Option>, + extern_prelude: FxHashMap>, /// N.B., this is used only for better diagnostics, not name resolution itself. field_names: LocalDefIdMap>, @@ -1004,10 +1004,10 @@ pub struct Resolver<'a, 'tcx> { field_visibility_spans: FxHashMap>, /// All imports known to succeed or fail. - determined_imports: Vec>, + determined_imports: Vec>, /// All non-determined imports. - indeterminate_imports: Vec>, + indeterminate_imports: Vec>, // Spans for local variables found during pattern resolution. // Used for suggestions during error reporting. @@ -1018,7 +1018,7 @@ pub struct Resolver<'a, 'tcx> { /// Resolutions for import nodes, which have multiple resolutions in different namespaces. import_res_map: NodeMap>>, /// An import will be inserted into this map if it has been used. - import_use_map: FxHashMap, Used>, + import_use_map: FxHashMap, Used>, /// Resolutions for labels (node IDs of their corresponding blocks or loops). label_res_map: NodeMap, /// Resolutions for lifetimes. @@ -1045,13 +1045,13 @@ pub struct Resolver<'a, 'tcx> { /// /// There will be an anonymous module created around `g` with the ID of the /// entry block for `f`. - block_map: NodeMap>, + block_map: NodeMap>, /// A fake module that contains no definition and no prelude. Used so that /// some AST passes can generate identifiers that only resolve to local or /// lang items. - empty_module: Module<'a>, - module_map: FxHashMap>, - binding_parent_modules: FxHashMap, Module<'a>>, + empty_module: Module<'ra>, + module_map: FxHashMap>, + binding_parent_modules: FxHashMap, Module<'ra>>, underscore_disambiguator: u32, /// Disambiguator for anonymous adts. @@ -1065,57 +1065,57 @@ pub struct Resolver<'a, 'tcx> { maybe_unused_trait_imports: FxIndexSet, /// Privacy errors are delayed until the end in order to deduplicate them. - privacy_errors: Vec>, + privacy_errors: Vec>, /// Ambiguity errors are delayed for deduplication. - ambiguity_errors: Vec>, + ambiguity_errors: Vec>, /// `use` injections are delayed for better placement and deduplication. use_injections: Vec>, /// Crate-local macro expanded `macro_export` referred to by a module-relative path. macro_expanded_macro_export_errors: BTreeSet<(Span, Span)>, - arenas: &'a ResolverArenas<'a>, - dummy_binding: NameBinding<'a>, - builtin_types_bindings: FxHashMap>, - builtin_attrs_bindings: FxHashMap>, - registered_tool_bindings: FxHashMap>, + arenas: &'ra ResolverArenas<'ra>, + dummy_binding: NameBinding<'ra>, + builtin_types_bindings: FxHashMap>, + builtin_attrs_bindings: FxHashMap>, + registered_tool_bindings: FxHashMap>, /// Binding for implicitly declared names that come with a module, /// like `self` (not yet used), or `crate`/`$crate` (for root modules). - module_self_bindings: FxHashMap, NameBinding<'a>>, + module_self_bindings: FxHashMap, NameBinding<'ra>>, used_extern_options: FxHashSet, macro_names: FxHashSet, builtin_macros: FxHashMap, registered_tools: &'tcx RegisteredTools, - macro_use_prelude: FxHashMap>, + macro_use_prelude: FxHashMap>, macro_map: FxHashMap, dummy_ext_bang: Lrc, dummy_ext_derive: Lrc, non_macro_attr: MacroData, - local_macro_def_scopes: FxHashMap>, - ast_transform_scopes: FxHashMap>, + local_macro_def_scopes: FxHashMap>, + ast_transform_scopes: FxHashMap>, unused_macros: FxHashMap, unused_macro_rules: FxHashMap<(LocalDefId, usize), (Ident, Span)>, proc_macro_stubs: FxHashSet, /// Traces collected during macro resolution and validated when it's complete. single_segment_macro_resolutions: - Vec<(Ident, MacroKind, ParentScope<'a>, Option>)>, + Vec<(Ident, MacroKind, ParentScope<'ra>, Option>)>, multi_segment_macro_resolutions: - Vec<(Vec, Span, MacroKind, ParentScope<'a>, Option, Namespace)>, - builtin_attrs: Vec<(Ident, ParentScope<'a>)>, + Vec<(Vec, Span, MacroKind, ParentScope<'ra>, Option, Namespace)>, + builtin_attrs: Vec<(Ident, ParentScope<'ra>)>, /// `derive(Copy)` marks items they are applied to so they are treated specially later. /// Derive macros cannot modify the item themselves and have to store the markers in the global /// context, so they attach the markers to derive container IDs using this resolver table. containers_deriving_copy: FxHashSet, /// Parent scopes in which the macros were invoked. /// FIXME: `derives` are missing in these parent scopes and need to be taken from elsewhere. - invocation_parent_scopes: FxHashMap>, + invocation_parent_scopes: FxHashMap>, /// `macro_rules` scopes *produced* by expanding the macro invocations, /// include all the `macro_rules` items and other invocations generated by them. - output_macro_rules_scopes: FxHashMap>, + output_macro_rules_scopes: FxHashMap>, /// `macro_rules` scopes produced by `macro_rules` item definitions. - macro_rules_scopes: FxHashMap>, + macro_rules_scopes: FxHashMap>, /// Helper attributes that are in scope for the given expansion. - helper_attrs: FxHashMap)>>, + helper_attrs: FxHashMap)>>, /// Ready or in-progress results of resolving paths inside the `#[derive(...)]` attribute /// with the given `ExpnId`. derive_data: FxHashMap, @@ -1123,9 +1123,9 @@ pub struct Resolver<'a, 'tcx> { /// Avoid duplicated errors for "name already defined". name_already_seen: FxHashMap, - potentially_unused_imports: Vec>, + potentially_unused_imports: Vec>, - potentially_unnecessary_qualifications: Vec>, + potentially_unnecessary_qualifications: Vec>, /// Table for mapping struct IDs into struct constructor IDs, /// it's not used during normal resolution, only for better error reporting. @@ -1186,28 +1186,29 @@ pub struct Resolver<'a, 'tcx> { current_crate_outer_attr_insert_span: Span, } -/// Nothing really interesting here; it just provides memory for the rest of the crate. +/// This provides memory for the rest of the crate. The `'ra` lifetime that is +/// used by many types in this crate is an abbreviation of `ResolverArenas`. #[derive(Default)] -pub struct ResolverArenas<'a> { - modules: TypedArena>, - local_modules: RefCell>>, - imports: TypedArena>, - name_resolutions: TypedArena>>, +pub struct ResolverArenas<'ra> { + modules: TypedArena>, + local_modules: RefCell>>, + imports: TypedArena>, + name_resolutions: TypedArena>>, ast_paths: TypedArena, dropless: DroplessArena, } -impl<'a> ResolverArenas<'a> { +impl<'ra> ResolverArenas<'ra> { fn new_module( - &'a self, - parent: Option>, + &'ra self, + parent: Option>, kind: ModuleKind, expn_id: ExpnId, span: Span, no_implicit_prelude: bool, - module_map: &mut FxHashMap>, - module_self_bindings: &mut FxHashMap, NameBinding<'a>>, - ) -> Module<'a> { + module_map: &mut FxHashMap>, + module_self_bindings: &mut FxHashMap, NameBinding<'ra>>, + ) -> Module<'ra> { let module = Module(Interned::new_unchecked(self.modules.alloc(ModuleData::new( parent, kind, @@ -1227,37 +1228,37 @@ fn new_module( } module } - fn local_modules(&'a self) -> std::cell::Ref<'a, Vec>> { + fn local_modules(&'ra self) -> std::cell::Ref<'ra, Vec>> { self.local_modules.borrow() } - fn alloc_name_binding(&'a self, name_binding: NameBindingData<'a>) -> NameBinding<'a> { + fn alloc_name_binding(&'ra self, name_binding: NameBindingData<'ra>) -> NameBinding<'ra> { Interned::new_unchecked(self.dropless.alloc(name_binding)) } - fn alloc_import(&'a self, import: ImportData<'a>) -> Import<'a> { + fn alloc_import(&'ra self, import: ImportData<'ra>) -> Import<'ra> { Interned::new_unchecked(self.imports.alloc(import)) } - fn alloc_name_resolution(&'a self) -> &'a RefCell> { + fn alloc_name_resolution(&'ra self) -> &'ra RefCell> { self.name_resolutions.alloc(Default::default()) } - fn alloc_macro_rules_scope(&'a self, scope: MacroRulesScope<'a>) -> MacroRulesScopeRef<'a> { + fn alloc_macro_rules_scope(&'ra self, scope: MacroRulesScope<'ra>) -> MacroRulesScopeRef<'ra> { Interned::new_unchecked(self.dropless.alloc(Cell::new(scope))) } fn alloc_macro_rules_binding( - &'a self, - binding: MacroRulesBinding<'a>, - ) -> &'a MacroRulesBinding<'a> { + &'ra self, + binding: MacroRulesBinding<'ra>, + ) -> &'ra MacroRulesBinding<'ra> { self.dropless.alloc(binding) } - fn alloc_ast_paths(&'a self, paths: &[ast::Path]) -> &'a [ast::Path] { + fn alloc_ast_paths(&'ra self, paths: &[ast::Path]) -> &'ra [ast::Path] { self.ast_paths.alloc_from_iter(paths.iter().cloned()) } - fn alloc_pattern_spans(&'a self, spans: impl Iterator) -> &'a [Span] { + fn alloc_pattern_spans(&'ra self, spans: impl Iterator) -> &'ra [Span] { self.dropless.alloc_from_iter(spans) } } -impl<'a, 'tcx> AsMut> for Resolver<'a, 'tcx> { - fn as_mut(&mut self) -> &mut Resolver<'a, 'tcx> { +impl<'ra, 'tcx> AsMut> for Resolver<'ra, 'tcx> { + fn as_mut(&mut self) -> &mut Resolver<'ra, 'tcx> { self } } @@ -1341,14 +1342,14 @@ pub fn tcx(&self) -> TyCtxt<'tcx> { } } -impl<'a, 'tcx> Resolver<'a, 'tcx> { +impl<'ra, 'tcx> Resolver<'ra, 'tcx> { pub fn new( tcx: TyCtxt<'tcx>, attrs: &[ast::Attribute], crate_span: Span, current_crate_outer_attr_insert_span: Span, - arenas: &'a ResolverArenas<'a>, - ) -> Resolver<'a, 'tcx> { + arenas: &'ra ResolverArenas<'ra>, + ) -> Resolver<'ra, 'tcx> { let root_def_id = CRATE_DEF_ID.to_def_id(); let mut module_map = FxHashMap::default(); let mut module_self_bindings = FxHashMap::default(); @@ -1541,12 +1542,12 @@ pub fn new( fn new_module( &mut self, - parent: Option>, + parent: Option>, kind: ModuleKind, expn_id: ExpnId, span: Span, no_implicit_prelude: bool, - ) -> Module<'a> { + ) -> Module<'ra> { let module_map = &mut self.module_map; let module_self_bindings = &mut self.module_self_bindings; self.arenas.new_module( @@ -1578,7 +1579,7 @@ pub fn lint_buffer(&mut self) -> &mut LintBuffer { &mut self.lint_buffer } - pub fn arenas() -> ResolverArenas<'a> { + pub fn arenas() -> ResolverArenas<'ra> { Default::default() } @@ -1719,8 +1720,8 @@ pub fn resolve_crate(&mut self, krate: &Crate) { fn traits_in_scope( &mut self, - current_trait: Option>, - parent_scope: &ParentScope<'a>, + current_trait: Option>, + parent_scope: &ParentScope<'ra>, ctxt: SyntaxContext, assoc_item: Option<(Symbol, Namespace)>, ) -> Vec { @@ -1754,7 +1755,7 @@ fn traits_in_scope( fn traits_in_module( &mut self, - module: Module<'a>, + module: Module<'ra>, assoc_item: Option<(Symbol, Namespace)>, found_traits: &mut Vec, ) { @@ -1776,7 +1777,7 @@ fn traits_in_module( // associated items. fn trait_may_have_item( &mut self, - trait_module: Option>, + trait_module: Option>, assoc_item: Option<(Symbol, Namespace)>, ) -> bool { match (trait_module, assoc_item) { @@ -1822,7 +1823,7 @@ fn new_disambiguated_key(&mut self, ident: Ident, ns: Namespace) -> BindingKey { BindingKey { ident, ns, disambiguator } } - fn resolutions(&mut self, module: Module<'a>) -> &'a Resolutions<'a> { + fn resolutions(&mut self, module: Module<'ra>) -> &'ra Resolutions<'ra> { if module.populate_on_access.get() { module.populate_on_access.set(false); self.build_reduced_graph_external(module); @@ -1832,9 +1833,9 @@ fn resolutions(&mut self, module: Module<'a>) -> &'a Resolutions<'a> { fn resolution( &mut self, - module: Module<'a>, + module: Module<'ra>, key: BindingKey, - ) -> &'a RefCell> { + ) -> &'ra RefCell> { *self .resolutions(module) .borrow_mut() @@ -1860,14 +1861,14 @@ fn matches_previous_ambiguity_error(&self, ambi: &AmbiguityError<'_>) -> bool { false } - fn record_use(&mut self, ident: Ident, used_binding: NameBinding<'a>, used: Used) { + fn record_use(&mut self, ident: Ident, used_binding: NameBinding<'ra>, used: Used) { self.record_use_inner(ident, used_binding, used, used_binding.warn_ambiguity); } fn record_use_inner( &mut self, ident: Ident, - used_binding: NameBinding<'a>, + used_binding: NameBinding<'ra>, used: Used, warn_ambiguity: bool, ) { @@ -1929,7 +1930,7 @@ fn add_to_glob_map(&mut self, import: Import<'_>, ident: Ident) { } } - fn resolve_crate_root(&mut self, ident: Ident) -> Module<'a> { + fn resolve_crate_root(&mut self, ident: Ident) -> Module<'ra> { debug!("resolve_crate_root({:?})", ident); let mut ctxt = ident.span.ctxt(); let mark = if ident.name == kw::DollarCrate { @@ -2002,7 +2003,7 @@ fn resolve_crate_root(&mut self, ident: Ident) -> Module<'a> { module } - fn resolve_self(&mut self, ctxt: &mut SyntaxContext, module: Module<'a>) -> Module<'a> { + fn resolve_self(&mut self, ctxt: &mut SyntaxContext, module: Module<'ra>) -> Module<'ra> { let mut module = self.expect_module(module.nearest_parent_mod()); while module.span.ctxt().normalize_to_macros_2_0() != *ctxt { let parent = module.parent.unwrap_or_else(|| self.expn_def_scope(ctxt.remove_mark())); @@ -2026,12 +2027,12 @@ fn record_pat_span(&mut self, node: NodeId, span: Span) { fn is_accessible_from( &self, vis: ty::Visibility>, - module: Module<'a>, + module: Module<'ra>, ) -> bool { vis.is_accessible_from(module.nearest_parent_mod(), self.tcx) } - fn set_binding_parent_module(&mut self, binding: NameBinding<'a>, module: Module<'a>) { + fn set_binding_parent_module(&mut self, binding: NameBinding<'ra>, module: Module<'ra>) { if let Some(old_module) = self.binding_parent_modules.insert(binding, module) { if module != old_module { span_bug!(binding.span, "parent module is reset for binding"); @@ -2041,8 +2042,8 @@ fn set_binding_parent_module(&mut self, binding: NameBinding<'a>, module: Module fn disambiguate_macro_rules_vs_modularized( &self, - macro_rules: NameBinding<'a>, - modularized: NameBinding<'a>, + macro_rules: NameBinding<'ra>, + modularized: NameBinding<'ra>, ) -> bool { // Some non-controversial subset of ambiguities "modularized macro name" vs "macro_rules" // is disambiguated to mitigate regressions from macro modularization. @@ -2059,7 +2060,7 @@ fn disambiguate_macro_rules_vs_modularized( } } - fn extern_prelude_get(&mut self, ident: Ident, finalize: bool) -> Option> { + fn extern_prelude_get(&mut self, ident: Ident, finalize: bool) -> Option> { if ident.is_path_segment_keyword() { // Make sure `self`, `super` etc produce an error when passed to here. return None; @@ -2108,7 +2109,7 @@ fn resolve_rustdoc_path( &mut self, path_str: &str, ns: Namespace, - parent_scope: ParentScope<'a>, + parent_scope: ParentScope<'ra>, ) -> Option { let mut segments = Vec::from_iter(path_str.split("::").map(Ident::from_str).map(Segment::from_ident)); diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 7203fbe4a0c..8a81f068a1c 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -52,10 +52,10 @@ /// Binding produced by a `macro_rules` item. /// Not modularized, can shadow previous `macro_rules` bindings, etc. #[derive(Debug)] -pub(crate) struct MacroRulesBinding<'a> { - pub(crate) binding: NameBinding<'a>, +pub(crate) struct MacroRulesBinding<'ra> { + pub(crate) binding: NameBinding<'ra>, /// `macro_rules` scope into which the `macro_rules` item was planted. - pub(crate) parent_macro_rules_scope: MacroRulesScopeRef<'a>, + pub(crate) parent_macro_rules_scope: MacroRulesScopeRef<'ra>, pub(crate) ident: Ident, } @@ -65,11 +65,11 @@ pub(crate) struct MacroRulesBinding<'a> { /// Some macro invocations need to introduce `macro_rules` scopes too because they /// can potentially expand into macro definitions. #[derive(Copy, Clone, Debug)] -pub(crate) enum MacroRulesScope<'a> { +pub(crate) enum MacroRulesScope<'ra> { /// Empty "root" scope at the crate start containing no names. Empty, /// The scope introduced by a `macro_rules!` macro definition. - Binding(&'a MacroRulesBinding<'a>), + Binding(&'ra MacroRulesBinding<'ra>), /// The scope introduced by a macro invocation that can potentially /// create a `macro_rules!` macro definition. Invocation(LocalExpnId), @@ -81,7 +81,7 @@ pub(crate) enum MacroRulesScope<'a> { /// This helps to avoid uncontrollable growth of `macro_rules!` scope chains, /// which usually grow linearly with the number of macro invocations /// in a module (including derives) and hurt performance. -pub(crate) type MacroRulesScopeRef<'a> = Interned<'a, Cell>>; +pub(crate) type MacroRulesScopeRef<'ra> = Interned<'ra, Cell>>; /// Macro namespace is separated into two sub-namespaces, one for bang macros and /// one for attribute-like macros (attributes, derives). @@ -177,7 +177,7 @@ fn soft_custom_inner_attributes_gate(path: &ast::Path, invoc: &Invocation) -> bo false } -impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> { +impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> { fn next_node_id(&mut self) -> NodeId { self.next_node_id() } @@ -528,7 +528,7 @@ fn glob_delegation_suffixes( } } -impl<'a, 'tcx> Resolver<'a, 'tcx> { +impl<'ra, 'tcx> Resolver<'ra, 'tcx> { /// Resolve macro path with error reporting and recovery. /// Uses dummy syntax extensions for unresolved macros or macros with unexpected resolutions /// for better error recovery. @@ -538,7 +538,7 @@ fn smart_resolve_macro_path( kind: MacroKind, supports_macro_expansion: SupportsMacroExpansion, inner_attr: bool, - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, node_id: NodeId, force: bool, soft_custom_inner_attributes_gate: bool, @@ -704,10 +704,10 @@ pub(crate) fn resolve_macro_path( &mut self, path: &ast::Path, kind: Option, - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, trace: bool, force: bool, - ignore_import: Option>, + ignore_import: Option>, ) -> Result<(Option>, Res), Determinacy> { self.resolve_macro_or_delegation_path( path, @@ -725,12 +725,12 @@ fn resolve_macro_or_delegation_path( &mut self, ast_path: &ast::Path, kind: Option, - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, trace: bool, force: bool, deleg_impl: Option, invoc_in_mod_inert_attr: Option<(LocalDefId, NodeId)>, - ignore_import: Option>, + ignore_import: Option>, ) -> Result<(Option>, Res), Determinacy> { let path_span = ast_path.span; let mut path = Segment::from_path(ast_path); @@ -1045,7 +1045,7 @@ fn check_stability_and_deprecation( fn prohibit_imported_non_macro_attrs( &self, - binding: Option>, + binding: Option>, res: Option, span: Span, ) { @@ -1065,9 +1065,9 @@ fn prohibit_imported_non_macro_attrs( fn report_out_of_scope_macro_calls( &mut self, path: &ast::Path, - parent_scope: &ParentScope<'a>, + parent_scope: &ParentScope<'ra>, invoc_in_mod_inert_attr: Option<(LocalDefId, NodeId)>, - binding: Option>, + binding: Option>, ) { if let Some((mod_def_id, node_id)) = invoc_in_mod_inert_attr && let Some(binding) = binding