Skip to content

Commit 6e2e9f6

Browse files
Don't ICE when encountering never in pattern
1 parent f6cb952 commit 6e2e9f6

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
402402
})
403403
| hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(..), .. }) => true,
404404

405+
hir::Node::Pat(_) => {
406+
self.dcx().span_delayed_bug(expr.span, "place expr not allowed in pattern");
407+
true
408+
}
409+
405410
// These nodes do not have direct sub-exprs.
406411
hir::Node::Param(_)
407412
| hir::Node::Item(_)
@@ -414,7 +419,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
414419
| hir::Node::Ty(_)
415420
| hir::Node::AssocItemConstraint(_)
416421
| hir::Node::TraitRef(_)
417-
| hir::Node::Pat(_)
418422
| hir::Node::PatField(_)
419423
| hir::Node::LetStmt(_)
420424
| hir::Node::Synthetic
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/133947>.
2+
3+
// Make sure we don't ICE when there's `!` in a range pattern.
4+
//
5+
// This shouldn't be allowed anyways, but we only deny it during MIR
6+
// building, so make sure we handle it semi-gracefully during typeck.
7+
8+
#![feature(never_type)]
9+
10+
fn main() {
11+
let x: !;
12+
match 1 {
13+
0..x => {}
14+
//~^ ERROR only `char` and numeric types are allowed in range patterns
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0029]: only `char` and numeric types are allowed in range patterns
2+
--> $DIR/never-in-range-pat.rs:13:12
3+
|
4+
LL | 0..x => {}
5+
| - ^ this is of type `!` but it should be `char` or numeric
6+
| |
7+
| this is of type `{integer}`
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0029`.

0 commit comments

Comments
 (0)