From b8deb93b22b8f67b53f400849aa233610e32381c Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Thu, 23 Sep 2021 11:29:52 +0000 Subject: [PATCH 1/2] Add test --- src/test/ui/typeck/call-block.rs | 3 +++ src/test/ui/typeck/call-block.stderr | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/test/ui/typeck/call-block.rs create mode 100644 src/test/ui/typeck/call-block.stderr diff --git a/src/test/ui/typeck/call-block.rs b/src/test/ui/typeck/call-block.rs new file mode 100644 index 0000000000000..1d5244411a226 --- /dev/null +++ b/src/test/ui/typeck/call-block.rs @@ -0,0 +1,3 @@ +fn main() { + let _ = {42}(); //~ ERROR expected function, found `_` +} diff --git a/src/test/ui/typeck/call-block.stderr b/src/test/ui/typeck/call-block.stderr new file mode 100644 index 0000000000000..20f61dd23ac4e --- /dev/null +++ b/src/test/ui/typeck/call-block.stderr @@ -0,0 +1,11 @@ +error[E0618]: expected function, found `_` + --> $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`. From 072d107b438207e2c2c83fdf8c22bb5e8699138e Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Thu, 23 Sep 2021 11:37:29 +0000 Subject: [PATCH 2/2] Resolve infered types when complaining about unexpected call type --- compiler/rustc_typeck/src/check/callee.rs | 1 + src/test/ui/typeck/call-block.rs | 2 +- src/test/ui/typeck/call-block.stderr | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_typeck/src/check/callee.rs b/compiler/rustc_typeck/src/check/callee.rs index 1cc06b8c2e544..6cdd38664c864 100644 --- a/compiler/rustc_typeck/src/check/callee.rs +++ b/compiler/rustc_typeck/src/check/callee.rs @@ -350,6 +350,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } + let callee_ty = self.resolve_vars_if_possible(callee_ty); let mut err = type_error_struct!( self.tcx.sess, callee_expr.span, diff --git a/src/test/ui/typeck/call-block.rs b/src/test/ui/typeck/call-block.rs index 1d5244411a226..0390d7db040b4 100644 --- a/src/test/ui/typeck/call-block.rs +++ b/src/test/ui/typeck/call-block.rs @@ -1,3 +1,3 @@ fn main() { - let _ = {42}(); //~ ERROR expected function, found `_` + let _ = {42}(); //~ ERROR expected function, found `{integer}` } diff --git a/src/test/ui/typeck/call-block.stderr b/src/test/ui/typeck/call-block.stderr index 20f61dd23ac4e..68984bc1c453f 100644 --- a/src/test/ui/typeck/call-block.stderr +++ b/src/test/ui/typeck/call-block.stderr @@ -1,4 +1,4 @@ -error[E0618]: expected function, found `_` +error[E0618]: expected function, found `{integer}` --> $DIR/call-block.rs:2:13 | LL | let _ = {42}();