Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying use trait alias for Fn() in impl #60755

Closed
DustinByfuglien opened this issue May 12, 2019 · 2 comments · Fixed by #107355
Closed

Error when trying use trait alias for Fn() in impl #60755

DustinByfuglien opened this issue May 12, 2019 · 2 comments · Fixed by #107355
Labels
A-traits Area: Trait system C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-trait_alias `#![feature(trait_alias)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DustinByfuglien
Copy link

This code produce compiling error:

#![feature(trait_alias)]

struct MyStruct {}
trait MyFn = Fn(&MyStruct);

fn foo (_: impl MyFn) {}

fn main () {
    foo(|_| {});
}

(Playground)

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)) {}

@jonas-schievink jonas-schievink added A-traits Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 12, 2019
@DustinByfuglien
Copy link
Author

May be "F-trait_alias" label needed for this issue.

@kadiwa4
Copy link
Contributor

kadiwa4 commented Jan 16, 2023

Fixed on latest nightly 2023-01-15.
@rustbot label: +F-trait_alias +E-needs-test

@rustbot rustbot added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-trait_alias `#![feature(trait_alias)]` labels Jan 16, 2023
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jan 27, 2023
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 27, 2023
…errors

Add regression test for rust-lang#60755

Closes rust-lang#60755
r? compiler-errors
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 28, 2023
…errors

Add regression test for rust-lang#60755

Closes rust-lang#60755
r? compiler-errors
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 28, 2023
…errors

Add regression test for rust-lang#60755

Closes rust-lang#60755
r? compiler-errors
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 28, 2023
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#104012 (Improve unexpected close and mismatch delimiter hint in TokenTreesReader)
 - rust-lang#104252 (Stabilize the const_socketaddr feature)
 - rust-lang#105524 (Replace libc::{type} with crate::ffi::{type})
 - rust-lang#107096 (Detect references to non-existant messages in Fluent resources)
 - rust-lang#107355 (Add regression test for rust-lang#60755)
 - rust-lang#107384 (Remove `BOOL_TY_FOR_UNIT_TESTING`)
 - rust-lang#107385 (Use `FallibleTypeFolder` for `ConstInferUnifier` not `TypeRelation`)
 - rust-lang#107391 (rustdoc: remove inline javascript from copy-path button)
 - rust-lang#107398 (Remove `ControlFlow::{BREAK, CONTINUE}`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
flip1995 pushed a commit to flip1995/rust that referenced this issue Feb 10, 2023
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#104012 (Improve unexpected close and mismatch delimiter hint in TokenTreesReader)
 - rust-lang#104252 (Stabilize the const_socketaddr feature)
 - rust-lang#105524 (Replace libc::{type} with crate::ffi::{type})
 - rust-lang#107096 (Detect references to non-existant messages in Fluent resources)
 - rust-lang#107355 (Add regression test for rust-lang#60755)
 - rust-lang#107384 (Remove `BOOL_TY_FOR_UNIT_TESTING`)
 - rust-lang#107385 (Use `FallibleTypeFolder` for `ConstInferUnifier` not `TypeRelation`)
 - rust-lang#107391 (rustdoc: remove inline javascript from copy-path button)
 - rust-lang#107398 (Remove `ControlFlow::{BREAK, CONTINUE}`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-trait_alias `#![feature(trait_alias)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants