don't suggest unsized indirection in where-clauses
Skip where-clauses when suggesting using indirection in combination with `?Sized` bounds on type parameters.
This commit is contained in:
parent
2577825799
commit
e848be06e1
3 changed files with 33 additions and 0 deletions
|
@ -1878,6 +1878,10 @@ impl<'v> Visitor<'v> for FindTypeParam {
|
||||||
hir::intravisit::NestedVisitorMap::None
|
hir::intravisit::NestedVisitorMap::None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_where_predicate(&mut self, _: &'v hir::WherePredicate<'v>) {
|
||||||
|
// Skip where-clauses, to avoid suggesting indirection for type parameters found there.
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_ty(&mut self, ty: &hir::Ty<'_>) {
|
fn visit_ty(&mut self, ty: &hir::Ty<'_>) {
|
||||||
// We collect the spans of all uses of the "bare" type param, like in `field: T` or
|
// We collect the spans of all uses of the "bare" type param, like in `field: T` or
|
||||||
// `field: (T, T)` where we could make `T: ?Sized` while skipping cases that are known to be
|
// `field: (T, T)` where we could make `T: ?Sized` while skipping cases that are known to be
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
// Regression test for #85943: should not emit suggestions for adding
|
||||||
|
// indirection to type parameters in where-clauses when suggesting
|
||||||
|
// adding `?Sized`.
|
||||||
|
struct A<T>(T) where T: Send;
|
||||||
|
struct B(A<[u8]>);
|
||||||
|
//~^ ERROR the size for values of type
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
|
||||||
|
--> $DIR/issue-85943-no-suggest-unsized-indirection-in-where-clause.rs:5:10
|
||||||
|
|
|
||||||
|
LL | struct A<T>(T) where T: Send;
|
||||||
|
| - required by this bound in `A`
|
||||||
|
LL | struct B(A<[u8]>);
|
||||||
|
| ^^^^^^^ doesn't have a size known at compile-time
|
||||||
|
|
|
||||||
|
= help: the trait `Sized` is not implemented for `[u8]`
|
||||||
|
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
|
||||||
|
--> $DIR/issue-85943-no-suggest-unsized-indirection-in-where-clause.rs:4:10
|
||||||
|
|
|
||||||
|
LL | struct A<T>(T) where T: Send;
|
||||||
|
| ^ - ...if indirection were used here: `Box<T>`
|
||||||
|
| |
|
||||||
|
| this could be changed to `T: ?Sized`...
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0277`.
|
Loading…
Add table
Add a link
Reference in a new issue