Rework how the disallowed qualifier in function type diagnostics are generated#142302
Merged
bors merged 2 commits intorust-lang:masterfrom Jun 14, 2025
Merged
Rework how the disallowed qualifier in function type diagnostics are generated#142302bors merged 2 commits intorust-lang:masterfrom
bors merged 2 commits intorust-lang:masterfrom
Conversation
43f3afd to
dc49bef
Compare
Contributor
|
@rustbot author |
Collaborator
|
Reminder, once the PR becomes ready for a review, use |
f4135a4 to
8cfeeb8
Compare
Contributor
Author
|
@rustbot ready |
compiler/rustc_parse/messages.ftl
Outdated
| parse_fn_pointer_cannot_be_const = an `fn` pointer type cannot be `const` | ||
| .label = `const` because of this | ||
| .suggestion = remove the `const` qualifier | ||
| .note = allowed qualifiers are: `unsafe`, `extern` |
Contributor
There was a problem hiding this comment.
could you say
unsafeandextern
?
Contributor
Author
There was a problem hiding this comment.
Fixed.
I decided to keep the : in the allowed qualifiers are: 'unsafe' and 'extern', but if you want to remove that lmk
Contributor
|
r=me after that |
Contributor
|
@rustbot author |
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
8cfeeb8 to
b131b6f
Compare
Contributor
Author
|
@rustbot ready |
Contributor
Collaborator
bors
added a commit
that referenced
this pull request
Jun 14, 2025
Rollup of 16 pull requests Successful merges: - #140969 (Allow initializing logger with additional tracing Layer) - #141352 (builtin dyn impl no guide inference) - #142046 (add Vec::peek_mut) - #142273 (tests: Minicore `extern "gpu-kernel"` feature test) - #142302 (Rework how the disallowed qualifier in function type diagnostics are generated) - #142405 (Don't hardcode the intrinsic return types twice in the compiler) - #142434 ( Pre-install JS dependencies in tidy Dockerfile) - #142439 (doc: mention that intrinsics should not be called in user code) - #142441 (Delay replacing escaping bound vars in `FindParamInClause`) - #142449 (Require generic params for const generic params) - #142452 (Remove "intermittent" wording from `ReadDir`) - #142459 (Remove output helper bootstrap) - #142460 (cleanup search graph impl) - #142461 (compiletest: Clarify that `--no-capture` is needed with `--verbose`) - #142475 (Add platform support docs & maintainers for *-windows-msvc) - #142480 (tests: Convert two handwritten minicores to add-core-stubs) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
that referenced
this pull request
Jun 14, 2025
Rollup merge of #142302 - JonathanBrouwer:invalid-const-token, r=jdonszelmann Rework how the disallowed qualifier in function type diagnostics are generated This pull request fixes two independent issues: 1. When qualifiers of a function type ptr are in the wrong order and one of them is async/const (not permitted on function types), the diagnostic suggests removing the incorrect qualifier. Fixes #142268, which is an issue created by #133151. This is fixed by moving the check into `parse_fn_front_matter`, where better span information is available to generate the right suggestions. 2. When qualifiers of a function type ptr are in the wrong order and one of them is async/const (not permitted on function types), `cargo fix` crashes because "cannot replace slice of data that was already replaced". This is fixed by not generating a suggestion for the "wrong order" diagnostic if the "disallowed qualifier" diagnostic is triggered. There is a commit with failing tests so the test diff is clearer r? `@jdonszelmann`
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

This pull request fixes two independent issues:
unsafe const fn()type #142268, which is an issue created by Trim extra whitespace in fn ptr suggestion span #133151. This is fixed by moving the check intoparse_fn_front_matter, where better span information is available to generate the right suggestions.cargo fixcrashes because "cannot replace slice of data that was already replaced". This is fixed by not generating a suggestion for the "wrong order" diagnostic if the "disallowed qualifier" diagnostic is triggered.There is a commit with failing tests so the test diff is clearer
r? @jdonszelmann