-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Failure to determine impls with higher-ranked lifetimes involved #32600
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
This is an inference thing. I'm not sure if it's expected or not, but the fact that this works: trait Foo<T> {
fn process(&mut self, T);
}
impl<T, F> Foo<T> for F where F: FnMut(T) {
fn process(&mut self, data: T) {
self(data)
}
}
fn bar<F: for<'a> Foo<&'a str>>(mut foo: F) {
foo.process("foobar");
}
fn main() {
bar(|x:&str| println!("{}", x));
} is evidence that it's probably more to do with inference than anything else. Interesting though is that this: trait Foo<T> {
fn process(&mut self, T);
}
impl<T, F> Foo<T> for F where F: FnMut(T) {
fn process(&mut self, data: T) {
self(data)
}
}
fn bar<F: Foo<String>>(mut foo: F) {
foo.process("foobar".into());
}
fn main() {
bar(|x| println!("{}", x));
} works, so the lifetimes are probably a factor. |
It also compiles with |
This also works (using the static lifetime): trait Foo<T> {
fn process(&mut self, T);
}
impl<T, F> Foo<T> for F where F: FnMut(T) {
fn process(&mut self, data: T) {
self(data)
}
}
fn bar<F: Foo<&'static str>>(mut foo: F) {
foo.process("foobar");
}
fn main() {
bar(|x| println!("{}", x));
} This does not (using a specific method of str, instead of the generic println! macro) trait Foo<T> {
fn process(&mut self, T);
}
impl<T, F> Foo<T> for F where F: FnMut(T) {
fn process(&mut self, data: T) {
self(data)
}
}
fn bar<F: for<'a> Foo<&'a str>>(mut foo: F) {
foo.process("foobar");
}
fn main() {
bar(|x| str::len(x));
} |
I also haven't posted the error message, its:
|
I believe this is another instance of the same issue: fn foo<F1, X, F2>(f1: F1, f2: F2)
where F1: FnOnce() -> X,
F2: Fn(&mut X)
{
let mut x = f1();
f2(&mut x);
}
fn main() {
let a = || 0 as u32;
let b = |_| {};
foo(a, b);
} Yields:
|
I think you're right. Again it can be fixed by changing |
Closing in favor of #41078. |
This does not work:
This does work:
So does this:
Perhaps I am mistaken, but I believe that
FnMut(T): Foo<T>
impliesfor<'a> FnMut(&'a str): for<'a> Foo<&'a str>
. rustc seems unable to make the determination that this is true.The text was updated successfully, but these errors were encountered: