-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r? @cjgillot (rustbot has picked a reviewer for you, use r? to override) |
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
force-pushed
the
better_fn_trait_note
branch
from
January 10, 2023 06:31
1336850
to
593c60c
Compare
cjgillot
reviewed
Jan 11, 2023
JulianKnodt
force-pushed
the
better_fn_trait_note
branch
2 times, most recently
from
January 12, 2023 01:11
1bd462e
to
b9df4ac
Compare
cjgillot
reviewed
Jan 14, 2023
compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Outdated
Show resolved
Hide resolved
JulianKnodt
force-pushed
the
better_fn_trait_note
branch
4 times, most recently
from
January 14, 2023 10:06
437670b
to
dab1eb7
Compare
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).
JulianKnodt
force-pushed
the
better_fn_trait_note
branch
from
January 14, 2023 10:38
dab1eb7
to
2de9d67
Compare
@bors r+ |
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I encountered an instance where an
FnPtr
implemented a trait, but I was passing anFnDef
. 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 anFnDef
to anFnPtr
, but it is necessary to cast to the generic function in order to compile. It is thus useful to suggestas
in the help note, (even if theFn
output implements the trait).