Rollup merge of #70982 - ldm0:fncoerce, r=eddyb
Normalize function signature in function casting check procedure Fixes #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:96d77f0e5f/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`).96d77f0e5f/src/librustc_typeck/check/coercion.rs (L687-L729)
This inconsistency leads to the error:`Err(Sorts(ExpectedFound { expected: <u16 as Zoo>::X, found: usize }))`.
This commit is contained in:
commit
0a6d1778ff
@ -536,7 +536,10 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||
match self.expr_ty.kind {
|
||||
ty::FnDef(..) => {
|
||||
// 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),
|
||||
);
|
||||
let res = fcx.try_coerce(
|
||||
self.expr,
|
||||
self.expr_ty,
|
||||
|
14
src/test/ui/issues/issue-54094.rs
Normal file
14
src/test/ui/issues/issue-54094.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// check-pass
|
||||
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 _;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user