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

Bad span for ? removal suggestion in parentheses #114392

Closed
ehuss opened this issue Aug 2, 2023 · 0 comments · Fixed by #114403
Closed

Bad span for ? removal suggestion in parentheses #114392

ehuss opened this issue Aug 2, 2023 · 0 comments · Fixed by #114403
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Aug 2, 2023

Code

fn foo() -> Option<()> {
    let x = Some(());
    (x?)
}

Current output

warning: unnecessary parentheses around block return value
 --> src/lib.rs:3:5
  |
3 |     (x?)
  |     ^  ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
3 -     (x?)
3 +     x?
  |

error[E0308]: `?` operator has incompatible types
 --> src/lib.rs:3:6
  |
3 |     (x?)
  |      ^^ expected `Option<()>`, found `()`
  |
  = note: `?` operator cannot convert from `()` to `Option<()>`
  = note:   expected enum `Option<()>`
          found unit type `()`
help: try removing this `?`
  |
3 -     (x?)
3 +     (x?
  |
help: try wrapping the expression in `Some`
  |
3 |     (Some(x?))
  |      +++++  +

For more information about this error, try `rustc --explain E0308`.

Desired output

...
help: try removing this `?`
  |
3 -     (x?)
3 +     (x)

Rationale and extra context

The suggestion span for removing the ? is off-by-one, and suggests removing the parenthesis instead of the ?.

Other cases

No response

Anything else?

rustc 1.73.0-nightly (7bd81ee 2023-07-13)
binary: rustc
commit-hash: 7bd81ee
commit-date: 2023-07-13
host: aarch64-apple-darwin
release: 1.73.0-nightly
LLVM version: 16.0.5

@ehuss ehuss 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. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Aug 2, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 2, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 3, 2023
fix the span in the suggestion of remove question mark

Fixes rust-lang#114392

Use a more precise span.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 3, 2023
fix the span in the suggestion of remove question mark

Fixes rust-lang#114392

Use a more precise span.
@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 3, 2023
@bors bors closed this as completed in 284f176 Aug 3, 2023
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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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.

3 participants