Duplicate errors for missing trait instance in struct definition
Open
Nobody has claimed this yet.
A-diagnostics
D-verbose
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
trait With {
type Assoc;
}
struct Foo(<u32 as With>::Assoc);
fn use_foo(f: Foo) {
drop(f);
}
Current output
error[E0277]: the trait bound `u32: With` is not satisfied
--> src/lib.rs:5:12
|
5 | struct Foo(<u32 as With>::Assoc);
| ^^^^^^^^^^^^^^^^^^^^ the trait `With` is not implemented for `u32`
|
help: this trait has no implementations, consider adding one
--> src/lib.rs:1:1
|
1 | trait With {
| ^^^^^^^^^^
error[E0277]: the trait bound `u32: With` is not satisfied in `Foo`
--> src/lib.rs:7:15
|
7 | fn use_foo(f: Foo) {
| ^^^ within `Foo`, the trait `With` is not implemented for `u32`
|
help: this trait has no implementations, consider adding one
--> src/lib.rs:1:1
|
1 | trait With {
| ^^^^^^^^^^
note: required because it appears within the type `Foo`
--> src/lib.rs:5:8
|
5 | struct Foo(<u32 as With>::Assoc);
| ^^^
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
7 | fn use_foo(f: &Foo) {
| +
error[E0277]: the trait bound `u32: With` is not satisfied in `Foo`
--> src/lib.rs:8:10
|
8 | drop(f);
| ---- ^ within `Foo`, the trait `With` is not implemented for `u32`
| |
| required by a bound introduced by this call
|
help: this trait has no implementations, consider adding one
--> src/lib.rs:1:1
|
1 | trait With {
| ^^^^^^^^^^
note: required because it appears within the type `Foo`
--> src/lib.rs:5:8
|
5 | struct Foo(<u32 as With>::Assoc);
| ^^^
note: required by an implicit `Sized` bound in `std::mem::drop`
--> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/mem/mod.rs:971:19
|
971 | pub const fn drop<T>(_x: T)
| ^ required by the implicit `Sized` requirement on this type parameter in `drop`
Desired output
error[E0277]: the trait bound `u32: With` is not satisfied
--> src/lib.rs:5:12
|
5 | struct Foo(<u32 as With>::Assoc);
| ^^^^^^^^^^^^^^^^^^^^ the trait `With` is not implemented for `u32`
|
help: this trait has no implementations, consider adding one
--> src/lib.rs:1:1
|
1 | trait With {
| ^^^^^^^^^^
Rationale and extra context
Errors in the definition of a struct should not cause all uses of the struct to error too.
Other cases
trait With {
type Assoc;
}
struct Foo(<u32 as With>::Assoc);
trait Other {}
impl Other for Foo {}
Rust Version
rustc 1.93.0 (254b59607 2026-01-19)
binary: rustc
commit-hash: 254b59607d4417e9dffbc307138ae5c86280fe4c
commit-date: 2026-01-19
host: x86_64-unknown-linux-gnu
release: 1.93.0
LLVM version: 21.1.8
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
Start by reproducing the Rust snippet and comparing diagnostics for the struct definition, its use, and the Other implementation case. Trace how the compiler propagates the missing trait-instance error from the struct definition into later uses, then add regression coverage showing that only the definition error remains and the duplicate downstream errors disappear.
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