Auto merge of #75898 - lcnr:variant-def-recovered, r=petrochenkov
VariantDef: move `recovered` into `VariantFlags`
This commit is contained in:
commit
45a83e97cc
3 changed files with 15 additions and 6 deletions
|
@ -1971,6 +1971,9 @@ bitflags! {
|
||||||
const NO_VARIANT_FLAGS = 0;
|
const NO_VARIANT_FLAGS = 0;
|
||||||
/// Indicates whether the field list of this variant is `#[non_exhaustive]`.
|
/// Indicates whether the field list of this variant is `#[non_exhaustive]`.
|
||||||
const IS_FIELD_LIST_NON_EXHAUSTIVE = 1 << 0;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1994,9 +1997,6 @@ pub struct VariantDef {
|
||||||
pub ctor_kind: CtorKind,
|
pub ctor_kind: CtorKind,
|
||||||
/// Flags of the variant (e.g. is field list non-exhaustive)?
|
/// Flags of the variant (e.g. is field list non-exhaustive)?
|
||||||
flags: VariantFlags,
|
flags: VariantFlags,
|
||||||
/// Variant is obtained as part of recovering from a syntactic error.
|
|
||||||
/// May be incomplete or bogus.
|
|
||||||
pub recovered: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> VariantDef {
|
impl<'tcx> VariantDef {
|
||||||
|
@ -2039,6 +2039,10 @@ impl<'tcx> VariantDef {
|
||||||
flags |= VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE;
|
flags |= VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if recovered {
|
||||||
|
flags |= VariantFlags::IS_RECOVERED;
|
||||||
|
}
|
||||||
|
|
||||||
VariantDef {
|
VariantDef {
|
||||||
def_id: variant_did.unwrap_or(parent_did),
|
def_id: variant_did.unwrap_or(parent_did),
|
||||||
ctor_def_id,
|
ctor_def_id,
|
||||||
|
@ -2047,7 +2051,6 @@ impl<'tcx> VariantDef {
|
||||||
fields,
|
fields,
|
||||||
ctor_kind,
|
ctor_kind,
|
||||||
flags,
|
flags,
|
||||||
recovered,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2057,6 +2060,12 @@ impl<'tcx> VariantDef {
|
||||||
self.flags.intersects(VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE)
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
/// `repr(transparent)` structs can have a single non-ZST field, this function returns that
|
/// `repr(transparent)` structs can have a single non-ZST field, this function returns that
|
||||||
/// field.
|
/// field.
|
||||||
pub fn transparent_newtype_field(&self, tcx: TyCtxt<'tcx>) -> Option<&FieldDef> {
|
pub fn transparent_newtype_field(&self, tcx: TyCtxt<'tcx>) -> Option<&FieldDef> {
|
||||||
|
|
|
@ -1296,7 +1296,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
kind_name: &str,
|
kind_name: &str,
|
||||||
ty_span: Span,
|
ty_span: Span,
|
||||||
) {
|
) {
|
||||||
if variant.recovered {
|
if variant.is_recovered() {
|
||||||
self.set_tainted_by_errors();
|
self.set_tainted_by_errors();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1080,7 +1080,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
.filter(|ident| !used_fields.contains_key(&ident))
|
.filter(|ident| !used_fields.contains_key(&ident))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let inexistent_fields_err = if !inexistent_fields.is_empty() && !variant.recovered {
|
let inexistent_fields_err = if !(inexistent_fields.is_empty() || variant.is_recovered()) {
|
||||||
Some(self.error_inexistent_fields(
|
Some(self.error_inexistent_fields(
|
||||||
adt.variant_descr(),
|
adt.variant_descr(),
|
||||||
&inexistent_fields,
|
&inexistent_fields,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue