Skip to content

Commit 040dac1

Browse files
authored
Unrolled build for rust-lang#134103
Rollup merge of rust-lang#134103 - compiler-errors:never-pat-range, r=oli-obk Don't ICE when encountering never in range pattern Fixes rust-lang#133947 r? oli-obk
2 parents 33c245b + 6e2e9f6 commit 040dac1

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Diff for: compiler/rustc_hir_typeck/src/expr.rs

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

406+
hir::Node::Pat(_) => {
407+
self.dcx().span_delayed_bug(expr.span, "place expr not allowed in pattern");
408+
true
409+
}
410+
406411
// These nodes do not have direct sub-exprs.
407412
hir::Node::Param(_)
408413
| hir::Node::Item(_)
@@ -415,7 +420,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
415420
| hir::Node::Ty(_)
416421
| hir::Node::AssocItemConstraint(_)
417422
| hir::Node::TraitRef(_)
418-
| hir::Node::Pat(_)
419423
| hir::Node::PatField(_)
420424
| hir::Node::LetStmt(_)
421425
| hir::Node::Synthetic

Diff for: tests/ui/never_type/never-in-range-pat.rs

+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+
}

Diff for: tests/ui/never_type/never-in-range-pat.stderr

+11
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)