Skip to content

Resolve infered types when complaining about unexpected call type #89202

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

Merged
merged 2 commits into from
Oct 1, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_typeck/src/check/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

let callee_ty = self.resolve_vars_if_possible(callee_ty);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why callee_ty is an TyVar and not an IntVar, I think we should dig into this a bit instead of just patching up the diagnostic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the TyVar is coming from the {} block's tail expression not having unified yet?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that were the case, wouldn't we also see the tyvar, when using a function type?

I think we're doing something odd when type checking the literal expression.

I'm currently somewhere deep in that code anyway, I'll check and post my findings

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, you're right. The tail block expression will fall back to a type variable in case we don't know anything about the type. This happens in

fcx.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::MiscVariable, span })

So... I guess we can't avoid this at creation time. oh well...

let mut err = type_error_struct!(
self.tcx.sess,
callee_expr.span,
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/typeck/call-block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
let _ = {42}(); //~ ERROR expected function, found `{integer}`
}
11 changes: 11 additions & 0 deletions src/test/ui/typeck/call-block.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0618]: expected function, found `{integer}`
--> $DIR/call-block.rs:2:13
|
LL | let _ = {42}();
| ^^^^--
| |
| call expression requires function

error: aborting due to previous error

For more information about this error, try `rustc --explain E0618`.