@@ -4,7 +4,7 @@ use crate::type_error_struct;
4
4
5
5
use rustc_errors:: { struct_span_err, Applicability , DiagnosticBuilder } ;
6
6
use rustc_hir as hir;
7
- use rustc_hir:: def:: Res ;
7
+ use rustc_hir:: def:: { Namespace , Res } ;
8
8
use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
9
9
use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
10
10
use rustc_infer:: { infer, traits} ;
@@ -374,7 +374,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
374
374
|p| format ! ( "`{}` defined here returns `{}`" , p, callee_ty) ,
375
375
)
376
376
}
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
+ }
378
397
} ;
379
398
if let Some ( label) = label {
380
399
err. span_label ( span, label) ;
0 commit comments