rust-lang / rust-lang/rust

unhelpful E0277 when writing `func(&a: &T)` instead of `func(a: &T)`

Open
#134,461 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
use std::path::Path;

fn main() {
    fun_with_path(&Path::new("."));
    fun_with_int(&0);
}

// &a: &Path    should've been a: &Path
pub fn fun_with_path(&a: &Path) {
    println!("{:?}", a);
}

// ok 
pub fn fun_with_int(&a: &i32) {
    println!("{:?}", a);
}
Current output
Compiling playground v0.0.1 (/playground)
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
    --> src/main.rs:9:23
     |
9    | pub fn fun_with_path(&a: &Path) {
     |                       ^ doesn't have a size known at compile-time
     |
     = help: within `Path`, the trait `Sized` is not implemented for `[u8]`
note: required because it appears within the type `Path`
    --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/path.rs:2137:12
     |
2137 | pub struct Path {
     |            ^^^^
     = note: all local variables must have a statically known size
     = help: unsized locals are gated as an unstable feature

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (bin "playground") due to 1 previous error
Desired output
point at the `&` of `&a` in `fun_with_path` and suggest removing it?
Rationale and extra context

No response

Other cases

Rust Version
rustc 1.85.0-nightly (a4cb3c831 2024-12-17)
binary: rustc
commit-hash: a4cb3c831823d9baa56c3d90514b75b2660116fa
commit-date: 2024-12-17
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5
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 report using the code in src/main.rs and compare the current E0277 output with the requested diagnostic. The payload names no compiler implementation file or test; done means the erroneous & before the parameter name is highlighted and the diagnostic suggests removing it.

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.