Skip to content

Commit aace614

Browse files
committed
Implement feature gate logic
1 parent bb453d0 commit aace614

File tree

7 files changed

+787
-142
lines changed

7 files changed

+787
-142
lines changed

compiler/rustc_pattern_analysis/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub trait TypeCx: Sized + fmt::Debug {
5757
type PatData: Clone;
5858

5959
fn is_exhaustive_patterns_feature_on(&self) -> bool;
60+
fn is_min_exhaustive_patterns_feature_on(&self) -> bool;
6061

6162
/// The number of fields for this constructor.
6263
fn ctor_arity(&self, ctor: &Constructor<Self>, ty: Self::Ty) -> usize;

compiler/rustc_pattern_analysis/src/rustc.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
182182
// `field.ty()` doesn't normalize after substituting.
183183
let ty = cx.tcx.normalize_erasing_regions(cx.param_env, ty);
184184
let is_visible = adt.is_enum() || field.vis.is_accessible_from(cx.module, cx.tcx);
185-
let is_uninhabited = cx.tcx.features().exhaustive_patterns && cx.is_uninhabited(ty);
185+
let is_uninhabited = (cx.tcx.features().exhaustive_patterns
186+
|| cx.tcx.features().min_exhaustive_patterns)
187+
&& cx.is_uninhabited(ty);
186188

187189
if is_uninhabited && (!is_visible || is_non_exhaustive) {
188190
None
@@ -960,6 +962,9 @@ impl<'p, 'tcx> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
960962
fn is_exhaustive_patterns_feature_on(&self) -> bool {
961963
self.tcx.features().exhaustive_patterns
962964
}
965+
fn is_min_exhaustive_patterns_feature_on(&self) -> bool {
966+
self.tcx.features().min_exhaustive_patterns
967+
}
963968

964969
fn ctor_arity(&self, ctor: &crate::constructor::Constructor<Self>, ty: Self::Ty) -> usize {
965970
self.ctor_arity(ctor, ty)

compiler/rustc_pattern_analysis/src/usefulness.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1440,9 +1440,14 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
14401440
let is_toplevel_exception =
14411441
is_top_level && matches!(ctors_for_ty, ConstructorSet::NoConstructors);
14421442
// Whether empty patterns can be omitted for exhaustiveness.
1443-
let can_omit_empty_arms = is_toplevel_exception || mcx.tycx.is_exhaustive_patterns_feature_on();
1443+
let can_omit_empty_arms = is_toplevel_exception
1444+
|| mcx.tycx.is_exhaustive_patterns_feature_on()
1445+
|| (mcx.tycx.is_min_exhaustive_patterns_feature_on() && place_validity.is_known_valid());
14441446
// Whether empty patterns are counted as useful or not.
1445-
let empty_arms_are_unreachable = place_validity.is_known_valid() && can_omit_empty_arms;
1447+
let empty_arms_are_unreachable = place_validity.is_known_valid()
1448+
&& (is_toplevel_exception
1449+
|| mcx.tycx.is_exhaustive_patterns_feature_on()
1450+
|| mcx.tycx.is_min_exhaustive_patterns_feature_on());
14461451

14471452
// Analyze the constructors present in this column.
14481453
let ctors = matrix.heads().map(|p| p.ctor());

0 commit comments

Comments
 (0)