Skip to content

Commit 8be729c

Browse files
committed
chore: convert to a multi-part suggestion
1 parent d98892b commit 8be729c

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

compiler/rustc_typeck/src/check/expr.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1853,10 +1853,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18531853
let expr_snippet =
18541854
self.tcx.sess.source_map().span_to_snippet(expr.span).unwrap_or(String::new());
18551855
if expr_is_call && expr_snippet.starts_with("(") && expr_snippet.ends_with(")") {
1856-
err.span_suggestion_short(
1857-
expr.span,
1856+
let after_open = expr.span.lo() + rustc_span::BytePos(1);
1857+
let before_close = expr.span.hi() - rustc_span::BytePos(1);
1858+
err.multipart_suggestion(
18581859
"remove wrapping parentheses to call the method",
1859-
expr_snippet[1..expr_snippet.len() - 1].to_owned(),
1860+
vec![
1861+
(expr.span.with_hi(after_open), String::new()),
1862+
(expr.span.with_lo(before_close), String::new()),
1863+
],
18601864
Applicability::MachineApplicable,
18611865
);
18621866
} else if !self.expr_in_place(expr.hir_id) {

src/test/ui/typeck/issue-88803-call-expr-method.stderr

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ error[E0615]: attempted to take value of method `unwrap` on type `Option<{intege
22
--> $DIR/issue-88803-call-expr-method.rs:7:12
33
|
44
LL | (a.unwrap)()
5-
| ---^^^^^^-
6-
| | |
7-
| | method, not a field
8-
| help: remove wrapping parentheses to call the method
5+
| ^^^^^^ method, not a field
6+
|
7+
help: remove wrapping parentheses to call the method
8+
|
9+
LL - (a.unwrap)()
10+
LL + a.unwrap()
11+
|
912

1013
error: aborting due to previous error
1114

0 commit comments

Comments
 (0)