-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Normalize function signature in function casting check procedure #70982
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
// Attempt a coercion to a fn pointer type. | ||
let f = self.expr_ty.fn_sig(fcx.tcx); | ||
let f = fcx.normalize_associated_types_in( | ||
self.expr.span, | ||
&self.expr_ty.fn_sig(fcx.tcx), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @nikomatsakis This makes sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it seems like it is necessary, given that fn_sig
returns the result of data from the def_id
..
@bors r+ |
📌 Commit 75cc403 has been approved by |
// Attempt a coercion to a fn pointer type. | ||
let f = self.expr_ty.fn_sig(fcx.tcx); | ||
let f = fcx.normalize_associated_types_in( | ||
self.expr.span, | ||
&self.expr_ty.fn_sig(fcx.tcx), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it seems like it is necessary, given that fn_sig
returns the result of data from the def_id
..
Normalize function signature in function casting check procedure Fixes rust-lang#54094 ```rust trait Zoo { type X; } impl Zoo for u16 { type X = usize; } fn foo(abc: <u16 as Zoo>::X) {} fn main() { let x: *const u8 = foo as _; } ``` Currently a `FnDef` need to be checked if it's able to cast to `FnPtr` before it is actually casted. But the signature of `FnPtr` target's associated types are not normalized: https://github.com/rust-lang/rust/blob/96d77f0e5f103612d62b85938aacfb33f5768433/src/librustc_typeck/check/cast.rs#L536-L553 However, during the coercion check, the signature of `FnPtr` target's associated types are normalized (The `<u16 as Zoo>::X` turns into `usize`). https://github.com/rust-lang/rust/blob/96d77f0e5f103612d62b85938aacfb33f5768433/src/librustc_typeck/check/coercion.rs#L687-L729 This inconsistency leads to the error:`Err(Sorts(ExpectedFound { expected: <u16 as Zoo>::X, found: usize }))`.
Rollup of 5 pull requests Successful merges: - rust-lang#69573 (tests encoding current behavior for various cases of "binding" to _.) - rust-lang#70881 (bootstrap: work around "unused attribute" errors in incremental stdlib rebuilds.) - rust-lang#70957 (Normalize MIR locals' types for generator layout computation.) - rust-lang#70962 (added machine hooks to track deallocations) - rust-lang#70982 (Normalize function signature in function casting check procedure) Failed merges: r? @ghost
Fixes #54094
Currently a
FnDef
need to be checked if it's able to cast toFnPtr
before it is actually casted. But the signature ofFnPtr
target's associated types are not normalized:rust/src/librustc_typeck/check/cast.rs
Lines 536 to 553 in 96d77f0
However, during the coercion check, the signature of
FnPtr
target's associated types are normalized (The<u16 as Zoo>::X
turns intousize
).rust/src/librustc_typeck/check/coercion.rs
Lines 687 to 729 in 96d77f0
This inconsistency leads to the error:
Err(Sorts(ExpectedFound { expected: <u16 as Zoo>::X, found: usize }))
.