summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-03-24 17:49:58 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-03-24 17:59:18 +0300
commit2cbc25e6fce9bb594ea78ccfd58ef1b6ea42ea38 (patch)
tree96398c53c365693a2e0a0843b957478e22803139
parent5bcf9f4f119b8109c6c642dcfeb63fb39c26950a (diff)
downloadrust-2cbc25e6fce9bb594ea78ccfd58ef1b6ea42ea38.tar.gz
Merge `DefPathData::VariantCtor` and `DefPathData::StructCtor`
-rw-r--r--src/librustc/hir/map/def_collector.rs10
-rw-r--r--src/librustc/hir/map/definitions.rs12
-rw-r--r--src/librustc/ty/instance.rs3
-rw-r--r--src/librustc/ty/mod.rs4
-rw-r--r--src/librustc/ty/print/pretty.rs11
-rw-r--r--src/librustc/ty/util.rs4
-rw-r--r--src/librustc_codegen_utils/symbol_names.rs2
-rw-r--r--src/librustc_metadata/decoder.rs4
-rw-r--r--src/librustc_mir/borrow_check/mod.rs4
-rw-r--r--src/librustc_mir/borrow_check/nll/type_check/mod.rs4
-rw-r--r--src/librustc_typeck/check/mod.rs2
-rw-r--r--src/test/mir-opt/unusual-item-types.rs4
12 files changed, 26 insertions, 38 deletions
diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs
index 2c92d907201..1a3bbc5ecc4 100644
--- a/src/librustc/hir/map/def_collector.rs
+++ b/src/librustc/hir/map/def_collector.rs
@@ -160,10 +160,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
ItemKind::Struct(ref struct_def, _) | ItemKind::Union(ref struct_def, _) => {
// If this is a unit or tuple-like struct, register the constructor.
if let Some(ctor_hir_id) = struct_def.ctor_id() {
- this.create_def(ctor_hir_id,
- DefPathData::StructCtor,
- REGULAR_SPACE,
- i.span);
+ this.create_def(ctor_hir_id, DefPathData::Ctor, REGULAR_SPACE, i.span);
}
}
_ => {}
@@ -199,10 +196,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
v.span);
self.with_parent(def, |this| {
if let Some(ctor_hir_id) = v.node.data.ctor_id() {
- this.create_def(ctor_hir_id,
- DefPathData::VariantCtor,
- REGULAR_SPACE,
- v.span);
+ this.create_def(ctor_hir_id, DefPathData::Ctor, REGULAR_SPACE, v.span);
}
visit::walk_variant(this, v, g, item_id)
});
diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs
index dc23b55c1fc..1006d813e65 100644
--- a/src/librustc/hir/map/definitions.rs
+++ b/src/librustc/hir/map/definitions.rs
@@ -366,10 +366,8 @@ pub enum DefPathData {
EnumVariant(InternedString),
/// A struct field
Field(InternedString),
- /// Implicit ctor for a unit or tuple-like struct
- StructCtor,
- /// Implicit ctor for a unit or tuple-like enum variant
- VariantCtor,
+ /// Implicit ctor for a unit or tuple-like struct or enum variant.
+ Ctor,
/// A constant expression (see {ast,hir}::AnonConst).
AnonConst,
/// An `impl Trait` type node
@@ -654,8 +652,7 @@ impl DefPathData {
CrateRoot |
Misc |
ClosureExpr |
- StructCtor |
- VariantCtor |
+ Ctor |
AnonConst |
ImplTrait => None
}
@@ -686,8 +683,7 @@ impl DefPathData {
Impl => "{{impl}}",
Misc => "{{misc}}",
ClosureExpr => "{{closure}}",
- StructCtor => "{{struct constructor}}",
- VariantCtor => "{{variant constructor}}",
+ Ctor => "{{constructor}}",
AnonConst => "{{constant}}",
ImplTrait => "{{opaque}}",
};
diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs
index 84ce826c6a5..f54e69f352a 100644
--- a/src/librustc/ty/instance.rs
+++ b/src/librustc/ty/instance.rs
@@ -150,8 +150,7 @@ impl<'tcx> InstanceDef<'tcx> {
_ => return true
};
match tcx.def_key(def_id).disambiguated_data.data {
- DefPathData::StructCtor | DefPathData::VariantCtor |
- DefPathData::ClosureExpr => true,
+ DefPathData::Ctor | DefPathData::ClosureExpr => true,
_ => false
}
}
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs
index 3ab3ae0c537..880f75ab9dd 100644
--- a/src/librustc/ty/mod.rs
+++ b/src/librustc/ty/mod.rs
@@ -2960,8 +2960,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
} else {
let def_key = self.def_key(id);
match def_key.disambiguated_data.data {
- // The name of a `StructCtor` or `VariantCtor` is that of its parent.
- hir_map::DefPathData::StructCtor | hir_map::DefPathData::VariantCtor =>
+ // The name of a constructor is that of its parent.
+ hir_map::DefPathData::Ctor =>
self.item_name(DefId {
krate: id.krate,
index: def_key.parent.unwrap()
diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs
index 3d6a2cf9224..c9a4961a8e0 100644
--- a/src/librustc/ty/print/pretty.rs
+++ b/src/librustc/ty/print/pretty.rs
@@ -285,13 +285,13 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
let mut cur_def_key = self.tcx().def_key(def_id);
debug!("try_print_visible_def_path: cur_def_key={:?}", cur_def_key);
- // For a UnitStruct or TupleStruct we want the name of its parent rather than <unnamed>.
+ // For a constructor we want the name of its parent rather than <unnamed>.
match cur_def_key.disambiguated_data.data {
- DefPathData::StructCtor | DefPathData::VariantCtor => {
+ DefPathData::Ctor => {
let parent = DefId {
krate: def_id.krate,
index: cur_def_key.parent
- .expect("DefPathData::StructCtor/VariantData missing a parent"),
+ .expect("DefPathData::Ctor/VariantData missing a parent"),
};
cur_def_key = self.tcx().def_key(parent);
@@ -864,8 +864,7 @@ impl TyCtxt<'_, '_, '_> {
DefPathData::AnonConst |
DefPathData::ConstParam(..) |
DefPathData::ClosureExpr |
- DefPathData::VariantCtor |
- DefPathData::StructCtor => Namespace::ValueNS,
+ DefPathData::Ctor => Namespace::ValueNS,
DefPathData::MacroDef(..) => Namespace::MacroNS,
@@ -1029,7 +1028,7 @@ impl<F: fmt::Write> Printer<'gcx, 'tcx> for FmtPrinter<'_, 'gcx, 'tcx, F> {
// Skip `::{{constructor}}` on tuple/unit structs.
match disambiguated_data.data {
- DefPathData::StructCtor | DefPathData::VariantCtor => return Ok(self),
+ DefPathData::Ctor => return Ok(self),
_ => {}
}
diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs
index 4fb2bfb075c..ccead14e76b 100644
--- a/src/librustc/ty/util.rs
+++ b/src/librustc/ty/util.rs
@@ -549,8 +549,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
/// Returns `true` if this `DefId` refers to the implicit constructor for
/// a tuple struct like `struct Foo(u32)`, and `false` otherwise.
- pub fn is_struct_constructor(self, def_id: DefId) -> bool {
- self.def_key(def_id).disambiguated_data.data == DefPathData::StructCtor
+ pub fn is_constructor(self, def_id: DefId) -> bool {
+ self.def_key(def_id).disambiguated_data.data == DefPathData::Ctor
}
/// Given the `DefId` of a fn or closure, returns the `DefId` of
diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs
index 0fa935199f9..ebd48f0ae1e 100644
--- a/src/librustc_codegen_utils/symbol_names.rs
+++ b/src/librustc_codegen_utils/symbol_names.rs
@@ -522,7 +522,7 @@ impl Printer<'tcx, 'tcx> for SymbolPrinter<'_, 'tcx> {
// Skip `::{{constructor}}` on tuple/unit structs.
match disambiguated_data.data {
- DefPathData::StructCtor => return Ok(self),
+ DefPathData::Ctor => return Ok(self),
_ => {}
}
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs
index c6f7b46d383..0e750cd15ee 100644
--- a/src/librustc_metadata/decoder.rs
+++ b/src/librustc_metadata/decoder.rs
@@ -947,11 +947,11 @@ impl<'a, 'tcx> CrateMetadata {
return Lrc::new([]);
}
- // The attributes for a tuple struct are attached to the definition, not the ctor;
+ // The attributes for a tuple struct/variant are attached to the definition, not the ctor;
// we assume that someone passing in a tuple struct ctor is actually wanting to
// look at the definition
let def_key = self.def_key(node_id);
- let item_id = if def_key.disambiguated_data.data == DefPathData::StructCtor {
+ let item_id = if def_key.disambiguated_data.data == DefPathData::Ctor {
def_key.parent.unwrap()
} else {
node_id
diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs
index c4e371d5afe..5f0892d1d46 100644
--- a/src/librustc_mir/borrow_check/mod.rs
+++ b/src/librustc_mir/borrow_check/mod.rs
@@ -75,8 +75,8 @@ fn mir_borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> BorrowC
// Return early if we are not supposed to use MIR borrow checker for this function.
return_early = !tcx.has_attr(def_id, "rustc_mir") && !tcx.use_mir_borrowck();
- if tcx.is_struct_constructor(def_id) {
- // We are not borrow checking the automatically generated struct constructors
+ if tcx.is_constructor(def_id) {
+ // We are not borrow checking the automatically generated struct/variant constructors
// because we want to accept structs such as this (taken from the `linked-hash-map`
// crate):
// ```rust
diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs
index 25a3160a498..d3d6b986277 100644
--- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs
+++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs
@@ -2685,8 +2685,8 @@ impl MirPass for TypeckMir {
return;
}
- if tcx.is_struct_constructor(def_id) {
- // We just assume that the automatically generated struct constructors are
+ if tcx.is_constructor(def_id) {
+ // We just assume that the automatically generated struct/variant constructors are
// correct. See the comment in the `mir_borrowck` implementation for an
// explanation why we need this.
return;
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index e842be0d7e1..f4f17e1dcc5 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -5334,7 +5334,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
Some(original_span.with_lo(original_span.hi() - BytePos(1)))
}
- // Rewrite `SelfCtor` to `StructCtor`
+ // Rewrite `SelfCtor` to `Ctor`
pub fn rewrite_self_ctor(&self, def: Def, span: Span) -> (Def, DefId, Ty<'tcx>) {
let tcx = self.tcx;
if let Def::SelfCtor(impl_def_id) = def {
diff --git a/src/test/mir-opt/unusual-item-types.rs b/src/test/mir-opt/unusual-item-types.rs
index 29c97ed6d38..606503151c9 100644
--- a/src/test/mir-opt/unusual-item-types.rs
+++ b/src/test/mir-opt/unusual-item-types.rs
@@ -72,7 +72,7 @@ fn main() {
// }
// END rustc.ptr-real_drop_in_place.std__vec__Vec_i32_.AddMovesForPackedDrops.before.mir
-// START rustc.Test-X-{{variant constructor}}.mir_map.0.mir
+// START rustc.Test-X-{{constructor}}.mir_map.0.mir
// fn Test::X(_1: usize) -> Test {
// let mut _0: Test;
//
@@ -81,4 +81,4 @@ fn main() {
// return;
// }
// }
-// END rustc.Test-X-{{variant constructor}}.mir_map.0.mir
+// END rustc.Test-X-{{constructor}}.mir_map.0.mir