Skip to content

Commit 92235a0

Browse files
committed
Auto merge of rust-lang#148602 - BoxyUwU:coercion_cleanup_uncontroversial, r=lcnr
misc coercion cleanups and handle safety correctly r? lcnr ### "remove normalize call" Fixes rust-lang#132765 If the normalization fails we would sometimes get a `TypeError` containing inference variables created inside of the probe used by coercion. These would then get leaked out causing ICEs in diagnostics logic ### "leak check and lub for closure<->closure coerce-lubs of same defids" Fixes rust-lang/trait-system-refactor-initiative#233 ```rust fn peculiar() -> impl Fn(u8) -> u8 { return |x| x + 1 } ``` the `|x| x + 1` expr has a type of `Closure(?31t)` which we wind up inferring the RPIT to. The `CoerceMany` `ret_coercion` for the whole `peculiar` typeck has an expected type of `RPIT` (unnormalized). When we type check the `return |x| x + 1` expr we go from the never type to `Closure(?31t)` which then participates in the `ret_coercion` giving us a `coerce-lub(RPIT, Closure(?31t))`. Normalizing `RPIT` gives us some `Closure(?50t)` where `?31t` and `?50t` have been unified with `?31t` as the root var. `resolve_vars_if_possible` doesn't resolve infer vars to their roots so these wind up with different structural identities so the fast path doesn't apply and we fall back to coercing to a `fn` ptr. cc rust-lang#147193 which also fixes this New solver probably just gets more inference variables here because canonicalization + generally different approach to normalization of opaques. Idk :3 ### FCP worthy stuffy there are some other FCP worthy things but they're in my FCP comment which also contains some analysis of the breaking nature of the previously listed changes in this PR: rust-lang#148602 (comment)
2 parents cac9606 + d304aa3 commit 92235a0

File tree

2 files changed

+4
-2
lines changed
  • compiler/rustc_public/src

2 files changed

+4
-2
lines changed

compiler/rustc_public/src/mir/body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ pub enum Safety {
978978
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
979979
pub enum PointerCoercion {
980980
/// Go from a fn-item type to a fn-pointer type.
981-
ReifyFnPointer,
981+
ReifyFnPointer(Safety),
982982

983983
/// Go from a safe fn pointer to an unsafe fn pointer.
984984
UnsafeFnPointer,

compiler/rustc_public/src/unstable/convert/stable/ty.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ impl<'tcx> Stable<'tcx> for ty::adjustment::PointerCoercion {
130130
) -> Self::T {
131131
use rustc_middle::ty::adjustment::PointerCoercion;
132132
match self {
133-
PointerCoercion::ReifyFnPointer => crate::mir::PointerCoercion::ReifyFnPointer,
133+
PointerCoercion::ReifyFnPointer(safety) => {
134+
crate::mir::PointerCoercion::ReifyFnPointer(safety.stable(tables, cx))
135+
}
134136
PointerCoercion::UnsafeFnPointer => crate::mir::PointerCoercion::UnsafeFnPointer,
135137
PointerCoercion::ClosureFnPointer(safety) => {
136138
crate::mir::PointerCoercion::ClosureFnPointer(safety.stable(tables, cx))

0 commit comments

Comments
 (0)