diff options
Diffstat (limited to 'compiler/rustc_pattern_analysis/src')
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/constructor.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/lints.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/pat.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/rustc.rs | 29 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/usefulness.rs | 8 |
6 files changed, 25 insertions, 23 deletions
diff --git a/compiler/rustc_pattern_analysis/src/constructor.rs b/compiler/rustc_pattern_analysis/src/constructor.rs index 3a2a75a638f..3cb7576154f 100644 --- a/compiler/rustc_pattern_analysis/src/constructor.rs +++ b/compiler/rustc_pattern_analysis/src/constructor.rs @@ -176,13 +176,13 @@ //! we assume they never cover each other. In order to respect the invariants of //! [`SplitConstructorSet`], we give each `Opaque` constructor a unique id so we can recognize it. -use std::cmp::{self, max, min, Ordering}; +use std::cmp::{self, Ordering, max, min}; use std::fmt; use std::iter::once; use rustc_apfloat::ieee::{DoubleS, HalfS, IeeeFloat, QuadS, SingleS}; -use rustc_index::bit_set::{BitSet, GrowableBitSet}; use rustc_index::IndexVec; +use rustc_index::bit_set::{BitSet, GrowableBitSet}; use smallvec::SmallVec; use self::Constructor::*; @@ -288,7 +288,7 @@ impl IntRange { /// Best effort; will not know that e.g. `255u8..` is a singleton. pub fn is_singleton(&self) -> bool { // Since `lo` and `hi` can't be the same `Infinity` and `plus_one` never changes from finite - // to infinite, this correctly only detects ranges that contain exacly one `Finite(x)`. + // to infinite, this correctly only detects ranges that contain exactly one `Finite(x)`. self.lo.plus_one() == Some(self.hi) } diff --git a/compiler/rustc_pattern_analysis/src/lib.rs b/compiler/rustc_pattern_analysis/src/lib.rs index 6c9c848bb10..fec44d5af55 100644 --- a/compiler/rustc_pattern_analysis/src/lib.rs +++ b/compiler/rustc_pattern_analysis/src/lib.rs @@ -6,6 +6,7 @@ #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] #![cfg_attr(feature = "rustc", feature(let_chains))] +#![warn(unreachable_pub)] // tidy-alphabetical-end pub mod constructor; diff --git a/compiler/rustc_pattern_analysis/src/lints.rs b/compiler/rustc_pattern_analysis/src/lints.rs index 6bcef0ec879..585cda1d24b 100644 --- a/compiler/rustc_pattern_analysis/src/lints.rs +++ b/compiler/rustc_pattern_analysis/src/lints.rs @@ -2,11 +2,11 @@ use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS; use rustc_span::ErrorGuaranteed; use tracing::instrument; +use crate::MatchArm; use crate::constructor::Constructor; use crate::errors::{NonExhaustiveOmittedPattern, NonExhaustiveOmittedPatternLintOnArm, Uncovered}; use crate::pat_column::PatternColumn; use crate::rustc::{RevealedTy, RustcPatCtxt, WitnessPat}; -use crate::MatchArm; /// Traverse the patterns to collect any variants of a non_exhaustive enum that fail to be mentioned /// in a given column. diff --git a/compiler/rustc_pattern_analysis/src/pat.rs b/compiler/rustc_pattern_analysis/src/pat.rs index d91deab160c..901b72e5399 100644 --- a/compiler/rustc_pattern_analysis/src/pat.rs +++ b/compiler/rustc_pattern_analysis/src/pat.rs @@ -3,7 +3,7 @@ use std::fmt; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use self::Constructor::*; use crate::constructor::{Constructor, Slice, SliceKind}; diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index d7885e05a2f..72737fb98cb 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -2,8 +2,8 @@ use std::fmt; use std::iter::once; use rustc_arena::DroplessArena; -use rustc_hir::def_id::DefId; use rustc_hir::HirId; +use rustc_hir::def_id::DefId; use rustc_index::{Idx, IndexVec}; use rustc_middle::middle::stability::EvalResult; use rustc_middle::mir::{self, Const}; @@ -14,8 +14,8 @@ use rustc_middle::ty::{ }; use rustc_middle::{bug, span_bug}; use rustc_session::lint; -use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP}; -use rustc_target::abi::{FieldIdx, Integer, VariantIdx, FIRST_VARIANT}; +use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span}; +use rustc_target::abi::{FIRST_VARIANT, FieldIdx, Integer, VariantIdx}; use crate::constructor::Constructor::*; use crate::constructor::{ @@ -24,8 +24,8 @@ use crate::constructor::{ use crate::lints::lint_nonexhaustive_missing_variants; use crate::pat_column::PatternColumn; use crate::rustc::print::EnumInfo; -use crate::usefulness::{compute_match_usefulness, PlaceValidity}; -use crate::{errors, Captures, PatCx, PrivateUninhabitedField}; +use crate::usefulness::{PlaceValidity, compute_match_usefulness}; +use crate::{Captures, PatCx, PrivateUninhabitedField, errors}; mod print; @@ -229,17 +229,11 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { } else { let variant = &adt.variant(RustcPatCtxt::variant_index_for_adt(&ctor, *adt)); - - // In the cases of either a `#[non_exhaustive]` field list or a non-public - // field, we skip uninhabited fields in order not to reveal the - // uninhabitedness of the whole variant. - let is_non_exhaustive = - variant.is_field_list_non_exhaustive() && !adt.did().is_local(); let tys = cx.variant_sub_tys(ty, variant).map(|(field, ty)| { let is_visible = adt.is_enum() || field.vis.is_accessible_from(cx.module, cx.tcx); let is_uninhabited = cx.is_uninhabited(*ty); - let skip = is_uninhabited && (!is_visible || is_non_exhaustive); + let skip = is_uninhabited && !is_visible; (ty, PrivateUninhabitedField(skip)) }); cx.dropless_arena.alloc_from_iter(tys) @@ -358,7 +352,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { ty::Array(sub_ty, len) => { // We treat arrays of a constant but unknown length like slices. ConstructorSet::Slice { - array_len: len.try_eval_target_usize(cx.tcx, cx.param_env).map(|l| l as usize), + array_len: len.try_to_target_usize(cx.tcx).map(|l| l as usize), subtype_is_empty: cx.is_uninhabited(*sub_ty), } } @@ -691,9 +685,12 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { } PatKind::Array { prefix, slice, suffix } | PatKind::Slice { prefix, slice, suffix } => { let array_len = match ty.kind() { - ty::Array(_, length) => { - Some(length.eval_target_usize(cx.tcx, cx.param_env) as usize) - } + ty::Array(_, length) => Some( + length + .try_to_target_usize(cx.tcx) + .expect("expected len of array pat to be definite") + as usize, + ), ty::Slice(_) => None, _ => span_bug!(pat.span, "bad ty {} for slice pattern", ty.inner()), }; diff --git a/compiler/rustc_pattern_analysis/src/usefulness.rs b/compiler/rustc_pattern_analysis/src/usefulness.rs index 6535afcc398..99261eaa95c 100644 --- a/compiler/rustc_pattern_analysis/src/usefulness.rs +++ b/compiler/rustc_pattern_analysis/src/usefulness.rs @@ -713,7 +713,7 @@ use std::fmt; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_hash::{FxHashMap, FxHashSet}; use rustc_index::bit_set::BitSet; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use tracing::{debug, instrument}; use self::PlaceValidity::*; @@ -951,7 +951,11 @@ impl<Cx: PatCx> PlaceInfo<Cx> { self.is_scrutinee && matches!(ctors_for_ty, ConstructorSet::NoConstructors); // Whether empty patterns are counted as useful or not. We only warn an empty arm unreachable if // it is guaranteed unreachable by the opsem (i.e. if the place is `known_valid`). - let empty_arms_are_unreachable = self.validity.is_known_valid(); + // We don't want to warn empty patterns as unreachable by default just yet. We will in a + // later version of rust or under a different lint name, see + // https://github.com/rust-lang/rust/pull/129103. + let empty_arms_are_unreachable = self.validity.is_known_valid() + && (is_toplevel_exception || cx.is_exhaustive_patterns_feature_on()); // Whether empty patterns can be omitted for exhaustiveness. We ignore place validity in the // toplevel exception and `exhaustive_patterns` cases for backwards compatibility. let can_omit_empty_arms = self.validity.is_known_valid() |
