Skip to content

Commit 284f176

Browse files
authored
Rollup merge of #114403 - bvanjoi:fix-114392, r=estebank
fix the span in the suggestion of remove question mark Fixes #114392 Use a more precise span.
2 parents 2413f50 + 2195fa6 commit 284f176

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
764764
Some(ty) if expected == ty => {
765765
let source_map = self.tcx.sess.source_map();
766766
err.span_suggestion(
767-
source_map.end_point(cause.span),
767+
source_map.end_point(cause.span()),
768768
"try removing this `?`",
769769
"",
770770
Applicability::MachineApplicable,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// https://github.com/rust-lang/rust/issues/114392
2+
3+
fn foo() -> Option<()> {
4+
let x = Some(());
5+
(x?)
6+
//~^ ERROR `?` operator has incompatible types
7+
}
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0308]: `?` operator has incompatible types
2+
--> $DIR/remove-question-symbol-with-paren.rs:5:6
3+
|
4+
LL | (x?)
5+
| ^^ expected `Option<()>`, found `()`
6+
|
7+
= note: `?` operator cannot convert from `()` to `Option<()>`
8+
= note: expected enum `Option<()>`
9+
found unit type `()`
10+
help: try removing this `?`
11+
|
12+
LL - (x?)
13+
LL + (x)
14+
|
15+
help: try wrapping the expression in `Some`
16+
|
17+
LL | (Some(x?))
18+
| +++++ +
19+
20+
error: aborting due to previous error
21+
22+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)