rust-lang / rust-lang/rust

wrong span for E0277

Open
#141,234 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics D-confusing D-imprecise-spans D-incorrect T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the diagnostic with the Rust snippet and the reported nightly version, comparing the current underline with the desired str span. Trace the compiler diagnostic span selection for E0277 and verify the result against the shown desired output; no source file or test is identified in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.