-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-inferenceArea: Type inferenceArea: Type inferenceA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I tried this code:
trait Foo<T> {
type Bar<_T>;
fn bar() -> Self::Bar<T>;
}
impl<T> Foo<T> for usize {
type Bar<_T> = u32;
fn bar() -> Self::Bar<T> {
Self::Bar::default()
}
}
I expected to see this happen: The code would compile, since _T
is known to be T
in <usize as Foo<T>>::bar
Instead, this happened: The _T
parameter is not inferred, and the code fails to compile with the following message:
error[E0282]: type annotations needed
--> src/main.rs:13:9
|
13 | Self::Bar::default()
| ^^^^^^^^^ cannot infer type for type parameter `_T` declared on the associated type `Bar`
For more information about this error, try `rustc --explain E0282`.
error: could not compile `rust-testing` (bin "rust-testing") due to 1 previous error
Meta
rustc --version --verbose
:
rustc 1.91.0-nightly (425a9c0a0 2025-08-17)
binary: rustc
commit-hash: 425a9c0a0e365c0b8c6cfd00c2ded83a73bed9a0
commit-date: 2025-08-17
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 21.1.0
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-inferenceArea: Type inferenceArea: Type inferenceA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.