about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHenry Boisdequin <65845077+henryboisdequin@users.noreply.github.com>2021-02-17 20:20:59 +0530
committerHenry Boisdequin <65845077+henryboisdequin@users.noreply.github.com>2021-02-25 16:11:18 +0530
commitd7cb66d389c3ef542891a26ee3c12308b407fcd6 (patch)
tree5bf2af8f6bbeafcf40135b662f65d420bd83a955
parent1279b3b9232e4c44112d98f19cfa8846776d1fe8 (diff)
downloadrust-d7cb66d389c3ef542891a26ee3c12308b407fcd6.tar.gz
rust-d7cb66d389c3ef542891a26ee3c12308b407fcd6.zip
add helpful error notes and fix the false 'defined here' messages
-rw-r--r--compiler/rustc_typeck/src/check/callee.rs23
-rw-r--r--src/test/ui/consts/const-as-fn.rs5
-rw-r--r--src/test/ui/consts/const-as-fn.stderr14
-rw-r--r--src/test/ui/error-codes/E0618.stderr2
-rw-r--r--src/test/ui/issues/issue-10969.stderr4
-rw-r--r--src/test/ui/issues/issue-21701.stderr2
-rw-r--r--src/test/ui/issues/issue-22468.stderr2
-rw-r--r--src/test/ui/issues/issue-26237.stderr2
-rw-r--r--src/test/ui/parser/parse-error-correct.stderr2
-rw-r--r--src/test/ui/structs/80853.rs7
-rw-r--r--src/test/ui/structs/80853.stderr13
11 files changed, 67 insertions, 9 deletions
diff --git a/compiler/rustc_typeck/src/check/callee.rs b/compiler/rustc_typeck/src/check/callee.rs
index 4836418b3c2..bd41ef85ce8 100644
--- a/compiler/rustc_typeck/src/check/callee.rs
+++ b/compiler/rustc_typeck/src/check/callee.rs
@@ -4,7 +4,7 @@ use crate::type_error_struct;
 
 use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
 use rustc_hir as hir;
-use rustc_hir::def::Res;
+use rustc_hir::def::{Namespace, Res};
 use rustc_hir::def_id::{DefId, LOCAL_CRATE};
 use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
 use rustc_infer::{infer, traits};
@@ -374,7 +374,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                                     |p| format!("`{}` defined here returns `{}`", p, callee_ty),
                                 )
                             }
