Skip to content

Commit

Permalink
Use param.name.indent().span if trait bounds not exists.
Browse files Browse the repository at this point in the history
To fix the following issue.
Diagnostic suggests adding : ?Sized in an incorrect place if a type parameter default is present
  • Loading branch information
OdenShirataki committed Feb 11, 2024
1 parent 0cbef48 commit 5a7be2e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/traits/issue-120878.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main() {
struct StructA<A, B = A> {
_marker: std::marker::PhantomData<fn() -> (A, B)>,
}

struct StructB {
//~^ ERROR: the size for values of type `[u8]` cannot be known
a: StructA<isize, [u8]>,
}
}
20 changes: 20 additions & 0 deletions tests/ui/traits/issue-120878.stderr
Original file line number Diff line number Diff line change
@@ -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<isize, [u8]>,
| ^^^^^^^^^^^^^^^^^^^^ 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<A, B = A> {
| ^^^^^ required by the implicit `Sized` requirement on this type parameter in `StructA`
help: consider relaxing the implicit `Sized` restriction
|
LL | struct StructA<A, B: ?Sized = A> {
| ++++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
8 changes: 4 additions & 4 deletions tests/ui/traits/issue-28576.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ LL | pub trait Bar: Foo<Assoc=()> + Sized {
| +++++++
help: consider relaxing the implicit `Sized` restriction
|
LL | pub trait Foo<RHS=Self: ?Sized> {
| ++++++++
LL | pub trait Foo<RHS: ?Sized=Self> {
| ++++++++

error[E0277]: the size for values of type `Self` cannot be known at compilation time
--> $DIR/issue-28576.rs:5:16
Expand All @@ -56,8 +56,8 @@ LL | ) where Self: Sized;
| +++++++++++++++++
help: consider relaxing the implicit `Sized` restriction
|
LL | pub trait Foo<RHS=Self: ?Sized> {
| ++++++++
LL | pub trait Foo<RHS: ?Sized=Self> {
| ++++++++

error: aborting due to 3 previous errors

Expand Down

0 comments on commit 5a7be2e

Please sign in to comment.