@@ -19,7 +19,7 @@ use rustc_middle::ty::fold::TypeFoldable;
1919use  rustc_middle:: ty:: { self ,  Ty } ; 
2020use  rustc_session:: Session ; 
2121use  rustc_span:: symbol:: { sym,  Ident } ; 
22- use  rustc_span:: { self ,  Span } ; 
22+ use  rustc_span:: { self ,  MultiSpan ,   Span } ; 
2323use  rustc_trait_selection:: traits:: { self ,  ObligationCauseCode } ; 
2424
2525use  std:: mem:: replace; 
@@ -83,7 +83,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8383            args_no_rcvr, 
8484            method. sig . c_variadic , 
8585            tuple_arguments, 
86-             self . tcx . hir ( ) . span_if_local ( method. def_id ) , 
86+             Some ( method. def_id ) , 
8787        ) ; 
8888        method. sig . output ( ) 
8989    } 
@@ -99,7 +99,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9999        args :  & ' tcx  [ hir:: Expr < ' tcx > ] , 
100100        c_variadic :  bool , 
101101        tuple_arguments :  TupleArgumentsFlag , 
102-         def_span :  Option < Span > , 
102+         def_id :  Option < DefId > , 
103103    )  { 
104104        let  tcx = self . tcx ; 
105105        // Grab the argument types, supplying fresh type variables 
@@ -172,9 +172,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
172172                ) ; 
173173            } 
174174
175-             if  let  Some ( def_s)  = def_span. map ( |sp| tcx. sess . source_map ( ) . guess_head_span ( sp) )  { 
176-                 err. span_label ( def_s,  "defined here" ) ; 
175+             if  let  Some ( def_id)  = def_id { 
176+                 if  let  Some ( node)  = tcx. hir ( ) . get_if_local ( def_id)  { 
177+                     let  mut  spans:  MultiSpan  = node
178+                         . ident ( ) 
179+                         . map ( |ident| ident. span ) 
180+                         . unwrap_or_else ( || tcx. hir ( ) . span ( node. hir_id ( ) . unwrap ( ) ) ) 
181+                         . into ( ) ; 
182+ 
183+                     if  let  Some ( id)  = node. body_id ( )  { 
184+                         let  body = tcx. hir ( ) . body ( id) ; 
185+                         for  param in  body. params  { 
186+                             spans. push_span_label ( param. span ,  String :: new ( ) ) ; 
187+                         } 
188+                     } 
189+ 
190+                     let  def_kind = tcx. def_kind ( def_id) ; 
191+                     err. span_note ( spans,  & format ! ( "{} defined here" ,  def_kind. descr( def_id) ) ) ; 
192+                 } 
177193            } 
194+ 
178195            if  sugg_unit { 
179196                let  sugg_span = tcx. sess . source_map ( ) . end_point ( expr. span ) ; 
180197                // remove closing `)` from the span 
0 commit comments