Closed
Description
This code produce compiling error:
#![feature(trait_alias)]
struct MyStruct {}
trait MyFn = Fn(&MyStruct);
fn foo (_: impl MyFn) {}
fn main () {
foo(|_| {});
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0631]: type mismatch in closure arguments
--> src/main.rs:9:5
|
9 | foo(|_| {});
| ^^^ --- found signature of `fn(_) -> _`
| |
| expected signature of `for<'r> fn(&'r MyStruct) -> _`
|
note: required by `foo`
--> src/main.rs:6:1
|
6 | fn foo (_: impl MyFn) {}
| ^^^^^^^^^^^^^^^^^^^^^
error[E0271]: type mismatch resolving `for<'r> <[closure@src/main.rs:9:9: 9:15] as std::ops::FnOnce<(&'r MyStruct,)>>::Output == ()`
--> src/main.rs:9:5
|
9 | foo(|_| {});
| ^^^ expected bound lifetime parameter, found concrete lifetime
|
note: required by `foo`
--> src/main.rs:6:1
|
6 | fn foo (_: impl MyFn) {}
| ^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0271`.
error: Could not compile `playground`.
To learn more, run the command again with --verbose.
But when non aliased trait used, then no error occured. That is when we replace
fn foo (_: impl MyFn) {}
with
fn foo (_: impl Fn(&MyStruct)) {}