Rollup merge of #152661 - BartSimpson001:fix-next-solver-from-ice, r=petrochenkov

Avoid ICE in From/TryFrom diagnostic under -Znext-solver

Fixes rust-lang/rust#152518.

Under `-Znext-solver=globally`, `trait_ref.args` may contain fewer
elements than expected. The diagnostic logic in
`fulfillment_errors.rs` assumed at least two elements and
unconditionally called `type_at(1)`, which could lead to an
index out-of-bounds panic during error reporting.

This change adds a defensive check before accessing the second
argument to avoid the ICE. A UI regression test has been added.
This commit is contained in:
Stuart Cook 2026-02-17 13:02:22 +11:00 committed by GitHub
commit 572b53fdaf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 51 additions and 13 deletions

View file

@ -0,0 +1,9 @@
//@compile-flags: -Znext-solver=globally
//@check-fail
fn check<T: Iterator>() {
<f32 as From<<T as Iterator>::Item>>::from;
//~^ ERROR the trait bound `f32: From<<T as Iterator>::Item>` is not satisfied
}
fn main() {}

View file

@ -0,0 +1,21 @@
error[E0277]: the trait bound `f32: From<<T as Iterator>::Item>` is not satisfied
--> $DIR/next-solver-ice.rs:5:6
|
LL | <f32 as From<<T as Iterator>::Item>>::from;
| ^^^ the nightly-only, unstable trait `ZeroablePrimitive` is not implemented for `f32`
|
= help: the following other types implement trait `ZeroablePrimitive`:
i128
i16
i32
i64
i8
isize
u128
u16
and 4 others
= note: required for `f32` to implement `From<<T as Iterator>::Item>`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.