report pat no field error no recoverd struct variant
This commit is contained in:
parent
35b658fb10
commit
07e6dd95bd
10 changed files with 131 additions and 32 deletions
|
@ -1159,11 +1159,8 @@ bitflags::bitflags! {
|
|||
const NO_VARIANT_FLAGS = 0;
|
||||
/// Indicates whether the field list of this variant is `#[non_exhaustive]`.
|
||||
const IS_FIELD_LIST_NON_EXHAUSTIVE = 1 << 0;
|
||||
/// Indicates whether this variant was obtained as part of recovering from
|
||||
/// a syntactic error. May be incomplete or bogus.
|
||||
const IS_RECOVERED = 1 << 1;
|
||||
/// Indicates whether this variant has unnamed fields.
|
||||
const HAS_UNNAMED_FIELDS = 1 << 2;
|
||||
const HAS_UNNAMED_FIELDS = 1 << 1;
|
||||
}
|
||||
}
|
||||
rustc_data_structures::external_bitflags_debug! { VariantFlags }
|
||||
|
@ -1183,6 +1180,8 @@ pub struct VariantDef {
|
|||
pub discr: VariantDiscr,
|
||||
/// Fields of this variant.
|
||||
pub fields: IndexVec<FieldIdx, FieldDef>,
|
||||
/// The error guarantees from parser, if any.
|
||||
tainted: Option<ErrorGuaranteed>,
|
||||
/// Flags of the variant (e.g. is field list non-exhaustive)?
|
||||
flags: VariantFlags,
|
||||
}
|
||||
|
@ -1212,7 +1211,7 @@ impl VariantDef {
|
|||
fields: IndexVec<FieldIdx, FieldDef>,
|
||||
adt_kind: AdtKind,
|
||||
parent_did: DefId,
|
||||
recovered: bool,
|
||||
recover_tainted: Option<ErrorGuaranteed>,
|
||||
is_field_list_non_exhaustive: bool,
|
||||
has_unnamed_fields: bool,
|
||||
) -> Self {
|
||||
|
@ -1227,15 +1226,19 @@ impl VariantDef {
|
|||
flags |= VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE;
|
||||
}
|
||||
|
||||
if recovered {
|
||||
flags |= VariantFlags::IS_RECOVERED;
|
||||
}
|
||||
|
||||
if has_unnamed_fields {
|
||||
flags |= VariantFlags::HAS_UNNAMED_FIELDS;
|
||||
}
|
||||
|
||||
VariantDef { def_id: variant_did.unwrap_or(parent_did), ctor, name, discr, fields, flags }
|
||||
VariantDef {
|
||||
def_id: variant_did.unwrap_or(parent_did),
|
||||
ctor,
|
||||
name,
|
||||
discr,
|
||||
fields,
|
||||
flags,
|
||||
tainted: recover_tainted,
|
||||
}
|
||||
}
|
||||
|
||||
/// Is this field list non-exhaustive?
|
||||
|
@ -1244,12 +1247,6 @@ impl VariantDef {
|
|||
self.flags.intersects(VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE)
|
||||
}
|
||||
|
||||
/// Was this variant obtained as part of recovering from a syntactic error?
|
||||
#[inline]
|
||||
pub fn is_recovered(&self) -> bool {
|
||||
self.flags.intersects(VariantFlags::IS_RECOVERED)
|
||||
}
|
||||
|
||||
/// Does this variant contains unnamed fields
|
||||
#[inline]
|
||||
pub fn has_unnamed_fields(&self) -> bool {
|
||||
|
@ -1261,6 +1258,12 @@ impl VariantDef {
|
|||
Ident::new(self.name, tcx.def_ident_span(self.def_id).unwrap())
|
||||
}
|
||||
|
||||
/// Was this variant obtained as part of recovering from a syntactic error?
|
||||
#[inline]
|
||||
pub fn has_errors(&self) -> Result<(), ErrorGuaranteed> {
|
||||
self.tainted.map_or(Ok(()), Err)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn ctor_kind(&self) -> Option<CtorKind> {
|
||||
self.ctor.map(|(kind, _)| kind)
|
||||
|
@ -1308,8 +1311,24 @@ impl PartialEq for VariantDef {
|
|||
// definition of `VariantDef` changes, a compile-error will be produced,
|
||||
// reminding us to revisit this assumption.
|
||||
|
||||
let Self { def_id: lhs_def_id, ctor: _, name: _, discr: _, fields: _, flags: _ } = &self;
|
||||
let Self { def_id: rhs_def_id, ctor: _, name: _, discr: _, fields: _, flags: _ } = other;
|
||||
let Self {
|
||||
def_id: lhs_def_id,
|
||||
ctor: _,
|
||||
name: _,
|
||||
discr: _,
|
||||
fields: _,
|
||||
flags: _,
|
||||
tainted: _,
|
||||
} = &self;
|
||||
let Self {
|
||||
def_id: rhs_def_id,
|
||||
ctor: _,
|
||||
name: _,
|
||||
discr: _,
|
||||
fields: _,
|
||||
flags: _,
|
||||
tainted: _,
|
||||
} = other;
|
||||
|
||||
let res = lhs_def_id == rhs_def_id;
|
||||
|
||||
|
@ -1339,7 +1358,7 @@ impl Hash for VariantDef {
|
|||
// of `VariantDef` changes, a compile-error will be produced, reminding
|
||||
// us to revisit this assumption.
|
||||
|
||||
let Self { def_id, ctor: _, name: _, discr: _, fields: _, flags: _ } = &self;
|
||||
let Self { def_id, ctor: _, name: _, discr: _, fields: _, flags: _, tainted: _ } = &self;
|
||||
def_id.hash(s)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue