diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index 07e4fef9dd4f2..fa02c0ab99a6c 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -2993,7 +2993,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, diff --git a/tests/ui/traits/issue-120878.rs b/tests/ui/traits/issue-120878.rs new file mode 100644 index 0000000000000..cd8297189e2ea --- /dev/null +++ b/tests/ui/traits/issue-120878.rs @@ -0,0 +1,10 @@ +fn main() { + struct StructA { + _marker: std::marker::PhantomData (A, B)>, + } + + struct StructB { + //~^ ERROR: the size for values of type `[u8]` cannot be known + a: StructA, + } +} diff --git a/tests/ui/traits/issue-120878.stderr b/tests/ui/traits/issue-120878.stderr new file mode 100644 index 0000000000000..57e551b9ef2fa --- /dev/null +++ b/tests/ui/traits/issue-120878.stderr @@ -0,0 +1,20 @@ +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time + --> $DIR/issue-120878.rs:7:12 + | +LL | a: StructA, + | ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `[u8]` +note: required by an implicit `Sized` bound in `StructA` + --> $DIR/issue-120878.rs:2:23 + | +LL | struct StructA { + | ^^^^^ required by the implicit `Sized` requirement on this type parameter in `StructA` +help: consider relaxing the implicit `Sized` restriction + | +LL | struct StructA { + | ++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/issue-28576.stderr b/tests/ui/traits/issue-28576.stderr index adba5830b10e1..653ce05d28574 100644 --- a/tests/ui/traits/issue-28576.stderr +++ b/tests/ui/traits/issue-28576.stderr @@ -36,8 +36,8 @@ LL | pub trait Bar: Foo + Sized { | +++++++ help: consider relaxing the implicit `Sized` restriction | -LL | pub trait Foo { - | ++++++++ +LL | pub trait Foo { + | ++++++++ error[E0277]: the size for values of type `Self` cannot be known at compilation time --> $DIR/issue-28576.rs:5:16 @@ -56,8 +56,8 @@ LL | ) where Self: Sized; | +++++++++++++++++ help: consider relaxing the implicit `Sized` restriction | -LL | pub trait Foo { - | ++++++++ +LL | pub trait Foo { + | ++++++++ error: aborting due to 3 previous errors