Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions compiler/rustc_mir_build/src/builder/matches/match_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
) {
let tcx = self.tcx;
let (min_length, exact_size) = if let Some(place_resolved) = place.try_to_place(self) {
match place_resolved.ty(&self.local_decls, tcx).ty.kind() {
ty::Array(_, length) => (
length
.try_to_target_usize(tcx)
.expect("expected len of array pat to be definite"),
true,
),
let place_ty = place_resolved.ty(&self.local_decls, tcx).ty;
match place_ty.kind() {
ty::Array(_, length) => {
if let Some(length) = length.try_to_target_usize(tcx) {
(length, true)
} else {
// This can happen when the array length is a generic const
// expression that couldn't be evaluated (e.g., due to an error).
// Since there's already a compilation error, we use a fallback
// to avoid an ICE.
tcx.dcx().span_delayed_bug(
tcx.def_span(self.def_id),
"array length in pattern couldn't be evaluated",
);
((prefix.len() + suffix.len()).try_into().unwrap(), false)
}
}
_ => ((prefix.len() + suffix.len()).try_into().unwrap(), false),
}
} else {
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/const-generics/generic-const-array-pattern-ice-139815.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ compile-flags: --crate-type=lib

#![feature(generic_const_exprs)]
//~^ WARN the feature `generic_const_exprs` is incomplete

fn is_123<const N: usize>(
x: [u32; {
//~^ ERROR overly complex generic constant
N + 1;
5
}],
) -> bool {
match x {
[1, 2] => true,
_ => false,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/generic-const-array-pattern-ice-139815.rs:3:12
|
LL | #![feature(generic_const_exprs)]
| ^^^^^^^^^^^^^^^^^^^
|
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
= note: `#[warn(incomplete_features)]` on by default

error: overly complex generic constant
--> $DIR/generic-const-array-pattern-ice-139815.rs:7:14
|
LL | x: [u32; {
| ______________^
LL | |
LL | | N + 1;
LL | | 5
LL | | }],
| |_____^ blocks are not supported in generic constants
|
= help: consider moving this anonymous constant into a `const` function
= note: this operation may be supported in the future

error: aborting due to 1 previous error; 1 warning emitted