Skip to content

Commit 071f8f6

Browse files
authored
Rollup merge of rust-lang#118157 - Nadrieril:never_pat-feature-gate, r=compiler-errors
Add `never_patterns` feature gate This PR adds the feature gate and most basic parsing for the experimental `never_patterns` feature. See the tracking issue (rust-lang#118155) for details on the experiment. `@scottmcm` has agreed to be my lang-team liaison for this experiment.
2 parents 684c4bf + 02e50f0 commit 071f8f6

File tree

6 files changed

+8
-2
lines changed

6 files changed

+8
-2
lines changed

clippy_lints/src/equatable_if_let.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn unary_pattern(pat: &Pat<'_>) -> bool {
4646
pats.iter().all(unary_pattern)
4747
}
4848
match &pat.kind {
49-
PatKind::Slice(_, _, _) | PatKind::Range(_, _, _) | PatKind::Binding(..) | PatKind::Wild | PatKind::Or(_) => {
49+
PatKind::Slice(_, _, _) | PatKind::Range(_, _, _) | PatKind::Binding(..) | PatKind::Wild | PatKind::Never | PatKind::Or(_) => {
5050
false
5151
},
5252
PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)),

clippy_lints/src/matches/match_same_arms.rs

+3
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) {
150150
#[derive(Clone, Copy)]
151151
enum NormalizedPat<'a> {
152152
Wild,
153+
Never,
153154
Struct(Option<DefId>, &'a [(Symbol, Self)]),
154155
Tuple(Option<DefId>, &'a [Self]),
155156
Or(&'a [Self]),
@@ -229,6 +230,7 @@ impl<'a> NormalizedPat<'a> {
229230
PatKind::Binding(.., Some(pat)) | PatKind::Box(pat) | PatKind::Ref(pat, _) => {
230231
Self::from_pat(cx, arena, pat)
231232
},
233+
PatKind::Never => Self::Never,
232234
PatKind::Struct(ref path, fields, _) => {
233235
let fields =
234236
arena.alloc_from_iter(fields.iter().map(|f| (f.ident.name, Self::from_pat(cx, arena, f.pat))));
@@ -333,6 +335,7 @@ impl<'a> NormalizedPat<'a> {
333335
fn has_overlapping_values(&self, other: &Self) -> bool {
334336
match (*self, *other) {
335337
(Self::Wild, _) | (_, Self::Wild) => true,
338+
(Self::Never, Self::Never) => true,
336339
(Self::Or(pats), ref other) | (ref other, Self::Or(pats)) => {
337340
pats.iter().any(|pat| pat.has_overlapping_values(other))
338341
},

clippy_lints/src/unnested_or_patterns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec<P<Pat>>, focus_idx: us
226226
// Therefore they are not some form of constructor `C`,
227227
// with which a pattern `C(p_0)` may be formed,
228228
// which we would want to join with other `C(p_j)`s.
229-
Ident(.., None) | Lit(_) | Wild | Path(..) | Range(..) | Rest | MacCall(_)
229+
Ident(.., None) | Lit(_) | Wild | Never | Path(..) | Range(..) | Rest | MacCall(_)
230230
// Skip immutable refs, as grouping them saves few characters,
231231
// and almost always requires adding parens (increasing noisiness).
232232
// In the case of only two patterns, replacement adds net characters.

clippy_lints/src/utils/author.rs

+1
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
629629

630630
match pat.value.kind {
631631
PatKind::Wild => kind!("Wild"),
632+
PatKind::Never => kind!("Never"),
632633
PatKind::Binding(ann, _, name, sub) => {
633634
bind!(self, name);
634635
opt_bind!(self, sub);

clippy_utils/src/hir_utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
10171017
}
10181018
e.hash(&mut self.s);
10191019
},
1020+
PatKind::Never => {},
10201021
PatKind::Wild => {},
10211022
}
10221023
}

clippy_utils/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool {
17071707

17081708
match pat.kind {
17091709
PatKind::Wild => false,
1710+
PatKind::Never => false, // If `!` typechecked then the type is empty, so not refutable.
17101711
PatKind::Binding(_, _, _, pat) => pat.map_or(false, |pat| is_refutable(cx, pat)),
17111712
PatKind::Box(pat) | PatKind::Ref(pat, _) => is_refutable(cx, pat),
17121713
PatKind::Lit(..) | PatKind::Range(..) => true,

0 commit comments

Comments
 (0)