diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2024-12-10 20:16:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-10 20:16:04 +0100 |
| commit | c5a83862a200c9460cc92d526652ebee3f40bce4 (patch) | |
| tree | 95c3bee3c6885153fbe6e5cac49ce7d5dc589147 | |
| parent | f621be4ecce2d8a0d128c8f2c9392e2cde2af381 (diff) | |
| parent | 6e2e9f676c03128e3c988c393904e3e6181b938b (diff) | |
| download | rust-c5a83862a200c9460cc92d526652ebee3f40bce4.tar.gz rust-c5a83862a200c9460cc92d526652ebee3f40bce4.zip | |
Rollup merge of #134103 - compiler-errors:never-pat-range, r=oli-obk
Don't ICE when encountering never in range pattern Fixes #133947 r? oli-obk
| -rw-r--r-- | compiler/rustc_hir_typeck/src/expr.rs | 6 | ||||
| -rw-r--r-- | tests/ui/never_type/never-in-range-pat.rs | 16 | ||||
| -rw-r--r-- | tests/ui/never_type/never-in-range-pat.stderr | 11 |
3 files changed, 32 insertions, 1 deletions
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 0e079b03769..30f02b80ea6 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -403,6 +403,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }) | hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(..), .. }) => true, + hir::Node::Pat(_) => { + self.dcx().span_delayed_bug(expr.span, "place expr not allowed in pattern"); + true + } + // These nodes do not have direct sub-exprs. hir::Node::Param(_) | hir::Node::Item(_) @@ -415,7 +420,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | hir::Node::Ty(_) | hir::Node::AssocItemConstraint(_) | hir::Node::TraitRef(_) - | hir::Node::Pat(_) | hir::Node::PatField(_) | hir::Node::LetStmt(_) | hir::Node::Synthetic diff --git a/tests/ui/never_type/never-in-range-pat.rs b/tests/ui/never_type/never-in-range-pat.rs new file mode 100644 index 00000000000..ae2d76c172e --- /dev/null +++ b/tests/ui/never_type/never-in-range-pat.rs @@ -0,0 +1,16 @@ +// Regression test for <https://github.com/rust-lang/rust/issues/133947>. + +// Make sure we don't ICE when there's `!` in a range pattern. +// +// This shouldn't be allowed anyways, but we only deny it during MIR +// building, so make sure we handle it semi-gracefully during typeck. + +#![feature(never_type)] + +fn main() { + let x: !; + match 1 { + 0..x => {} + //~^ ERROR only `char` and numeric types are allowed in range patterns + } +} diff --git a/tests/ui/never_type/never-in-range-pat.stderr b/tests/ui/never_type/never-in-range-pat.stderr new file mode 100644 index 00000000000..c78be5350e0 --- /dev/null +++ b/tests/ui/never_type/never-in-range-pat.stderr @@ -0,0 +1,11 @@ +error[E0029]: only `char` and numeric types are allowed in range patterns + --> $DIR/never-in-range-pat.rs:13:12 + | +LL | 0..x => {} + | - ^ this is of type `!` but it should be `char` or numeric + | | + | this is of type `{integer}` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0029`. |
