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

Use parenthetical notation for Fn traits #125778

Merged
merged 1 commit into from
Jun 3, 2024
Merged

Conversation

estebank
Copy link
Contributor

@estebank estebank commented May 30, 2024

Always use the Fn(T) -> R format when printing closure traits instead of Fn<(T,), Output = R>.

Address #67100:

error[E0277]: expected a `Fn()` closure, found `F`
 --> file.rs:6:13
  |
6 |     call_fn(f)
  |     ------- ^ expected an `Fn()` closure, found `F`
  |     |
  |     required by a bound introduced by this call
  |
  = note: wrap the `F` in a closure with no arguments: `|| { /* code */ }`
note: required by a bound in `call_fn`
 --> file.rs:1:15
  |
1 | fn call_fn<F: Fn() -> ()>(f: &F) {
  |               ^^^^^^^^^^ required by this bound in `call_fn`
help: consider further restricting this bound
  |
5 | fn call_any<F: std::any::Any + Fn()>(f: &F) {
  |                              ++++++

Always use the `Fn(T) -> R` format when printing closure traits instead of `Fn<(T,), Output = R>`.

Fix rust-lang#67100:

```
error[E0277]: expected a `Fn()` closure, found `F`
 --> file.rs:6:13
  |
6 |     call_fn(f)
  |     ------- ^ expected an `Fn()` closure, found `F`
  |     |
  |     required by a bound introduced by this call
  |
  = note: wrap the `F` in a closure with no arguments: `|| { /* code */ }`
note: required by a bound in `call_fn`
 --> file.rs:1:15
  |
1 | fn call_fn<F: Fn() -> ()>(f: &F) {
  |               ^^^^^^^^^^ required by this bound in `call_fn`
help: consider further restricting this bound
  |
5 | fn call_any<F: std::any::Any + Fn()>(f: &F) {
  |                              ++++++
```
@rustbot
Copy link
Collaborator

rustbot commented May 30, 2024

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels May 30, 2024
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me when ci

@compiler-errors
Copy link
Member

compiler-errors commented May 30, 2024

To be clear, since it was not acknowledged in the PR description, this is not a general fix for #67100. Specifically, the suggestion is not going to be right when the trait bound suggestion needs a return type, since all we have is a trait ref (no return type) and not a projection predicate (has a return type).

Slightly modifying the test from the issue:

fn call_fn<F: Fn() -> i32>(f: &F) {
    f()
}

fn call_any<F: std::any::Any>(f: &F) {
    call_fn(f)
}

fn main() {
    call_any(&|| { 1 });
}

...which suggests Fn() instead of Fn() -> i32. I would prefer if you keep that issue open or file a new issue to capture this, though for the purposes of error messages I'm fine if this PR goes in as-is.

@estebank
Copy link
Contributor Author

@compiler-errors you're absolutely right. I missed that because I looked at the suggestion to turn Fn<Args, Output = Ret> to Fn(Arg, Arg) -> Ret which does handle that correctly (because we do have the whole info then) and failed to notice that of course didn't apply here. Furthermore, the follow up errors aren't great either.

@estebank
Copy link
Contributor Author

estebank commented Jun 3, 2024

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Jun 3, 2024

📌 Commit e6bd6c2 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 3, 2024
@bors
Copy link
Contributor

bors commented Jun 3, 2024

⌛ Testing commit e6bd6c2 with merge 1d52972...

@bors
Copy link
Contributor

bors commented Jun 3, 2024

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 1d52972 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 3, 2024
@bors bors merged commit 1d52972 into rust-lang:master Jun 3, 2024
7 checks passed
@rustbot rustbot added this to the 1.80.0 milestone Jun 3, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1d52972): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.6% [1.6%, 1.6%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -3.4%, secondary -3.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.4% [-4.4%, -2.1%] 3
Improvements ✅
(secondary)
-3.2% [-3.8%, -2.2%] 9
All ❌✅ (primary) -3.4% [-4.4%, -2.1%] 3

Cycles

Results (secondary -2.7%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.7% [-2.7%, -2.7%] 1
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 670.518s -> 669.197s (-0.20%)
Artifact size: 318.94 MiB -> 318.98 MiB (0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants