add reference location error
Open
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
fn foo<'a, T: Foo>(_: impl Iterator<Item = T>) { }
trait Foo { }
impl Foo for &i32 { }
fn main() {
foo([2i32].into_iter())
}
Current output
Checking test_ v0.1.0 (/home/lrne/Project/Rust/test_)
error[E0277]: the trait bound `i32: Foo` is not satisfied
--> src/main.rs:7:5
|
7 | foo([2i32].into_iter())
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `i32`
|
note: required by a bound in `foo`
--> src/main.rs:1:15
|
1 | fn foo<'a, T: Foo>(_: impl Iterator<Item = T>) { }
| ^^^ required by this bound in `foo`
help: consider borrowing here
|
7 | &foo([2i32].into_iter())
| +
For more information about this error, try `rustc --explain E0277`.
error: could not compile `test_` (bin "test_") due to 1 previous error
Desired output
Checking test_ v0.1.0 (/home/lrne/Project/Rust/test_)
error[E0277]: the trait bound `i32: Foo` is not satisfied
--> src/main.rs:7:5
|
7 | foo([2i32].into_iter())
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `i32`
|
note: required by a bound in `foo`
--> src/main.rs:1:15
|
1 | fn foo<'a, T: Foo>(_: impl Iterator<Item = T>) { }
| ^^^ required by this bound in `foo`
help: consider borrowing here
|
7 | foo([&2i32].into_iter())
| +
For more information about this error, try `rustc --explain E0277`.
error: could not compile `test_` (bin "test_") due to 1 previous error
or
Checking test_ v0.1.0 (/home/lrne/Project/Rust/test_)
error[E0277]: the trait bound `i32: Foo` is not satisfied
--> src/main.rs:7:5
|
7 | foo([2i32].into_iter())
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `i32`
|
note: required by a bound in `foo`
--> src/main.rs:1:15
|
1 | fn foo<'a, T: Foo>(_: impl Iterator<Item = T>) { }
| ^^^ required by this bound in `foo`
help: consider borrowing here
|
7 | foo((&[2i32]).into_iter())
| ++ +
For more information about this error, try `rustc --explain E0277`.
error: could not compile `test_` (bin "test_") due to 1 previous error
Rationale and extra context
No response
Other cases
No response
Rust Version
rustc 1.82.0-nightly (7c2012d0e 2024-07-26)
binary: rustc
commit-hash: 7c2012d0ec3aae89fefc40e5d6b317a0949cda36
commit-date: 2024-07-26
host: aarch64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7
Anything else?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example in src/main.rs with the reported Rust nightly and compare the current and desired E0277 diagnostics. Trace the compiler diagnostic path that emits the borrowing suggestion, then add a regression test covering the reference location and verify the suggestion matches one of the desired outputs.
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