Skip to content

Commit 45a83e9

Browse files
committed
Auto merge of #75898 - lcnr:variant-def-recovered, r=petrochenkov
VariantDef: move `recovered` into `VariantFlags`
2 parents 2d8a3b9 + 89daef8 commit 45a83e9

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/librustc_middle/ty/mod.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,9 @@ bitflags! {
19711971
const NO_VARIANT_FLAGS = 0;
19721972
/// Indicates whether the field list of this variant is `#[non_exhaustive]`.
19731973
const IS_FIELD_LIST_NON_EXHAUSTIVE = 1 << 0;
1974+
/// Indicates whether this variant was obtained as part of recovering from
1975+
/// a syntactic error. May be incomplete or bogus.
1976+
const IS_RECOVERED = 1 << 1;
19741977
}
19751978
}
19761979

@@ -1994,9 +1997,6 @@ pub struct VariantDef {
19941997
pub ctor_kind: CtorKind,
19951998
/// Flags of the variant (e.g. is field list non-exhaustive)?
19961999
flags: VariantFlags,
1997-
/// Variant is obtained as part of recovering from a syntactic error.
1998-
/// May be incomplete or bogus.
1999-
pub recovered: bool,
20002000
}
20012001

20022002
impl<'tcx> VariantDef {
@@ -2039,6 +2039,10 @@ impl<'tcx> VariantDef {
20392039
flags |= VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE;
20402040
}
20412041

2042+
if recovered {
2043+
flags |= VariantFlags::IS_RECOVERED;
2044+
}
2045+
20422046
VariantDef {
20432047
def_id: variant_did.unwrap_or(parent_did),
20442048
ctor_def_id,
@@ -2047,7 +2051,6 @@ impl<'tcx> VariantDef {
20472051
fields,
20482052
ctor_kind,
20492053
flags,
2050-
recovered,
20512054
}
20522055
}
20532056

@@ -2057,6 +2060,12 @@ impl<'tcx> VariantDef {
20572060
self.flags.intersects(VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE)
20582061
}
20592062

2063+
/// Was this variant obtained as part of recovering from a syntactic error?
2064+
#[inline]
2065+
pub fn is_recovered(&self) -> bool {
2066+
self.flags.intersects(VariantFlags::IS_RECOVERED)
2067+
}
2068+
20602069
/// `repr(transparent)` structs can have a single non-ZST field, this function returns that
20612070
/// field.
20622071
pub fn transparent_newtype_field(&self, tcx: TyCtxt<'tcx>) -> Option<&FieldDef> {

src/librustc_typeck/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12961296
kind_name: &str,
12971297
ty_span: Span,
12981298
) {
1299-
if variant.recovered {
1299+
if variant.is_recovered() {
13001300
self.set_tainted_by_errors();
13011301
return;
13021302
}

src/librustc_typeck/check/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10801080
.filter(|ident| !used_fields.contains_key(&ident))
10811081
.collect::<Vec<_>>();
10821082

1083-
let inexistent_fields_err = if !inexistent_fields.is_empty() && !variant.recovered {
1083+
let inexistent_fields_err = if !(inexistent_fields.is_empty() || variant.is_recovered()) {
10841084
Some(self.error_inexistent_fields(
10851085
adt.variant_descr(),
10861086
&inexistent_fields,

0 commit comments

Comments
 (0)