Confusing diagnostic when trying to define a field in a trait
Open
@raushan728 is already working on this.
Since Aug 27, 2026.
A-diagnostics
A-parser
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
trait MyTrait {
field_name: String,
}
Current output
error: expected one of `!` or `::`, found `:`
--> src/main.rs:25:15
|
24 | trait MyTrait {
| - while parsing this item list starting here
25 | field_name: String,
| ^ expected one of `!` or `::`
26 | }
| - the item list ends here
Desired output
Maybe something like "fields not supported/allowed in traits, use getter/setter function instead"
Rust Version
rustc 1.97.0 (2d8144b78 2026-07-07)
binary: rustc
commit-hash: 2d8144b7880597b6e6d3dfd63a9a9efae3f533d3
commit-date: 2026-07-07
host: x86_64-unknown-linux-gnu
release: 1.97.0
LLVM version: 22.1.6
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.
Assessment
This issue has not been assessed yet.