Blanket impl of super trait with method returning associated type: "incompatible type for trait"
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
pub trait Super {
type X;
// Change return type to `()` and everything is fine.
fn method(&self) -> Self::X;
}
// Remove the `: Super` and everything is fine.
pub trait Helper: Super {}
impl<T: Helper> Super for T {
type X = ();
fn method(&self) {}
}
I expected to see this happen: The code compiles
Instead, this happened: The code fails to compile.
Maybe this is working as intended, but intuitively I wouldn't have expected the Helper: Super to make a difference for the impl Super for T.
The type error is a lot more confusing if the associated type is implicit, (i.e. -> impl Future or async fn), because that results in "expected signature fn(&_) -> X, found signature fn(&_) -> X"
error[E0053]: method `method` has an incompatible type for trait
--> src/lib.rs:14:21
|
14 | fn method(&self) {}
| ^ expected associated type, found `()`
|
note: type in trait
--> src/lib.rs:5:25
|
5 | fn method(&self) -> Self::X;
| ^^^^^^^
= note: expected signature `fn(&_) -> <T as Super>::X`
found signature `fn(&_) -> ()`
Meta
rustc --version --verbose:
Build using the Nightly version: 1.89.0-nightly(2025-05-30 70b3f4666e24ce22fc32)
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 with the minimal reproduction in src/lib.rs, then compare the compiler behavior with the Helper: Super bound removed and with the method returning (). Investigate the associated-type and blanket-impl diagnostics, including the implicit return-type case described in the issue. Done means the intended behavior is confirmed or corrected and the incompatible-type error is accurately handled.
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
- Clearly specified
- Newbie friendliness
- 38/100