Skip to content

Commit a427c6a

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 a427c6a

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
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

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn main() {
2+
struct StructA<A, B = A> {
3+
_marker: std::marker::PhantomData<fn() -> (A, B)>,
4+
}
5+
6+
struct StructB {
7+
a: StructA<isize, [u8]>,
8+
}
9+
}

tests/ui/traits/issue-120878.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)