Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when suggesting ?Sized, don't suggest indirection in where clauses #85943

Closed
tlyu opened this issue Jun 2, 2021 · 0 comments · Fixed by #85979
Closed

when suggesting ?Sized, don't suggest indirection in where clauses #85943

tlyu opened this issue Jun 2, 2021 · 0 comments · Fixed by #85979
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system A-type-system Area: Type system D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tlyu
Copy link
Contributor

tlyu commented Jun 2, 2021

Given the following code: (playground)

struct A<T>(T) where T: Send;
struct B(A<[u8]>);

The current output is:

error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
 --> src/lib.rs:2:10
  |
1 | struct A<T>(T) where T: Send;
  |          - required by this bound in `A`
2 | 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>`
 --> src/lib.rs:1:10
  |
1 | struct A<T>(T) where T: Send;
  |          ^  -        - ...if indirection were used here: `Box<T>`
  |          |  |
  |          |  ...if indirection were used here: `Box<T>`
  |          this could be changed to `T: ?Sized`...

Ideally the output should look like:

error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
 --> src/lib.rs:2:10
  |
1 | struct A<T>(T) where T: Send;
  |          - required by this bound in `A`
2 | 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>`
 --> src/lib.rs:1:10
  |
1 | struct A<T>(T) where T: Send;
  |          ^  -
  |          |  |
  |          |  ...if indirection were used here: `Box<T>`
  |          this could be changed to `T: ?Sized`...

The visitor that collects bare type parameters should skip where clauses. I can work on this in an in-progress pull request where I'm making other improvements to unsized suggestions.

@rustbot claim
@rustbot label +A-traits +A-typesystem +D-invalid-suggestion +D-papercut

@tlyu tlyu added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 2, 2021
@rustbot rustbot added A-trait-system Area: Trait system A-type-system Area: Type system D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-papercut Diagnostics: An error or lint that needs small tweaks. labels Jun 2, 2021
@bors bors closed this as completed in 2da4295 Jun 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system A-type-system Area: Type system D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants