Skip to content

Commit 74ad9d3

Browse files
committed
Track lifetime_elision_allowed per owner, and discard fn ptr and Fn() syntax registrations of it, they are never used
1 parent 335a667 commit 74ad9d3

4 files changed

Lines changed: 10 additions & 12 deletions

File tree

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,6 @@ impl<'tcx> ResolverAstLowering<'tcx> {
321321
fn owner_def_id(&self, id: NodeId) -> LocalDefId {
322322
self.owners[&id].def_id
323323
}
324-
325-
fn lifetime_elision_allowed(&self, id: NodeId) -> bool {
326-
self.lifetime_elision_allowed.contains(&id)
327-
}
328324
}
329325

330326
/// How relaxed bounds `?Trait` should be treated.
@@ -1866,7 +1862,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
18661862
_ => hir::ImplicitSelfKind::None,
18671863
}
18681864
}))
1869-
.set_lifetime_elision_allowed(self.resolver.lifetime_elision_allowed(fn_node_id))
1865+
.set_lifetime_elision_allowed(
1866+
self.owner.id == fn_node_id && self.owner.lifetime_elision_allowed,
1867+
)
18701868
.set_c_variadic(c_variadic);
18711869

18721870
self.arena.alloc(hir::FnDecl { inputs, output, fn_decl_kind })

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use rustc_ast as ast;
3131
use rustc_ast::expand::typetree::{FncTree, Kind, Type, TypeTree};
3232
use rustc_ast::node_id::NodeMap;
3333
pub use rustc_ast_ir::{Movability, Mutability, try_visit};
34-
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
34+
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
3535
use rustc_data_structures::intern::Interned;
3636
use rustc_data_structures::stable_hash::{StableHash, StableHashCtxt, StableHasher};
3737
use rustc_data_structures::steal::Steal;
@@ -207,6 +207,9 @@ pub struct ResolverGlobalCtxt {
207207
#[derive(Debug)]
208208
pub struct PerOwnerResolverData {
209209
pub node_id_to_def_id: NodeMap<LocalDefId> = Default::default(),
210+
/// Whether lifetime elision was successful.
211+
pub lifetime_elision_allowed: bool = false,
212+
210213
/// The id of the owner
211214
pub id: ast::NodeId,
212215
/// The `DefId` of the owner, can't be found in `node_id_to_def_id`.
@@ -239,8 +242,6 @@ pub struct ResolverAstLowering<'tcx> {
239242
pub owners: NodeMap<PerOwnerResolverData>,
240243

241244
pub trait_map: NodeMap<&'tcx [hir::TraitCandidate<'tcx>]>,
242-
/// List functions and methods for which lifetime elision was successful.
243-
pub lifetime_elision_allowed: FxHashSet<ast::NodeId>,
244245

245246
/// Lints that were emitted by the resolver and early lints.
246247
pub lint_buffer: Steal<LintBuffer>,

compiler/rustc_resolve/src/late.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2456,7 +2456,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
24562456

24572457
let outer_failures = take(&mut this.diag_metadata.current_elision_failures);
24582458
let output_rib = if let Ok(res) = elision_lifetime.as_ref() {
2459-
this.r.lifetime_elision_allowed.insert(fn_id);
2459+
if fn_id == this.r.current_owner.id {
2460+
this.r.current_owner.lifetime_elision_allowed = true;
2461+
}
24602462
LifetimeRibKind::Elided(*res)
24612463
} else {
24622464
LifetimeRibKind::ElisionFailure

compiler/rustc_resolve/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,8 +1533,6 @@ pub struct Resolver<'ra, 'tcx> {
15331533
/// they are declared in the static array generated by proc_macro_harness.
15341534
proc_macros: Vec<LocalDefId> = Vec::new(),
15351535
confused_type_with_std_module: FxIndexMap<Span, Span>,
1536-
/// Whether lifetime elision was successful.
1537-
lifetime_elision_allowed: FxHashSet<NodeId> = default::fx_hash_set(),
15381536

15391537
/// Names of items that were stripped out via cfg with their corresponding cfg meta item.
15401538
stripped_cfg_items: Vec<StrippedCfgItem<NodeId>> = Vec::new(),
@@ -2023,7 +2021,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20232021
next_node_id: self.next_node_id,
20242022
owners: self.owners,
20252023
trait_map: self.trait_map,
2026-
lifetime_elision_allowed: self.lifetime_elision_allowed,
20272024
lint_buffer: Steal::new(self.lint_buffer),
20282025
delegation_infos: self.delegation_infos,
20292026
disambiguators,

0 commit comments

Comments
 (0)