]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_typeck/src/check/callee.rs
Auto merge of #81458 - estebank:match-stmt-remove-semi, r=oli-obk
[rust.git] / compiler / rustc_typeck / src / check / callee.rs
index 4836418b3c2100ad76b5ed23bd5509c3e4f52498..ca1e79fac73e9d8fea6d9c7245fc8777070328ad 100644 (file)
@@ -4,7 +4,7 @@
 
 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};
@@ -346,7 +346,7 @@ fn confirm_builtin_call(
                             if call_is_multiline {
                                 err.span_suggestion(
                                     callee.span.shrink_to_hi(),
-                                    "try adding a semicolon",
+                                    "consider using a semicolon here",
                                     ";".to_owned(),
                                     Applicability::MaybeIncorrect,
                                 );
@@ -374,7 +374,26 @@ fn confirm_builtin_call(
                                     |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);