@@ -19,7 +19,7 @@ use rustc_middle::ty::fold::TypeFoldable;
19
19
use rustc_middle:: ty:: { self , Ty } ;
20
20
use rustc_session:: Session ;
21
21
use rustc_span:: symbol:: { sym, Ident } ;
22
- use rustc_span:: { self , Span } ;
22
+ use rustc_span:: { self , MultiSpan , Span } ;
23
23
use rustc_trait_selection:: traits:: { self , ObligationCauseCode } ;
24
24
25
25
use std:: mem:: replace;
@@ -83,7 +83,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
83
83
args_no_rcvr,
84
84
method. sig . c_variadic ,
85
85
tuple_arguments,
86
- self . tcx . hir ( ) . span_if_local ( method. def_id ) ,
86
+ Some ( method. def_id ) ,
87
87
) ;
88
88
method. sig . output ( )
89
89
}
@@ -99,7 +99,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
99
99
args : & ' tcx [ hir:: Expr < ' tcx > ] ,
100
100
c_variadic : bool ,
101
101
tuple_arguments : TupleArgumentsFlag ,
102
- def_span : Option < Span > ,
102
+ def_id : Option < DefId > ,
103
103
) {
104
104
let tcx = self . tcx ;
105
105
// Grab the argument types, supplying fresh type variables
@@ -172,9 +172,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
172
172
) ;
173
173
}
174
174
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
+ }
177
193
}
194
+
178
195
if sugg_unit {
179
196
let sugg_span = tcx. sess . source_map ( ) . end_point ( expr. span ) ;
180
197
// remove closing `)` from the span
0 commit comments