Skip to content

Commit 5c0e8e9

Browse files
committed
Place delegations' disambiguators in Steal near DelegationInfos
1 parent b9ef605 commit 5c0e8e9

5 files changed

Lines changed: 19 additions & 14 deletions

File tree

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> ItemLowerer<'_, 'hir, R> {
7979
if let hir::MaybeOwner::Phantom = owner {
8080
let node = self.ast_index[def_id];
8181

82-
let disambig = if let Some(info) = self.resolver.delegation_infos.get_mut(&def_id) {
82+
let disambig = if let Some(disambig) = self.resolver.delegation_disambiguator(def_id) {
8383
// Here we use disambiguator that we saved from resolve stage, as we generate
8484
// new def_ids with names from other code, there may be situations when there
8585
// will be def path hash collision (see #153410).
86-
std::mem::take(&mut info.disambig)
86+
disambig.steal()
8787
} else {
8888
DisambiguatorState::new()
8989
};

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use rustc_attr_parsing::{AttributeParser, Late, OmitDoc};
4444
use rustc_data_structures::fingerprint::Fingerprint;
4545
use rustc_data_structures::sorted_map::SortedMap;
4646
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
47+
use rustc_data_structures::steal::Steal;
4748
use rustc_data_structures::sync::spawn;
4849
use rustc_data_structures::tagged_ptr::TaggedRef;
4950
use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle};
@@ -315,7 +316,11 @@ impl<'tcx> ResolverAstLowering<'tcx> {
315316
}
316317

317318
fn delegation_info(&self, id: LocalDefId) -> Option<&DelegationInfo> {
318-
self.delegation_infos.get(&id)
319+
self.delegation_infos.get(&id).map(|(i, _)| i)
320+
}
321+
322+
fn delegation_disambiguator(&self, id: LocalDefId) -> Option<&Steal<DisambiguatorState>> {
323+
self.delegation_infos.get(&id).map(|(_, d)| d)
319324
}
320325

321326
fn opt_local_def_id(&self, id: NodeId) -> Option<LocalDefId> {

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ pub struct ResolverAstLowering<'tcx> {
224224
/// Information about functions signatures for delegation items expansion
225225
pub delegation_fn_sigs: LocalDefIdMap<DelegationFnSig>,
226226
// Information about delegations which is used when handling recursive delegations
227-
pub delegation_infos: LocalDefIdMap<DelegationInfo>,
227+
// and disambiguator associated with each delegation.
228+
pub delegation_infos: LocalDefIdMap<(DelegationInfo, Steal<DisambiguatorState>)>,
228229
}
229230

230231
bitflags::bitflags! {
@@ -243,16 +244,11 @@ pub struct DelegationInfo {
243244
// for details see https://github.com/rust-lang/rust/issues/118212#issuecomment-2160686914
244245
pub resolution_node: ast::NodeId,
245246
pub attrs: DelegationAttrs,
246-
pub disambig: DisambiguatorState,
247247
}
248248

249249
impl Default for DelegationInfo {
250250
fn default() -> DelegationInfo {
251-
DelegationInfo {
252-
resolution_node: DUMMY_NODE_ID,
253-
attrs: Default::default(),
254-
disambig: Default::default(),
255-
}
251+
DelegationInfo { resolution_node: DUMMY_NODE_ID, attrs: Default::default() }
256252
}
257253
}
258254

compiler/rustc_resolve/src/late.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3819,7 +3819,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
38193819

38203820
self.visit_path(&delegation.path);
38213821

3822-
let info = self.r.delegation_infos.entry(self.r.local_def_id(item_id)).or_default();
3822+
let info = &mut self.r.delegation_infos.entry(self.r.local_def_id(item_id)).or_default().0;
38233823
info.attrs = create_delegation_attrs(attrs);
38243824
info.resolution_node = if is_in_trait_impl { item_id } else { delegation.id };
38253825

compiler/rustc_resolve/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ pub struct Resolver<'ra, 'tcx> {
13401340
/// Generic args to suggest for required params (e.g. `<'_>`, `<_, _>`), if any.
13411341
item_required_generic_args_suggestions: FxHashMap<LocalDefId, String> = default::fx_hash_map(),
13421342
delegation_fn_sigs: LocalDefIdMap<DelegationFnSig> = Default::default(),
1343-
delegation_infos: LocalDefIdMap<DelegationInfo> = Default::default(),
1343+
delegation_infos: LocalDefIdMap<(DelegationInfo, DisambiguatorState)> = Default::default(),
13441344

13451345
main_def: Option<MainDefinition> = None,
13461346
trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
@@ -1528,7 +1528,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
15281528

15291529
if is_delegation {
15301530
let data = def_kind.def_path_data(name);
1531-
self.delegation_infos.entry(parent).or_default().disambig.next(parent, data);
1531+
self.delegation_infos.entry(parent).or_default().1.next(parent, data);
15321532
}
15331533

15341534
// FIXME: remove `def_span` body, pass in the right spans here and call `tcx.at().create_def()`
@@ -1867,7 +1867,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
18671867
lifetime_elision_allowed: self.lifetime_elision_allowed,
18681868
lint_buffer: Steal::new(self.lint_buffer),
18691869
delegation_fn_sigs: self.delegation_fn_sigs,
1870-
delegation_infos: self.delegation_infos,
1870+
delegation_infos: self
1871+
.delegation_infos
1872+
.into_items()
1873+
.map(|(key, (i, d))| (key, (i, Steal::new(d))))
1874+
.collect(),
18711875
};
18721876
ResolverOutputs { global_ctxt, ast_lowering }
18731877
}

0 commit comments

Comments
 (0)