Skip to content

Commit 782c768

Browse files
committed
Implement feature gate logic
1 parent 7d0177f commit 782c768

File tree

7 files changed

+786
-142
lines changed

7 files changed

+786
-142
lines changed

Diff for: compiler/rustc_pattern_analysis/src/lib.rs

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

6464
fn is_exhaustive_patterns_feature_on(&self) -> bool;
65+
fn is_min_exhaustive_patterns_feature_on(&self) -> bool;
6566

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

Diff for: compiler/rustc_pattern_analysis/src/rustc.rs

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

185187
if is_uninhabited && (!is_visible || is_non_exhaustive) {
186188
None
@@ -952,6 +954,9 @@ impl<'p, 'tcx> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
952954
fn is_exhaustive_patterns_feature_on(&self) -> bool {
953955
self.tcx.features().exhaustive_patterns
954956
}
957+
fn is_min_exhaustive_patterns_feature_on(&self) -> bool {
958+
self.tcx.features().min_exhaustive_patterns
959+
}
955960

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

Diff for: compiler/rustc_pattern_analysis/src/usefulness.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1368,9 +1368,13 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
13681368
is_top_level && matches!(ctors_for_ty, ConstructorSet::NoConstructors);
13691369
// Whether empty patterns are counted as useful or not.
13701370
let empty_arms_are_unreachable = place_validity.is_known_valid()
1371-
&& (is_toplevel_exception || mcx.tycx.is_exhaustive_patterns_feature_on());
1371+
&& (is_toplevel_exception
1372+
|| mcx.tycx.is_exhaustive_patterns_feature_on()
1373+
|| mcx.tycx.is_min_exhaustive_patterns_feature_on());
13721374
// Whether empty patterns can be omitted for exhaustiveness.
1373-
let can_omit_empty_arms = is_toplevel_exception || mcx.tycx.is_exhaustive_patterns_feature_on();
1375+
let can_omit_empty_arms = is_toplevel_exception
1376+
|| mcx.tycx.is_exhaustive_patterns_feature_on()
1377+
|| (mcx.tycx.is_min_exhaustive_patterns_feature_on() && place_validity.is_known_valid());
13741378

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

0 commit comments

Comments
 (0)