Skip to content

Commit e4c71f1

Browse files
Fix value suggestion for array in generic context
1 parent d6ac50e commit e4c71f1

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

compiler/rustc_trait_selection/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#![feature(box_patterns)]
2323
#![feature(control_flow_enum)]
2424
#![feature(extract_if)]
25+
#![feature(if_let_guard)]
2526
#![feature(let_chains)]
2627
#![feature(option_take_if)]
2728
#![feature(never_type)]

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4583,11 +4583,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
45834583
format!("&{}{ty}", mutability.prefix_str())
45844584
}
45854585
}
4586-
ty::Array(ty, len) => format!(
4587-
"[{}; {}]",
4588-
self.ty_kind_suggestion(param_env, *ty)?,
4589-
len.eval_target_usize(tcx, ty::ParamEnv::reveal_all()),
4590-
),
4586+
ty::Array(ty, len) if let Some(len) = len.try_eval_target_usize(tcx, param_env) => {
4587+
format!("[{}; {}]", self.ty_kind_suggestion(param_env, *ty)?, len)
4588+
}
45914589
ty::Tuple(tys) => format!(
45924590
"({})",
45934591
tys.iter()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn as_chunks<const N: usize>() -> [u8; N] {
2+
loop {
3+
break;
4+
//~^ ERROR mismatched types
5+
}
6+
}
7+
8+
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/value-suggestion-ice-123906.rs:3:9
3+
|
4+
LL | fn as_chunks<const N: usize>() -> [u8; N] {
5+
| ------- expected `[u8; ]` because of this return type
6+
LL | loop {
7+
| ---- this loop is expected to be of type `[u8; N]`
8+
LL | break;
9+
| ^^^^^ expected `[u8; N]`, found `()`
10+
|
11+
help: give the `break` a value of the expected type
12+
|
13+
LL | break value;
14+
| +++++
15+
16+
error: aborting due to 1 previous error
17+
18+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)