Skip to content

Commit ea7c3ba

Browse files
committed
Stop passing resolver disambiguator state to AST lowering.
1 parent fd9ca71 commit ea7c3ba

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.
@@ -520,6 +523,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
520523
node_id: ast::NodeId,
521524
name: Option<Symbol>,
522525
def_kind: DefKind,
526+
def_path_data: DefPathData,
523527
span: Span,
524528
) -> LocalDefId {
525529
let parent = self.current_hir_id_owner.def_id;
@@ -535,7 +539,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
535539
let def_id = self
536540
.tcx
537541
.at(span)
538-
.create_def(parent, name, def_kind, None, &mut self.resolver.disambiguator)
542+
.create_def(parent, name, def_kind, Some(def_path_data), &mut self.disambiguator)
539543
.def_id();
540544

541545
debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
@@ -820,6 +824,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
820824
param,
821825
Some(kw::UnderscoreLifetime),
822826
DefKind::LifetimeParam,
827+
DefPathData::DesugaredAnonymousLifetime,
823828
ident.span,
824829
);
825830
debug!(?_def_id);
@@ -2155,7 +2160,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21552160
// We're lowering a const argument that was originally thought to be a type argument,
21562161
// so the def collector didn't create the def ahead of time. That's why we have to do
21572162
// it here.
2158-
let def_id = self.create_def(node_id, None, DefKind::AnonConst, span);
2163+
let def_id = self.create_def(
2164+
node_id,
2165+
None,
2166+
DefKind::AnonConst,
2167+
DefPathData::LateAnonConst,
2168+
span,
2169+
);
21592170
let hir_id = self.lower_node_id(node_id);
21602171

21612172
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
@@ -306,6 +306,10 @@ pub enum DefPathData {
306306
Ctor,
307307
/// A constant expression (see `{ast,hir}::AnonConst`).
308308
AnonConst,
309+
/// A constant expression created during AST->HIR lowering..
310+
LateAnonConst,
311+
/// A fresh anonymous lifetime created by desugaring elided lifetimes.
312+
DesugaredAnonymousLifetime,
309313
/// An existential `impl Trait` type node.
310314
/// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name.
311315
OpaqueTy,
@@ -450,6 +454,8 @@ impl DefPathData {
450454
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name)
451455
| OpaqueLifetime(name) => Some(name),
452456

457+
DesugaredAnonymousLifetime => Some(kw::UnderscoreLifetime),
458+
453459
Impl
454460
| ForeignMod
455461
| CrateRoot
@@ -458,6 +464,7 @@ impl DefPathData {
458464
| Closure
459465
| Ctor
460466
| AnonConst
467+
| LateAnonConst
461468
| OpaqueTy
462469
| AnonAssocTy(..)
463470
| SyntheticCoroutineBody
@@ -471,6 +478,8 @@ impl DefPathData {
471478
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) | AnonAssocTy(name)
472479
| OpaqueLifetime(name) => Some(name),
473480

481+
DesugaredAnonymousLifetime => Some(kw::UnderscoreLifetime),
482+
474483
Impl
475484
| ForeignMod
476485
| CrateRoot
@@ -479,6 +488,7 @@ impl DefPathData {
479488
| Closure
480489
| Ctor
481490
| AnonConst
491+
| LateAnonConst
482492
| OpaqueTy
483493
| SyntheticCoroutineBody
484494
| NestedStatic => None,
@@ -498,7 +508,8 @@ impl DefPathData {
498508
GlobalAsm => DefPathDataName::Anon { namespace: sym::global_asm },
499509
Closure => DefPathDataName::Anon { namespace: sym::closure },
500510
Ctor => DefPathDataName::Anon { namespace: sym::constructor },
501-
AnonConst => DefPathDataName::Anon { namespace: sym::constant },
511+
AnonConst | LateAnonConst => DefPathDataName::Anon { namespace: sym::constant },
512+
DesugaredAnonymousLifetime => DefPathDataName::Named(kw::UnderscoreLifetime),
502513
OpaqueTy => DefPathDataName::Anon { namespace: sym::opaque },
503514
AnonAssocTy(..) => DefPathDataName::Anon { namespace: sym::anon_assoc },
504515
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
@@ -38,7 +38,6 @@ use rustc_errors::{Diag, ErrorGuaranteed};
3838
use rustc_hir::LangItem;
3939
use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res};
4040
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap};
41-
use rustc_hir::definitions::DisambiguatorState;
4241
use rustc_index::IndexVec;
4342
use rustc_index::bit_set::BitMatrix;
4443
use rustc_macros::{
@@ -221,8 +220,6 @@ pub struct ResolverAstLowering {
221220

222221
pub node_id_to_def_id: NodeMap<LocalDefId>,
223222

224-
pub disambiguator: DisambiguatorState,
225-
226223
pub trait_map: NodeMap<Vec<hir::TraitCandidate>>,
227224
/// List functions and methods for which lifetime elision was successful.
228225
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
@@ -2186,6 +2186,7 @@ fn guess_def_namespace(tcx: TyCtxt<'_>, def_id: DefId) -> Namespace {
21862186

21872187
DefPathData::ValueNs(..)
21882188
| DefPathData::AnonConst
2189+
| DefPathData::LateAnonConst
21892190
| DefPathData::Closure
21902191
| DefPathData::Ctor => Namespace::ValueNS,
21912192

compiler/rustc_resolve/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16931693
.into_items()
16941694
.map(|(k, f)| (k, f.key()))
16951695
.collect(),
1696-
disambiguator: self.disambiguator,
16971696
trait_map: self.trait_map,
16981697
lifetime_elision_allowed: self.lifetime_elision_allowed,
16991698
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)