@@ -4,7 +4,7 @@ use crate::type_error_struct;
44
55use rustc_errors:: { struct_span_err, Applicability , DiagnosticBuilder } ;
66use rustc_hir as hir;
7- use rustc_hir:: def:: Res ;
7+ use rustc_hir:: def:: { Namespace , Res } ;
88use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
99use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
1010use rustc_infer:: { infer, traits} ;
@@ -374,7 +374,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
374374 |p| format ! ( "`{}` defined here returns `{}`" , p, callee_ty) ,
375375 )
376376 }
377- _ => Some ( format ! ( "`{}` defined here" , callee_ty) ) ,
377+ _ => {
378+ match def {
379+ // Emit a different diagnostic for local variables, as they are not
380+ // type definitions themselves, but rather variables *of* that type.
381+ Res :: Local ( hir_id) => Some ( format ! (
382+ "`{}` has type `{}`" ,
383+ self . tcx. hir( ) . name( hir_id) ,
384+ callee_ty
385+ ) ) ,
386+ Res :: Def ( kind, def_id)
387+ if kind. ns ( ) == Some ( Namespace :: ValueNS ) =>
388+ {
389+ Some ( format ! (
390+ "`{}` defined here" ,
391+ self . tcx. def_path_str( def_id) ,
392+ ) )
393+ }
394+ _ => Some ( format ! ( "`{}` defined here" , callee_ty) ) ,
395+ }
396+ }
378397 } ;
379398 if let Some ( label) = label {
380399 err. span_label ( span, label) ;
0 commit comments