-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.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
Minimal example I could create:
trait Callback<Args> {
fn call(&mut self, args: Args);
}
impl<F, Args> Callback<Args> for F where F: FnMut(Args) {
fn call(&mut self, args: Args) {
self(args)
}
}
#[derive(Debug)]
struct Wrapper<T>(T);
#[derive(Debug)]
enum Foo {
Bar,
Baz,
Baq
}
fn use_cb<C: Callback<Wrapper<Foo>>>(mut c: C) {
c.call(Wrapper(Foo::Baz))
}
fn main() {
// this one works
use_cb(|variant| {
println!("the variant is: {:?}", variant);
});
// this one fails to infer
use_cb(|variant| {
println!("the variant is: {:?}", variant.0);
});
// with these annotations it works
use_cb(|variant: Wrapper<_>| {
println!("the variant is: {:?}", variant.0);
});
}
note that the sole difference between the first and second closure is that the first prints variant
while the other tries to access its inner field.
It reproduces on both stable and nightly.
Metadata
Metadata
Assignees
Labels
A-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.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.