@@ -64,11 +64,11 @@ use rustc_errors::{
6464 codes::*, pluralize, struct_span_code_err, Applicability, Diag, DiagCtxt, DiagStyledString,
6565 ErrorGuaranteed, IntoDiagArg, StringPart,
6666};
67- use rustc_hir as hir;
6867use rustc_hir::def::DefKind;
6968use rustc_hir::def_id::{DefId, LocalDefId};
7069use rustc_hir::intravisit::Visitor;
7170use rustc_hir::lang_items::LangItem;
71+ use rustc_hir::{self as hir, ParamName};
7272use rustc_macros::extension;
7373use rustc_middle::bug;
7474use rustc_middle::dep_graph::DepContext;
@@ -2429,7 +2429,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
24292429 let (type_scope, type_param_sugg_span) = match bound_kind {
24302430 GenericKind::Param(param) => {
24312431 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();
24332434 let scope = self.tcx.local_def_id_to_hir_id(def_id).owner.def_id;
24342435 // Get the `hir::Param` to verify whether it already has any bounds.
24352436 // We do this to avoid suggesting code that ends up as `T: 'a'b`,
@@ -2439,7 +2440,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
24392440 Some((span, open_paren_sp)) => Some((span, true, open_paren_sp)),
24402441 // If `param` corresponds to `Self`, no usable suggestion span.
24412442 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+ }
24432455 };
24442456 (scope, sugg_span)
24452457 }
0 commit comments