From 8be729cdd6473859f4fb54aaf74dce56f0775ef1 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 12 Sep 2021 19:51:09 -0700 Subject: [PATCH] chore: convert to a multi-part suggestion --- compiler/rustc_typeck/src/check/expr.rs | 10 +++++++--- .../ui/typeck/issue-88803-call-expr-method.stderr | 11 +++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 61d5b6985f1bf..f4e3c8e0d9f7f 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -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) { diff --git a/src/test/ui/typeck/issue-88803-call-expr-method.stderr b/src/test/ui/typeck/issue-88803-call-expr-method.stderr index 4b7ea95dee2a7..dd717ed9416d3 100644 --- a/src/test/ui/typeck/issue-88803-call-expr-method.stderr +++ b/src/test/ui/typeck/issue-88803-call-expr-method.stderr @@ -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