-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Tweak fn pointer suggestion span #136412
Merged
Merged
Tweak fn pointer suggestion span #136412
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
Use a more targeted span when suggesting casting an `fn` item to an `fn` pointer. ``` error[E0308]: cannot coerce functions which must be inlined to function pointers --> $DIR/cast.rs:10:33 | LL | let _: fn(isize) -> usize = callee; | ------------------ ^^^^^^ cannot coerce functions which must be inlined to function pointers | | | expected due to this | = note: expected fn pointer `fn(_) -> _` found fn item `fn(_) -> _ {callee}` = note: fn items are distinct from fn pointers help: consider casting to a fn pointer | LL | let _: fn(isize) -> usize = callee as fn(isize) -> usize; | +++++++++++++++++++++ ``` ``` error[E0308]: mismatched types --> $DIR/fn-pointer-mismatch.rs:42:30 | LL | let d: &fn(u32) -> u32 = foo; | --------------- ^^^ expected `&fn(u32) -> u32`, found fn item | | | expected due to this | = note: expected reference `&fn(_) -> _` found fn item `fn(_) -> _ {foo}` help: consider using a reference | LL | let d: &fn(u32) -> u32 = &foo; | + ``` Previously we'd point at the whole expression for replacement, instead of marking what was being added. We could also modify the suggestions for `&(name as fn())`, but for that we require storing more accurate spans than we have now.
rustbot has assigned @petrochenkov. Use |
jieyouxu
approved these changes
Feb 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
r? jieyouxu @bors r+ rollup |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Feb 2, 2025
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#133266 (ci: fix explanation why LLVM download is disabled for windows-gnu) - rust-lang#136133 (Fix sentence in process::abort) - rust-lang#136279 (Rename `tcx.ensure()` to `tcx.ensure_ok()`, and improve the associated docs) - rust-lang#136328 (Rework "long type names" printing logic) - rust-lang#136358 (`#[optimize(none)]` implies `#[inline(never)]`) - rust-lang#136368 (Make comma separated lists of anything easier to make for errors) - rust-lang#136412 (Tweak fn pointer suggestion span) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Feb 2, 2025
Rollup merge of rust-lang#136412 - estebank:fn-ptr-cast-suggestion, r=jieyouxu Tweak fn pointer suggestion span Use a more targeted span when suggesting casting an `fn` item to an `fn` pointer. ``` error[E0308]: cannot coerce functions which must be inlined to function pointers --> $DIR/cast.rs:10:33 | LL | let _: fn(isize) -> usize = callee; | ------------------ ^^^^^^ cannot coerce functions which must be inlined to function pointers | | | expected due to this | = note: expected fn pointer `fn(_) -> _` found fn item `fn(_) -> _ {callee}` = note: fn items are distinct from fn pointers help: consider casting to a fn pointer | LL | let _: fn(isize) -> usize = callee as fn(isize) -> usize; | +++++++++++++++++++++ ``` ``` error[E0308]: mismatched types --> $DIR/fn-pointer-mismatch.rs:42:30 | LL | let d: &fn(u32) -> u32 = foo; | --------------- ^^^ expected `&fn(u32) -> u32`, found fn item | | | expected due to this | = note: expected reference `&fn(_) -> _` found fn item `fn(_) -> _ {foo}` help: consider using a reference | LL | let d: &fn(u32) -> u32 = &foo; | + ``` Previously we'd point at the whole expression for replacement, instead of marking what was being added. We could also modify the suggestions for `&(name as fn())`, but for that we require storing more accurate spans than we have now.
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.
Use a more targeted span when suggesting casting an
fn
item to anfn
pointer.Previously we'd point at the whole expression for replacement, instead of marking what was being added.
We could also modify the suggestions for
&(name as fn())
, but for that we require storing more accurate spans than we have now.