Closed
Description
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