Skip to content

Commit 2cbc25e

Browse files
committed
Merge DefPathData::VariantCtor and DefPathData::StructCtor
1 parent 5bcf9f4 commit 2cbc25e

File tree

12 files changed

+26
-38
lines changed

12 files changed

+26
-38
lines changed

src/librustc/hir/map/def_collector.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
160160
ItemKind::Struct(ref struct_def, _) | ItemKind::Union(ref struct_def, _) => {
161161
// If this is a unit or tuple-like struct, register the constructor.
162162
if let Some(ctor_hir_id) = struct_def.ctor_id() {
163-
this.create_def(ctor_hir_id,
164-
DefPathData::StructCtor,
165-
REGULAR_SPACE,
166-
i.span);
163+
this.create_def(ctor_hir_id, DefPathData::Ctor, REGULAR_SPACE, i.span);
167164
}
168165
}
169166
_ => {}
@@ -199,10 +196,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
199196
v.span);
200197
self.with_parent(def, |this| {
201198
if let Some(ctor_hir_id) = v.node.data.ctor_id() {
202-
this.create_def(ctor_hir_id,
203-
DefPathData::VariantCtor,
204-
REGULAR_SPACE,
205-
v.span);
199+
this.create_def(ctor_hir_id, DefPathData::Ctor, REGULAR_SPACE, v.span);
206200
}
207201
visit::walk_variant(this, v, g, item_id)
208202
});

src/librustc/hir/map/definitions.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,8 @@ pub enum DefPathData {
366366
EnumVariant(InternedString),
367367
/// A struct field
368368
Field(InternedString),
369-
/// Implicit ctor for a unit or tuple-like struct
370-
StructCtor,
371-
/// Implicit ctor for a unit or tuple-like enum variant
372-
VariantCtor,
369+
/// Implicit ctor for a unit or tuple-like struct or enum variant.
370+
Ctor,
373371
/// A constant expression (see {ast,hir}::AnonConst).
374372
AnonConst,
375373
/// An `impl Trait` type node
@@ -654,8 +652,7 @@ impl DefPathData {
654652
CrateRoot |
655653
Misc |
656654
ClosureExpr |
657-
StructCtor |
658-
VariantCtor |
655+
Ctor |
659656
AnonConst |
660657
ImplTrait => None
661658
}
@@ -686,8 +683,7 @@ impl DefPathData {
686683
Impl => "{{impl}}",
687684
Misc => "{{misc}}",
688685
ClosureExpr => "{{closure}}",
689-
StructCtor => "{{struct constructor}}",
690-
VariantCtor => "{{variant constructor}}",
686+
Ctor => "{{constructor}}",
691687
AnonConst => "{{constant}}",
692688
ImplTrait => "{{opaque}}",
693689
};

src/librustc/ty/instance.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ impl<'tcx> InstanceDef<'tcx> {
150150
_ => return true
151151
};
152152
match tcx.def_key(def_id).disambiguated_data.data {
153-
DefPathData::StructCtor | DefPathData::VariantCtor |
154-
DefPathData::ClosureExpr => true,
153+
DefPathData::Ctor | DefPathData::ClosureExpr => true,
155154
_ => false
156155
}
157156
}

