Rollup merge of #120915 - OdenShirataki:master, r=fmease

Fix suggestion span for `?Sized` when param type has default

Fixes #120878

Diagnostic suggests adding `: ?Sized` in an incorrect place if a type parameter default is present

r? `@fmease`
This commit is contained in:
Oli Scherer 2024-02-14 11:53:39 +01:00 committed by GitHub
commit f3e66edd63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 64 additions and 7 deletions

View file

@ -3041,7 +3041,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
this = "the implicit `Sized` requirement on this type parameter";
}
if let Some(hir::Node::TraitItem(hir::TraitItem {
ident,
generics,
kind: hir::TraitItemKind::Type(bounds, None),
..
})) = tcx.hir().get_if_local(item_def_id)
@ -3053,7 +3053,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let (span, separator) = if let [.., last] = bounds {
(last.span().shrink_to_hi(), " +")
} else {
(ident.span.shrink_to_hi(), ":")
(generics.span.shrink_to_hi(), ":")
};
err.span_suggestion_verbose(
span,

View file

@ -2990,7 +2990,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
{
(s, " +")
} else {
(span.shrink_to_hi(), ":")
(param.name.ident().span.shrink_to_hi(), ":")
};
err.span_suggestion_verbose(
span,