Skip to content

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

Closed
@tlyu

Description

@tlyu
Contributor

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

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Jun 2, 2021
added
D-papercutDiagnostics: An error or lint that needs small tweaks.
on Jun 2, 2021
added 2 commits that reference this issue on Nov 16, 2021

Rollup merge of rust-lang#86455 - tlyu:check-where-before-suggesting-…

37cf942

Rollup merge of rust-lang#86455 - tlyu:check-where-before-suggesting-…

ebef3ce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemA-type-systemArea: Type systemD-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @tlyu@rustbot

    Issue actions

      before suggesting `?Sized`, check where clause for explicit `Sized` · Issue #85945 · rust-lang/rust