diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index a916ee1f143b..b0b8efff0246 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -321,10 +321,6 @@ fn delegation_info(&self, id: LocalDefId) -> Option<&DelegationInfo> { fn owner_def_id(&self, id: NodeId) -> LocalDefId { self.owners[&id].def_id } - - fn lifetime_elision_allowed(&self, id: NodeId) -> bool { - self.lifetime_elision_allowed.contains(&id) - } } /// How relaxed bounds `?Trait` should be treated. @@ -1866,7 +1862,9 @@ fn lower_fn_decl( _ => hir::ImplicitSelfKind::None, } })) - .set_lifetime_elision_allowed(self.resolver.lifetime_elision_allowed(fn_node_id)) + .set_lifetime_elision_allowed( + self.owner.id == fn_node_id && self.owner.lifetime_elision_allowed, + ) .set_c_variadic(c_variadic); self.arena.alloc(hir::FnDecl { inputs, output, fn_decl_kind }) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index d68f0806812a..0c4ce6659934 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -31,7 +31,7 @@ use rustc_ast::expand::typetree::{FncTree, Kind, Type, TypeTree}; use rustc_ast::node_id::NodeMap; pub use rustc_ast_ir::{Movability, Mutability, try_visit}; -use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; +use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::intern::Interned; use rustc_data_structures::stable_hash::{StableHash, StableHashCtxt, StableHasher}; use rustc_data_structures::steal::Steal; @@ -207,6 +207,9 @@ pub struct ResolverGlobalCtxt { #[derive(Debug)] pub struct PerOwnerResolverData { pub node_id_to_def_id: NodeMap = Default::default(), + /// Whether lifetime elision was successful. + pub lifetime_elision_allowed: bool = false, + /// The id of the owner pub id: ast::NodeId, /// The `DefId` of the owner, can't be found in `node_id_to_def_id`. @@ -239,8 +242,6 @@ pub struct ResolverAstLowering<'tcx> { pub owners: NodeMap, pub trait_map: NodeMap<&'tcx [hir::TraitCandidate<'tcx>]>, - /// List functions and methods for which lifetime elision was successful. - pub lifetime_elision_allowed: FxHashSet, /// Lints that were emitted by the resolver and early lints. pub lint_buffer: Steal, diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index fb8de90d28ac..8764524e2322 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -2456,7 +2456,9 @@ fn resolve_fn_signature( let outer_failures = take(&mut this.diag_metadata.current_elision_failures); let output_rib = if let Ok(res) = elision_lifetime.as_ref() { - this.r.lifetime_elision_allowed.insert(fn_id); + if fn_id == this.r.current_owner.id { + this.r.current_owner.lifetime_elision_allowed = true; + } LifetimeRibKind::Elided(*res) } else { LifetimeRibKind::ElisionFailure diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index f5f4c9e6e258..9cbbc3c6f78d 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -1533,8 +1533,6 @@ pub struct Resolver<'ra, 'tcx> { /// they are declared in the static array generated by proc_macro_harness. proc_macros: Vec = Vec::new(), confused_type_with_std_module: FxIndexMap, - /// Whether lifetime elision was successful. - lifetime_elision_allowed: FxHashSet = default::fx_hash_set(), /// Names of items that were stripped out via cfg with their corresponding cfg meta item. stripped_cfg_items: Vec> = Vec::new(), @@ -2023,7 +2021,6 @@ pub fn into_outputs(self) -> ResolverOutputs<'tcx> { next_node_id: self.next_node_id, owners: self.owners, trait_map: self.trait_map, - lifetime_elision_allowed: self.lifetime_elision_allowed, lint_buffer: Steal::new(self.lint_buffer), delegation_infos: self.delegation_infos, disambiguators,