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;`
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),
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)
// 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,
}
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;
}
(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));
}
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)
}
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
}