]> git.lizzy.rs Git - rust.git/commitdiff
Slightly more uniform treatment of struct and variant constructors
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sun, 24 Mar 2019 12:29:57 +0000 (15:29 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sun, 24 Mar 2019 14:36:43 +0000 (17:36 +0300)
src/librustc/hir/def.rs
src/librustc/ty/mod.rs
src/librustc_mir/hair/cx/expr.rs
src/librustc_resolve/error_reporting.rs
src/librustc_typeck/check/_match.rs
src/librustc_typeck/check/mod.rs

index 87a6065bb75ecf270e18f6e43e340cde3cc4f13a..6567d9e8c7a9d2ff9840edac4bb5feaf30e00b8f 100644 (file)
@@ -37,13 +37,11 @@ pub enum NonMacroAttrKind {
 pub enum Def {
     // Type namespace
     Mod(DefId),
-    /// `DefId` refers to `NodeId` of the struct. `Def::VariantCtor` represents the constructor of
-    /// a struct.
+    /// `DefId` refers to the struct itself, `Def::Ctor` refers to its constructor if it exists.
     Struct(DefId),
     Union(DefId),
     Enum(DefId),
-    /// `DefId` refers to the `NodeId` of the variant. `Def::VariantCtor` represents the
-    /// constructor of an enum variant.
+    /// `DefId` refers to the variant itself, `Def::Ctor` refers to its constructor if it exists.
     Variant(DefId),
     Trait(DefId),
     /// `existential type Foo: Bar;`
@@ -65,7 +63,7 @@ pub enum Def {
     Const(DefId),
     ConstParam(DefId),
     Static(DefId, bool /* is_mutbl */),
-    /// `DefId` refers to `NodeId` of the struct or enum variant's constructor.
+    /// `DefId` refers to the struct or enum variant's constructor.
     Ctor(hir::CtorOf, DefId, CtorKind),
     SelfCtor(DefId /* impl */),  // `DefId` refers to the impl
     Method(DefId),
index 10755a9c0218e798b031bb3428de9f94a9b5631e..3ab3ae0c537bb0732a21b54c99d2b26c4afa3581 100644 (file)
@@ -2322,8 +2322,8 @@ pub fn variant_index_with_ctor_id(&self, cid: DefId) -> VariantIdx {
     pub fn variant_of_def(&self, def: Def) -> &VariantDef {
         match def {
             Def::Variant(vid) => self.variant_with_id(vid),
-            Def::Ctor(hir::CtorOf::Variant, cid, ..) => self.variant_with_ctor_id(cid),
-            Def::Struct(..) | Def::Ctor(..) | Def::Union(..) |
+            Def::Ctor(_, cid, ..) => self.variant_with_ctor_id(cid),
+            Def::Struct(..) | Def::Union(..) |
             Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) |
             Def::SelfCtor(..) => self.non_enum_variant(),
             _ => bug!("unexpected def {:?} in variant_of_def", def)
index 610c63b208cb6500349a39803ad41203da9374c0..27dba512dfb58363c24c33ceeeb4f735a9143a6c 100644 (file)
@@ -261,10 +261,8 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
                     // Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
                     expr_ty.ty_adt_def().and_then(|adt_def| {
                         match path.def {
-                            Def::Ctor(hir::CtorOf::Variant, variant_ctor_id, CtorKind::Fn) => {
-                                Some((adt_def, adt_def.variant_index_with_ctor_id(variant_ctor_id)))
-                            }
-                            Def::Ctor(hir::CtorOf::Struct, _, CtorKind::Fn) |
+                            Def::Ctor(_, ctor_id, CtorKind::Fn) =>
+                                Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id))),
                             Def::SelfCtor(..) => Some((adt_def, VariantIdx::new(0))),
                             _ => None,
                         }
index 6426ca12c6c92eb8684781fcbbb97a8879d335c0..dbd323821949db6a3f3a4535c0c3af3d50bdef1c 100644 (file)
@@ -2,7 +2,7 @@
 
 use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
 use log::debug;
-use rustc::hir::{self, def::*};
+use rustc::hir::def::{Def, CtorKind};
 use rustc::hir::def::Namespace::*;
 use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
 use rustc::session::config::nightly_options;
@@ -417,7 +417,7 @@ fn smart_resolve_context_dependent_help(
             }
             (Def::Union(..), _) |
             (Def::Variant(..), _) |
-            (Def::Ctor(hir::CtorOf::Variant, _, CtorKind::Fictive), _) if ns == ValueNS => {
+            (Def::Ctor(_, _, CtorKind::Fictive), _) if ns == ValueNS => {
                 err.span_label(span, format!("did you mean `{} {{ /* fields */ }}`?",
                                              path_str));
             }
index d56a0dcc0446ca737f3d288c9f453cc93fee8276..5f46a5a165213470d68f15b2f1f9c6fb22d07348 100644 (file)
@@ -807,13 +807,13 @@ fn check_pat_path(
                 report_unexpected_variant_def(tcx, &def, pat.span, qpath);
                 return tcx.types.err;
             }
-            Def::Ctor(hir::CtorOf::Variant, _, CtorKind::Fictive) |
-            Def::Ctor(hir::CtorOf::Variant, _, CtorKind::Fn) => {
+            Def::Ctor(_, _, CtorKind::Fictive) |
+            Def::Ctor(_, _, CtorKind::Fn) => {
                 report_unexpected_variant_def(tcx, &def, pat.span, qpath);
                 return tcx.types.err;
             }
-            Def::Ctor(_, _, CtorKind::Const) | Def::SelfCtor(..) | Def::Const(..) |
-            Def::AssociatedConst(..) => {} // OK
+            Def::Ctor(_, _, CtorKind::Const) | Def::SelfCtor(..) |
+            Def::Const(..) | Def::AssociatedConst(..) => {} // OK
             _ => bug!("unexpected pattern definition: {:?}", def)
         }
 
index b6bfa9ce27bd2a23e3dbf42912732f791ef6f675..e842be0d7e1a5b72efa28eefe8d4d283f1dde5e5 100644 (file)
@@ -4238,7 +4238,7 @@ fn check_expr_kind(
                         self.set_tainted_by_errors();
                         tcx.types.err
                     }
-                    Def::Ctor(hir::CtorOf::Variant, _, CtorKind::Fictive) => {
+                    Def::Ctor(_, _, CtorKind::Fictive) => {
                         report_unexpected_variant_def(tcx, &def, expr.span, qpath);
                         tcx.types.err
                     }