Skip to content

Commit

Permalink
Fixed minor issues raised in review.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Regueiro authored and pietroalbini committed Dec 31, 2018
1 parent 48d930c commit 33417ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ bitflags! {
const IS_ENUM = 1 << 0;
const IS_UNION = 1 << 1;
const IS_STRUCT = 1 << 2;
const IS_TUPLE_STRUCT = 1 << 3;
const HAS_CTOR = 1 << 3;
const IS_PHANTOM_DATA = 1 << 4;
const IS_FUNDAMENTAL = 1 << 5;
const IS_BOX = 1 << 6;
Expand Down Expand Up @@ -2096,7 +2096,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
let variant_def = &variants[VariantIdx::new(0)];
let def_key = tcx.def_key(variant_def.did);
match def_key.disambiguated_data.data {
DefPathData::StructCtor => flags |= AdtFlags::IS_TUPLE_STRUCT,
DefPathData::StructCtor => flags |= AdtFlags::HAS_CTOR,
_ => (),
}
}
Expand Down Expand Up @@ -2131,12 +2131,6 @@ impl<'a, 'gcx, 'tcx> AdtDef {
self.flags.contains(AdtFlags::IS_STRUCT)
}

/// If this function returns `true`, it implies that `is_struct` must return `true`.
#[inline]
pub fn is_tuple_struct(&self) -> bool {
self.flags.contains(AdtFlags::IS_TUPLE_STRUCT)
}

#[inline]
pub fn is_union(&self) -> bool {
self.flags.contains(AdtFlags::IS_UNION)
Expand Down Expand Up @@ -2181,6 +2175,12 @@ impl<'a, 'gcx, 'tcx> AdtDef {
}
}

/// If this function returns `true`, it implies that `is_struct` must return `true`.
#[inline]
pub fn has_ctor(&self) -> bool {
self.flags.contains(AdtFlags::HAS_CTOR)
}

/// Returns whether this type is `#[fundamental]` for the purposes
/// of coherence checking.
#[inline]
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5168,7 +5168,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let adt_def = ty.ty_adt_def();

match adt_def {
Some(adt_def) if adt_def.is_tuple_struct() => {
Some(adt_def) if adt_def.has_ctor() => {
let variant = adt_def.non_enum_variant();
new_def = Def::StructCtor(variant.did, variant.ctor_kind);
(variant.did, self.tcx.type_of(variant.did))
Expand All @@ -5181,8 +5181,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
AdtKind::Enum => {
err.note("did you mean to use one of the enum's variants?");
},
AdtKind::Union => {},
AdtKind::Struct => {
AdtKind::Struct |
AdtKind::Union => {
err.span_label(
span,
format!("did you mean `Self {{ /* fields */ }}`?"),
Expand Down

0 comments on commit 33417ae

Please sign in to comment.