src/librustc/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2960,8 +2960,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
29602960
} else {
29612961
let def_key = self.def_key(id);
29622962
match def_key.disambiguated_data.data {
2963-
// The name of a `StructCtor` or `VariantCtor` is that of its parent.
2964-
hir_map::DefPathData::StructCtor | hir_map::DefPathData::VariantCtor =>
2963+
// The name of a constructor is that of its parent.
2964+
hir_map::DefPathData::Ctor =>
29652965
self.item_name(DefId {
29662966
krate: id.krate,
29672967
index: def_key.parent.unwrap()

src/librustc/ty/print/pretty.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
285285
let mut cur_def_key = self.tcx().def_key(def_id);
286286
debug!("try_print_visible_def_path: cur_def_key={:?}", cur_def_key);
287287

288-
// For a UnitStruct or TupleStruct we want the name of its parent rather than <unnamed>.
288+
// For a constructor we want the name of its parent rather than <unnamed>.
289289
match cur_def_key.disambiguated_data.data {
290-
DefPathData::StructCtor | DefPathData::VariantCtor => {
290+
DefPathData::Ctor => {
291291
let parent = DefId {
292292
krate: def_id.krate,
293293
index: cur_def_key.parent
294-
.expect("DefPathData::StructCtor/VariantData missing a parent"),
294+
.expect("DefPathData::Ctor/VariantData missing a parent"),
295295
};
296296

297297
cur_def_key = self.tcx().def_key(parent);
@@ -864,8 +864,7 @@ impl TyCtxt<'_, '_, '_> {
864864
DefPathData::AnonConst |
865865
DefPathData::ConstParam(..) |
866866
DefPathData::ClosureExpr |
867-
DefPathData::VariantCtor |
868-
DefPathData::StructCtor => Namespace::ValueNS,
867+
DefPathData::Ctor => Namespace::ValueNS,
869868

870869
DefPathData::MacroDef(..) => Namespace::MacroNS,
871870

@@ -1029,7 +1028,7 @@ impl<F: fmt::Write> Printer<'gcx, 'tcx> for FmtPrinter<'_, 'gcx, 'tcx, F> {
10291028

10301029
// Skip `::{{constructor}}` on tuple/unit structs.
10311030
match disambiguated_data.data {
1032-
DefPathData::StructCtor | DefPathData::VariantCtor => return Ok(self),
1031+
DefPathData::Ctor => return Ok(self),
10331032
_ => {}
10341033
}
10351034

src/librustc/ty/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
549549

550550
/// Returns `true` if this `DefId` refers to the implicit constructor for
551551
/// a tuple struct like `struct Foo(u32)`, and `false` otherwise.
552-
pub fn is_struct_constructor(self, def_id: DefId) -> bool {
553-
self.def_key(def_id).disambiguated_data.data == DefPathData::StructCtor
552+
pub fn is_constructor(self, def_id: DefId) -> bool {
553+
self.def_key(def_id).disambiguated_data.data == DefPathData::Ctor
554554
}
555555

556556
/// Given the `DefId` of a fn or closure, returns the `DefId` of

src/librustc_codegen_utils/symbol_names.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ impl Printer<'tcx, 'tcx> for SymbolPrinter<'_, 'tcx> {
522522

523523
// Skip `::{{constructor}}` on tuple/unit structs.
524524
match disambiguated_data.data {
525-
DefPathData::StructCtor => return Ok(self),
525+
DefPathData::Ctor => return Ok(self),
526526
_ => {}
527527
}
528528

src/librustc_metadata/decoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -947,11 +947,11 @@ impl<'a, 'tcx> CrateMetadata {
947947
return Lrc::new([]);
948948
}
949949

950-
// The attributes for a tuple struct are attached to the definition, not the ctor;
950+
// The attributes for a tuple struct/variant are attached to the definition, not the ctor;
951951
// we assume that someone passing in a tuple struct ctor is actually wanting to
952952
// look at the definition
953953
let def_key = self.def_key(node_id);
954-
let item_id = if def_key.disambiguated_data.data == DefPathData::StructCtor {
954+
let item_id = if def_key.disambiguated_data.data == DefPathData::Ctor {
955955
def_key.parent.unwrap()
956956
} else {
957957
node_id

src/librustc_mir/borrow_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ fn mir_borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> BorrowC
7575
// Return early if we are not supposed to use MIR borrow checker for this function.
7676
return_early = !tcx.has_attr(def_id, "rustc_mir") && !tcx.use_mir_borrowck();
7777

78-
if tcx.is_struct_constructor(def_id) {
79-
// We are not borrow checking the automatically generated struct constructors
78+
if tcx.is_constructor(def_id) {
79+
// We are not borrow checking the automatically generated struct/variant constructors
8080
// because we want to accept structs such as this (taken from the `linked-hash-map`
8181
// crate):
8282
// ```rust

src/librustc_mir/borrow_check/nll/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2685,8 +2685,8 @@ impl MirPass for TypeckMir {
26852685
return;
26862686
}
26872687

2688-
if tcx.is_struct_constructor(def_id) {
2689-
// We just assume that the automatically generated struct constructors are
2688+
if tcx.is_constructor(def_id) {
2689+
// We just assume that the automatically generated struct/variant constructors are
26902690
// correct. See the comment in the `mir_borrowck` implementation for an
26912691
// explanation why we need this.
26922692
return;

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5334,7 +5334,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
53345334
Some(original_span.with_lo(original_span.hi() - BytePos(1)))
53355335
}
53365336

5337-
// Rewrite `SelfCtor` to `StructCtor`
5337+
// Rewrite `SelfCtor` to `Ctor`
53385338
pub fn rewrite_self_ctor(&self, def: Def, span: Span) -> (Def, DefId, Ty<'tcx>) {
53395339
let tcx = self.tcx;
53405340
if let Def::SelfCtor(impl_def_id) = def {

src/test/mir-opt/unusual-item-types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn main() {
7272
// }
7373
// END rustc.ptr-real_drop_in_place.std__vec__Vec_i32_.AddMovesForPackedDrops.before.mir
7474

75-
// START rustc.Test-X-{{variant constructor}}.mir_map.0.mir
75+
// START rustc.Test-X-{{constructor}}.mir_map.0.mir
7676
// fn Test::X(_1: usize) -> Test {
7777
// let mut _0: Test;
7878
//
@@ -81,4 +81,4 @@ fn main() {
8181
// return;
8282
// }
8383
// }
84-
// END rustc.Test-X-{{variant constructor}}.mir_map.0.mir
84+
// END rustc.Test-X-{{constructor}}.mir_map.0.mir

0 commit comments

Comments
 (0)