Skip to content

wrong span for E0277 #141234

Open
Open
@jendrikw

Description

@jendrikw

Code

pub fn f() {
    let _: Box<[str]>;
}

Current output

error[E0277]: the size for values of type `str` cannot be known at compilation time
 --> src/lib.rs:2:12
  |
2 |     let _: Box<[str]>;
  |            ^^^^^^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `str`
  = note: slice and array elements must have `Sized` type

Desired output

error[E0277]: the size for values of type `str` cannot be known at compilation time
 --> src/lib.rs:2:12
  |
2 |     let _: Box<[str]>;
  |                 ^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `str`
  = note: slice and array elements must have `Sized` type

Rationale and extra context

The type that "doesn't have a size known at compile time is "str". The size of a box is known (wither one or two pointers), it is therefore wrong to underline the Box part.

Other cases

Rust Version

1.89.0-nightly (2025-05-17 777d372772aa3b39ba72)

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.D-imprecise-spansDiagnostics: spans don't point to exactly the erroneous codeD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.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