diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-03-24 17:49:58 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-03-24 17:59:18 +0300 |
| commit | 2cbc25e6fce9bb594ea78ccfd58ef1b6ea42ea38 (patch) | |
| tree | 96398c53c365693a2e0a0843b957478e22803139 /src/librustc | |
| parent | 5bcf9f4f119b8109c6c642dcfeb63fb39c26950a (diff) | |
Merge `DefPathData::VariantCtor` and `DefPathData::StructCtor`
Diffstat (limited to 'src/librustc')
| -rw-r--r-- | src/librustc/hir/map/def_collector.rs | 10 | ||||
| -rw-r--r-- | src/librustc/hir/map/definitions.rs | 12 | ||||
| -rw-r--r-- | src/librustc/ty/instance.rs | 3 | ||||
| -rw-r--r-- | src/librustc/ty/mod.rs | 4 | ||||
| -rw-r--r-- | src/librustc/ty/print/pretty.rs | 11 | ||||
| -rw-r--r-- | src/librustc/ty/util.rs | 4 |
6 files changed, 16 insertions, 28 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 |
