diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-09-12 19:03:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-12 19:03:42 +0200 |
| commit | b0ff0b7bf96b460d71d9be4ad3beb25c490ec27c (patch) | |
| tree | db6e12adedb709d7aab018a6a8a38d16e768486d /compiler/rustc_resolve/src/imports.rs | |
| parent | 4428d6f36306b2d17ad7eb11bd0bbc553800578b (diff) | |
| parent | d4fc76cbf386eeeb184bf0411af670912e9bc70d (diff) | |
| download | rust-b0ff0b7bf96b460d71d9be4ad3beb25c490ec27c.tar.gz rust-b0ff0b7bf96b460d71d9be4ad3beb25c490ec27c.zip | |
Rollup merge of #130208 - nnethercote:rslv-lifetime, r=petrochenkov
Introduce `'ra` lifetime name. `rustc_resolve` allocates many things in `ResolverArenas`. The lifetime used for references into the arena is mostly `'a`, and sometimes `'b`. This commit changes it to `'rslv`, which is much more descriptive. The commit also changes the order of lifetimes on a couple of structs so that '`rslv` is second last, before `'tcx`, and does other minor renamings such as `'r` to `'a`. r? ``@petrochenkov`` cc ``@oli-obk``
Diffstat (limited to 'compiler/rustc_resolve/src/imports.rs')
| -rw-r--r-- | compiler/rustc_resolve/src/imports.rs | 72 |
1 files changed, 38 insertions, 34 deletions
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 @@ type Res = def::Res<NodeId>; /// 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<Cell<Result<NameBinding<'a>, Determinacy>>>, + source_bindings: PerNS<Cell<Result<NameBinding<'ra>, Determinacy>>>, /// Bindings introduced by `target`. - target_bindings: PerNS<Cell<Option<NameBinding<'a>>>>, + target_bindings: PerNS<Cell<Option<NameBinding<'ra>>>>, /// `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 @@ impl<'a> std::fmt::Debug for ImportKind<'a> { /// 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<Segment>, /// The resolution of `module_path`. - pub imported_module: Cell<Option<ModuleOrUniformRoot<'a>>>, + pub imported_module: Cell<Option<ModuleOrUniformRoot<'ra>>>, 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 @@ impl<'a> ImportData<'a> { /// 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<Import<'a>>, + pub single_imports: FxHashSet<Import<'ra>>, /// The least shadowable known binding for this name, or None if there are no known bindings. - pub binding: Option<NameBinding<'a>>, - pub shadowed_glob: Option<NameBinding<'a>>, + pub binding: Option<NameBinding<'ra>>, + pub shadowed_glob: Option<NameBinding<'ra>>, } -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<NameBinding<'a>> { + pub(crate) fn binding(&self) -> Option<NameBinding<'ra>> { 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 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { /// `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 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { 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 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // If the resolution becomes a success, define it in the module's glob importers. fn update_resolution<T, F>( &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 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // 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 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { pub(crate) fn check_hidden_glob_reexports( &mut self, - exported_ambiguities: FxHashSet<NameBinding<'a>>, + exported_ambiguities: FxHashSet<NameBinding<'ra>>, ) { for module in self.arenas.local_modules().iter() { for (key, resolution) in self.resolutions(*module).borrow().iter() { @@ -759,7 +763,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { /// /// 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 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { /// /// 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<UnresolvedImportError> { + fn finalize_import(&mut self, import: Import<'ra>) -> Option<UnresolvedImportError> { let ignore_binding = match &import.kind { ImportKind::Single { target_bindings, .. } => target_bindings[TypeNS].get(), _ => None, @@ -1317,7 +1321,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { None } - pub(crate) fn check_for_redundant_imports(&mut self, import: Import<'a>) -> 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 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { 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 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // 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(); |
