diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index 7c90cbb9092b8..c1ec5d68a7b6b 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -85,6 +85,7 @@ macro_rules! arena_types { [] attribute: rustc_ast::Attribute, [] name_set: rustc_data_structures::fx::FxHashSet, [] hir_id_set: rustc_hir::HirIdSet, + [] late_bound_lifetimes: rustc_data_structures::fx::FxIndexSet, // Interned types [] tys: rustc_data_structures::intern::WithStableHash>, diff --git a/compiler/rustc_middle/src/middle/resolve_lifetime.rs b/compiler/rustc_middle/src/middle/resolve_lifetime.rs index 70586cefaeee1..11ce6313147d4 100644 --- a/compiler/rustc_middle/src/middle/resolve_lifetime.rs +++ b/compiler/rustc_middle/src/middle/resolve_lifetime.rs @@ -2,7 +2,7 @@ use crate::ty; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::{FxHashMap, FxIndexSet}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::ItemLocalId; use rustc_macros::HashStable; @@ -64,7 +64,7 @@ pub struct ResolveLifetimes { /// Set of lifetime def ids that are late-bound; a region can /// be late-bound if (a) it does NOT appear in a where-clause and /// (b) it DOES appear in the arguments. - pub late_bound: FxHashMap>, + pub late_bound: FxHashMap>, pub late_bound_vars: FxHashMap>>, } diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 6d7ec247d0452..a23ff302a40aa 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1537,7 +1537,7 @@ rustc_queries! { Option<&'tcx FxHashMap> { desc { "looking up a named region" } } - query is_late_bound_map(_: LocalDefId) -> Option<(LocalDefId, &'tcx FxHashSet)> { + query is_late_bound_map(_: LocalDefId) -> Option<(LocalDefId, &'tcx FxIndexSet)> { desc { "testing if a region is late bound" } } /// For a given item (like a struct), gets the default lifetimes to be used diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index fb937ded65af1..1bb49a59ba47b 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -36,7 +36,7 @@ use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, T use rustc_ast as ast; use rustc_ast::expand::allocator::AllocatorKind; use rustc_attr as attr; -use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::steal::Steal; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::Lrc; diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index ff75e4eae3568..9b4184840bd27 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -8,7 +8,7 @@ use crate::late::diagnostics::{ForLifetimeSpanType, MissingLifetimeSpot}; use rustc_ast::walk_list; -use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; use rustc_errors::{struct_span_err, Applicability, Diagnostic}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; @@ -482,6 +482,11 @@ fn convert_named_region_map(tcx: TyCtxt<'_>, named_region_map: NamedRegionMap) - let def_id = tcx.hir().local_def_id(hir_id); map.insert(def_id); } + for (_, late_bound) in &mut rl.late_bound { + late_bound.sort_by(|&a, &b| { + tcx.def_path_hash(a.to_def_id()).cmp(&tcx.def_path_hash(b.to_def_id())) + }); + } for (hir_id, v) in named_region_map.late_bound_vars { let map = rl.late_bound_vars.entry(hir_id.owner).or_default(); map.insert(hir_id.local_id, v); @@ -540,7 +545,7 @@ fn item_for(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> LocalDefId { fn is_late_bound_map<'tcx>( tcx: TyCtxt<'tcx>, def_id: LocalDefId, -) -> Option<(LocalDefId, &'tcx FxHashSet)> { +) -> Option<(LocalDefId, &'tcx FxIndexSet)> { match tcx.def_kind(def_id) { DefKind::AnonConst | DefKind::InlineConst => { let mut def_id = tcx.local_parent(def_id); diff --git a/src/test/incremental/async-lifetimes.rs b/src/test/incremental/async-lifetimes.rs new file mode 100644 index 0000000000000..90a0b93b99a13 --- /dev/null +++ b/src/test/incremental/async-lifetimes.rs @@ -0,0 +1,19 @@ +// revisions: rpass1 rpass2 +// edition:2021 + +// See https://github.com/rust-lang/rust/issues/98890 + +#![allow(unused)] + +struct Foo; + +impl Foo { + async fn f(&self, _: &&()) -> &() { + &() + } +} + +#[cfg(rpass2)] +enum Bar {} + +fn main() {}