@@ -64,11 +64,11 @@ use rustc_errors::{
64
64
codes:: * , pluralize, struct_span_code_err, Applicability , Diag , DiagCtxt , DiagStyledString ,
65
65
ErrorGuaranteed , IntoDiagArg , StringPart ,
66
66
} ;
67
- use rustc_hir as hir;
68
67
use rustc_hir:: def:: DefKind ;
69
68
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
70
69
use rustc_hir:: intravisit:: Visitor ;
71
70
use rustc_hir:: lang_items:: LangItem ;
71
+ use rustc_hir:: { self as hir, ParamName } ;
72
72
use rustc_macros:: extension;
73
73
use rustc_middle:: bug;
74
74
use rustc_middle:: dep_graph:: DepContext ;
@@ -2429,7 +2429,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2429
2429
let ( type_scope, type_param_sugg_span) = match bound_kind {
2430
2430
GenericKind :: Param ( param) => {
2431
2431
let generics = self . tcx . generics_of ( generic_param_scope) ;
2432
- let def_id = generics. type_param ( param, self . tcx ) . def_id . expect_local ( ) ;
2432
+ let type_param = generics. type_param ( param, self . tcx ) ;
2433
+ let def_id = type_param. def_id . expect_local ( ) ;
2433
2434
let scope = self . tcx . local_def_id_to_hir_id ( def_id) . owner . def_id ;
2434
2435
// Get the `hir::Param` to verify whether it already has any bounds.
2435
2436
// We do this to avoid suggesting code that ends up as `T: 'a'b`,
@@ -2439,7 +2440,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2439
2440
Some ( ( span, open_paren_sp) ) => Some ( ( span, true , open_paren_sp) ) ,
2440
2441
// If `param` corresponds to `Self`, no usable suggestion span.
2441
2442
None if generics. has_self && param. index == 0 => None ,
2442
- None => Some ( ( self . tcx . def_span ( def_id) . shrink_to_hi ( ) , false , None ) ) ,
2443
+ None => {
2444
+ let span = if let Some ( param) =
2445
+ hir_generics. params . iter ( ) . find ( |param| param. def_id == def_id)
2446
+ && let ParamName :: Plain ( ident) = param. name
2447
+ {
2448
+ ident. span . shrink_to_hi ( )
2449
+ } else {
2450
+ let span = self . tcx . def_span ( def_id) ;
2451
+ span. shrink_to_hi ( )
2452
+ } ;
2453
+ Some ( ( span, false , None ) )
2454
+ }
2443
2455
} ;
2444
2456
( scope, sugg_span)
2445
2457
}
0 commit comments