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

before suggesting ?Sized, check where clause for explicit Sized #85945

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

before suggesting ?Sized, check where clause for explicit Sized #85945

tlyu opened this issue Jun 2, 2021 · 0 comments · Fixed by #86455
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system A-type-system Area: Type system 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)

fn foo<T>(_: &T) where T: Sized {}
fn bar() { foo(""); }

The current output is:

error[E0277]: the size for values of type `str` cannot be known at compilation time
 --> src/lib.rs:2:16
  |
1 | fn foo<T>(_: &T) where T: Sized {}
  |        - required by this bound in `foo`
2 | fn bar() { foo(""); }
  |                ^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `str`
help: consider relaxing the implicit `Sized` restriction
  |
1 | fn foo<T: ?Sized>(_: &T) where T: Sized {}
  |         ^^^^^^^^

Ideally, the diagnostic shouldn't suggest relaxing an explicit Sized bound in the where clause. (There is already code that skips the ?Sized suggestion for type parameters that have an explicit Sized bound.)

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-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-papercut Diagnostics: An error or lint that needs small tweaks. labels Jun 2, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 16, 2021
…unsized, r=estebank

check where-clause for explicit `Sized` before suggesting `?Sized`

Fixes rust-lang#85945.

Based on rust-lang#86454.

`@rustbot` label +A-diagnostics +A-traits +A-typesystem +D-papercut +T-compiler
@bors bors closed this as completed in ebef3ce Nov 16, 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-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