diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-04-08 21:26:02 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-08 21:26:02 +0200 |
| commit | 8a64ba5c3f88ad97bf3c32fb43cb3d849c75973b (patch) | |
| tree | 6e2d23783817ef577110b2e148783277d203fe98 | |
| parent | 049d897baef5ba9fb9cbd5a2d27a826d0e1fdabc (diff) | |
| parent | 68692b7fbb674ea51c0b504ac4b8cc791311b10d (diff) | |
| download | rust-8a64ba5c3f88ad97bf3c32fb43cb3d849c75973b.tar.gz rust-8a64ba5c3f88ad97bf3c32fb43cb3d849c75973b.zip | |
Rollup merge of #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 #139538 r? `@lcnr` or reassign
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/select/confirmation.rs | 6 | ||||
| -rw-r--r-- | tests/ui/transmutability/transmute-higher-ranked.rs | 18 |
2 files changed, 21 insertions, 3 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 9d5eb551fe6..69e7b2a43ff 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -317,7 +317,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation.cause.clone(), obligation.recursion_depth + 1, obligation.param_env, - obligation.predicate.rebind(trait_ref), + trait_ref, ) }; @@ -343,7 +343,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation.cause.clone(), obligation.recursion_depth + 1, obligation.param_env, - obligation.predicate.rebind(outlives), + outlives, ) }; @@ -404,7 +404,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - let predicate = obligation.predicate.skip_binder(); + let predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate); let mut assume = predicate.trait_ref.args.const_at(2); // FIXME(mgca): We should shallowly normalize this. diff --git a/tests/ui/transmutability/transmute-higher-ranked.rs b/tests/ui/transmutability/transmute-higher-ranked.rs new file mode 100644 index 00000000000..f0fe02a7908 --- /dev/null +++ b/tests/ui/transmutability/transmute-higher-ranked.rs @@ -0,0 +1,18 @@ +// Ensure we don't ICE when transmuting higher-ranked types via a +// higher-ranked transmute goal. + +//@ check-pass + +#![feature(transmutability)] + +use std::mem::TransmuteFrom; + +pub fn transmute() +where + for<'a> &'a &'a i32: TransmuteFrom<&'a &'a u32>, +{ +} + +fn main() { + transmute(); +} |
