Skip to content

Commit 8a64ba5

Browse files
authored
Rollup merge of rust-lang#139541 - compiler-errors:transmute, r=lcnr
Instantiate higher-ranked transmute goal w/ placeholders before emitting sub-obligations This avoids an ICE where we weren't keeping track of bound variables correctly in the `Freeze` obligations we emit for transmute goals. We could use `rebind` instead on that goal, but I think it's better just to instantiate the binder. Fixes rust-lang#139538 r? `@lcnr` or reassign
2 parents 049d897 + 68692b7 commit 8a64ba5

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Diff for: compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
317317
obligation.cause.clone(),
318318
obligation.recursion_depth + 1,
319319
obligation.param_env,
320-
obligation.predicate.rebind(trait_ref),
320+
trait_ref,
321321
)
322322
};
323323

@@ -343,7 +343,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
343343
obligation.cause.clone(),
344344
obligation.recursion_depth + 1,
345345
obligation.param_env,
346-
obligation.predicate.rebind(outlives),
346+
outlives,
347347
)
348348
};
349349

@@ -404,7 +404,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
404404
}
405405
}
406406

407-
let predicate = obligation.predicate.skip_binder();
407+
let predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
408408

409409
let mut assume = predicate.trait_ref.args.const_at(2);
410410
// FIXME(mgca): We should shallowly normalize this.

Diff for: tests/ui/transmutability/transmute-higher-ranked.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Ensure we don't ICE when transmuting higher-ranked types via a
2+
// higher-ranked transmute goal.
3+
4+
//@ check-pass
5+
6+
#![feature(transmutability)]
7+
8+
use std::mem::TransmuteFrom;
9+
10+
pub fn transmute()
11+
where
12+
for<'a> &'a &'a i32: TransmuteFrom<&'a &'a u32>,
13+
{
14+
}
15+
16+
fn main() {
17+
transmute();
18+
}

0 commit comments

Comments
 (0)