mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-05 03:23:25 +00:00
rustc::ty: Rename struct_variant
to non_enum_variant
It is also intended for use with unions.
This commit is contained in:
parent
6828cf9014
commit
cf3fefe97f
@ -102,7 +102,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
|||||||
fn handle_field_access(&mut self, lhs: &hir::Expr, name: ast::Name) {
|
fn handle_field_access(&mut self, lhs: &hir::Expr, name: ast::Name) {
|
||||||
match self.tables.expr_ty_adjusted(lhs).sty {
|
match self.tables.expr_ty_adjusted(lhs).sty {
|
||||||
ty::TyAdt(def, _) => {
|
ty::TyAdt(def, _) => {
|
||||||
self.insert_def_id(def.struct_variant().field_named(name).did);
|
self.insert_def_id(def.non_enum_variant().field_named(name).did);
|
||||||
}
|
}
|
||||||
_ => span_bug!(lhs.span, "named field access on non-ADT"),
|
_ => span_bug!(lhs.span, "named field access on non-ADT"),
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
|||||||
fn handle_tup_field_access(&mut self, lhs: &hir::Expr, idx: usize) {
|
fn handle_tup_field_access(&mut self, lhs: &hir::Expr, idx: usize) {
|
||||||
match self.tables.expr_ty_adjusted(lhs).sty {
|
match self.tables.expr_ty_adjusted(lhs).sty {
|
||||||
ty::TyAdt(def, _) => {
|
ty::TyAdt(def, _) => {
|
||||||
self.insert_def_id(def.struct_variant().fields[idx].did);
|
self.insert_def_id(def.non_enum_variant().fields[idx].did);
|
||||||
}
|
}
|
||||||
ty::TyTuple(..) => {}
|
ty::TyTuple(..) => {}
|
||||||
_ => span_bug!(lhs.span, "numeric field access on non-ADT"),
|
_ => span_bug!(lhs.span, "numeric field access on non-ADT"),
|
||||||
|
@ -663,7 +663,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
|||||||
match with_cmt.ty.sty {
|
match with_cmt.ty.sty {
|
||||||
ty::TyAdt(adt, substs) if adt.is_struct() => {
|
ty::TyAdt(adt, substs) if adt.is_struct() => {
|
||||||
// Consume those fields of the with expression that are needed.
|
// Consume those fields of the with expression that are needed.
|
||||||
for with_field in &adt.struct_variant().fields {
|
for with_field in &adt.non_enum_variant().fields {
|
||||||
if !contains_field_named(with_field, fields) {
|
if !contains_field_named(with_field, fields) {
|
||||||
let cmt_field = self.mc.cat_field(
|
let cmt_field = self.mc.cat_field(
|
||||||
&*with_expr,
|
&*with_expr,
|
||||||
|
@ -1248,7 +1248,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||||||
Def::StructCtor(_, CtorKind::Fn) => {
|
Def::StructCtor(_, CtorKind::Fn) => {
|
||||||
match self.pat_ty(&pat)?.sty {
|
match self.pat_ty(&pat)?.sty {
|
||||||
ty::TyAdt(adt_def, _) => {
|
ty::TyAdt(adt_def, _) => {
|
||||||
(cmt, adt_def.struct_variant().fields.len())
|
(cmt, adt_def.non_enum_variant().fields.len())
|
||||||
}
|
}
|
||||||
ref ty => {
|
ref ty => {
|
||||||
span_bug!(pat.span, "tuple struct pattern unexpected type {:?}", ty);
|
span_bug!(pat.span, "tuple struct pattern unexpected type {:?}", ty);
|
||||||
|
@ -1691,10 +1691,9 @@ impl<'a, 'gcx, 'tcx> AdtDef {
|
|||||||
self.destructor(tcx).is_some()
|
self.destructor(tcx).is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Asserts this is a struct and returns the struct's unique
|
/// Asserts this is a struct or union and returns its unique variant.
|
||||||
/// variant.
|
pub fn non_enum_variant(&self) -> &VariantDef {
|
||||||
pub fn struct_variant(&self) -> &VariantDef {
|
assert!(self.is_struct() || self.is_union());
|
||||||
assert!(!self.is_enum());
|
|
||||||
&self.variants[0]
|
&self.variants[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1733,7 +1732,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
|
|||||||
match def {
|
match def {
|
||||||
Def::Variant(vid) | Def::VariantCtor(vid, ..) => self.variant_with_id(vid),
|
Def::Variant(vid) | Def::VariantCtor(vid, ..) => self.variant_with_id(vid),
|
||||||
Def::Struct(..) | Def::StructCtor(..) | Def::Union(..) |
|
Def::Struct(..) | Def::StructCtor(..) | Def::Union(..) |
|
||||||
Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) => self.struct_variant(),
|
Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) => self.non_enum_variant(),
|
||||||
_ => bug!("unexpected def {:?} in variant_of_def", def)
|
_ => bug!("unexpected def {:?} in variant_of_def", def)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2319,11 +2318,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||||||
self.adt_def(enum_did).variant_with_id(did)
|
self.adt_def(enum_did).variant_with_id(did)
|
||||||
}
|
}
|
||||||
Def::Struct(did) | Def::Union(did) => {
|
Def::Struct(did) | Def::Union(did) => {
|
||||||
self.adt_def(did).struct_variant()
|
self.adt_def(did).non_enum_variant()
|
||||||
}
|
}
|
||||||
Def::StructCtor(ctor_did, ..) => {
|
Def::StructCtor(ctor_did, ..) => {
|
||||||
let did = self.parent_def_id(ctor_did).expect("struct ctor has no parent");
|
let did = self.parent_def_id(ctor_did).expect("struct ctor has no parent");
|
||||||
self.adt_def(did).struct_variant()
|
self.adt_def(did).non_enum_variant()
|
||||||
}
|
}
|
||||||
_ => bug!("expect_variant_def used with unexpected def {:?}", def)
|
_ => bug!("expect_variant_def used with unexpected def {:?}", def)
|
||||||
}
|
}
|
||||||
|
@ -1351,7 +1351,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
|
|||||||
pub fn simd_type(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
|
pub fn simd_type(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
|
||||||
match self.sty {
|
match self.sty {
|
||||||
TyAdt(def, substs) => {
|
TyAdt(def, substs) => {
|
||||||
def.struct_variant().fields[0].ty(tcx, substs)
|
def.non_enum_variant().fields[0].ty(tcx, substs)
|
||||||
}
|
}
|
||||||
_ => bug!("simd_type called on invalid type")
|
_ => bug!("simd_type called on invalid type")
|
||||||
}
|
}
|
||||||
@ -1359,7 +1359,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
|
|||||||
|
|
||||||
pub fn simd_size(&self, _cx: TyCtxt) -> usize {
|
pub fn simd_size(&self, _cx: TyCtxt) -> usize {
|
||||||
match self.sty {
|
match self.sty {
|
||||||
TyAdt(def, _) => def.struct_variant().fields.len(),
|
TyAdt(def, _) => def.non_enum_variant().fields.len(),
|
||||||
_ => bug!("simd_size called on invalid type")
|
_ => bug!("simd_size called on invalid type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||||||
adt.variant_with_id(vid).fields.get(i).map(|f| f.ty(self, substs))
|
adt.variant_with_id(vid).fields.get(i).map(|f| f.ty(self, substs))
|
||||||
}
|
}
|
||||||
(&TyAdt(adt, substs), None) => {
|
(&TyAdt(adt, substs), None) => {
|
||||||
// Don't use `struct_variant`, this may be a univariant enum.
|
// Don't use `non_enum_variant`, this may be a univariant enum.
|
||||||
adt.variants[0].fields.get(i).map(|f| f.ty(self, substs))
|
adt.variants[0].fields.get(i).map(|f| f.ty(self, substs))
|
||||||
}
|
}
|
||||||
(&TyTuple(ref v, _), None) => v.get(i).cloned(),
|
(&TyTuple(ref v, _), None) => v.get(i).cloned(),
|
||||||
@ -277,7 +277,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||||||
adt.variant_with_id(vid).find_field_named(n).map(|f| f.ty(self, substs))
|
adt.variant_with_id(vid).find_field_named(n).map(|f| f.ty(self, substs))
|
||||||
}
|
}
|
||||||
(&TyAdt(adt, substs), None) => {
|
(&TyAdt(adt, substs), None) => {
|
||||||
adt.struct_variant().find_field_named(n).map(|f| f.ty(self, substs))
|
adt.non_enum_variant().find_field_named(n).map(|f| f.ty(self, substs))
|
||||||
}
|
}
|
||||||
_ => return None
|
_ => return None
|
||||||
}
|
}
|
||||||
@ -293,7 +293,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||||||
if !def.is_struct() {
|
if !def.is_struct() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
match def.struct_variant().fields.last() {
|
match def.non_enum_variant().fields.last() {
|
||||||
Some(f) => ty = f.ty(self, substs),
|
Some(f) => ty = f.ty(self, substs),
|
||||||
None => break,
|
None => break,
|
||||||
}
|
}
|
||||||
@ -329,7 +329,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||||||
match (&a.sty, &b.sty) {
|
match (&a.sty, &b.sty) {
|
||||||
(&TyAdt(a_def, a_substs), &TyAdt(b_def, b_substs))
|
(&TyAdt(a_def, a_substs), &TyAdt(b_def, b_substs))
|
||||||
if a_def == b_def && a_def.is_struct() => {
|
if a_def == b_def && a_def.is_struct() => {
|
||||||
if let Some(f) = a_def.struct_variant().fields.last() {
|
if let Some(f) = a_def.non_enum_variant().fields.last() {
|
||||||
a = f.ty(self, a_substs);
|
a = f.ty(self, a_substs);
|
||||||
b = f.ty(self, b_substs);
|
b = f.ty(self, b_substs);
|
||||||
} else {
|
} else {
|
||||||
|
@ -107,7 +107,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
|
|||||||
ty::TyAdt(adt_def, _) if adt_def.is_union() => match result {
|
ty::TyAdt(adt_def, _) if adt_def.is_union() => match result {
|
||||||
RestrictionResult::Safe => RestrictionResult::Safe,
|
RestrictionResult::Safe => RestrictionResult::Safe,
|
||||||
RestrictionResult::SafeIf(base_lp, mut base_vec) => {
|
RestrictionResult::SafeIf(base_lp, mut base_vec) => {
|
||||||
for field in &adt_def.struct_variant().fields {
|
for field in &adt_def.non_enum_variant().fields {
|
||||||
let field = InteriorKind::InteriorField(mc::NamedField(field.name));
|
let field = InteriorKind::InteriorField(mc::NamedField(field.name));
|
||||||
let field_ty = if field == interior {
|
let field_ty = if field == interior {
|
||||||
cmt.ty
|
cmt.ty
|
||||||
|
@ -343,7 +343,7 @@ impl<'a, 'tcx> MoveData<'tcx> {
|
|||||||
if let (&ty::TyAdt(adt_def, _), LpInterior(opt_variant_id, interior))
|
if let (&ty::TyAdt(adt_def, _), LpInterior(opt_variant_id, interior))
|
||||||
= (&base_lp.ty.sty, lp_elem) {
|
= (&base_lp.ty.sty, lp_elem) {
|
||||||
if adt_def.is_union() {
|
if adt_def.is_union() {
|
||||||
for field in &adt_def.struct_variant().fields {
|
for field in &adt_def.non_enum_variant().fields {
|
||||||
let field = InteriorKind::InteriorField(mc::NamedField(field.name));
|
let field = InteriorKind::InteriorField(mc::NamedField(field.name));
|
||||||
if field != interior {
|
if field != interior {
|
||||||
let sibling_lp_kind =
|
let sibling_lp_kind =
|
||||||
@ -395,7 +395,7 @@ impl<'a, 'tcx> MoveData<'tcx> {
|
|||||||
if let LpExtend(ref base_lp, mutbl, LpInterior(opt_variant_id, interior)) = lp.kind {
|
if let LpExtend(ref base_lp, mutbl, LpInterior(opt_variant_id, interior)) = lp.kind {
|
||||||
if let ty::TyAdt(adt_def, _) = base_lp.ty.sty {
|
if let ty::TyAdt(adt_def, _) = base_lp.ty.sty {
|
||||||
if adt_def.is_union() {
|
if adt_def.is_union() {
|
||||||
for field in &adt_def.struct_variant().fields {
|
for field in &adt_def.non_enum_variant().fields {
|
||||||
let field = InteriorKind::InteriorField(mc::NamedField(field.name));
|
let field = InteriorKind::InteriorField(mc::NamedField(field.name));
|
||||||
let field_ty = if field == interior {
|
let field_ty = if field == interior {
|
||||||
lp.ty
|
lp.ty
|
||||||
|
@ -422,7 +422,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
|||||||
consider adding a #[repr(C)] attribute to the type");
|
consider adding a #[repr(C)] attribute to the type");
|
||||||
}
|
}
|
||||||
|
|
||||||
if def.struct_variant().fields.is_empty() {
|
if def.non_enum_variant().fields.is_empty() {
|
||||||
return FfiUnsafe("found zero-size struct in foreign module, consider \
|
return FfiUnsafe("found zero-size struct in foreign module, consider \
|
||||||
adding a member to this struct");
|
adding a member to this struct");
|
||||||
}
|
}
|
||||||
@ -430,7 +430,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
|||||||
// We can't completely trust repr(C) markings; make sure the
|
// We can't completely trust repr(C) markings; make sure the
|
||||||
// fields are actually safe.
|
// fields are actually safe.
|
||||||
let mut all_phantom = true;
|
let mut all_phantom = true;
|
||||||
for field in &def.struct_variant().fields {
|
for field in &def.non_enum_variant().fields {
|
||||||
let field_ty = cx.fully_normalize_associated_types_in(
|
let field_ty = cx.fully_normalize_associated_types_in(
|
||||||
&field.ty(cx, substs)
|
&field.ty(cx, substs)
|
||||||
);
|
);
|
||||||
@ -458,13 +458,13 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
|||||||
consider adding a #[repr(C)] attribute to the type");
|
consider adding a #[repr(C)] attribute to the type");
|
||||||
}
|
}
|
||||||
|
|
||||||
if def.struct_variant().fields.is_empty() {
|
if def.non_enum_variant().fields.is_empty() {
|
||||||
return FfiUnsafe("found zero-size union in foreign module, consider \
|
return FfiUnsafe("found zero-size union in foreign module, consider \
|
||||||
adding a member to this union");
|
adding a member to this union");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut all_phantom = true;
|
let mut all_phantom = true;
|
||||||
for field in &def.struct_variant().fields {
|
for field in &def.non_enum_variant().fields {
|
||||||
let field_ty = cx.fully_normalize_associated_types_in(
|
let field_ty = cx.fully_normalize_associated_types_in(
|
||||||
&field.ty(cx, substs)
|
&field.ty(cx, substs)
|
||||||
);
|
);
|
||||||
|
@ -587,7 +587,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
|
|||||||
debug!("IsolatedEncoder::encode_struct_ctor({:?})", def_id);
|
debug!("IsolatedEncoder::encode_struct_ctor({:?})", def_id);
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
let adt_def = tcx.adt_def(adt_def_id);
|
let adt_def = tcx.adt_def(adt_def_id);
|
||||||
let variant = adt_def.struct_variant();
|
let variant = adt_def.non_enum_variant();
|
||||||
|
|
||||||
let data = VariantData {
|
let data = VariantData {
|
||||||
ctor_kind: variant.ctor_kind,
|
ctor_kind: variant.ctor_kind,
|
||||||
@ -897,7 +897,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
|
|||||||
hir::ItemTy(..) => EntryKind::Type,
|
hir::ItemTy(..) => EntryKind::Type,
|
||||||
hir::ItemEnum(..) => EntryKind::Enum(get_repr_options(&tcx, def_id)),
|
hir::ItemEnum(..) => EntryKind::Enum(get_repr_options(&tcx, def_id)),
|
||||||
hir::ItemStruct(ref struct_def, _) => {
|
hir::ItemStruct(ref struct_def, _) => {
|
||||||
let variant = tcx.adt_def(def_id).struct_variant();
|
let variant = tcx.adt_def(def_id).non_enum_variant();
|
||||||
|
|
||||||
// Encode def_ids for each field and method
|
// Encode def_ids for each field and method
|
||||||
// for methods, write all the stuff get_trait_method
|
// for methods, write all the stuff get_trait_method
|
||||||
@ -918,7 +918,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
|
|||||||
}), repr_options)
|
}), repr_options)
|
||||||
}
|
}
|
||||||
hir::ItemUnion(..) => {
|
hir::ItemUnion(..) => {
|
||||||
let variant = tcx.adt_def(def_id).struct_variant();
|
let variant = tcx.adt_def(def_id).non_enum_variant();
|
||||||
let repr_options = get_repr_options(&tcx, def_id);
|
let repr_options = get_repr_options(&tcx, def_id);
|
||||||
|
|
||||||
EntryKind::Union(self.lazy(&VariantData {
|
EntryKind::Union(self.lazy(&VariantData {
|
||||||
@ -1011,7 +1011,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
|
|||||||
hir::ItemStruct(..) |
|
hir::ItemStruct(..) |
|
||||||
hir::ItemUnion(..) => {
|
hir::ItemUnion(..) => {
|
||||||
let def = self.tcx.adt_def(def_id);
|
let def = self.tcx.adt_def(def_id);
|
||||||
self.lazy_seq(def.struct_variant().fields.iter().map(|f| {
|
self.lazy_seq(def.non_enum_variant().fields.iter().map(|f| {
|
||||||
assert!(f.did.is_local());
|
assert!(f.did.is_local());
|
||||||
f.did.index
|
f.did.index
|
||||||
}))
|
}))
|
||||||
|
@ -719,7 +719,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|||||||
ty::TyAdt(def, _) => if def.is_enum() {
|
ty::TyAdt(def, _) => if def.is_enum() {
|
||||||
format!("{}", field.index())
|
format!("{}", field.index())
|
||||||
} else {
|
} else {
|
||||||
format!("{}", def.struct_variant().fields[field.index()].name)
|
format!("{}", def.non_enum_variant().fields[field.index()].name)
|
||||||
},
|
},
|
||||||
ty::TyTuple(_, _) => format!("{}", field.index()),
|
ty::TyTuple(_, _) => format!("{}", field.index()),
|
||||||
ty::TyRef(_, tnm) | ty::TyRawPtr(tnm) => {
|
ty::TyRef(_, tnm) | ty::TyRawPtr(tnm) => {
|
||||||
|
@ -488,7 +488,7 @@ fn check_ctfe_against_miri<'a, 'tcx>(
|
|||||||
miri_place = ecx.place_downcast(miri_place, variant).unwrap();
|
miri_place = ecx.place_downcast(miri_place, variant).unwrap();
|
||||||
&def.variants[variant]
|
&def.variants[variant]
|
||||||
} else {
|
} else {
|
||||||
def.struct_variant()
|
def.non_enum_variant()
|
||||||
};
|
};
|
||||||
let vec = match ctfe {
|
let vec = match ctfe {
|
||||||
ConstVal::Aggregate(Struct(v)) => v,
|
ConstVal::Aggregate(Struct(v)) => v,
|
||||||
|
@ -838,8 +838,8 @@ fn find_vtable_types_for_unsizing<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||||||
CustomCoerceUnsized::Struct(i) => i
|
CustomCoerceUnsized::Struct(i) => i
|
||||||
};
|
};
|
||||||
|
|
||||||
let source_fields = &source_adt_def.struct_variant().fields;
|
let source_fields = &source_adt_def.non_enum_variant().fields;
|
||||||
let target_fields = &target_adt_def.struct_variant().fields;
|
let target_fields = &target_adt_def.non_enum_variant().fields;
|
||||||
|
|
||||||
assert!(coerce_index < source_fields.len() &&
|
assert!(coerce_index < source_fields.len() &&
|
||||||
source_fields.len() == target_fields.len());
|
source_fields.len() == target_fields.len());
|
||||||
|
@ -1583,10 +1583,12 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
|
|||||||
if !self.span.filter_generated(sub_span, ex.span) {
|
if !self.span.filter_generated(sub_span, ex.span) {
|
||||||
let span =
|
let span =
|
||||||
self.span_from_span(sub_span.expect("No span found for var ref"));
|
self.span_from_span(sub_span.expect("No span found for var ref"));
|
||||||
|
let ref_id =
|
||||||
|
::id_from_def_id(def.non_enum_variant().fields[idx.node].did);
|
||||||
self.dumper.dump_ref(Ref {
|
self.dumper.dump_ref(Ref {
|
||||||
kind: RefKind::Variable,
|
kind: RefKind::Variable,
|
||||||
span,
|
span,
|
||||||
ref_id: ::id_from_def_id(def.struct_variant().fields[idx.node].did),
|
ref_id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -528,7 +528,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||||||
};
|
};
|
||||||
match self.tables.expr_ty_adjusted(&hir_node).sty {
|
match self.tables.expr_ty_adjusted(&hir_node).sty {
|
||||||
ty::TyAdt(def, _) if !def.is_enum() => {
|
ty::TyAdt(def, _) if !def.is_enum() => {
|
||||||
let f = def.struct_variant().field_named(ident.node.name);
|
let f = def.non_enum_variant().field_named(ident.node.name);
|
||||||
let sub_span = self.span_utils.span_for_last_ident(expr.span);
|
let sub_span = self.span_utils.span_for_last_ident(expr.span);
|
||||||
filter!(self.span_utils, sub_span, expr.span, None);
|
filter!(self.span_utils, sub_span, expr.span, None);
|
||||||
let span = self.span_from_span(sub_span.unwrap());
|
let span = self.span_from_span(sub_span.unwrap());
|
||||||
|
@ -969,7 +969,7 @@ fn prepare_struct_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
|||||||
let struct_name = compute_debuginfo_type_name(cx, struct_type, false);
|
let struct_name = compute_debuginfo_type_name(cx, struct_type, false);
|
||||||
|
|
||||||
let (struct_def_id, variant) = match struct_type.sty {
|
let (struct_def_id, variant) = match struct_type.sty {
|
||||||
ty::TyAdt(def, _) => (def.did, def.struct_variant()),
|
ty::TyAdt(def, _) => (def.did, def.non_enum_variant()),
|
||||||
_ => bug!("prepare_struct_metadata on a non-ADT")
|
_ => bug!("prepare_struct_metadata on a non-ADT")
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1084,7 +1084,7 @@ fn prepare_union_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
|||||||
let union_name = compute_debuginfo_type_name(cx, union_type, false);
|
let union_name = compute_debuginfo_type_name(cx, union_type, false);
|
||||||
|
|
||||||
let (union_def_id, variant) = match union_type.sty {
|
let (union_def_id, variant) = match union_type.sty {
|
||||||
ty::TyAdt(def, _) => (def.did, def.struct_variant()),
|
ty::TyAdt(def, _) => (def.did, def.non_enum_variant()),
|
||||||
_ => bug!("prepare_union_metadata on a non-ADT")
|
_ => bug!("prepare_union_metadata on a non-ADT")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
ty::TyDynamic(ref tty, ..) =>
|
ty::TyDynamic(ref tty, ..) =>
|
||||||
Some(PointerKind::Vtable(tty.principal().map(|p| p.def_id()))),
|
Some(PointerKind::Vtable(tty.principal().map(|p| p.def_id()))),
|
||||||
ty::TyAdt(def, substs) if def.is_struct() => {
|
ty::TyAdt(def, substs) if def.is_struct() => {
|
||||||
match def.struct_variant().fields.last() {
|
match def.non_enum_variant().fields.last() {
|
||||||
None => Some(PointerKind::Thin),
|
None => Some(PointerKind::Thin),
|
||||||
Some(f) => {
|
Some(f) => {
|
||||||
let field_ty = self.field_ty(span, f, substs);
|
let field_ty = self.field_ty(span, f, substs);
|
||||||
|
@ -228,7 +228,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
for (ty, _) in self.autoderef(span, rcvr_ty) {
|
for (ty, _) in self.autoderef(span, rcvr_ty) {
|
||||||
match ty.sty {
|
match ty.sty {
|
||||||
ty::TyAdt(def, substs) if !def.is_enum() => {
|
ty::TyAdt(def, substs) if !def.is_enum() => {
|
||||||
if let Some(field) = def.struct_variant()
|
if let Some(field) = def.non_enum_variant()
|
||||||
.find_field_named(item_name) {
|
.find_field_named(item_name) {
|
||||||
let snippet = tcx.sess.codemap().span_to_snippet(expr.span);
|
let snippet = tcx.sess.codemap().span_to_snippet(expr.span);
|
||||||
let expr_string = match snippet {
|
let expr_string = match snippet {
|
||||||
|
@ -1444,7 +1444,7 @@ pub fn check_simd<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: DefId
|
|||||||
let t = tcx.type_of(def_id);
|
let t = tcx.type_of(def_id);
|
||||||
match t.sty {
|
match t.sty {
|
||||||
ty::TyAdt(def, substs) if def.is_struct() => {
|
ty::TyAdt(def, substs) if def.is_struct() => {
|
||||||
let fields = &def.struct_variant().fields;
|
let fields = &def.non_enum_variant().fields;
|
||||||
if fields.is_empty() {
|
if fields.is_empty() {
|
||||||
span_err!(tcx.sess, sp, E0075, "SIMD vector cannot be empty");
|
span_err!(tcx.sess, sp, E0075, "SIMD vector cannot be empty");
|
||||||
return;
|
return;
|
||||||
@ -1498,7 +1498,7 @@ fn check_packed_inner<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||||||
}
|
}
|
||||||
// push struct def_id before checking fields
|
// push struct def_id before checking fields
|
||||||
stack.push(def_id);
|
stack.push(def_id);
|
||||||
for field in &def.struct_variant().fields {
|
for field in &def.non_enum_variant().fields {
|
||||||
let f = field.ty(tcx, substs);
|
let f = field.ty(tcx, substs);
|
||||||
match f.sty {
|
match f.sty {
|
||||||
ty::TyAdt(def, _) => {
|
ty::TyAdt(def, _) => {
|
||||||
@ -2945,7 +2945,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
debug!("struct named {:?}", base_t);
|
debug!("struct named {:?}", base_t);
|
||||||
let (ident, def_scope) =
|
let (ident, def_scope) =
|
||||||
self.tcx.adjust(field.node, base_def.did, self.body_id);
|
self.tcx.adjust(field.node, base_def.did, self.body_id);
|
||||||
let fields = &base_def.struct_variant().fields;
|
let fields = &base_def.non_enum_variant().fields;
|
||||||
if let Some(field) = fields.iter().find(|f| f.name.to_ident() == ident) {
|
if let Some(field) = fields.iter().find(|f| f.name.to_ident() == ident) {
|
||||||
let field_ty = self.field_ty(expr.span, field, substs);
|
let field_ty = self.field_ty(expr.span, field, substs);
|
||||||
if field.vis.is_accessible_from(def_scope, self.tcx) {
|
if field.vis.is_accessible_from(def_scope, self.tcx) {
|
||||||
@ -2993,12 +2993,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
match expr_t.sty {
|
match expr_t.sty {
|
||||||
ty::TyAdt(def, _) if !def.is_enum() => {
|
ty::TyAdt(def, _) if !def.is_enum() => {
|
||||||
if let Some(suggested_field_name) =
|
if let Some(suggested_field_name) =
|
||||||
Self::suggest_field_name(def.struct_variant(), field, vec![]) {
|
Self::suggest_field_name(def.non_enum_variant(), field, vec![]) {
|
||||||
err.span_label(field.span,
|
err.span_label(field.span,
|
||||||
format!("did you mean `{}`?", suggested_field_name));
|
format!("did you mean `{}`?", suggested_field_name));
|
||||||
} else {
|
} else {
|
||||||
err.span_label(field.span, "unknown field");
|
err.span_label(field.span, "unknown field");
|
||||||
let struct_variant_def = def.struct_variant();
|
let struct_variant_def = def.non_enum_variant();
|
||||||
let field_names = self.available_field_names(struct_variant_def);
|
let field_names = self.available_field_names(struct_variant_def);
|
||||||
if !field_names.is_empty() {
|
if !field_names.is_empty() {
|
||||||
err.note(&format!("available fields are: {}",
|
err.note(&format!("available fields are: {}",
|
||||||
@ -3080,7 +3080,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
while let Some((base_t, _)) = autoderef.next() {
|
while let Some((base_t, _)) = autoderef.next() {
|
||||||
let field = match base_t.sty {
|
let field = match base_t.sty {
|
||||||
ty::TyAdt(base_def, substs) if base_def.is_struct() => {
|
ty::TyAdt(base_def, substs) if base_def.is_struct() => {
|
||||||
tuple_like = base_def.struct_variant().ctor_kind == CtorKind::Fn;
|
tuple_like = base_def.non_enum_variant().ctor_kind == CtorKind::Fn;
|
||||||
if !tuple_like { continue }
|
if !tuple_like { continue }
|
||||||
|
|
||||||
debug!("tuple struct named {:?}", base_t);
|
debug!("tuple struct named {:?}", base_t);
|
||||||
@ -3090,7 +3090,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
};
|
};
|
||||||
let (ident, def_scope) =
|
let (ident, def_scope) =
|
||||||
self.tcx.adjust_ident(ident, base_def.did, self.body_id);
|
self.tcx.adjust_ident(ident, base_def.did, self.body_id);
|
||||||
let fields = &base_def.struct_variant().fields;
|
let fields = &base_def.non_enum_variant().fields;
|
||||||
if let Some(field) = fields.iter().find(|f| f.name.to_ident() == ident) {
|
if let Some(field) = fields.iter().find(|f| f.name.to_ident() == ident) {
|
||||||
let field_ty = self.field_ty(expr.span, field, substs);
|
let field_ty = self.field_ty(expr.span, field, substs);
|
||||||
if field.vis.is_accessible_from(def_scope, self.tcx) {
|
if field.vis.is_accessible_from(def_scope, self.tcx) {
|
||||||
@ -3350,7 +3350,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
Def::AssociatedTy(..) | Def::SelfTy(..) => {
|
Def::AssociatedTy(..) | Def::SelfTy(..) => {
|
||||||
match ty.sty {
|
match ty.sty {
|
||||||
ty::TyAdt(adt, substs) if !adt.is_enum() => {
|
ty::TyAdt(adt, substs) if !adt.is_enum() => {
|
||||||
Some((adt.struct_variant(), adt.did, substs))
|
Some((adt.non_enum_variant(), adt.did, substs))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
@ -3412,7 +3412,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
self.check_expr_has_type_or_error(base_expr, struct_ty);
|
self.check_expr_has_type_or_error(base_expr, struct_ty);
|
||||||
match struct_ty.sty {
|
match struct_ty.sty {
|
||||||
ty::TyAdt(adt, substs) if adt.is_struct() => {
|
ty::TyAdt(adt, substs) if adt.is_struct() => {
|
||||||
let fru_field_types = adt.struct_variant().fields.iter().map(|f| {
|
let fru_field_types = adt.non_enum_variant().fields.iter().map(|f| {
|
||||||
self.normalize_associated_types_in(expr.span, &f.ty(self.tcx, substs))
|
self.normalize_associated_types_in(expr.span, &f.ty(self.tcx, substs))
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
|
@ -130,14 +130,14 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
|
|||||||
}
|
}
|
||||||
hir::ItemStruct(ref struct_def, ref ast_generics) => {
|
hir::ItemStruct(ref struct_def, ref ast_generics) => {
|
||||||
self.check_type_defn(item, false, |fcx| {
|
self.check_type_defn(item, false, |fcx| {
|
||||||
vec![fcx.struct_variant(struct_def)]
|
vec![fcx.non_enum_variant(struct_def)]
|
||||||
});
|
});
|
||||||
|
|
||||||
self.check_variances_for_type_defn(item, ast_generics);
|
self.check_variances_for_type_defn(item, ast_generics);
|
||||||
}
|
}
|
||||||
hir::ItemUnion(ref struct_def, ref ast_generics) => {
|
hir::ItemUnion(ref struct_def, ref ast_generics) => {
|
||||||
self.check_type_defn(item, true, |fcx| {
|
self.check_type_defn(item, true, |fcx| {
|
||||||
vec![fcx.struct_variant(struct_def)]
|
vec![fcx.non_enum_variant(struct_def)]
|
||||||
});
|
});
|
||||||
|
|
||||||
self.check_variances_for_type_defn(item, ast_generics);
|
self.check_variances_for_type_defn(item, ast_generics);
|
||||||
@ -689,7 +689,7 @@ struct AdtField<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
fn struct_variant(&self, struct_def: &hir::VariantData) -> AdtVariant<'tcx> {
|
fn non_enum_variant(&self, struct_def: &hir::VariantData) -> AdtVariant<'tcx> {
|
||||||
let fields =
|
let fields =
|
||||||
struct_def.fields().iter()
|
struct_def.fields().iter()
|
||||||
.map(|field| {
|
.map(|field| {
|
||||||
@ -704,7 +704,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
|
|
||||||
fn enum_variants(&self, enum_def: &hir::EnumDef) -> Vec<AdtVariant<'tcx>> {
|
fn enum_variants(&self, enum_def: &hir::EnumDef) -> Vec<AdtVariant<'tcx>> {
|
||||||
enum_def.variants.iter()
|
enum_def.variants.iter()
|
||||||
.map(|variant| self.struct_variant(&variant.node.data))
|
.map(|variant| self.non_enum_variant(&variant.node.data))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ pub fn coerce_unsized_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||||||
// conversion). This will work out because `U:
|
// conversion). This will work out because `U:
|
||||||
// Unsize<V>`, and we have a builtin rule that `*mut
|
// Unsize<V>`, and we have a builtin rule that `*mut
|
||||||
// U` can be coerced to `*mut V` if `U: Unsize<V>`.
|
// U` can be coerced to `*mut V` if `U: Unsize<V>`.
|
||||||
let fields = &def_a.struct_variant().fields;
|
let fields = &def_a.non_enum_variant().fields;
|
||||||
let diff_fields = fields.iter()
|
let diff_fields = fields.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(i, f)| {
|
.filter_map(|(i, f)| {
|
||||||
|
@ -186,7 +186,7 @@ fn build_enum(cx: &DocContext, did: DefId) -> clean::Enum {
|
|||||||
|
|
||||||
fn build_struct(cx: &DocContext, did: DefId) -> clean::Struct {
|
fn build_struct(cx: &DocContext, did: DefId) -> clean::Struct {
|
||||||
let predicates = cx.tcx.predicates_of(did);
|
let predicates = cx.tcx.predicates_of(did);
|
||||||
let variant = cx.tcx.adt_def(did).struct_variant();
|
let variant = cx.tcx.adt_def(did).non_enum_variant();
|
||||||
|
|
||||||
clean::Struct {
|
clean::Struct {
|
||||||
struct_type: match variant.ctor_kind {
|
struct_type: match variant.ctor_kind {
|
||||||
@ -202,7 +202,7 @@ fn build_struct(cx: &DocContext, did: DefId) -> clean::Struct {
|
|||||||
|
|
||||||
fn build_union(cx: &DocContext, did: DefId) -> clean::Union {
|
fn build_union(cx: &DocContext, did: DefId) -> clean::Union {
|
||||||
let predicates = cx.tcx.predicates_of(did);
|
let predicates = cx.tcx.predicates_of(did);
|
||||||
let variant = cx.tcx.adt_def(did).struct_variant();
|
let variant = cx.tcx.adt_def(did).non_enum_variant();
|
||||||
|
|
||||||
clean::Union {
|
clean::Union {
|
||||||
struct_type: doctree::Plain,
|
struct_type: doctree::Plain,
|
||||||
|
Loading…
Reference in New Issue
Block a user