@@ -2,10 +2,10 @@ use crate::traits::{ObligationCause, ObligationCauseCode};
2
2
use crate :: ty:: diagnostics:: suggest_constraining_type_param;
3
3
use crate :: ty:: print:: { with_forced_trimmed_paths, FmtPrinter , Printer } ;
4
4
use crate :: ty:: { self , BoundRegionKind , Region , Ty , TyCtxt } ;
5
- use hir:: def:: DefKind ;
6
5
use rustc_errors:: Applicability :: { MachineApplicable , MaybeIncorrect } ;
7
6
use rustc_errors:: { pluralize, Diagnostic , MultiSpan } ;
8
7
use rustc_hir as hir;
8
+ use rustc_hir:: def:: { CtorOf , DefKind } ;
9
9
use rustc_hir:: def_id:: DefId ;
10
10
use rustc_span:: symbol:: { sym, Symbol } ;
11
11
use rustc_span:: { BytePos , Span } ;
@@ -319,7 +319,11 @@ impl<'tcx> Ty<'tcx> {
319
319
. into ( )
320
320
}
321
321
}
322
- ty:: FnDef ( ..) => "fn item" . into ( ) ,
322
+ ty:: FnDef ( def_id, ..) => match tcx. def_kind ( def_id) {
323
+ DefKind :: Ctor ( CtorOf :: Struct , _) => "struct constructor" . into ( ) ,
324
+ DefKind :: Ctor ( CtorOf :: Variant , _) => "enum constructor" . into ( ) ,
325
+ _ => "fn item" . into ( ) ,
326
+ } ,
323
327
ty:: FnPtr ( _) => "fn pointer" . into ( ) ,
324
328
ty:: Dynamic ( ref inner, ..) if let Some ( principal) = inner. principal ( ) => {
325
329
format ! ( "trait object `dyn {}`" , tcx. def_path_str( principal. def_id( ) ) ) . into ( )
@@ -366,7 +370,11 @@ impl<'tcx> Ty<'tcx> {
366
370
_ => "reference" ,
367
371
}
368
372
. into ( ) ,
369
- ty:: FnDef ( ..) => "fn item" . into ( ) ,
373
+ ty:: FnDef ( def_id, ..) => match tcx. def_kind ( def_id) {
374
+ DefKind :: Ctor ( CtorOf :: Struct , _) => "struct constructor" . into ( ) ,
375
+ DefKind :: Ctor ( CtorOf :: Variant , _) => "enum constructor" . into ( ) ,
376
+ _ => "fn item" . into ( ) ,
377
+ } ,
370
378
ty:: FnPtr ( _) => "fn pointer" . into ( ) ,
371
379
ty:: Dynamic ( ..) => "trait object" . into ( ) ,
372
380
ty:: Closure ( ..) => "closure" . into ( ) ,
0 commit comments