Skip to content
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

Normalize function signature in function casting check procedure #70982

Merged
merged 2 commits into from Apr 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/librustc_typeck/check/cast.rs
Expand Up @@ -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),
);
Comment on lines 538 to +542
Copy link
Member

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.

Copy link
Contributor

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 ..

let res = fcx.try_coerce(
self.expr,
self.expr_ty,
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/issues/issue-54094.rs
@@ -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 _;
}