diff options
| author | bors <bors@rust-lang.org> | 2021-07-30 23:18:12 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-07-30 23:18:12 +0000 |
| commit | 199d1aebe472585e1066334d5e1f740f02eba661 (patch) | |
| tree | e51d508876c7a8ee511aab04dd6132c0b4f2aa8e /compiler/rustc_parse/src/parser | |
| parent | 1f0a591b3a5963a0ab11a35dc525ad9d46f612e4 (diff) | |
| parent | 0b8f192cfee2f107867e7b9a0b0f781a5cb48787 (diff) | |
| download | rust-199d1aebe472585e1066334d5e1f740f02eba661.tar.gz rust-199d1aebe472585e1066334d5e1f740f02eba661.zip | |
Auto merge of #86754 - estebank:use-multispans-more, r=varkor
Use `multipart_suggestions` more Built on top of #86532
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/pat.rs | 2 |
3 files changed, 8 insertions, 10 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 9818bd8d314..273fbea3580 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1770,7 +1770,7 @@ impl<'a> Parser<'a> { let mut err = self.struct_span_err(span, &msg); let sp = self.sess.source_map().start_point(self.token.span); if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) { - self.sess.expr_parentheses_needed(&mut err, *sp, None); + self.sess.expr_parentheses_needed(&mut err, *sp); } err.span_label(span, "expected expression"); err diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index ef05f64da94..b774c76103f 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -358,7 +358,7 @@ impl<'a> Parser<'a> { &format!("expected expression, found `{}`", pprust::token_to_string(&self.token),), ); err.span_label(self.token.span, "expected expression"); - self.sess.expr_parentheses_needed(&mut err, lhs.span, Some(pprust::expr_to_string(&lhs))); + self.sess.expr_parentheses_needed(&mut err, lhs.span); err.emit(); } @@ -696,20 +696,18 @@ impl<'a> Parser<'a> { let expr = mk_expr(self, lhs, self.mk_ty(path.span, TyKind::Path(None, path))); - let expr_str = self - .span_to_snippet(expr.span) - .unwrap_or_else(|_| pprust::expr_to_string(&expr)); - self.struct_span_err(self.token.span, &msg) .span_label( self.look_ahead(1, |t| t.span).to(span_after_type), "interpreted as generic arguments", ) .span_label(self.token.span, format!("not interpreted as {}", op_noun)) - .span_suggestion( - expr.span, + .multipart_suggestion( &format!("try {} the cast value", op_verb), - format!("({})", expr_str), + vec![ + (expr.span.shrink_to_lo(), "(".to_string()), + (expr.span.shrink_to_hi(), ")".to_string()), + ], Applicability::MachineApplicable, ) .emit(); diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 7219e39ea6b..b03b5459981 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -763,7 +763,7 @@ impl<'a> Parser<'a> { let sp = self.sess.source_map().start_point(self.token.span); if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) { - self.sess.expr_parentheses_needed(&mut err, *sp, None); + self.sess.expr_parentheses_needed(&mut err, *sp); } Err(err) |
