Skip to content

Multiple Fn bounds #100295

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

Closed
SoniEx2 opened this issue Aug 9, 2022 · 0 comments · Fixed by #101360
Closed

Multiple Fn bounds #100295

SoniEx2 opened this issue Aug 9, 2022 · 0 comments · Fixed by #101360
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@SoniEx2
Copy link
Contributor

SoniEx2 commented Aug 9, 2022

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=cedda74405870f1697d8323ea0fa041d

fn foo<F: Fn(&char) -> bool + Fn(char) -> bool>(f: F) {
    todo!();
}

fn main() {
    let v = true;
    foo(move |x| v);
}

The current output is:

error[[E0631]](https://doc.rust-lang.org/stable/error-index.html#E0631): type mismatch in closure arguments
 --> src/main.rs:7:5
  |
7 |     foo(move |x| v);
  |     ^^^ ---------- found signature of `for<'r> fn(&'r char) -> _`
  |     |
  |     expected signature of `fn(char) -> _`
  |
note: required by a bound in `foo`
 --> src/main.rs:1:31
  |
1 | fn foo<F: Fn(&char) -> bool + Fn(char) -> bool>(f: F) {
  |                               ^^^^^^^^^^^^^^^^ required by this bound in `foo`

Ideally the output should look like:

We don't have a specific output in mind, but it'd be nice if the error helpfully specified that this bound is impossible to satisfy with a closure. However, we do acknowledge that Fn traits (specifically, implementing them) are still unstable.

@SoniEx2 SoniEx2 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 9, 2022
@compiler-errors compiler-errors self-assigned this Aug 12, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Oct 10, 2022
…ounds, r=petrochenkov

Point out incompatible closure bounds

Fixes rust-lang#100295
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Oct 10, 2022
…ounds, r=petrochenkov

Point out incompatible closure bounds

Fixes rust-lang#100295
@bors bors closed this as completed in d8d01e3 Oct 11, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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.

2 participants