From 33417ae39170a06d98483de9340d0f815b66f436 Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Thu, 13 Dec 2018 15:35:45 +0000 Subject: [PATCH] Fixed minor issues raised in review. --- src/librustc/ty/mod.rs | 16 ++++++++-------- src/librustc_typeck/check/mod.rs | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index c3bb1afd98f23..3adb7f1c5f371 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -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; @@ -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, _ => (), } } @@ -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) @@ -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] diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 57d808d9d78fa..c7e923967b8b3 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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)) @@ -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 */ }}`?"),