about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-08-03 17:29:09 +0200
committerGitHub <noreply@github.com>2023-08-03 17:29:09 +0200
commit284f176bbd35480bfcd41523fe07a64a9837615f (patch)
treeef7020f4e8c873b698aa3c271e10a4cecf1c0329
parent2413f50a0b990a231798182038fc549dfca5f5cf (diff)
parent2195fa6a9bad1e95511875c93c34b55fe7ae55fa (diff)
downloadrust-284f176bbd35480bfcd41523fe07a64a9837615f.tar.gz
rust-284f176bbd35480bfcd41523fe07a64a9837615f.zip
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.
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/mod.rs2
-rw-r--r--tests/ui/suggestions/remove-question-symbol-with-paren.rs9
-rw-r--r--tests/ui/suggestions/remove-question-symbol-with-paren.stderr22
3 files changed, 32 insertions, 1 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs
index 25077f9bb97..7739cf1ee05 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs
@@ -764,7 +764,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
                             Some(ty) if expected == ty => {
                                 let source_map = self.tcx.sess.source_map();
                                 err.span_suggestion(
-                                    source_map.end_point(cause.span),
+                                    source_map.end_point(cause.span()),
                                     "try removing this `?`",
                                     "",
                                     Applicability::MachineApplicable,
diff --git a/tests/ui/suggestions/remove-question-symbol-with-paren.rs b/tests/ui/suggestions/remove-question-symbol-with-paren.rs
new file mode 100644
index 00000000000..c522793dbcb
--- /dev/null
+++ b/tests/ui/suggestions/remove-question-symbol-with-paren.rs
@@ -0,0 +1,9 @@
+// https://github.com/rust-lang/rust/issues/114392
+
+fn foo() -> Option<()> {
+    let x = Some(());
+    (x?)
+    //~^ ERROR `?` operator has incompatible types
+}
+
+fn main() {}
diff --git a/tests/ui/suggestions/remove-question-symbol-with-paren.stderr b/tests/ui/suggestions/remove-question-symbol-with-paren.stderr
new file mode 100644
index 00000000000..39e35f733a1
--- /dev/null
+++ b/tests/ui/suggestions/remove-question-symbol-with-paren.stderr
@@ -0,0 +1,22 @@
+error[E0308]: `?` operator has incompatible types
+  --> $DIR/remove-question-symbol-with-paren.rs:5:6
+   |
+LL |     (x?)
+   |      ^^ expected `Option<()>`, found `()`
+   |
+   = note: `?` operator cannot convert from `()` to `Option<()>`
+   = note:   expected enum `Option<()>`
+           found unit type `()`
+help: try removing this `?`
+   |
+LL -     (x?)
+LL +     (x)
+   |
+help: try wrapping the expression in `Some`
+   |
+LL |     (Some(x?))
+   |      +++++  +
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.