Skip to content

Detect unsized expressions that are deref expressions like *"" #128199

Closed

Description

@estebank

Code

fn foo() -> impl Sized {
    *""
}

Current output

error[E0277]: the size for values of type `str` cannot be known at compilation time
 --> src/main.rs:1:13
  |
1 | fn foo() -> impl Sized {
  |             ^^^^^^^^^^ doesn't have a size known at compile-time
2 |     *""
  |     --- return type was inferred to be `str` here
  |
  = help: the trait `Sized` is not implemented for `str`

Desired output

error[E0277]: the size for values of type `str` cannot be known at compilation time
 --> src/main.rs:1:13
  |
1 | fn foo() -> impl Sized {
  |             ^^^^^^^^^^ doesn't have a size known at compile-time
2 |     *""
  |     --- return type was inferred to be `str` here
  |
  = help: the trait `Sized` is not implemented for `str`
help: remove the `*` dereference so the expression is of type `&str`, which is `Sized`
  |
2 -     *""
2 +     ""
  |

Rationale and extra context

The change is obvious when presented in isolation, but with a lot of diagnostics (and Sized errors can cause multiple knock-down errors) the problem gets hidden.

Other cases

No response

Rust Version

rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7

Anything else?

No response

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
    D-papercutDiagnostics: An error or lint that needs small tweaks.
    D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.
    on Jul 25, 2024
  2. added 3 commits that reference this issue on Aug 24, 2024
    81862e1
    e587486
    1a70ad1
  3. added 2 commits that reference this issue on Aug 24, 2024
    5dbb40d
    d75c245
  4. added a commit that references this issue on Aug 25, 2024
    0030892
  5. added a commit that references this issue on Aug 25, 2024
    86bccf7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-papercutDiagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.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

      Development

      No branches or pull requests

      Issue actions