-                            _ => Some(format!("`{}` defined here", callee_ty)),
+                            _ => {
+                                match def {
+                                    // Emit a different diagnostic for local variables, as they are not
+                                    // type definitions themselves, but rather variables *of* that type.
+                                    Res::Local(hir_id) => Some(format!(
+                                        "`{}` has type `{}`",
+                                        self.tcx.hir().name(hir_id),
+                                        callee_ty
+                                    )),
+                                    Res::Def(kind, def_id)
+                                        if kind.ns() == Some(Namespace::ValueNS) =>
+                                    {
+                                        Some(format!(
+                                            "`{}` defined here",
+                                            self.tcx.def_path_str(def_id),
+                                        ))
+                                    }
+                                    _ => Some(format!("`{}` defined here", callee_ty)),
+                                }
+                            }
                         };
                         if let Some(label) = label {
                             err.span_label(span, label);
diff --git a/src/test/ui/consts/const-as-fn.rs b/src/test/ui/consts/const-as-fn.rs
new file mode 100644
index 00000000000..388f907f8d2
--- /dev/null
+++ b/src/test/ui/consts/const-as-fn.rs
@@ -0,0 +1,5 @@
+const FOO: usize = 0;
+
+fn main() {
+    FOO(); //~ ERROR expected function, found `usize`
+}
diff --git a/src/test/ui/consts/const-as-fn.stderr b/src/test/ui/consts/const-as-fn.stderr
new file mode 100644
index 00000000000..b8dd4134b28
--- /dev/null
+++ b/src/test/ui/consts/const-as-fn.stderr
@@ -0,0 +1,14 @@
+error[E0618]: expected function, found `usize`
+  --> $DIR/const-as-fn.rs:4:5
+   |
+LL | const FOO: usize = 0;
+   | --------------------- `FOO` defined here
+...
+LL |     FOO();
+   |     ^^^--
+   |     |
+   |     call expression requires function
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0618`.
diff --git a/src/test/ui/error-codes/E0618.stderr b/src/test/ui/error-codes/E0618.stderr
index 6ddda3bf8b5..714c8d1e4d7 100644
--- a/src/test/ui/error-codes/E0618.stderr
+++ b/src/test/ui/error-codes/E0618.stderr
@@ -18,7 +18,7 @@ error[E0618]: expected function, found `i32`
   --> $DIR/E0618.rs:9:5
    |
 LL |     let x = 0i32;
-   |         - `i32` defined here
+   |         - `x` has type `i32`
 LL |     x();
    |     ^--
    |     |
diff --git a/src/test/ui/issues/issue-10969.stderr b/src/test/ui/issues/issue-10969.stderr
index 9e28a665e30..f64b61aaeb0 100644
--- a/src/test/ui/issues/issue-10969.stderr
+++ b/src/test/ui/issues/issue-10969.stderr
@@ -2,7 +2,7 @@ error[E0618]: expected function, found `i32`
   --> $DIR/issue-10969.rs:2:5
    |
 LL | fn func(i: i32) {
-   |         - `i32` defined here
+   |         - `i` has type `i32`
 LL |     i();
    |     ^--
    |     |
@@ -12,7 +12,7 @@ error[E0618]: expected function, found `i32`
   --> $DIR/issue-10969.rs:6:5
    |
 LL |     let i = 0i32;
-   |         - `i32` defined here
+   |         - `i` has type `i32`
 LL |     i();
    |     ^--
    |     |
diff --git a/src/test/ui/issues/issue-21701.stderr b/src/test/ui/issues/issue-21701.stderr
index 77bb3802d86..0405ce551b0 100644
--- a/src/test/ui/issues/issue-21701.stderr
+++ b/src/test/ui/issues/issue-21701.stderr
@@ -2,7 +2,7 @@ error[E0618]: expected function, found `U`
   --> $DIR/issue-21701.rs:2:13
    |
 LL | fn foo<U>(t: U) {
-   |           - `U` defined here
+   |           - `t` has type `U`
 LL |     let y = t();
    |             ^--
    |             |
diff --git a/src/test/ui/issues/issue-22468.stderr b/src/test/ui/issues/issue-22468.stderr
index 8d8601b3111..3fff91acbc2 100644
--- a/src/test/ui/issues/issue-22468.stderr
+++ b/src/test/ui/issues/issue-22468.stderr
@@ -2,7 +2,7 @@ error[E0618]: expected function, found `&str`
   --> $DIR/issue-22468.rs:3:13
    |
 LL |     let foo = "bar";
-   |         --- `&str` defined here
+   |         --- `foo` has type `&str`
 LL |     let x = foo("baz");
    |             ^^^-------
    |             |
diff --git a/src/test/ui/issues/issue-26237.stderr b/src/test/ui/issues/issue-26237.stderr
index f58c1bfe644..91d28a5e1e1 100644
--- a/src/test/ui/issues/issue-26237.stderr
+++ b/src/test/ui/issues/issue-26237.stderr
@@ -5,7 +5,7 @@ LL |         $not_a_function($some_argument)
    |         ------------------------------- call expression requires function
 ...
 LL |     let mut value_a = 0;
-   |         ----------- `{integer}` defined here
+   |         ----------- `value_a` has type `{integer}`
 LL |     let mut value_b = 0;
 LL |     macro_panic!(value_a, value_b);
    |                  ^^^^^^^
diff --git a/src/test/ui/parser/parse-error-correct.stderr b/src/test/ui/parser/parse-error-correct.stderr
index c54baf00b27..691df91268b 100644
--- a/src/test/ui/parser/parse-error-correct.stderr
+++ b/src/test/ui/parser/parse-error-correct.stderr
@@ -14,7 +14,7 @@ error[E0618]: expected function, found `{integer}`
   --> $DIR/parse-error-correct.rs:7:13
    |
 LL |     let y = 42;
-   |         - `{integer}` defined here
+   |         - `y` has type `{integer}`
 LL |     let x = y.;
 LL |     let x = y.();
    |             ^---
diff --git a/src/test/ui/structs/80853.rs b/src/test/ui/structs/80853.rs
new file mode 100644
index 00000000000..242d0af959d
--- /dev/null
+++ b/src/test/ui/structs/80853.rs
@@ -0,0 +1,7 @@
+struct S;
+
+fn repro_ref(thing: S) {
+    thing(); //~ ERROR expected function, found `S`
+}
+
+fn main() {}
diff --git a/src/test/ui/structs/80853.stderr b/src/test/ui/structs/80853.stderr
new file mode 100644
index 00000000000..8a38e32c1d0
--- /dev/null
+++ b/src/test/ui/structs/80853.stderr
@@ -0,0 +1,13 @@
+error[E0618]: expected function, found `S`
+  --> $DIR/80853.rs:4:5
+   |
+LL | fn repro_ref(thing: S) {
+   |              ----- `thing` has type `S`
+LL |     thing();
+   |     ^^^^^--
+   |     |
+   |     call expression requires function
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0618`.