-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.F-trait_alias`#![feature(trait_alias)]``#![feature(trait_alias)]`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
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)) {}
Metadata
Metadata
Assignees
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.F-trait_alias`#![feature(trait_alias)]``#![feature(trait_alias)]`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.