Skip to content

Commit ee135be

Browse files
committed
Fix ICE in next-solver TransmuteFrom candidate
Treat TransmuteFrom goals with non-region inference variables as ambiguous before running transmutability, instead of computing layouts for unresolved types. The old solver already treated these goals as ambiguous, so only the next solver could hit this ICE.
1 parent 30d0309 commit ee135be

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

‎compiler/rustc_next_trait_solver/src/solve/trait_goals.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,12 @@ where
665665
return Err(NoSolution);
666666
}
667667

668+
// Match the old solver by treating unresolved inference variables as
669+
// ambiguous until `rustc_transmute` can compute their layout.
670+
if goal.has_non_region_infer() {
671+
return ecx.forced_ambiguity(MaybeCause::Ambiguity);
672+
}
673+
668674
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
669675
let assume = ecx.structurally_normalize_const(
670676
goal.param_env,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//! Regression test for <https://github.com/rust-lang/rust/issues/153370>.
2+
3+
//@ edition:2024
4+
//@ compile-flags: -Znext-solver=globally
5+
6+
#![feature(transmutability)]
7+
8+
trait NodeImpl {}
9+
struct Wrap<F, P>(F, P);
10+
impl<F, P> Wrap<F, P> {
11+
fn new(_: F) -> Self {
12+
loop {}
13+
}
14+
}
15+
16+
impl<F, A> NodeImpl for Wrap<F, (A,)> where F: std::mem::TransmuteFrom<()> {}
17+
fn trigger_ice() {
18+
let _: &dyn NodeImpl = &Wrap::<_, (i128,)>::new(async |_: &(), i128| 0);
19+
//~^ ERROR type annotations needed
20+
}
21+
22+
fn main() {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0283]: type annotations needed
2+
--> $DIR/transmute-from-async-closure.rs:18:29
3+
|
4+
LL | let _: &dyn NodeImpl = &Wrap::<_, (i128,)>::new(async |_: &(), i128| 0);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `F` declared on the struct `Wrap`
6+
|
7+
= note: cannot satisfy `{async closure@$DIR/transmute-from-async-closure.rs:18:53: 18:73}: TransmuteFrom<(), Assume { alignment: false, lifetimes: false, safety: false, validity: false }>`
8+
note: required for `Wrap<{async closure@$DIR/transmute-from-async-closure.rs:18:53: 18:73}, (i128,)>` to implement `NodeImpl`
9+
--> $DIR/transmute-from-async-closure.rs:16:12
10+
|
11+
LL | impl<F, A> NodeImpl for Wrap<F, (A,)> where F: std::mem::TransmuteFrom<()> {}
12+
| ^^^^^^^^ ^^^^^^^^^^^^^ --------------------------- unsatisfied trait bound introduced here
13+
note: required because it appears within the type `Wrap<{async closure@$DIR/transmute-from-async-closure.rs:18:53: 18:73}, (i128,)>`
14+
--> $DIR/transmute-from-async-closure.rs:9:8
15+
|
16+
LL | struct Wrap<F, P>(F, P);
17+
| ^^^^
18+
= note: required for `&Wrap<{async closure@$DIR/transmute-from-async-closure.rs:18:53: 18:73}, (i128,)>` to implement `CoerceUnsized<&dyn NodeImpl>`
19+
= note: required for the cast from `&Wrap<{async closure@$DIR/transmute-from-async-closure.rs:18:53: 18:73}, (i128,)>` to `&dyn NodeImpl`
20+
21+
error: aborting due to 1 previous error
22+
23+
For more information about this error, try `rustc --explain E0283`.

0 commit comments

Comments
 (0)