Skip to content

Commit 5bcf9f4

Browse files
committed
Slightly more uniform treatment of struct and variant constructors
1 parent 7f5a8dc commit 5bcf9f4

File tree

6 files changed

+14
-18
lines changed

6 files changed

+14
-18
lines changed

src/librustc/hir/def.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@ pub enum NonMacroAttrKind {
3737
pub enum Def {
3838
// Type namespace
3939
Mod(DefId),
40-
/// `DefId` refers to `NodeId` of the struct. `Def::VariantCtor` represents the constructor of
41-
/// a struct.
40+
/// `DefId` refers to the struct itself, `Def::Ctor` refers to its constructor if it exists.
4241
Struct(DefId),
4342
Union(DefId),
4443
Enum(DefId),
45-
/// `DefId` refers to the `NodeId` of the variant. `Def::VariantCtor` represents the
46-
/// constructor of an enum variant.
44+
/// `DefId` refers to the variant itself, `Def::Ctor` refers to its constructor if it exists.
4745
Variant(DefId),
4846
Trait(DefId),
4947
/// `existential type Foo: Bar;`
@@ -65,7 +63,7 @@ pub enum Def {
6563
Const(DefId),
6664
ConstParam(DefId),
6765
Static(DefId, bool /* is_mutbl */),
68-
/// `DefId` refers to `NodeId` of the struct or enum variant's constructor.
66+
/// `DefId` refers to the struct or enum variant's constructor.
6967
Ctor(hir::CtorOf, DefId, CtorKind),
7068
SelfCtor(DefId /* impl */), // `DefId` refers to the impl
7169
Method(DefId),

src/librustc/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2322,8 +2322,8 @@ impl<'a, 'gcx, 'tcx> AdtDef {
23222322
pub fn variant_of_def(&self, def: Def) -> &VariantDef {
23232323
match def {
23242324
Def::Variant(vid) => self.variant_with_id(vid),
2325-
Def::Ctor(hir::CtorOf::Variant, cid, ..) => self.variant_with_ctor_id(cid),
2326-
Def::Struct(..) | Def::Ctor(..) | Def::Union(..) |
2325+
Def::Ctor(_, cid, ..) => self.variant_with_ctor_id(cid),
2326+
Def::Struct(..) | Def::Union(..) |
23272327
Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) |
23282328
Def::SelfCtor(..) => self.non_enum_variant(),
23292329
_ => bug!("unexpected def {:?} in variant_of_def", def)

src/librustc_mir/hair/cx/expr.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,8 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
261261
// Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
262262
expr_ty.ty_adt_def().and_then(|adt_def| {
263263
match path.def {
264-
Def::Ctor(hir::CtorOf::Variant, variant_ctor_id, CtorKind::Fn) => {
265-
Some((adt_def, adt_def.variant_index_with_ctor_id(variant_ctor_id)))
266-
}
267-
Def::Ctor(hir::CtorOf::Struct, _, CtorKind::Fn) |
264+
Def::Ctor(_, ctor_id, CtorKind::Fn) =>
265+
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id))),
268266
Def::SelfCtor(..) => Some((adt_def, VariantIdx::new(0))),
269267
_ => None,
270268
}

src/librustc_resolve/error_reporting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::cmp::Reverse;
22

33
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
44
use log::debug;
5-
use rustc::hir::{self, def::*};
5+
use rustc::hir::def::{Def, CtorKind};
66
use rustc::hir::def::Namespace::*;
77
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
88
use rustc::session::config::nightly_options;
@@ -417,7 +417,7 @@ impl<'a> Resolver<'a> {
417417
}
418418
(Def::Union(..), _) |
419419
(Def::Variant(..), _) |
420-
(Def::Ctor(hir::CtorOf::Variant, _, CtorKind::Fictive), _) if ns == ValueNS => {
420+
(Def::Ctor(_, _, CtorKind::Fictive), _) if ns == ValueNS => {
421421
err.span_label(span, format!("did you mean `{} {{ /* fields */ }}`?",
422422
path_str));
423423
}

src/librustc_typeck/check/_match.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -807,13 +807,13 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
807807
report_unexpected_variant_def(tcx, &def, pat.span, qpath);
808808
return tcx.types.err;
809809
}
810-
Def::Ctor(hir::CtorOf::Variant, _, CtorKind::Fictive) |
811-
Def::Ctor(hir::CtorOf::Variant, _, CtorKind::Fn) => {
810+
Def::Ctor(_, _, CtorKind::Fictive) |
811+
Def::Ctor(_, _, CtorKind::Fn) => {
812812
report_unexpected_variant_def(tcx, &def, pat.span, qpath);
813813
return tcx.types.err;
814814
}
815-
Def::Ctor(_, _, CtorKind::Const) | Def::SelfCtor(..) | Def::Const(..) |
816-
Def::AssociatedConst(..) => {} // OK
815+
Def::Ctor(_, _, CtorKind::Const) | Def::SelfCtor(..) |
816+
Def::Const(..) | Def::AssociatedConst(..) => {} // OK
817817
_ => bug!("unexpected pattern definition: {:?}", def)
818818
}
819819

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4238,7 +4238,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
42384238
self.set_tainted_by_errors();
42394239
tcx.types.err
42404240
}
4241-
Def::Ctor(hir::CtorOf::Variant, _, CtorKind::Fictive) => {
4241+
Def::Ctor(_, _, CtorKind::Fictive) => {
42424242
report_unexpected_variant_def(tcx, &def, expr.span, qpath);
42434243
tcx.types.err
42444244
}

0 commit comments

Comments
 (0)