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

fix the span in the suggestion of remove question mark #114403

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/suggestions/remove-question-symbol-with-paren.rs
Original file line number Diff line number Diff line change
@@ -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() {}
22 changes: 22 additions & 0 deletions tests/ui/suggestions/remove-question-symbol-with-paren.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Loading