Skip to content

Commit

Permalink
chore: convert to a multi-part suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Sep 13, 2021
1 parent d98892b commit 8be729c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 7 additions & 3 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1853,10 +1853,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let expr_snippet =
self.tcx.sess.source_map().span_to_snippet(expr.span).unwrap_or(String::new());
if expr_is_call && expr_snippet.starts_with("(") && expr_snippet.ends_with(")") {
err.span_suggestion_short(
expr.span,
let after_open = expr.span.lo() + rustc_span::BytePos(1);
let before_close = expr.span.hi() - rustc_span::BytePos(1);
err.multipart_suggestion(
"remove wrapping parentheses to call the method",
expr_snippet[1..expr_snippet.len() - 1].to_owned(),
vec![
(expr.span.with_hi(after_open), String::new()),
(expr.span.with_lo(before_close), String::new()),
],
Applicability::MachineApplicable,
);
} else if !self.expr_in_place(expr.hir_id) {
Expand Down
11 changes: 7 additions & 4 deletions src/test/ui/typeck/issue-88803-call-expr-method.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ error[E0615]: attempted to take value of method `unwrap` on type `Option<{intege
--> $DIR/issue-88803-call-expr-method.rs:7:12
|
LL | (a.unwrap)()
| ---^^^^^^-
| | |
| | method, not a field
| help: remove wrapping parentheses to call the method
| ^^^^^^ method, not a field
|
help: remove wrapping parentheses to call the method
|
LL - (a.unwrap)()
LL + a.unwrap()
|

error: aborting due to previous error

Expand Down

0 comments on commit 8be729c

Please sign in to comment.