Refactor definitions of ADTs in rustc::middle::def
This commit is contained in:
parent
c4c9628de7
commit
ceaaa1bc33
@ -610,11 +610,11 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
|
||||
hir::ExprPath(..) => {
|
||||
let def = v.tcx.def_map.borrow().get(&e.id).map(|d| d.full_def());
|
||||
match def {
|
||||
Some(def::DefVariant(_, _, _)) => {
|
||||
Some(def::DefVariant(..)) => {
|
||||
// Count the discriminator or function pointer.
|
||||
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
|
||||
}
|
||||
Some(def::DefStruct(_)) => {
|
||||
Some(def::DefStruct(..)) => {
|
||||
if let ty::TyBareFn(..) = node_ty.sty {
|
||||
// Count the function pointer.
|
||||
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
|
||||
@ -678,7 +678,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
|
||||
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
|
||||
true
|
||||
}
|
||||
Some(def::DefFn(did, _)) => {
|
||||
Some(def::DefFn(did)) => {
|
||||
v.handle_const_fn_call(e, did, node_ty)
|
||||
}
|
||||
Some(def::DefMethod(did)) => {
|
||||
|
@ -760,8 +760,8 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
|
||||
Some(DefConst(..)) | Some(DefAssociatedConst(..)) =>
|
||||
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
|
||||
been rewritten"),
|
||||
Some(DefStruct(_)) => vec!(Single),
|
||||
Some(DefVariant(_, id, _)) => vec!(Variant(id)),
|
||||
Some(DefStruct(..)) => vec!(Single),
|
||||
Some(DefVariant(_, id)) => vec!(Variant(id)),
|
||||
_ => vec!()
|
||||
},
|
||||
hir::PatEnum(..) =>
|
||||
@ -769,7 +769,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
|
||||
Some(DefConst(..)) | Some(DefAssociatedConst(..)) =>
|
||||
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
|
||||
been rewritten"),
|
||||
Some(DefVariant(_, id, _)) => vec!(Variant(id)),
|
||||
Some(DefVariant(_, id)) => vec!(Variant(id)),
|
||||
_ => vec!(Single)
|
||||
},
|
||||
hir::PatQPath(..) =>
|
||||
@ -780,7 +780,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
|
||||
Some(DefConst(..)) | Some(DefAssociatedConst(..)) =>
|
||||
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
|
||||
been rewritten"),
|
||||
Some(DefVariant(_, id, _)) => vec!(Variant(id)),
|
||||
Some(DefVariant(_, id)) => vec!(Variant(id)),
|
||||
_ => vec!(Single)
|
||||
},
|
||||
hir::PatLit(ref expr) =>
|
||||
@ -872,7 +872,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
||||
Some(DefConst(..)) | Some(DefAssociatedConst(..)) =>
|
||||
cx.tcx.sess.span_bug(pat_span, "const pattern should've \
|
||||
been rewritten"),
|
||||
Some(DefVariant(_, id, _)) => if *constructor == Variant(id) {
|
||||
Some(DefVariant(_, id)) => if *constructor == Variant(id) {
|
||||
Some(vec!())
|
||||
} else {
|
||||
None
|
||||
@ -887,7 +887,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
||||
DefConst(..) | DefAssociatedConst(..) =>
|
||||
cx.tcx.sess.span_bug(pat_span, "const pattern should've \
|
||||
been rewritten"),
|
||||
DefVariant(_, id, _) if *constructor != Variant(id) => None,
|
||||
DefVariant(_, id) if *constructor != Variant(id) => None,
|
||||
DefVariant(..) | DefStruct(..) => {
|
||||
Some(match args {
|
||||
&Some(ref args) => args.iter().map(|p| &**p).collect(),
|
||||
|
@ -263,7 +263,7 @@ fn visit_expr(&mut self, e: &'ast hir::Expr) {
|
||||
// affect the specific variant used, but we need to check
|
||||
// the whole enum definition to see what expression that
|
||||
// might be (if any).
|
||||
Some(DefVariant(enum_id, variant_id, false)) => {
|
||||
Some(DefVariant(enum_id, variant_id)) => {
|
||||
if let Some(enum_node_id) = self.ast_map.as_local_node_id(enum_id) {
|
||||
if let hir::ItemEnum(ref enum_def, ref generics) =
|
||||
self.ast_map.expect_item(enum_node_id).node
|
||||
|
@ -332,7 +332,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<hir::Pat>
|
||||
}
|
||||
let path = match def.full_def() {
|
||||
def::DefStruct(def_id) => def_to_path(tcx, def_id),
|
||||
def::DefVariant(_, variant_did, _) => def_to_path(tcx, variant_did),
|
||||
def::DefVariant(_, variant_did) => def_to_path(tcx, variant_did),
|
||||
def::DefFn(..) => return P(hir::Pat {
|
||||
id: expr.id,
|
||||
node: hir::PatLit(P(expr.clone())),
|
||||
@ -1052,10 +1052,10 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
|
||||
(lookup_const_by_id(tcx, def_id, Some(e.id), None), None)
|
||||
}
|
||||
}
|
||||
Some(def::DefVariant(enum_def, variant_def, _)) => {
|
||||
Some(def::DefVariant(enum_def, variant_def)) => {
|
||||
(lookup_variant_by_id(tcx, enum_def, variant_def), None)
|
||||
}
|
||||
Some(def::DefStruct(_)) => {
|
||||
Some(def::DefStruct(..)) => {
|
||||
return Ok(ConstVal::Struct(e.id))
|
||||
}
|
||||
Some(def::DefLocal(_, id)) => {
|
||||
@ -1066,7 +1066,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
|
||||
(None, None)
|
||||
}
|
||||
},
|
||||
Some(def::DefMethod(id)) | Some(def::DefFn(id, _)) => return Ok(Function(id)),
|
||||
Some(def::DefMethod(id)) | Some(def::DefFn(id)) => return Ok(Function(id)),
|
||||
_ => (None, None)
|
||||
};
|
||||
let const_expr = match const_expr {
|
||||
|
@ -26,7 +26,7 @@
|
||||
use front::map as hir_map;
|
||||
use middle::def;
|
||||
use middle::lang_items;
|
||||
use middle::ty::{self, Ty};
|
||||
use middle::ty::{self, Ty, VariantKind};
|
||||
use middle::def_id::{DefId, DefIndex};
|
||||
use mir::repr::Mir;
|
||||
use session::Session;
|
||||
@ -211,6 +211,8 @@ fn crate_struct_field_attrs(&self, cnum: ast::CrateNum)
|
||||
|
||||
// resolve
|
||||
fn def_path(&self, def: DefId) -> hir_map::DefPath;
|
||||
fn variant_kind(&self, def_id: DefId) -> Option<VariantKind>;
|
||||
fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option<DefId>;
|
||||
fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option<DefId>;
|
||||
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name>;
|
||||
fn item_children(&self, did: DefId) -> Vec<ChildItem>;
|
||||
@ -380,6 +382,9 @@ fn reachable_ids(&self, cnum: ast::CrateNum) -> Vec<DefId> { unimplemented!() }
|
||||
|
||||
// resolve
|
||||
fn def_path(&self, def: DefId) -> hir_map::DefPath { unimplemented!() }
|
||||
fn variant_kind(&self, def_id: DefId) -> Option<VariantKind> { unimplemented!() }
|
||||
fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option<DefId>
|
||||
{ unimplemented!() }
|
||||
fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option<DefId>
|
||||
{ unimplemented!() }
|
||||
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name> { unimplemented!() }
|
||||
|
@ -100,7 +100,7 @@ fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) {
|
||||
_ if self.ignore_non_const_paths => (),
|
||||
def::DefPrimTy(_) => (),
|
||||
def::DefSelfTy(..) => (),
|
||||
def::DefVariant(enum_id, variant_id, _) => {
|
||||
def::DefVariant(enum_id, variant_id) => {
|
||||
self.check_def_id(enum_id);
|
||||
if !self.ignore_variant_stack.contains(&variant_id) {
|
||||
self.check_def_id(variant_id);
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub enum Def {
|
||||
DefFn(DefId, bool /* is_ctor */),
|
||||
DefFn(DefId),
|
||||
DefSelfTy(Option<DefId>, // trait id
|
||||
Option<(ast::NodeId, ast::NodeId)>), // (impl id, self type id)
|
||||
DefMod(DefId),
|
||||
@ -29,8 +29,9 @@ pub enum Def {
|
||||
DefAssociatedConst(DefId),
|
||||
DefLocal(DefId, // def id of variable
|
||||
ast::NodeId), // node id of variable
|
||||
DefVariant(DefId /* enum */, DefId /* variant */, bool /* is_structure */),
|
||||
DefTy(DefId, bool /* is_enum */),
|
||||
DefVariant(DefId /* enum */, DefId /* variant */),
|
||||
DefEnum(DefId),
|
||||
DefTyAlias(DefId),
|
||||
DefAssociatedTy(DefId /* trait */, DefId),
|
||||
DefTrait(DefId),
|
||||
DefPrimTy(hir::PrimTy),
|
||||
@ -40,14 +41,10 @@ pub enum Def {
|
||||
usize, // index in the freevars list of the closure
|
||||
ast::NodeId), // expr node that creates the closure
|
||||
|
||||
/// Note that if it's a tuple struct's definition, the node id of the DefId
|
||||
/// may either refer to the item definition's id or the VariantData.ctor_id.
|
||||
///
|
||||
/// The cases that I have encountered so far are (this is not exhaustive):
|
||||
/// - If it's a ty_path referring to some tuple struct, then DefMap maps
|
||||
/// it to a def whose id is the item definition's id.
|
||||
/// - If it's an ExprPath referring to some tuple struct, then DefMap maps
|
||||
/// it to a def whose id is the VariantData.ctor_id.
|
||||
// If DefStruct lives in type namespace it denotes a struct item and its DefId refers
|
||||
// to NodeId of the struct itself.
|
||||
// If DefStruct lives in value namespace (e.g. tuple struct, unit struct expressions)
|
||||
// it denotes a constructor and its DefId refers to NodeId of the struct's constructor.
|
||||
DefStruct(DefId),
|
||||
DefLabel(ast::NodeId),
|
||||
DefMethod(DefId),
|
||||
@ -121,7 +118,7 @@ pub fn var_id(&self) -> ast::NodeId {
|
||||
}
|
||||
|
||||
DefFn(..) | DefMod(..) | DefForeignMod(..) | DefStatic(..) |
|
||||
DefVariant(..) | DefTy(..) | DefAssociatedTy(..) |
|
||||
DefVariant(..) | DefEnum(..) | DefTyAlias(..) | DefAssociatedTy(..) |
|
||||
DefTyParam(..) | DefStruct(..) | DefTrait(..) |
|
||||
DefMethod(..) | DefConst(..) | DefAssociatedConst(..) |
|
||||
DefPrimTy(..) | DefLabel(..) | DefSelfTy(..) | DefErr => {
|
||||
@ -132,8 +129,8 @@ pub fn var_id(&self) -> ast::NodeId {
|
||||
|
||||
pub fn def_id(&self) -> DefId {
|
||||
match *self {
|
||||
DefFn(id, _) | DefMod(id) | DefForeignMod(id) | DefStatic(id, _) |
|
||||
DefVariant(_, id, _) | DefTy(id, _) | DefAssociatedTy(_, id) |
|
||||
DefFn(id) | DefMod(id) | DefForeignMod(id) | DefStatic(id, _) |
|
||||
DefVariant(_, id) | DefEnum(id) | DefTyAlias(id) | DefAssociatedTy(_, id) |
|
||||
DefTyParam(_, _, id, _) | DefStruct(id) | DefTrait(id) |
|
||||
DefMethod(id) | DefConst(id) | DefAssociatedConst(id) |
|
||||
DefLocal(id, _) | DefUpvar(id, _, _, _) => {
|
||||
@ -151,7 +148,7 @@ pub fn def_id(&self) -> DefId {
|
||||
|
||||
pub fn variant_def_ids(&self) -> Option<(DefId, DefId)> {
|
||||
match *self {
|
||||
DefVariant(enum_id, var_id, _) => {
|
||||
DefVariant(enum_id, var_id) => {
|
||||
Some((enum_id, var_id))
|
||||
}
|
||||
_ => None
|
||||
|
@ -1077,7 +1077,7 @@ fn walk_pat(&mut self,
|
||||
// struct or enum pattern.
|
||||
}
|
||||
|
||||
Some(def::DefVariant(enum_did, variant_did, _is_struct)) => {
|
||||
Some(def::DefVariant(enum_did, variant_did)) => {
|
||||
let downcast_cmt =
|
||||
if tcx.lookup_adt_def(enum_did).is_univariant() {
|
||||
cmt_pat
|
||||
@ -1093,7 +1093,7 @@ fn walk_pat(&mut self,
|
||||
delegate.matched_pat(pat, downcast_cmt, match_mode);
|
||||
}
|
||||
|
||||
Some(def::DefStruct(..)) | Some(def::DefTy(_, false)) => {
|
||||
Some(def::DefStruct(..)) | Some(def::DefTyAlias(..)) => {
|
||||
// A struct (in either the value or type
|
||||
// namespace; we encounter the former on
|
||||
// e.g. patterns for unit structs).
|
||||
@ -1113,19 +1113,8 @@ fn walk_pat(&mut self,
|
||||
// `matched_pat` call.
|
||||
}
|
||||
|
||||
Some(def @ def::DefTy(_, true)) => {
|
||||
// An enum's type -- should never be in a
|
||||
// pattern.
|
||||
|
||||
if !tcx.sess.has_errors() {
|
||||
let msg = format!("Pattern has unexpected type: {:?} and type {:?}",
|
||||
def,
|
||||
cmt_pat.ty);
|
||||
tcx.sess.span_bug(pat.span, &msg)
|
||||
}
|
||||
}
|
||||
|
||||
Some(def) => {
|
||||
// An enum type should never be in a pattern.
|
||||
// Remaining cases are e.g. DefFn, to
|
||||
// which identifiers within patterns
|
||||
// should not resolve. However, we do
|
||||
|
@ -1404,7 +1404,7 @@ fn rebuild_arg_ty_or_output(&self,
|
||||
Some(d) => d.full_def()
|
||||
};
|
||||
match a_def {
|
||||
def::DefTy(did, _) | def::DefStruct(did) => {
|
||||
def::DefEnum(did) | def::DefTyAlias(did) | def::DefStruct(did) => {
|
||||
let generics = self.tcx.lookup_item_type(did).generics;
|
||||
|
||||
let expected =
|
||||
@ -1452,7 +1452,6 @@ fn rebuild_arg_ty_or_output(&self,
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
hir::TyPtr(ref mut_ty) => {
|
||||
|
@ -235,7 +235,7 @@ fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v hir::FnDecl,
|
||||
fn visit_expr(&mut self, expr: &hir::Expr) {
|
||||
if let hir::ExprPath(..) = expr.node {
|
||||
match self.tcx.resolve_expr(expr) {
|
||||
DefFn(did, _) if self.def_id_is_transmute(did) => {
|
||||
DefFn(did) if self.def_id_is_transmute(did) => {
|
||||
let typ = self.tcx.node_id_to_type(expr.id);
|
||||
match typ.sty {
|
||||
TyBareFn(_, ref bare_fn_ty) if bare_fn_ty.abi == RustIntrinsic => {
|
||||
|
@ -552,19 +552,14 @@ pub fn cat_def(&self,
|
||||
def::DefAssociatedConst(..) | def::DefFn(..) | def::DefMethod(..) => {
|
||||
Ok(self.cat_rvalue_node(id, span, expr_ty))
|
||||
}
|
||||
|
||||
def::DefMod(_) | def::DefForeignMod(_) |
|
||||
def::DefTrait(_) | def::DefTy(..) | def::DefPrimTy(_) |
|
||||
def::DefTrait(_) | def::DefEnum(..) | def::DefTyAlias(..) | def::DefPrimTy(_) |
|
||||
def::DefTyParam(..) |
|
||||
def::DefLabel(_) | def::DefSelfTy(..) |
|
||||
def::DefAssociatedTy(..) => {
|
||||
Ok(Rc::new(cmt_ {
|
||||
id:id,
|
||||
span:span,
|
||||
cat:Categorization::StaticItem,
|
||||
mutbl: McImmutable,
|
||||
ty:expr_ty,
|
||||
note: NoteNone
|
||||
}))
|
||||
self.tcx().sess.span_bug(span, &format!("Unexpected definition in \
|
||||
memory categorization: {:?}", def));
|
||||
}
|
||||
|
||||
def::DefStatic(_, mutbl) => {
|
||||
@ -1218,7 +1213,7 @@ fn cat_pattern_<F>(&self, cmt: cmt<'tcx>, pat: &hir::Pat, op: &mut F)
|
||||
// alone) because struct patterns can refer to struct types or
|
||||
// to struct variants within enums.
|
||||
let cmt = match opt_def {
|
||||
Some(def::DefVariant(enum_did, variant_did, _))
|
||||
Some(def::DefVariant(enum_did, variant_did))
|
||||
// univariant enums do not need downcasts
|
||||
if !self.tcx().lookup_adt_def(enum_did).is_univariant() => {
|
||||
self.cat_downcast(pat, cmt.clone(), cmt.ty, variant_did)
|
||||
|
@ -228,7 +228,7 @@ pub fn necessary_variants(dm: &DefMap, pat: &hir::Pat) -> Vec<DefId> {
|
||||
hir::PatIdent(_, _, None) |
|
||||
hir::PatStruct(..) => {
|
||||
match dm.get(&p.id) {
|
||||
Some(&PathResolution { base_def: DefVariant(_, id, _), .. }) => {
|
||||
Some(&PathResolution { base_def: DefVariant(_, id), .. }) => {
|
||||
variants.push(id);
|
||||
}
|
||||
_ => ()
|
||||
|
@ -1429,9 +1429,19 @@ fn decode<D: Decoder>(d: &mut D) -> Result<AdtDef<'tcx>, D::Error> {
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum AdtKind { Struct, Enum }
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
|
||||
pub enum VariantKind { Struct, Tuple, Unit }
|
||||
|
||||
impl VariantKind {
|
||||
pub fn from_variant_data(vdata: &hir::VariantData) -> Self {
|
||||
match *vdata {
|
||||
hir::VariantData::Struct(..) => VariantKind::Struct,
|
||||
hir::VariantData::Tuple(..) => VariantKind::Tuple,
|
||||
hir::VariantData::Unit(..) => VariantKind::Unit,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, 'container> AdtDefData<'tcx, 'container> {
|
||||
fn new(tcx: &ctxt<'tcx>,
|
||||
did: DefId,
|
||||
@ -1577,8 +1587,8 @@ pub fn variant_index_with_id(&self, vid: DefId) -> usize {
|
||||
|
||||
pub fn variant_of_def(&self, def: def::Def) -> &VariantDefData<'tcx, 'container> {
|
||||
match def {
|
||||
def::DefVariant(_, vid, _) => self.variant_with_id(vid),
|
||||
def::DefStruct(..) | def::DefTy(..) => self.struct_variant(),
|
||||
def::DefVariant(_, vid) => self.variant_with_id(vid),
|
||||
def::DefStruct(..) | def::DefTyAlias(..) => self.struct_variant(),
|
||||
_ => panic!("unexpected def {:?} in variant_of_def", def)
|
||||
}
|
||||
}
|
||||
|
@ -1060,7 +1060,7 @@ fn get_transmute_from_to<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr)
|
||||
hir::ExprPath(..) => (),
|
||||
_ => return None
|
||||
}
|
||||
if let def::DefFn(did, _) = cx.tcx.resolve_expr(expr) {
|
||||
if let def::DefFn(did) = cx.tcx.resolve_expr(expr) {
|
||||
if !def_id_is_transmute(cx, did) {
|
||||
return None;
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ fn decode_def(dcx: &DecodeContext, dsr: &mut reader::Decoder) -> def::Def {
|
||||
impl tr for def::Def {
|
||||
fn tr(&self, dcx: &DecodeContext) -> def::Def {
|
||||
match *self {
|
||||
def::DefFn(did, is_ctor) => def::DefFn(did.tr(dcx), is_ctor),
|
||||
def::DefFn(did) => def::DefFn(did.tr(dcx)),
|
||||
def::DefMethod(did) => def::DefMethod(did.tr(dcx)),
|
||||
def::DefSelfTy(opt_did, impl_ids) => { def::DefSelfTy(opt_did.map(|did| did.tr(dcx)),
|
||||
impl_ids.map(|(nid1, nid2)| {
|
||||
@ -393,11 +393,10 @@ fn tr(&self, dcx: &DecodeContext) -> def::Def {
|
||||
let did = dcx.tcx.map.local_def_id(nid);
|
||||
def::DefLocal(did, nid)
|
||||
}
|
||||
def::DefVariant(e_did, v_did, is_s) => {
|
||||
def::DefVariant(e_did.tr(dcx), v_did.tr(dcx), is_s)
|
||||
},
|
||||
def::DefVariant(e_did, v_did) => def::DefVariant(e_did.tr(dcx), v_did.tr(dcx)),
|
||||
def::DefTrait(did) => def::DefTrait(did.tr(dcx)),
|
||||
def::DefTy(did, is_enum) => def::DefTy(did.tr(dcx), is_enum),
|
||||
def::DefEnum(did) => def::DefEnum(did.tr(dcx)),
|
||||
def::DefTyAlias(did) => def::DefTyAlias(did.tr(dcx)),
|
||||
def::DefAssociatedTy(trait_did, did) =>
|
||||
def::DefAssociatedTy(trait_did.tr(dcx), did.tr(dcx)),
|
||||
def::DefPrimTy(p) => def::DefPrimTy(p),
|
||||
|
@ -18,7 +18,7 @@
|
||||
use middle::cstore::{NativeLibraryKind, LinkMeta, LinkagePreference};
|
||||
use middle::def;
|
||||
use middle::lang_items;
|
||||
use middle::ty::{self, Ty};
|
||||
use middle::ty::{self, Ty, VariantKind};
|
||||
use middle::def_id::{DefId, DefIndex};
|
||||
|
||||
use rustc::front::map as hir_map;
|
||||
@ -377,6 +377,17 @@ fn def_path(&self, def: DefId) -> hir_map::DefPath
|
||||
local_path.into_iter().chain(path).collect()
|
||||
}
|
||||
|
||||
fn variant_kind(&self, def_id: DefId) -> Option<VariantKind> {
|
||||
let cdata = self.get_crate_data(def_id.krate);
|
||||
decoder::get_variant_kind(&cdata, def_id.index)
|
||||
}
|
||||
|
||||
fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option<DefId>
|
||||
{
|
||||
let cdata = self.get_crate_data(struct_def_id.krate);
|
||||
decoder::get_struct_ctor_def_id(&cdata, struct_def_id.index)
|
||||
}
|
||||
|
||||
fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option<DefId>
|
||||
{
|
||||
let cdata = self.get_crate_data(did.krate);
|
||||
|
@ -33,7 +33,7 @@
|
||||
use middle::lang_items;
|
||||
use middle::subst;
|
||||
use middle::ty::{ImplContainer, TraitContainer};
|
||||
use middle::ty::{self, Ty, TypeFoldable};
|
||||
use middle::ty::{self, Ty, TypeFoldable, VariantKind};
|
||||
|
||||
use rustc::mir;
|
||||
use rustc::mir::visit::MutVisitor;
|
||||
@ -89,27 +89,22 @@ pub fn load_xrefs(data: &[u8]) -> index::DenseIndex {
|
||||
index::DenseIndex::from_buf(index.data, index.start, index.end)
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
enum Family {
|
||||
ImmStatic, // c
|
||||
MutStatic, // b
|
||||
Fn, // f
|
||||
CtorFn, // o
|
||||
StaticMethod, // F
|
||||
Method, // h
|
||||
Type, // y
|
||||
Mod, // m
|
||||
ForeignMod, // n
|
||||
Enum, // t
|
||||
StructVariant, // V
|
||||
TupleVariant, // v
|
||||
UnitVariant, // w
|
||||
Variant(VariantKind), // V, v, w
|
||||
Impl, // i
|
||||
DefaultImpl, // d
|
||||
Trait, // I
|
||||
Struct, // S
|
||||
TupleStruct, // s
|
||||
UnitStruct, // u
|
||||
Struct(VariantKind), // S, s, u
|
||||
PublicField, // g
|
||||
InheritedField, // N
|
||||
Constant, // C
|
||||
@ -122,22 +117,21 @@ fn item_family(item: rbml::Doc) -> Family {
|
||||
'c' => ImmStatic,
|
||||
'b' => MutStatic,
|
||||
'f' => Fn,
|
||||
'o' => CtorFn,
|
||||
'F' => StaticMethod,
|
||||
'h' => Method,
|
||||
'y' => Type,
|
||||
'm' => Mod,
|
||||
'n' => ForeignMod,
|
||||
't' => Enum,
|
||||
'V' => StructVariant,
|
||||
'v' => TupleVariant,
|
||||
'w' => UnitVariant,
|
||||
'V' => Variant(VariantKind::Struct),
|
||||
'v' => Variant(VariantKind::Tuple),
|
||||
'w' => Variant(VariantKind::Unit),
|
||||
'i' => Impl,
|
||||
'd' => DefaultImpl,
|
||||
'I' => Trait,
|
||||
'S' => Struct,
|
||||
's' => TupleStruct,
|
||||
'u' => UnitStruct,
|
||||
'S' => Struct(VariantKind::Struct),
|
||||
's' => Struct(VariantKind::Tuple),
|
||||
'u' => Struct(VariantKind::Unit),
|
||||
'g' => PublicField,
|
||||
'N' => InheritedField,
|
||||
c => panic!("unexpected family char: {}", c)
|
||||
@ -271,6 +265,18 @@ fn item_name(intr: &IdentInterner, item: rbml::Doc) -> ast::Name {
|
||||
}
|
||||
}
|
||||
|
||||
fn family_to_variant_kind<'tcx>(family: Family) -> Option<ty::VariantKind> {
|
||||
match family {
|
||||
Struct(VariantKind::Struct) | Variant(VariantKind::Struct) =>
|
||||
Some(ty::VariantKind::Struct),
|
||||
Struct(VariantKind::Tuple) | Variant(VariantKind::Tuple) =>
|
||||
Some(ty::VariantKind::Tuple),
|
||||
Struct(VariantKind::Unit) | Variant(VariantKind::Unit) =>
|
||||
Some(ty::VariantKind::Unit),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn item_to_def_like(cdata: Cmd, item: rbml::Doc, did: DefId) -> DefLike {
|
||||
let fam = item_family(item);
|
||||
match fam {
|
||||
@ -288,9 +294,8 @@ fn item_to_def_like(cdata: Cmd, item: rbml::Doc, did: DefId) -> DefLike {
|
||||
}
|
||||
ImmStatic => DlDef(def::DefStatic(did, false)),
|
||||
MutStatic => DlDef(def::DefStatic(did, true)),
|
||||
Struct | TupleStruct | UnitStruct => DlDef(def::DefStruct(did)),
|
||||
Fn => DlDef(def::DefFn(did, false)),
|
||||
CtorFn => DlDef(def::DefFn(did, true)),
|
||||
Struct(..) => DlDef(def::DefStruct(did)),
|
||||
Fn => DlDef(def::DefFn(did)),
|
||||
Method | StaticMethod => {
|
||||
DlDef(def::DefMethod(did))
|
||||
}
|
||||
@ -299,21 +304,17 @@ fn item_to_def_like(cdata: Cmd, item: rbml::Doc, did: DefId) -> DefLike {
|
||||
let trait_did = item_require_parent_item(cdata, item);
|
||||
DlDef(def::DefAssociatedTy(trait_did, did))
|
||||
} else {
|
||||
DlDef(def::DefTy(did, false))
|
||||
DlDef(def::DefTyAlias(did))
|
||||
}
|
||||
}
|
||||
Mod => DlDef(def::DefMod(did)),
|
||||
ForeignMod => DlDef(def::DefForeignMod(did)),
|
||||
StructVariant => {
|
||||
Variant(..) => {
|
||||
let enum_did = item_require_parent_item(cdata, item);
|
||||
DlDef(def::DefVariant(enum_did, did, true))
|
||||
}
|
||||
TupleVariant | UnitVariant => {
|
||||
let enum_did = item_require_parent_item(cdata, item);
|
||||
DlDef(def::DefVariant(enum_did, did, false))
|
||||
DlDef(def::DefVariant(enum_did, did))
|
||||
}
|
||||
Trait => DlDef(def::DefTrait(did)),
|
||||
Enum => DlDef(def::DefTy(did, true)),
|
||||
Enum => DlDef(def::DefEnum(did)),
|
||||
Impl | DefaultImpl => DlImpl(did),
|
||||
PublicField | InheritedField => DlField,
|
||||
}
|
||||
@ -371,11 +372,9 @@ pub fn get_adt_def<'tcx>(intr: &IdentInterner,
|
||||
item_id: DefIndex,
|
||||
tcx: &ty::ctxt<'tcx>) -> ty::AdtDefMaster<'tcx>
|
||||
{
|
||||
fn family_to_variant_kind<'tcx>(family: Family, tcx: &ty::ctxt<'tcx>) -> ty::VariantKind {
|
||||
match family {
|
||||
Struct | StructVariant => ty::VariantKind::Struct,
|
||||
TupleStruct | TupleVariant => ty::VariantKind::Tuple,
|
||||
UnitStruct | UnitVariant => ty::VariantKind::Unit,
|
||||
fn expect_variant_kind<'tcx>(family: Family, tcx: &ty::ctxt<'tcx>) -> ty::VariantKind {
|
||||
match family_to_variant_kind(family) {
|
||||
Some(kind) => kind,
|
||||
_ => tcx.sess.bug(&format!("unexpected family: {:?}", family)),
|
||||
}
|
||||
}
|
||||
@ -399,7 +398,7 @@ fn get_enum_variants<'tcx>(intr: &IdentInterner,
|
||||
name: item_name(intr, item),
|
||||
fields: get_variant_fields(intr, cdata, item, tcx),
|
||||
disr_val: disr,
|
||||
kind: family_to_variant_kind(item_family(item), tcx),
|
||||
kind: expect_variant_kind(item_family(item), tcx),
|
||||
}
|
||||
}).collect()
|
||||
}
|
||||
@ -433,7 +432,7 @@ fn get_struct_variant<'tcx>(intr: &IdentInterner,
|
||||
name: item_name(intr, doc),
|
||||
fields: get_variant_fields(intr, cdata, doc, tcx),
|
||||
disr_val: 0,
|
||||
kind: family_to_variant_kind(item_family(doc), tcx),
|
||||
kind: expect_variant_kind(item_family(doc), tcx),
|
||||
}
|
||||
}
|
||||
|
||||
@ -444,7 +443,7 @@ fn get_struct_variant<'tcx>(intr: &IdentInterner,
|
||||
(ty::AdtKind::Enum,
|
||||
get_enum_variants(intr, cdata, doc, tcx))
|
||||
}
|
||||
Struct | TupleStruct | UnitStruct => {
|
||||
Struct(..) => {
|
||||
let ctor_did =
|
||||
reader::maybe_get_doc(doc, tag_items_data_item_struct_ctor).
|
||||
map_or(did, |ctor_doc| translated_def_id(cdata, ctor_doc));
|
||||
@ -1086,6 +1085,19 @@ pub fn get_associated_consts<'tcx>(intr: Rc<IdentInterner>,
|
||||
}).collect()
|
||||
}
|
||||
|
||||
pub fn get_variant_kind(cdata: Cmd, node_id: DefIndex) -> Option<VariantKind>
|
||||
{
|
||||
let item = cdata.lookup_item(node_id);
|
||||
family_to_variant_kind(item_family(item))
|
||||
}
|
||||
|
||||
pub fn get_struct_ctor_def_id(cdata: Cmd, node_id: DefIndex) -> Option<DefId>
|
||||
{
|
||||
let item = cdata.lookup_item(node_id);
|
||||
reader::maybe_get_doc(item, tag_items_data_item_struct_ctor).
|
||||
map(|ctor_doc| translated_def_id(cdata, ctor_doc))
|
||||
}
|
||||
|
||||
/// If node_id is the constructor of a tuple struct, retrieve the NodeId of
|
||||
/// the actual type definition, otherwise, return None
|
||||
pub fn get_tuple_struct_definition_if_ctor(cdata: Cmd,
|
||||
|
@ -508,15 +508,20 @@ fn encode_field<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
fn encode_info_for_struct_ctor<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
rbml_w: &mut Encoder,
|
||||
name: Name,
|
||||
ctor_id: NodeId,
|
||||
struct_def: &hir::VariantData,
|
||||
index: &mut CrateIndex<'tcx>,
|
||||
struct_id: NodeId) {
|
||||
let ctor_id = struct_def.id();
|
||||
let ctor_def_id = ecx.tcx.map.local_def_id(ctor_id);
|
||||
|
||||
index.record(ctor_def_id, rbml_w);
|
||||
rbml_w.start_tag(tag_items_data_item);
|
||||
encode_def_id_and_key(ecx, rbml_w, ctor_def_id);
|
||||
encode_family(rbml_w, 'o');
|
||||
encode_family(rbml_w, match *struct_def {
|
||||
hir::VariantData::Struct(..) => 'S',
|
||||
hir::VariantData::Tuple(..) => 's',
|
||||
hir::VariantData::Unit(..) => 'u',
|
||||
});
|
||||
encode_bounds_and_type_for_item(rbml_w, ecx, index, ctor_id);
|
||||
encode_name(rbml_w, name);
|
||||
ecx.tcx.map.with_path(ctor_id, |path| encode_path(rbml_w, path));
|
||||
@ -1084,7 +1089,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
|
||||
// If this is a tuple-like struct, encode the type of the constructor.
|
||||
if !struct_def.is_struct() {
|
||||
encode_info_for_struct_ctor(ecx, rbml_w, item.name, struct_def.id(), index, item.id);
|
||||
encode_info_for_struct_ctor(ecx, rbml_w, item.name, struct_def, index, item.id);
|
||||
}
|
||||
}
|
||||
hir::ItemDefaultImpl(unsafety, _) => {
|
||||
|
@ -67,10 +67,10 @@ fn make_mirror<'a>(self, cx: &mut Cx<'a, 'tcx>) -> Expr<'tcx> {
|
||||
// Tuple-like ADTs are represented as ExprCall. We convert them here.
|
||||
expr_ty.ty_adt_def().and_then(|adt_def|{
|
||||
match cx.tcx.def_map.borrow()[&fun.id].full_def() {
|
||||
def::DefVariant(_, variant_id, false) => {
|
||||
def::DefVariant(_, variant_id) => {
|
||||
Some((adt_def, adt_def.variant_index_with_id(variant_id)))
|
||||
},
|
||||
def::DefStruct(_) => {
|
||||
def::DefStruct(..) => {
|
||||
Some((adt_def, 0))
|
||||
},
|
||||
_ => None
|
||||
@ -231,7 +231,7 @@ fn make_mirror<'a>(self, cx: &mut Cx<'a, 'tcx>) -> Expr<'tcx> {
|
||||
}
|
||||
ty::TyEnum(adt, substs) => {
|
||||
match cx.tcx.def_map.borrow()[&self.id].full_def() {
|
||||
def::DefVariant(enum_id, variant_id, _) => {
|
||||
def::DefVariant(enum_id, variant_id) => {
|
||||
debug_assert!(adt.did == enum_id);
|
||||
let index = adt.variant_index_with_id(variant_id);
|
||||
let field_refs = field_refs(&adt.variants[index], fields);
|
||||
@ -573,7 +573,7 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
|
||||
let def = cx.tcx.def_map.borrow()[&expr.id].full_def();
|
||||
let (def_id, kind) = match def {
|
||||
// A regular function.
|
||||
def::DefFn(def_id, _) => (def_id, ItemKind::Function),
|
||||
def::DefFn(def_id) => (def_id, ItemKind::Function),
|
||||
def::DefMethod(def_id) => (def_id, ItemKind::Method),
|
||||
def::DefStruct(def_id) => match cx.tcx.node_id_to_type(expr.id).sty {
|
||||
// A tuple-struct constructor. Should only be reached if not called in the same
|
||||
@ -590,7 +590,7 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
|
||||
},
|
||||
ref sty => panic!("unexpected sty: {:?}", sty)
|
||||
},
|
||||
def::DefVariant(enum_id, variant_id, false) => match cx.tcx.node_id_to_type(expr.id).sty {
|
||||
def::DefVariant(enum_id, variant_id) => match cx.tcx.node_id_to_type(expr.id).sty {
|
||||
// A variant constructor. Should only be reached if not called in the same
|
||||
// expression.
|
||||
ty::TyBareFn(..) => (variant_id, ItemKind::Function),
|
||||
|
@ -290,7 +290,7 @@ fn variant_or_leaf(&mut self,
|
||||
-> PatternKind<'tcx> {
|
||||
let def = self.cx.tcx.def_map.borrow().get(&pat.id).unwrap().full_def();
|
||||
match def {
|
||||
def::DefVariant(enum_id, variant_id, _) => {
|
||||
def::DefVariant(enum_id, variant_id) => {
|
||||
let adt_def = self.cx.tcx.lookup_adt_def(enum_id);
|
||||
if adt_def.variants.len() > 1 {
|
||||
PatternKind::Variant {
|
||||
@ -303,9 +303,7 @@ fn variant_or_leaf(&mut self,
|
||||
}
|
||||
}
|
||||
|
||||
// NB: resolving to DefStruct means the struct *constructor*,
|
||||
// not the struct as a type.
|
||||
def::DefStruct(..) | def::DefTy(..) => {
|
||||
def::DefStruct(..) | def::DefTyAlias(..) => {
|
||||
PatternKind::Leaf { subpatterns: subpatterns }
|
||||
}
|
||||
|
||||
|
@ -811,8 +811,8 @@ fn check_path(&mut self, span: Span, path_id: ast::NodeId, last: ast::Name) {
|
||||
def::DefConst(..) => ck("const"),
|
||||
def::DefAssociatedConst(..) => ck("associated const"),
|
||||
def::DefVariant(..) => ck("variant"),
|
||||
def::DefTy(_, false) => ck("type"),
|
||||
def::DefTy(_, true) => ck("enum"),
|
||||
def::DefTyAlias(..) => ck("type"),
|
||||
def::DefEnum(..) => ck("enum"),
|
||||
def::DefTrait(..) => ck("trait"),
|
||||
def::DefStruct(..) => ck("struct"),
|
||||
def::DefMethod(..) => ck("method"),
|
||||
@ -887,7 +887,7 @@ fn visit_expr(&mut self, expr: &hir::Expr) {
|
||||
}
|
||||
hir::ExprPath(..) => {
|
||||
|
||||
if let def::DefStruct(_) = self.tcx.resolve_expr(expr) {
|
||||
if let def::DefStruct(..) = self.tcx.resolve_expr(expr) {
|
||||
let expr_ty = self.tcx.expr_ty(expr);
|
||||
let def = match expr_ty.sty {
|
||||
ty::TyBareFn(_, &ty::BareFnTy { sig: ty::Binder(ty::FnSig {
|
||||
@ -1515,7 +1515,7 @@ fn visit_ty(&mut self, ty: &hir::Ty) {
|
||||
// free type aliases, but this isn't done yet.
|
||||
return
|
||||
}
|
||||
def::DefStruct(def_id) | def::DefTy(def_id, _) |
|
||||
def::DefStruct(def_id) | def::DefEnum(def_id) | def::DefTyAlias(def_id) |
|
||||
def::DefTrait(def_id) | def::DefAssociatedTy(def_id, _) => {
|
||||
// Non-local means public (private items can't leave their crate, modulo bugs)
|
||||
if let Some(node_id) = self.tcx.map.as_local_node_id(def_id) {
|
||||
|
@ -31,6 +31,7 @@
|
||||
use rustc::middle::cstore::{CrateStore, ChildItem, DlDef, DlField, DlImpl};
|
||||
use rustc::middle::def::*;
|
||||
use rustc::middle::def_id::{CRATE_DEF_INDEX, DefId};
|
||||
use rustc::middle::ty::VariantKind;
|
||||
|
||||
use syntax::ast::{Name, NodeId};
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
@ -359,7 +360,7 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: Module<'b>) -> M
|
||||
ItemFn(_, _, _, _, _, _) => {
|
||||
let name_bindings = self.add_child(name, parent, ForbidDuplicateValues, sp);
|
||||
|
||||
let def = DefFn(self.ast_map.local_def_id(item.id), false);
|
||||
let def = DefFn(self.ast_map.local_def_id(item.id));
|
||||
name_bindings.define_value(def, sp, modifiers);
|
||||
parent
|
||||
}
|
||||
@ -372,7 +373,7 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: Module<'b>) -> M
|
||||
sp);
|
||||
|
||||
let parent_link = ModuleParentLink(parent, name);
|
||||
let def = DefTy(self.ast_map.local_def_id(item.id), false);
|
||||
let def = DefTyAlias(self.ast_map.local_def_id(item.id));
|
||||
let module = self.new_module(parent_link, Some(def), false, is_public);
|
||||
name_bindings.define_module(module, sp);
|
||||
parent
|
||||
@ -385,7 +386,7 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: Module<'b>) -> M
|
||||
sp);
|
||||
|
||||
let parent_link = ModuleParentLink(parent, name);
|
||||
let def = DefTy(self.ast_map.local_def_id(item.id), true);
|
||||
let def = DefEnum(self.ast_map.local_def_id(item.id));
|
||||
let module = self.new_module(parent_link, Some(def), false, is_public);
|
||||
name_bindings.define_module(module.clone(), sp);
|
||||
|
||||
@ -414,7 +415,7 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: Module<'b>) -> M
|
||||
let name_bindings = self.add_child(name, parent, forbid, sp);
|
||||
|
||||
// Define a name in the type namespace.
|
||||
name_bindings.define_type(DefTy(self.ast_map.local_def_id(item.id), false),
|
||||
name_bindings.define_type(DefStruct(self.ast_map.local_def_id(item.id)),
|
||||
sp,
|
||||
modifiers);
|
||||
|
||||
@ -502,26 +503,19 @@ fn build_reduced_graph_for_variant(&mut self,
|
||||
parent: Module<'b>,
|
||||
variant_modifiers: DefModifiers) {
|
||||
let name = variant.node.name;
|
||||
let is_exported = if variant.node.data.is_struct() {
|
||||
if variant.node.data.is_struct() {
|
||||
// Not adding fields for variants as they are not accessed with a self receiver
|
||||
let variant_def_id = self.ast_map.local_def_id(variant.node.data.id());
|
||||
self.structs.insert(variant_def_id, Vec::new());
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
}
|
||||
|
||||
let child = self.add_child(name, parent, ForbidDuplicateTypesAndValues, variant.span);
|
||||
// variants are always treated as importable to allow them to be glob
|
||||
// used
|
||||
child.define_value(DefVariant(item_id,
|
||||
self.ast_map.local_def_id(variant.node.data.id()),
|
||||
is_exported),
|
||||
child.define_value(DefVariant(item_id, self.ast_map.local_def_id(variant.node.data.id())),
|
||||
variant.span,
|
||||
DefModifiers::PUBLIC | DefModifiers::IMPORTABLE | variant_modifiers);
|
||||
child.define_type(DefVariant(item_id,
|
||||
self.ast_map.local_def_id(variant.node.data.id()),
|
||||
is_exported),
|
||||
child.define_type(DefVariant(item_id, self.ast_map.local_def_id(variant.node.data.id())),
|
||||
variant.span,
|
||||
DefModifiers::PUBLIC | DefModifiers::IMPORTABLE | variant_modifiers);
|
||||
}
|
||||
@ -541,7 +535,7 @@ fn build_reduced_graph_for_foreign_item(&mut self,
|
||||
|
||||
let def = match foreign_item.node {
|
||||
ForeignItemFn(..) => {
|
||||
DefFn(self.ast_map.local_def_id(foreign_item.id), false)
|
||||
DefFn(self.ast_map.local_def_id(foreign_item.id))
|
||||
}
|
||||
ForeignItemStatic(_, m) => {
|
||||
DefStatic(self.ast_map.local_def_id(foreign_item.id), m)
|
||||
@ -591,12 +585,18 @@ fn handle_external_def(&mut self,
|
||||
if is_exported {
|
||||
self.external_exports.insert(def.def_id());
|
||||
}
|
||||
let is_struct_ctor = if let DefStruct(def_id) = def {
|
||||
self.session.cstore.tuple_struct_definition_if_ctor(def_id).is_some()
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
match def {
|
||||
DefMod(_) |
|
||||
DefForeignMod(_) |
|
||||
DefStruct(_) |
|
||||
DefTy(..) => {
|
||||
DefStruct(..) |
|
||||
DefEnum(..) |
|
||||
DefTyAlias(..) if !is_struct_ctor => {
|
||||
if let Some(module_def) = child_name_bindings.type_ns.module() {
|
||||
debug!("(building reduced graph for external crate) already created module");
|
||||
module_def.def.set(Some(def));
|
||||
@ -614,13 +614,13 @@ fn handle_external_def(&mut self,
|
||||
|
||||
match def {
|
||||
DefMod(_) | DefForeignMod(_) => {}
|
||||
DefVariant(_, variant_id, is_struct) => {
|
||||
DefVariant(_, variant_id) => {
|
||||
debug!("(building reduced graph for external crate) building variant {}",
|
||||
final_ident);
|
||||
// variants are always treated as importable to allow them to be
|
||||
// glob used
|
||||
let modifiers = DefModifiers::PUBLIC | DefModifiers::IMPORTABLE;
|
||||
if is_struct {
|
||||
if self.session.cstore.variant_kind(variant_id) == Some(VariantKind::Struct) {
|
||||
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
|
||||
// Not adding fields for variants as they are not accessed with a self receiver
|
||||
self.structs.insert(variant_id, Vec::new());
|
||||
@ -628,11 +628,6 @@ fn handle_external_def(&mut self,
|
||||
child_name_bindings.define_value(def, DUMMY_SP, modifiers);
|
||||
}
|
||||
}
|
||||
DefFn(ctor_id, true) => {
|
||||
child_name_bindings.define_value(
|
||||
self.session.cstore.tuple_struct_definition_if_ctor(ctor_id)
|
||||
.map_or(def, |_| DefStruct(ctor_id)), DUMMY_SP, modifiers);
|
||||
}
|
||||
DefFn(..) |
|
||||
DefStatic(..) |
|
||||
DefConst(..) |
|
||||
@ -680,7 +675,7 @@ fn handle_external_def(&mut self,
|
||||
let module = self.new_module(parent_link, Some(def), true, is_public);
|
||||
child_name_bindings.define_module(module, DUMMY_SP);
|
||||
}
|
||||
DefTy(..) | DefAssociatedTy(..) => {
|
||||
DefEnum(..) | DefTyAlias(..) | DefAssociatedTy(..) => {
|
||||
debug!("(building reduced graph for external crate) building type {}",
|
||||
final_ident);
|
||||
|
||||
@ -689,24 +684,29 @@ fn handle_external_def(&mut self,
|
||||
_ => modifiers & !DefModifiers::IMPORTABLE,
|
||||
};
|
||||
|
||||
if let DefTy(..) = def {
|
||||
if let DefEnum(..) = def {
|
||||
child_name_bindings.type_ns.set_modifiers(modifiers);
|
||||
} else if let DefTyAlias(..) = def {
|
||||
child_name_bindings.type_ns.set_modifiers(modifiers);
|
||||
} else {
|
||||
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
|
||||
}
|
||||
}
|
||||
DefStruct(..) if is_struct_ctor => {
|
||||
// Do nothing
|
||||
}
|
||||
DefStruct(def_id) => {
|
||||
debug!("(building reduced graph for external crate) building type and value for \
|
||||
{}",
|
||||
final_ident);
|
||||
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
|
||||
let fields = self.session.cstore.struct_field_names(def_id);
|
||||
|
||||
if fields.is_empty() {
|
||||
child_name_bindings.define_value(def, DUMMY_SP, modifiers);
|
||||
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
|
||||
if let Some(ctor_def_id) = self.session.cstore.struct_ctor_def_id(def_id) {
|
||||
child_name_bindings.define_value(DefStruct(ctor_def_id), DUMMY_SP, modifiers);
|
||||
}
|
||||
|
||||
// Record the def ID and fields of this struct.
|
||||
let fields = self.session.cstore.struct_field_names(def_id);
|
||||
self.structs.insert(def_id, fields);
|
||||
}
|
||||
DefLocal(..) |
|
||||
|
@ -2076,7 +2076,8 @@ fn resolve_item(&mut self, item: &Item) {
|
||||
// check for imports shadowing primitive types
|
||||
let check_rename = |this: &Self, id, name| {
|
||||
match this.def_map.borrow().get(&id).map(|d| d.full_def()) {
|
||||
Some(DefTy(..)) | Some(DefStruct(..)) | Some(DefTrait(..)) | None => {
|
||||
Some(DefEnum(..)) | Some(DefTyAlias(..)) | Some(DefStruct(..)) |
|
||||
Some(DefTrait(..)) | None => {
|
||||
this.check_if_primitive_type_name(name, item.span);
|
||||
}
|
||||
_ => {}
|
||||
@ -2236,7 +2237,7 @@ fn resolve_trait_reference(&mut self,
|
||||
path_depth)));
|
||||
|
||||
// If it's a typedef, give a note
|
||||
if let DefTy(..) = path_res.base_def {
|
||||
if let DefTyAlias(..) = path_res.base_def {
|
||||
err.span_note(trait_path.span,
|
||||
"`type` aliases cannot be used for traits");
|
||||
}
|
||||
@ -3425,9 +3426,10 @@ fn is_static_method(this: &Resolver, did: DefId) -> bool {
|
||||
if allowed == Everything {
|
||||
// Look for a field with the same name in the current self_type.
|
||||
match self.def_map.borrow().get(&node_id).map(|d| d.full_def()) {
|
||||
Some(DefTy(did, _)) |
|
||||
Some(DefEnum(did)) |
|
||||
Some(DefTyAlias(did)) |
|
||||
Some(DefStruct(did)) |
|
||||
Some(DefVariant(_, did, _)) => match self.structs.get(&did) {
|
||||
Some(DefVariant(_, did)) => match self.structs.get(&did) {
|
||||
None => {}
|
||||
Some(fields) => {
|
||||
if fields.iter().any(|&field_name| name == field_name) {
|
||||
@ -3518,7 +3520,13 @@ fn resolve_expr(&mut self, expr: &Expr) {
|
||||
// scopes looking for it.
|
||||
if let Some(path_res) = resolution {
|
||||
// Check if struct variant
|
||||
if let DefVariant(_, _, true) = path_res.base_def {
|
||||
let is_struct_variant = if let DefVariant(_, variant_id) = path_res.base_def {
|
||||
self.structs.contains_key(&variant_id)
|
||||
} else {
|
||||
false
|
||||
};
|
||||
if is_struct_variant {
|
||||
let _ = self.structs.contains_key(&path_res.base_def.def_id());
|
||||
let path_name = path_names_to_string(path, 0);
|
||||
|
||||
let mut err = resolve_struct_error(self,
|
||||
@ -3561,7 +3569,7 @@ fn resolve_expr(&mut self, expr: &Expr) {
|
||||
|
||||
self.record_def(expr.id, err_path_resolution());
|
||||
match type_res.map(|r| r.base_def) {
|
||||
Some(DefTy(struct_id, _)) if self.structs.contains_key(&struct_id) => {
|
||||
Some(DefStruct(..)) => {
|
||||
let mut err = resolve_struct_error(self,
|
||||
expr.span,
|
||||
ResolutionError::StructVariantUsedAsFunction(&*path_name));
|
||||
|
@ -256,15 +256,16 @@ fn lookup_def_kind(&self, ref_id: NodeId, span: Span) -> Option<recorder::Row> {
|
||||
match def {
|
||||
def::DefMod(_) |
|
||||
def::DefForeignMod(_) => Some(recorder::ModRef),
|
||||
def::DefStruct(_) => Some(recorder::TypeRef),
|
||||
def::DefTy(..) |
|
||||
def::DefStruct(..) => Some(recorder::TypeRef),
|
||||
def::DefEnum(..) |
|
||||
def::DefTyAlias(..) |
|
||||
def::DefAssociatedTy(..) |
|
||||
def::DefTrait(_) => Some(recorder::TypeRef),
|
||||
def::DefStatic(_, _) |
|
||||
def::DefConst(_) |
|
||||
def::DefAssociatedConst(..) |
|
||||
def::DefLocal(..) |
|
||||
def::DefVariant(_, _, _) |
|
||||
def::DefVariant(..) |
|
||||
def::DefUpvar(..) => Some(recorder::VarRef),
|
||||
|
||||
def::DefFn(..) => Some(recorder::FnRef),
|
||||
@ -691,7 +692,7 @@ fn process_path(&mut self, id: NodeId, path: &ast::Path, ref_kind: Option<record
|
||||
def::DefStatic(_,_) |
|
||||
def::DefConst(..) |
|
||||
def::DefAssociatedConst(..) |
|
||||
def::DefStruct(_) |
|
||||
def::DefStruct(..) |
|
||||
def::DefVariant(..) |
|
||||
def::DefFn(..) => self.write_sub_paths_truncated(path, false),
|
||||
_ => {}
|
||||
@ -1174,7 +1175,8 @@ fn visit_arm(&mut self, arm: &ast::Arm) {
|
||||
"qualified path for local variable def in arm");
|
||||
self.fmt.variable_str(p.span, Some(p.span), id, &path_to_string(p), &value, "")
|
||||
}
|
||||
def::DefVariant(..) | def::DefTy(..) | def::DefStruct(..) => {
|
||||
def::DefVariant(..) | def::DefEnum(..) |
|
||||
def::DefTyAlias(..) | def::DefStruct(..) => {
|
||||
paths_to_process.push((id, p.clone(), Some(ref_kind)))
|
||||
}
|
||||
// FIXME(nrc) what are these doing here?
|
||||
|
@ -547,7 +547,8 @@ pub fn get_path_data(&self, id: NodeId, path: &ast::Path) -> Option<Data> {
|
||||
}))
|
||||
}
|
||||
def::DefStruct(def_id) |
|
||||
def::DefTy(def_id, _) |
|
||||
def::DefEnum(def_id) |
|
||||
def::DefTyAlias(def_id) |
|
||||
def::DefTrait(def_id) |
|
||||
def::DefTyParam(_, _, def_id, _) => {
|
||||
Some(Data::TypeRefData(TypeRefData {
|
||||
@ -591,7 +592,7 @@ pub fn get_path_data(&self, id: NodeId, path: &ast::Path) -> Option<Data> {
|
||||
decl_id: Some(decl_id),
|
||||
}))
|
||||
}
|
||||
def::DefFn(def_id, _) => {
|
||||
def::DefFn(def_id) => {
|
||||
Some(Data::FunctionCallData(FunctionCallData {
|
||||
ref_id: def_id,
|
||||
span: sub_span.unwrap(),
|
||||
|
@ -669,7 +669,7 @@ fn get_branches<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
// This is either an enum variant or a variable binding.
|
||||
let opt_def = tcx.def_map.borrow().get(&cur.id).map(|d| d.full_def());
|
||||
match opt_def {
|
||||
Some(def::DefVariant(enum_id, var_id, _)) => {
|
||||
Some(def::DefVariant(enum_id, var_id)) => {
|
||||
let variant = tcx.lookup_adt_def(enum_id).variant_with_id(var_id);
|
||||
Variant(Disr::from(variant.disr_val),
|
||||
adt::represent_node(bcx, cur.id),
|
||||
@ -1851,7 +1851,7 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
hir::PatEnum(_, ref sub_pats) => {
|
||||
let opt_def = bcx.tcx().def_map.borrow().get(&pat.id).map(|d| d.full_def());
|
||||
match opt_def {
|
||||
Some(def::DefVariant(enum_id, var_id, _)) => {
|
||||
Some(def::DefVariant(enum_id, var_id)) => {
|
||||
let repr = adt::represent_node(bcx, pat.id);
|
||||
let vinfo = ccx.tcx().lookup_adt_def(enum_id).variant_with_id(var_id);
|
||||
let args = extract_variant_args(bcx,
|
||||
|
@ -139,7 +139,7 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
debug!("trans_def(def={:?}, ref_expr={:?})", def, ref_expr);
|
||||
let expr_ty = common::node_id_type(bcx, ref_expr.id);
|
||||
match def {
|
||||
def::DefFn(did, _) if {
|
||||
def::DefFn(did) if {
|
||||
let maybe_def_id = inline::get_local_instance(bcx.ccx(), did);
|
||||
let maybe_ast_node = maybe_def_id.and_then(|def_id| {
|
||||
let node_id = bcx.tcx().map.as_local_node_id(def_id).unwrap();
|
||||
@ -156,7 +156,7 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
ty: expr_ty
|
||||
}
|
||||
}
|
||||
def::DefFn(did, _) if match expr_ty.sty {
|
||||
def::DefFn(did) if match expr_ty.sty {
|
||||
ty::TyBareFn(_, ref f) => f.abi == synabi::RustIntrinsic ||
|
||||
f.abi == synabi::PlatformIntrinsic,
|
||||
_ => false
|
||||
@ -168,7 +168,7 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
let node_id = bcx.tcx().map.as_local_node_id(def_id).unwrap();
|
||||
Callee { bcx: bcx, data: Intrinsic(node_id, substs), ty: expr_ty }
|
||||
}
|
||||
def::DefFn(did, _) => {
|
||||
def::DefFn(did) => {
|
||||
fn_callee(bcx, trans_fn_ref(bcx.ccx(), did, ExprId(ref_expr.id),
|
||||
bcx.fcx.param_substs))
|
||||
}
|
||||
@ -190,7 +190,7 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
};
|
||||
fn_callee(bcx, fn_datum)
|
||||
}
|
||||
def::DefVariant(tid, vid, _) => {
|
||||
def::DefVariant(tid, vid) => {
|
||||
let vinfo = bcx.tcx().lookup_adt_def(tid).variant_with_id(vid);
|
||||
assert_eq!(vinfo.kind(), ty::VariantKind::Tuple);
|
||||
|
||||
@ -200,7 +200,7 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
ty: expr_ty
|
||||
}
|
||||
}
|
||||
def::DefStruct(_) => {
|
||||
def::DefStruct(..) => {
|
||||
Callee {
|
||||
bcx: bcx,
|
||||
data: NamedTupleConstructor(Disr(0)),
|
||||
@ -215,8 +215,8 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
datum_callee(bcx, ref_expr)
|
||||
}
|
||||
def::DefMod(..) | def::DefForeignMod(..) | def::DefTrait(..) |
|
||||
def::DefTy(..) | def::DefPrimTy(..) | def::DefAssociatedTy(..) |
|
||||
def::DefLabel(..) | def::DefTyParam(..) |
|
||||
def::DefEnum(..) | def::DefTyAlias(..) | def::DefPrimTy(..) |
|
||||
def::DefAssociatedTy(..) | def::DefLabel(..) | def::DefTyParam(..) |
|
||||
def::DefSelfTy(..) | def::DefErr => {
|
||||
bcx.tcx().sess.span_bug(
|
||||
ref_expr.span,
|
||||
|
@ -894,7 +894,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
def::DefConst(def_id) | def::DefAssociatedConst(def_id) => {
|
||||
const_deref_ptr(cx, try!(get_const_val(cx, def_id, e, param_substs)))
|
||||
}
|
||||
def::DefVariant(enum_did, variant_did, _) => {
|
||||
def::DefVariant(enum_did, variant_did) => {
|
||||
let vinfo = cx.tcx().lookup_adt_def(enum_did).variant_with_id(variant_did);
|
||||
match vinfo.kind() {
|
||||
ty::VariantKind::Unit => {
|
||||
@ -909,7 +909,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
}
|
||||
}
|
||||
}
|
||||
def::DefStruct(_) => {
|
||||
def::DefStruct(..) => {
|
||||
if let ty::TyBareFn(..) = ety.sty {
|
||||
// Tuple struct.
|
||||
expr::trans_def_fn_unadjusted(cx, e, def, param_substs).val
|
||||
@ -938,7 +938,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
let def = cx.tcx().def_map.borrow()[&callee.id].full_def();
|
||||
let arg_vals = try!(map_list(args));
|
||||
match def {
|
||||
def::DefFn(did, _) | def::DefMethod(did) => {
|
||||
def::DefFn(did) | def::DefMethod(did) => {
|
||||
try!(const_fn_call(
|
||||
cx,
|
||||
ExprId(callee.id),
|
||||
@ -948,7 +948,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
trueconst,
|
||||
))
|
||||
}
|
||||
def::DefStruct(_) => {
|
||||
def::DefStruct(..) => {
|
||||
if ety.is_simd() {
|
||||
C_vector(&arg_vals[..])
|
||||
} else {
|
||||
@ -956,7 +956,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
adt::trans_const(cx, &*repr, Disr(0), &arg_vals[..])
|
||||
}
|
||||
}
|
||||
def::DefVariant(enum_did, variant_did, _) => {
|
||||
def::DefVariant(enum_did, variant_did) => {
|
||||
let repr = adt::represent_type(cx, ety);
|
||||
let vinfo = cx.tcx().lookup_adt_def(enum_did).variant_with_id(variant_did);
|
||||
adt::trans_const(cx,
|
||||
|
@ -910,7 +910,7 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
let _icx = push_ctxt("trans_def_lvalue");
|
||||
match def {
|
||||
def::DefFn(..) | def::DefMethod(..) |
|
||||
def::DefStruct(_) | def::DefVariant(..) => {
|
||||
def::DefStruct(..) | def::DefVariant(..) => {
|
||||
let datum = trans_def_fn_unadjusted(bcx.ccx(), ref_expr, def,
|
||||
bcx.fcx.param_substs);
|
||||
DatumBlock::new(bcx, datum.to_expr_datum())
|
||||
@ -1283,7 +1283,7 @@ fn trans_def_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
};
|
||||
|
||||
match def {
|
||||
def::DefVariant(tid, vid, _) => {
|
||||
def::DefVariant(tid, vid) => {
|
||||
let variant = bcx.tcx().lookup_adt_def(tid).variant_with_id(vid);
|
||||
if let ty::VariantKind::Tuple = variant.kind() {
|
||||
// N-ary variant.
|
||||
@ -1300,7 +1300,7 @@ fn trans_def_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
return bcx;
|
||||
}
|
||||
}
|
||||
def::DefStruct(_) => {
|
||||
def::DefStruct(..) => {
|
||||
let ty = expr_ty(bcx, ref_expr);
|
||||
match ty.sty {
|
||||
ty::TyStruct(def, _) if def.has_dtor() => {
|
||||
@ -1327,8 +1327,8 @@ pub fn trans_def_fn_unadjusted<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
let _icx = push_ctxt("trans_def_datum_unadjusted");
|
||||
|
||||
match def {
|
||||
def::DefFn(did, _) |
|
||||
def::DefStruct(did) | def::DefVariant(_, did, _) => {
|
||||
def::DefFn(did) |
|
||||
def::DefStruct(did) | def::DefVariant(_, did) => {
|
||||
callee::trans_fn_ref(ccx, did, ExprId(ref_expr.id), param_substs)
|
||||
}
|
||||
def::DefMethod(method_did) => {
|
||||
@ -2587,7 +2587,7 @@ fn expr_kind(tcx: &ty::ctxt, expr: &hir::Expr) -> ExprKind {
|
||||
match expr.node {
|
||||
hir::ExprPath(..) => {
|
||||
match tcx.resolve_expr(expr) {
|
||||
def::DefStruct(_) | def::DefVariant(..) => {
|
||||
def::DefStruct(..) | def::DefVariant(..) => {
|
||||
if let ty::TyBareFn(..) = tcx.node_id_to_type(expr.id).sty {
|
||||
// ctor function
|
||||
ExprKind::RvalueDatum
|
||||
@ -2596,12 +2596,6 @@ fn expr_kind(tcx: &ty::ctxt, expr: &hir::Expr) -> ExprKind {
|
||||
}
|
||||
}
|
||||
|
||||
// Special case: A unit like struct's constructor must be called without () at the
|
||||
// end (like `UnitStruct`) which means this is an ExprPath to a DefFn. But in case
|
||||
// of unit structs this is should not be interpreted as function pointer but as
|
||||
// call to the constructor.
|
||||
def::DefFn(_, true) => ExprKind::RvalueDps,
|
||||
|
||||
// Fn pointers are just scalar values.
|
||||
def::DefFn(..) | def::DefMethod(..) => ExprKind::RvalueDatum,
|
||||
|
||||
|
@ -1471,7 +1471,7 @@ fn base_def_to_ty<'tcx>(this: &AstConv<'tcx>,
|
||||
projection_bounds,
|
||||
&[])
|
||||
}
|
||||
def::DefTy(did, _) | def::DefStruct(did) => {
|
||||
def::DefEnum(did) | def::DefTyAlias(did) | def::DefStruct(did) => {
|
||||
prohibit_type_params(tcx, base_segments.split_last().unwrap().1);
|
||||
ast_path_to_ty(this,
|
||||
rscope,
|
||||
|
@ -693,10 +693,12 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
||||
|
||||
let real_path_ty = fcx.node_ty(pat.id);
|
||||
let (arg_tys, kind_name): (Vec<_>, &'static str) = match real_path_ty.sty {
|
||||
ty::TyEnum(enum_def, expected_substs)
|
||||
if def == def::DefVariant(enum_def.did, def.def_id(), false) =>
|
||||
{
|
||||
ty::TyEnum(enum_def, expected_substs) => {
|
||||
let variant = enum_def.variant_of_def(def);
|
||||
if variant.kind() == ty::VariantKind::Struct {
|
||||
report_bad_struct_kind(false);
|
||||
return;
|
||||
}
|
||||
if is_tuple_struct_pat && variant.kind() != ty::VariantKind::Tuple {
|
||||
// Matching unit variants with tuple variant patterns (`UnitVariant(..)`)
|
||||
// is allowed for backward compatibility.
|
||||
|
@ -1421,11 +1421,11 @@ pub fn def_struct_variant(&self,
|
||||
-> Option<(ty::AdtDef<'tcx>, ty::VariantDef<'tcx>)>
|
||||
{
|
||||
let (adt, variant) = match def {
|
||||
def::DefVariant(enum_id, variant_id, _) => {
|
||||
def::DefVariant(enum_id, variant_id) => {
|
||||
let adt = self.tcx().lookup_adt_def(enum_id);
|
||||
(adt, adt.variant_with_id(variant_id))
|
||||
}
|
||||
def::DefTy(did, _) | def::DefStruct(did) => {
|
||||
def::DefStruct(did) | def::DefTyAlias(did) => {
|
||||
let typ = self.tcx().lookup_item_type(did);
|
||||
if let ty::TyStruct(adt, _) = typ.ty.sty {
|
||||
(adt, adt.struct_variant())
|
||||
@ -4271,13 +4271,14 @@ fn type_scheme_and_predicates_for_def<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
(ty::TypeScheme { generics: ty::Generics::empty(), ty: typ },
|
||||
ty::GenericPredicates::empty())
|
||||
}
|
||||
def::DefFn(id, _) | def::DefMethod(id) |
|
||||
def::DefStatic(id, _) | def::DefVariant(_, id, _) |
|
||||
def::DefFn(id) | def::DefMethod(id) |
|
||||
def::DefStatic(id, _) | def::DefVariant(_, id) |
|
||||
def::DefStruct(id) | def::DefConst(id) | def::DefAssociatedConst(id) => {
|
||||
(fcx.tcx().lookup_item_type(id), fcx.tcx().lookup_predicates(id))
|
||||
}
|
||||
def::DefTrait(_) |
|
||||
def::DefTy(..) |
|
||||
def::DefEnum(..) |
|
||||
def::DefTyAlias(..) |
|
||||
def::DefAssociatedTy(..) |
|
||||
def::DefPrimTy(_) |
|
||||
def::DefTyParam(..) |
|
||||
@ -4385,7 +4386,8 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
def::DefSelfTy(..) |
|
||||
def::DefStruct(..) |
|
||||
def::DefVariant(..) |
|
||||
def::DefTy(..) |
|
||||
def::DefEnum(..) |
|
||||
def::DefTyAlias(..) |
|
||||
def::DefAssociatedTy(..) |
|
||||
def::DefTrait(..) |
|
||||
def::DefPrimTy(..) |
|
||||
|
@ -1007,11 +1007,7 @@ fn convert_struct_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
|
||||
name: name,
|
||||
disr_val: disr_val,
|
||||
fields: fields,
|
||||
kind: match *def {
|
||||
hir::VariantData::Struct(..) => ty::VariantKind::Struct,
|
||||
hir::VariantData::Tuple(..) => ty::VariantKind::Tuple,
|
||||
hir::VariantData::Unit(..) => ty::VariantKind::Unit,
|
||||
}
|
||||
kind: VariantKind::from_variant_data(def),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,22 +76,23 @@ fn try_inline_def(cx: &DocContext, tcx: &ty::ctxt,
|
||||
record_extern_fqn(cx, did, clean::TypeTrait);
|
||||
clean::TraitItem(build_external_trait(cx, tcx, did))
|
||||
}
|
||||
def::DefFn(did, false) => {
|
||||
// If this function is a tuple struct constructor, we just skip it
|
||||
def::DefFn(did) => {
|
||||
record_extern_fqn(cx, did, clean::TypeFunction);
|
||||
clean::FunctionItem(build_external_function(cx, tcx, did))
|
||||
}
|
||||
def::DefStruct(did) => {
|
||||
def::DefStruct(did)
|
||||
// If this is a struct constructor, we skip it
|
||||
if tcx.sess.cstore.tuple_struct_definition_if_ctor(did).is_none() => {
|
||||
record_extern_fqn(cx, did, clean::TypeStruct);
|
||||
ret.extend(build_impls(cx, tcx, did));
|
||||
clean::StructItem(build_struct(cx, tcx, did))
|
||||
}
|
||||
def::DefTy(did, false) => {
|
||||
def::DefTyAlias(did) => {
|
||||
record_extern_fqn(cx, did, clean::TypeTypedef);
|
||||
ret.extend(build_impls(cx, tcx, did));
|
||||
build_type(cx, tcx, did)
|
||||
}
|
||||
def::DefTy(did, true) => {
|
||||
def::DefEnum(did) => {
|
||||
record_extern_fqn(cx, did, clean::TypeEnum);
|
||||
ret.extend(build_impls(cx, tcx, did));
|
||||
build_type(cx, tcx, did)
|
||||
|
@ -2638,14 +2638,14 @@ fn register_def(cx: &DocContext, def: def::Def) -> DefId {
|
||||
debug!("register_def({:?})", def);
|
||||
|
||||
let (did, kind) = match def {
|
||||
def::DefFn(i, _) => (i, TypeFunction),
|
||||
def::DefTy(i, false) => (i, TypeTypedef),
|
||||
def::DefTy(i, true) => (i, TypeEnum),
|
||||
def::DefFn(i) => (i, TypeFunction),
|
||||
def::DefTyAlias(i) => (i, TypeTypedef),
|
||||
def::DefEnum(i) => (i, TypeEnum),
|
||||
def::DefTrait(i) => (i, TypeTrait),
|
||||
def::DefStruct(i) => (i, TypeStruct),
|
||||
def::DefMod(i) => (i, TypeModule),
|
||||
def::DefStatic(i, _) => (i, TypeStatic),
|
||||
def::DefVariant(i, _, _) => (i, TypeEnum),
|
||||
def::DefVariant(i, _) => (i, TypeEnum),
|
||||
def::DefSelfTy(Some(def_id), _) => (def_id, TypeTrait),
|
||||
def::DefSelfTy(_, Some((impl_id, _))) => return cx.map.local_def_id(impl_id),
|
||||
_ => return def.def_id()
|
||||
|
@ -29,9 +29,8 @@ fn main() {
|
||||
let e3 = E::Empty3; //~ ERROR `E::Empty3` is the name of a struct or struct variant
|
||||
let e3 = E::Empty3(); //~ ERROR `E::Empty3` is the name of a struct or struct variant
|
||||
|
||||
// FIXME: non-local struct kind should be known early (e.g. kept in `DefStruct`)
|
||||
// let xe1 = XEmpty1; // ERROR `XEmpty1` is the name of a struct or struct variant
|
||||
let xe1 = XEmpty1(); //~ ERROR expected function, found `empty_struct::XEmpty1`
|
||||
let xe1 = XEmpty1; //~ ERROR `XEmpty1` is the name of a struct or struct variant
|
||||
let xe1 = XEmpty1(); //~ ERROR `XEmpty1` is the name of a struct or struct variant
|
||||
let xe3 = XE::Empty3; //~ ERROR no associated item named `Empty3` found for type
|
||||
let xe3 = XE::Empty3(); //~ ERROR no associated item named `Empty3` found for type
|
||||
}
|
||||
|
@ -34,6 +34,6 @@ fn main() {
|
||||
Empty1(..) => () //~ ERROR unresolved enum variant, struct or const `Empty1`
|
||||
}
|
||||
match xe1 {
|
||||
XEmpty1(..) => () //~ ERROR `XEmpty1` does not name a tuple variant or a tuple struct
|
||||
XEmpty1(..) => () //~ ERROR unresolved enum variant, struct or const `XEmpty1`
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ mod a {
|
||||
impl S { }
|
||||
}
|
||||
|
||||
fn foo(_: a::S) { //~ ERROR: type `S` is private
|
||||
fn foo(_: a::S) { //~ ERROR: struct `S` is private
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -164,7 +164,7 @@ pub mod mytest {
|
||||
// Even though the inner `A` struct is a publicly exported item (usable from
|
||||
// external crates through `foo::foo`, it should not be accessible through
|
||||
// its definition path (which has the private `i` module).
|
||||
use self::foo::i::A; //~ ERROR: type `A` is inaccessible
|
||||
use self::foo::i::A; //~ ERROR: struct `A` is inaccessible
|
||||
//~^ NOTE: module `i` is private
|
||||
|
||||
pub mod foo {
|
||||
|
@ -28,7 +28,7 @@ pub struct B {
|
||||
}
|
||||
|
||||
fn test(a: A, b: inner::A, c: inner::B, d: xc::A, e: xc::B) {
|
||||
//~^ ERROR: type `A` is private
|
||||
//~^ ERROR: struct `A` is private
|
||||
//~^^ ERROR: struct `A` is private
|
||||
|
||||
a.a;
|
||||
|
@ -16,6 +16,7 @@
|
||||
extern crate xcrate_unit_struct;
|
||||
|
||||
fn main() {
|
||||
let _ = xcrate_unit_struct::StructWithFields; //~ ERROR: unresolved name
|
||||
let _ = xcrate_unit_struct::StructWithFields;
|
||||
//~^ ERROR: `xcrate_unit_struct::StructWithFields` is the name of a struct or struct variant
|
||||
let _ = xcrate_unit_struct::Struct;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
#![feature(associated_consts)]
|
||||
|
||||
struct Foo;
|
||||
type FooWorkaround = Foo;
|
||||
|
||||
enum Bar {
|
||||
Var1,
|
||||
@ -42,7 +43,7 @@ fn main() {
|
||||
});
|
||||
// Trait impl
|
||||
assert!(match Bar::Var1 {
|
||||
Foo::THEBAR => true,
|
||||
FooWorkaround::THEBAR => true,
|
||||
_ => false,
|
||||
});
|
||||
assert!(match Bar::Var1 {
|
||||
|
Loading…
Reference in New Issue
Block a user