chore: convert to a multi-part suggestion

This commit is contained in:
Michael Howell 2021-09-12 19:51:09 -07:00
parent d98892b67f
commit 8be729cdd6
2 changed files with 14 additions and 7 deletions

View File

@ -1853,10 +1853,14 @@ fn ban_take_value_of_method(&self, expr: &hir::Expr<'_>, expr_t: Ty<'tcx>, field
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) {

View File

@ -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