-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Open
Labels
A-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
Description
Here's an example (play):
trait Tr<Ctx> {
fn foo();
}
trait DefaultCtx {}
impl<T: Default, Ctx: DefaultCtx> Tr<Ctx> for T {
fn foo() {}
}
struct OneDefaultCtx;
impl DefaultCtx for OneDefaultCtx {}
fn main() {
<i32 as Tr<_>>::foo();
}The context type Ctx cannot be inferred even though:
- i32 implements Default
- There's at least one type (OneDefaultCtx) that implements DefaultCtx
- The trait method foo() doesn't use Ctx in its signature
Is this inability to infer Ctx an intentional design choice in Rust (perhaps due to coherence rules, ambiguity, or other language design principles), or is it a current limitation of the compiler's type inference that might be improved in the future?
Metadata
Metadata
Assignees
Labels
A-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.