-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Functions pointers with associated type parameters can't cast to pointers #54094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The following works:
|
Huh, what if you cast it to |
Adding an intermediate cast to |
So having a projection in the type, blocks the cast from happening? That's a bit weird. |
The fn_sig function on fn item types is returning unnormalized types directly from the tcx. Defined in Lines 1739 to 1747 in f1aefb4
The relevant call-site is at rust/src/librustc_typeck/check/cast.rs Lines 432 to 443 in f1aefb4
|
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 }))`.
(Playground)
Errors:
Seems like this should work.
The text was updated successfully, but these errors were encountered: