Closed
Description
The code:
struct Nothing;
fn foo<'a, F: FnMut(&'a mut Nothing) -> T, T>(_: F) {}
fn bar<'a, F: FnMut(&'a mut Nothing) -> &'a mut Nothing>(_: F) {}
fn main() {
bar(|x| x); // OK
bar(|x: &mut Nothing| x); // OK
foo(|x| x); // OK
foo(|x: &mut Nothing| x); // Error
}
Compiling this on playpen results in this compile error:
<anon>:11:27: 11:28 error: cannot infer an appropriate lifetime due to conflicting requirements
<anon>:11 foo(|x: &mut Nothing| x); // Error
^
<anon>:11:27: 11:28 note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the block at 11:26...
<anon>:11 foo(|x: &mut Nothing| x); // Error
^
<anon>:11:27: 11:28 note: ...so that expression is assignable (expected `&mut Nothing`, found `&mut Nothing`)
<anon>:11 foo(|x: &mut Nothing| x); // Error
^
<anon>:11:5: 11:8 note: but, the lifetime must be valid for the expression at 11:4...
<anon>:11 foo(|x: &mut Nothing| x); // Error
^~~
<anon>:11:5: 11:8 note: ...so that the type `&mut Nothing` will meet its required lifetime bounds
<anon>:11 foo(|x: &mut Nothing| x); // Error
^~~
error: aborting due to previous error
I think that this code is supposed to compile, and the error message isn't very helpful either. What exactly is (expected
&mut Nothing, found
&mut Nothing)
?