Skip to content

Commit 4b55098

Browse files
committed
Stop passing resolver disambiguator state to AST lowering.
1 parent 8f08b3a commit 4b55098

File tree

10 files changed

+46
-14
lines changed

10 files changed

+46
-14
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_data_structures::stack::ensure_sufficient_stack;
99
use rustc_hir as hir;
1010
use rustc_hir::HirId;
1111
use rustc_hir::def::{DefKind, Res};
12+
use rustc_hir::definitions::DefPathData;
1213
use rustc_middle::span_bug;
1314
use rustc_middle::ty::TyCtxt;
1415
use rustc_session::errors::report_lit_error;
@@ -488,7 +489,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
488489
for (idx, arg) in args.iter().cloned().enumerate() {
489490
if legacy_args_idx.contains(&idx) {
490491
let node_id = self.next_node_id();
491-
self.create_def(node_id, None, DefKind::AnonConst, f.span);
492+
self.create_def(
493+
node_id,
494+
None,
495+
DefKind::AnonConst,
496+
DefPathData::LateAnonConst,
497+
f.span,
498+
);
492499
let mut visitor = WillCreateDefIdsVisitor {};
493500
let const_value = if let ControlFlow::Break(span) = visitor.visit_expr(&arg) {
494501
AstP(Expr {

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use rustc_data_structures::tagged_ptr::TaggedRef;
5151
use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle};
5252
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
5353
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId};
54+
use rustc_hir::definitions::{DefPathData, DisambiguatorState};
5455
use rustc_hir::lints::DelayedLint;
5556
use rustc_hir::{
5657
self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LangItem,
@@ -92,6 +93,7 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
9293
struct LoweringContext<'a, 'hir> {
9394
tcx: TyCtxt<'hir>,
9495
resolver: &'a mut ResolverAstLowering,
96+
disambiguator: DisambiguatorState,
9597

9698
/// Used to allocate HIR nodes.
9799
arena: &'hir hir::Arena<'hir>,
@@ -154,6 +156,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
154156
// Pseudo-globals.
155157
tcx,
156158
resolver,
159+
disambiguator: DisambiguatorState::new(),
157160
arena: tcx.hir_arena,
158161

159162
// HirId handling.
@@ -525,6 +528,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
525528
node_id: ast::NodeId,
526529
name: Option<Symbol>,
527530
def_kind: DefKind,
531+
def_path_data: DefPathData,
528532
span: Span,
529533
) -> LocalDefId {
530534
let parent = self.current_hir_id_owner.def_id;
@@ -540,7 +544,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
540544
let def_id = self
541545
.tcx
542546
.at(span)
543-
.create_def(parent, name, def_kind, None, &mut self.resolver.disambiguator)
547+
.create_def(parent, name, def_kind, Some(def_path_data), &mut self.disambiguator)
544548
.def_id();
545549

546550
debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
@@ -825,6 +829,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
825829
param,
826830
Some(kw::UnderscoreLifetime),
827831
DefKind::LifetimeParam,
832+
DefPathData::DesugaredAnonymousLifetime,
828833
ident.span,
829834
);
830835
debug!(?_def_id);
@@ -2160,7 +2165,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21602165
// We're lowering a const argument that was originally thought to be a type argument,
21612166
// so the def collector didn't create the def ahead of time. That's why we have to do
21622167
// it here.
2163-
let def_id = self.create_def(node_id, None, DefKind::AnonConst, span);
2168+
let def_id = self.create_def(
2169+
node_id,
2170+
None,
2171+
DefKind::AnonConst,
2172+
DefPathData::LateAnonConst,
2173+
span,
2174+
);
21642175
let hir_id = self.lower_node_id(node_id);
21652176

21662177
let path_expr = Expr {

compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_ast::ptr::P;
44
use rustc_ast::*;
55
use rustc_data_structures::stack::ensure_sufficient_stack;
66
use rustc_hir::def::{DefKind, Res};
7+
use rustc_hir::definitions::DefPathData;
78
use rustc_hir::{self as hir, LangItem};
89
use rustc_middle::span_bug;
910
use rustc_span::source_map::{Spanned, respan};
@@ -524,7 +525,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
524525
// We're generating a range end that didn't exist in the AST,
525526
// so the def collector didn't create the def ahead of time. That's why we have to do
526527
// it here.
527-
let def_id = self.create_def(node_id, None, DefKind::AnonConst, span);
528+
let def_id =
529+
self.create_def(node_id, None, DefKind::AnonConst, DefPathData::LateAnonConst, span);
528530
let hir_id = self.lower_node_id(node_id);
529531

530532
let unstable_span = self.mark_span_with_reason(

compiler/rustc_hir/src/definitions.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ pub enum DefPathData {
302302
Ctor,
303303
/// A constant expression (see `{ast,hir}::AnonConst`).
304304
AnonConst,
305+
/// A constant expression created during AST->HIR lowering..
306+
LateAnonConst,
307+
/// A fresh anonymous lifetime created by desugaring elided lifetimes.
308+
DesugaredAnonymousLifetime,
305309
/// An existential `impl Trait` type node.
306310
/// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name.
307311
OpaqueTy,
@@ -454,6 +458,8 @@ impl DefPathData {
454458
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name)
455459
| OpaqueLifetime(name) => Some(name),
456460

461+
DesugaredAnonymousLifetime => Some(kw::UnderscoreLifetime),
462+
457463
Impl
458464
| ForeignMod
459465
| CrateRoot
@@ -462,6 +468,7 @@ impl DefPathData {
462468
| Closure
463469
| Ctor
464470
| AnonConst
471+
| LateAnonConst
465472
| OpaqueTy
466473
| AnonAssocTy(..)
467474
| SyntheticCoroutineBody
@@ -475,6 +482,8 @@ impl DefPathData {
475482
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) | AnonAssocTy(name)
476483
| OpaqueLifetime(name) => Some(name),
477484

485+
DesugaredAnonymousLifetime => Some(kw::UnderscoreLifetime),
486+
478487
Impl
479488
| ForeignMod
480489
| CrateRoot
@@ -483,6 +492,7 @@ impl DefPathData {
483492
| Closure
484493
| Ctor
485494
| AnonConst
495+
| LateAnonConst
486496
| OpaqueTy
487497
| SyntheticCoroutineBody
488498
| NestedStatic => None,
@@ -502,7 +512,8 @@ impl DefPathData {
502512
GlobalAsm => DefPathDataName::Anon { namespace: sym::global_asm },
503513
Closure => DefPathDataName::Anon { namespace: sym::closure },
504514
Ctor => DefPathDataName::Anon { namespace: sym::constructor },
505-
AnonConst => DefPathDataName::Anon { namespace: sym::constant },
515+
AnonConst | LateAnonConst => DefPathDataName::Anon { namespace: sym::constant },
516+
DesugaredAnonymousLifetime => DefPathDataName::Named(kw::UnderscoreLifetime),
506517
OpaqueTy => DefPathDataName::Anon { namespace: sym::opaque },
507518
AnonAssocTy(..) => DefPathDataName::Anon { namespace: sym::anon_assoc },
508519
SyntheticCoroutineBody => DefPathDataName::Anon { namespace: sym::synthetic },

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use rustc_errors::{Diag, ErrorGuaranteed};
3737
use rustc_hir::LangItem;
3838
use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res};
3939
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap};
40-
use rustc_hir::definitions::DisambiguatorState;
4140
use rustc_index::IndexVec;
4241
use rustc_index::bit_set::BitMatrix;
4342
use rustc_macros::{
@@ -220,8 +219,6 @@ pub struct ResolverAstLowering {
220219

221220
pub node_id_to_def_id: NodeMap<LocalDefId>,
222221

223-
pub disambiguator: DisambiguatorState,
224-
225222
pub trait_map: NodeMap<Vec<hir::TraitCandidate>>,
226223
/// List functions and methods for which lifetime elision was successful.
227224
pub lifetime_elision_allowed: FxHashSet<ast::NodeId>,

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,6 +2187,7 @@ fn guess_def_namespace(tcx: TyCtxt<'_>, def_id: DefId) -> Namespace {
21872187

21882188
DefPathData::ValueNs(..)
21892189
| DefPathData::AnonConst
2190+
| DefPathData::LateAnonConst
21902191
| DefPathData::Closure
21912192
| DefPathData::Ctor => Namespace::ValueNS,
21922193

compiler/rustc_resolve/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17281728
.into_items()
17291729
.map(|(k, f)| (k, f.key()))
17301730
.collect(),
1731-
disambiguator: self.disambiguator,
17321731
trait_map: self.trait_map,
17331732
lifetime_elision_allowed: self.lifetime_elision_allowed,
17341733
lint_buffer: Steal::new(self.lint_buffer),

compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,8 @@ fn encode_ty_name(tcx: TyCtxt<'_>, def_id: DefId) -> String {
713713
hir::definitions::DefPathData::ValueNs(..) => "v",
714714
hir::definitions::DefPathData::Closure => "C",
715715
hir::definitions::DefPathData::Ctor => "c",
716-
hir::definitions::DefPathData::AnonConst => "k",
716+
hir::definitions::DefPathData::AnonConst => "K",
717+
hir::definitions::DefPathData::LateAnonConst => "k",
717718
hir::definitions::DefPathData::OpaqueTy => "i",
718719
hir::definitions::DefPathData::SyntheticCoroutineBody => "s",
719720
hir::definitions::DefPathData::NestedStatic => "n",
@@ -723,6 +724,7 @@ fn encode_ty_name(tcx: TyCtxt<'_>, def_id: DefId) -> String {
723724
| hir::definitions::DefPathData::MacroNs(..)
724725
| hir::definitions::DefPathData::OpaqueLifetime(..)
725726
| hir::definitions::DefPathData::LifetimeNs(..)
727+
| hir::definitions::DefPathData::DesugaredAnonymousLifetime
726728
| hir::definitions::DefPathData::AnonAssocTy(..) => {
727729
bug!("encode_ty_name: unexpected `{:?}`", disambiguated_data.data);
728730
}

compiler/rustc_symbol_mangling/src/v0.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,8 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
872872
DefPathData::ValueNs(_) => 'v',
873873
DefPathData::Closure => 'C',
874874
DefPathData::Ctor => 'c',
875-
DefPathData::AnonConst => 'k',
875+
DefPathData::AnonConst => 'K',
876+
DefPathData::LateAnonConst => 'k',
876877
DefPathData::OpaqueTy => 'i',
877878
DefPathData::SyntheticCoroutineBody => 's',
878879
DefPathData::NestedStatic => 'n',
@@ -884,6 +885,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
884885
| DefPathData::Impl
885886
| DefPathData::MacroNs(_)
886887
| DefPathData::LifetimeNs(_)
888+
| DefPathData::DesugaredAnonymousLifetime
887889
| DefPathData::OpaqueLifetime(_)
888890
| DefPathData::AnonAssocTy(..) => {
889891
bug!("symbol_names: unexpected DefPathData: {:?}", disambiguated_data.data)

tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-paths.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ pub fn foo12(_: &Type4, _: &Type4, _: &Type4) {}
7878
// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo11{{[{}][{}]}}closure{{[}][}]}}3FooEE"}
7979
// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo11{{[{}][{}]}}closure{{[}][}]}}3FooES0_E"}
8080
// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo11{{[{}][{}]}}closure{{[}][}]}}3FooES0_S0_E"}
81-
// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooEE"}
82-
// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooES0_E"}
83-
// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooES0_S0_E"}
81+
// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNKNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooEE"}
82+
// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNKNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooES0_E"}
83+
// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNKNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooES0_S0_E"}
8484
// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo8{{[{}][{}]}}impl{{[}][}]}}3barEE"}
8585
// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo8{{[{}][{}]}}impl{{[}][}]}}3barES0_E"}
8686
// CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo8{{[{}][{}]}}impl{{[}][}]}}3barES0_S0_E"}

0 commit comments

Comments
 (0)