@@ -2,10 +2,10 @@ use crate::traits::{ObligationCause, ObligationCauseCode};
22use crate :: ty:: diagnostics:: suggest_constraining_type_param;
33use crate :: ty:: print:: { with_forced_trimmed_paths, FmtPrinter , Printer } ;
44use crate :: ty:: { self , BoundRegionKind , Region , Ty , TyCtxt } ;
5- use hir:: def:: DefKind ;
65use rustc_errors:: Applicability :: { MachineApplicable , MaybeIncorrect } ;
76use rustc_errors:: { pluralize, Diagnostic , MultiSpan } ;
87use rustc_hir as hir;
8+ use rustc_hir:: def:: { CtorOf , DefKind } ;
99use rustc_hir:: def_id:: DefId ;
1010use rustc_span:: symbol:: { sym, Symbol } ;
1111use rustc_span:: { BytePos , Span } ;
@@ -319,7 +319,11 @@ impl<'tcx> Ty<'tcx> {
319319 . into ( )
320320 }
321321 }
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+ } ,
323327 ty:: FnPtr ( _) => "fn pointer" . into ( ) ,
324328 ty:: Dynamic ( ref inner, ..) if let Some ( principal) = inner. principal ( ) => {
325329 format ! ( "trait object `dyn {}`" , tcx. def_path_str( principal. def_id( ) ) ) . into ( )
@@ -366,7 +370,11 @@ impl<'tcx> Ty<'tcx> {
366370 _ => "reference" ,
367371 }
368372 . 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+ } ,
370378 ty:: FnPtr ( _) => "fn pointer" . into ( ) ,
371379 ty:: Dynamic ( ..) => "trait object" . into ( ) ,
372380 ty:: Closure ( ..) => "closure" . into ( ) ,
0 commit comments