Skip to content

Commit 5a7be2e

Browse files
committed
Use param.name.indent().span if trait bounds not exists.
To fix the following issue. Diagnostic suggests adding : ?Sized in an incorrect place if a type parameter default is present
1 parent 0cbef48 commit 5a7be2e

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2993,7 +2993,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29932993
{
29942994
(s, " +")
29952995
} else {
2996-
(span.shrink_to_hi(), ":")
2996+
(param.name.ident().span.shrink_to_hi(), ":")
29972997
};
29982998
err.span_suggestion_verbose(
29992999
span,

tests/ui/traits/issue-120878.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn main() {
2+
struct StructA<A, B = A> {
3+
_marker: std::marker::PhantomData<fn() -> (A, B)>,
4+
}
5+
6+
struct StructB {
7+
//~^ ERROR: the size for values of type `[u8]` cannot be known
8+
a: StructA<isize, [u8]>,
9+
}
10+
}

tests/ui/traits/issue-120878.stderr

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
2+
--> $DIR/issue-120878.rs:7:12
3+
|
4+
LL | a: StructA<isize, [u8]>,
5+
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `[u8]`
8+
note: required by an implicit `Sized` bound in `StructA`
9+
--> $DIR/issue-120878.rs:2:23
10+
|
11+
LL | struct StructA<A, B = A> {
12+
| ^^^^^ required by the implicit `Sized` requirement on this type parameter in `StructA`
13+
help: consider relaxing the implicit `Sized` restriction
14+
|
15+
LL | struct StructA<A, B: ?Sized = A> {
16+
| ++++++++
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0277`.

tests/ui/traits/issue-28576.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ LL | pub trait Bar: Foo<Assoc=()> + Sized {
3636
| +++++++
3737
help: consider relaxing the implicit `Sized` restriction
3838
|
39-
LL | pub trait Foo<RHS=Self: ?Sized> {
40-
| ++++++++
39+
LL | pub trait Foo<RHS: ?Sized=Self> {
40+
| ++++++++
4141

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

6262
error: aborting due to 3 previous errors
6363

0 commit comments

Comments
 (0)