Skip to content

Commit e848be0

Browse files
committed
don't suggest unsized indirection in where-clauses
Skip where-clauses when suggesting using indirection in combination with `?Sized` bounds on type parameters.
1 parent 2577825 commit e848be0

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,10 @@ impl<'v> Visitor<'v> for FindTypeParam {
18781878
hir::intravisit::NestedVisitorMap::None
18791879
}
18801880

1881+
fn visit_where_predicate(&mut self, _: &'v hir::WherePredicate<'v>) {
1882+
// Skip where-clauses, to avoid suggesting indirection for type parameters found there.
1883+
}
1884+
18811885
fn visit_ty(&mut self, ty: &hir::Ty<'_>) {
18821886
// We collect the spans of all uses of the "bare" type param, like in `field: T` or
18831887
// `field: (T, T)` where we could make `T: ?Sized` while skipping cases that are known to be
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Regression test for #85943: should not emit suggestions for adding
2+
// indirection to type parameters in where-clauses when suggesting
3+
// adding `?Sized`.
4+
struct A<T>(T) where T: Send;
5+
struct B(A<[u8]>);
6+
//~^ ERROR the size for values of type
7+
8+
pub fn main() {
9+
}
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-85943-no-suggest-unsized-indirection-in-where-clause.rs:5:10
3+
|
4+
LL | struct A<T>(T) where T: Send;
5+
| - required by this bound in `A`
6+
LL | struct B(A<[u8]>);
7+
| ^^^^^^^ doesn't have a size known at compile-time
8+
|
9+
= help: the trait `Sized` is not implemented for `[u8]`
10+
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
11+
--> $DIR/issue-85943-no-suggest-unsized-indirection-in-where-clause.rs:4:10
12+
|
13+
LL | struct A<T>(T) where T: Send;
14+
| ^ - ...if indirection were used here: `Box<T>`
15+
| |
16+
| this could be changed to `T: ?Sized`...
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)