diff options
| author | bors <bors@rust-lang.org> | 2020-08-26 22:28:48 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-08-26 22:28:48 +0000 |
| commit | 45a83e97ccc70a99794346eb60c11e209c67ecba (patch) | |
| tree | 90a36982b69257347219e570270f736459127a82 | |
| parent | 2d8a3b9181f41d3af9b9f016c5d73b2553e344bf (diff) | |
| parent | 89daef82d0b9cf7ebbe94c2ff02d232ce7c18184 (diff) | |
| download | rust-45a83e97ccc70a99794346eb60c11e209c67ecba.tar.gz rust-45a83e97ccc70a99794346eb60c11e209c67ecba.zip | |
Auto merge of #75898 - lcnr:variant-def-recovered, r=petrochenkov
VariantDef: move `recovered` into `VariantFlags`
| -rw-r--r-- | src/librustc_middle/ty/mod.rs | 17 | ||||
| -rw-r--r-- | src/librustc_typeck/check/expr.rs | 2 | ||||
| -rw-r--r-- | src/librustc_typeck/check/pat.rs | 2 |
3 files changed, 15 insertions, 6 deletions
diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index a961d02f7a2..364059a5993 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1971,6 +1971,9 @@ 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; } } @@ -1994,9 +1997,6 @@ pub struct VariantDef { pub ctor_kind: CtorKind, /// Flags of the variant (e.g. is field list non-exhaustive)? flags: VariantFlags, - /// Variant is obtained as part of recovering from a syntactic error. - /// May be incomplete or bogus. - pub recovered: bool, } impl<'tcx> VariantDef { @@ -2039,6 +2039,10 @@ impl<'tcx> VariantDef { flags |= VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE; } + if recovered { + flags |= VariantFlags::IS_RECOVERED; + } + VariantDef { def_id: variant_did.unwrap_or(parent_did), ctor_def_id, @@ -2047,7 +2051,6 @@ impl<'tcx> VariantDef { fields, ctor_kind, flags, - recovered, } } @@ -2057,6 +2060,12 @@ impl<'tcx> 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) + } + /// `repr(transparent)` structs can have a single non-ZST field, this function returns that /// field. pub fn transparent_newtype_field(&self, tcx: TyCtxt<'tcx>) -> Option<&FieldDef> { diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 0e9f64c3596..8fb3d0b7d98 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -1296,7 +1296,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { kind_name: &str, ty_span: Span, ) { - if variant.recovered { + if variant.is_recovered() { self.set_tainted_by_errors(); return; } diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index dc1ce2d89ba..d1864ee2b35 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -1080,7 +1080,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .filter(|ident| !used_fields.contains_key(&ident)) .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( adt.variant_descr(), &inexistent_fields, |
