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

Extra whitespace when suggesting removal of invalid qualifiers from fn pointer #133083

Closed
tyrone-wu opened this issue Nov 15, 2024 · 1 comment · Fixed by #133151
Closed

Extra whitespace when suggesting removal of invalid qualifiers from fn pointer #133083

tyrone-wu opened this issue Nov 15, 2024 · 1 comment · Fixed by #133151
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tyrone-wu
Copy link
Contributor

Code

type FOO = const async fn();

Current output

error: an `fn` pointer type cannot be `const`
 --> src/main.rs:1:12
  |
1 | type FOO = const async fn();
  |            -----^^^^^^^^^^^
  |            |
  |            `const` because of this
  |
help: remove the `const` qualifier
  |
1 - type FOO = const async fn();
1 + type FOO =  async fn();
  |

error: an `fn` pointer type cannot be `async`
 --> src/main.rs:1:12
  |
1 | type FOO = const async fn();
  |            ^^^^^^-----^^^^^
  |                  |
  |                  `async` because of this
  |
help: remove the `async` qualifier
  |
1 - type FOO = const async fn();
1 + type FOO = const  fn();
  |

Desired output

1 - type FOO = const async fn();
1 + type FOO = async fn();

...

1 - type FOO = const async fn();
1 + type FOO = const fn();

Rationale and extra context

The suggestion of the current output produces an extra whitespace for each invalid qualifier.

type FOO =   fn();

Ideally, the desired output should fully remove the qualifier and following whitespaces up until the next token.

type FOO = fn();

Other cases

Rust Version

rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-unknown-linux-gnu
release: 1.82.0
LLVM version: 19.1.1

Anything else?

No response

@tyrone-wu tyrone-wu added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 15, 2024
@tyrone-wu
Copy link
Contributor Author

tyrone-wu commented Nov 15, 2024

After looking into FnPointerCannotBeConst and FnPointerCannotBeAsync, is there a reason the diagnostic need the whole_span?
Maybe a better visual indicator could be to only highlight the offending Span, something like this:

1 | type FOO = const async fn();
  |            ^^^^^
  |
help: remove the `const` qualifier

...

1 | type FOO = const async fn();
  |                  ^^^^^
  |
help: remove the `async` qualifier

I see the suggestion is maybe-incorrect, so perhaps highlighting the whole_span could be beneficial, although I'm not sure what it would look like when the suggestion is actually incorrect.

tyrone-wu added a commit to tyrone-wu/rust that referenced this issue Nov 17, 2024
Trim extra whitespace when suggesting removal of invalid qualifiers when
parsing function pointer type.

Fixes: rust-lang#133083

Signed-off-by: Tyrone Wu <[email protected]>
tyrone-wu added a commit to tyrone-wu/rust that referenced this issue Nov 18, 2024
Trim extra whitespace when suggesting removal of invalid qualifiers when
parsing function pointer type.

Fixes: rust-lang#133083

Signed-off-by: Tyrone Wu <[email protected]>
Zalathar added a commit to Zalathar/rust that referenced this issue Jan 28, 2025
…r=compiler-errors

Trim extra whitespace in fn ptr suggestion span

Trim extra whitespace when suggesting removal of invalid qualifiers when parsing function pointer type.

Fixes: rust-lang#133083

---

I made a comment about the format of the diagnostic error message in rust-lang#133083 (comment). I think the `.label` may be a little redundant if the diagnostic only highlights the bad qualifier instead of the entire `TyKind::BareFn` span. If it makes sense, I can include it in this PR.
Zalathar added a commit to Zalathar/rust that referenced this issue Jan 28, 2025
…r=compiler-errors

Trim extra whitespace in fn ptr suggestion span

Trim extra whitespace when suggesting removal of invalid qualifiers when parsing function pointer type.

Fixes: rust-lang#133083

---

I made a comment about the format of the diagnostic error message in rust-lang#133083 (comment). I think the `.label` may be a little redundant if the diagnostic only highlights the bad qualifier instead of the entire `TyKind::BareFn` span. If it makes sense, I can include it in this PR.
Zalathar added a commit to Zalathar/rust that referenced this issue Jan 28, 2025
…r=compiler-errors

Trim extra whitespace in fn ptr suggestion span

Trim extra whitespace when suggesting removal of invalid qualifiers when parsing function pointer type.

Fixes: rust-lang#133083

---

I made a comment about the format of the diagnostic error message in rust-lang#133083 (comment). I think the `.label` may be a little redundant if the diagnostic only highlights the bad qualifier instead of the entire `TyKind::BareFn` span. If it makes sense, I can include it in this PR.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 28, 2025
…r=compiler-errors

Trim extra whitespace in fn ptr suggestion span

Trim extra whitespace when suggesting removal of invalid qualifiers when parsing function pointer type.

Fixes: rust-lang#133083

---

I made a comment about the format of the diagnostic error message in rust-lang#133083 (comment). I think the `.label` may be a little redundant if the diagnostic only highlights the bad qualifier instead of the entire `TyKind::BareFn` span. If it makes sense, I can include it in this PR.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 28, 2025
…r=compiler-errors

Trim extra whitespace in fn ptr suggestion span

Trim extra whitespace when suggesting removal of invalid qualifiers when parsing function pointer type.

Fixes: rust-lang#133083

---

I made a comment about the format of the diagnostic error message in rust-lang#133083 (comment). I think the `.label` may be a little redundant if the diagnostic only highlights the bad qualifier instead of the entire `TyKind::BareFn` span. If it makes sense, I can include it in this PR.
@bors bors closed this as completed in 5082fd8 Jan 28, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 28, 2025
Rollup merge of rust-lang#133151 - tyrone-wu:trim-fn-ptr-whitespace, r=compiler-errors

Trim extra whitespace in fn ptr suggestion span

Trim extra whitespace when suggesting removal of invalid qualifiers when parsing function pointer type.

Fixes: rust-lang#133083

---

I made a comment about the format of the diagnostic error message in rust-lang#133083 (comment). I think the `.label` may be a little redundant if the diagnostic only highlights the bad qualifier instead of the entire `TyKind::BareFn` span. If it makes sense, I can include it in this PR.
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Jan 29, 2025
…r-errors

Trim extra whitespace in fn ptr suggestion span

Trim extra whitespace when suggesting removal of invalid qualifiers when parsing function pointer type.

Fixes: #133083

---

I made a comment about the format of the diagnostic error message in rust-lang/rust#133083 (comment). I think the `.label` may be a little redundant if the diagnostic only highlights the bad qualifier instead of the entire `TyKind::BareFn` span. If it makes sense, I can include it in this PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant