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

Add note when FnPtr vs. FnDef impl trait #106665

Merged
merged 1 commit into from
Jan 14, 2023

Conversation

JulianKnodt
Copy link
Contributor

I encountered an instance where an FnPtr implemented a trait, but I was passing an FnDef. I was confused for an hour and to examine the source code of the trait's crate's tests in order to understand how to cast it properly (it didn't help that it was behind a reference). To the end user, it might not be immediately obvious that they are different and how to convert from an FnDef to an FnPtr, but it is necessary to cast to the generic function in order to compile. It is thus useful to suggest as in the help note, (even if the Fn output implements the trait).

@rustbot
Copy link
Collaborator

rustbot commented Jan 10, 2023

r? @cjgillot

(rustbot has picked a reviewer for you, use r? to override)

@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. labels Jan 10, 2023
@JulianKnodt JulianKnodt marked this pull request as ready for review January 10, 2023 06:21
@JulianKnodt JulianKnodt force-pushed the better_fn_trait_note branch 2 times, most recently from 1bd462e to b9df4ac Compare January 12, 2023 01:11
@JulianKnodt JulianKnodt force-pushed the better_fn_trait_note branch 4 times, most recently from 437670b to dab1eb7 Compare January 14, 2023 10:06
I encountered an instance where an `FnPtr` implemented a trait, but I was passing an `FnDef`. To
the end user, there is really no way to differentiate each of them, but it is necessary to cast
to the generic function in order to compile. It is thus useful to suggest `as` in the help note,
(even if the Fn output implements the trait).
@cjgillot
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jan 14, 2023

📌 Commit 2de9d67 has been approved by cjgillot

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 Jan 14, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 14, 2023
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#106046 (Fix mir-opt tests for big-endian platforms)
 - rust-lang#106470 (tidy: Don't include wasm32 in compiler dependency check)
 - rust-lang#106566 (Emit a single error for contiguous sequences of unknown tokens)
 - rust-lang#106644 (Update the wasi-libc used for the wasm32-wasi target)
 - rust-lang#106665 (Add note when `FnPtr` vs. `FnDef` impl trait)
 - rust-lang#106752 (Emit a hint for bad call return types due to generic arguments)
 - rust-lang#106788 (Tweak E0599 and elaborate_predicates)
 - rust-lang#106831 (Use GitHub yaml templates for ICE, Docs and Diagnostics tickets)
 - rust-lang#106846 (Improve some comments and names in parser)
 - rust-lang#106848 (Fix wrong path in triage bot autolabel for wg-trait-solver-refactor)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3fa9be9 into rust-lang:master Jan 14, 2023
@rustbot rustbot added this to the 1.68.0 milestone Jan 14, 2023
@JulianKnodt JulianKnodt deleted the better_fn_trait_note branch January 14, 2023 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants