Use verbose suggestions and only match if the + is seen before a numeric literal

This commit is contained in:
Theodore Luo Wang 2021-09-04 22:35:59 -04:00
parent bc9877c5af
commit 65eb7e516c
9 changed files with 58 additions and 95 deletions

View file

@ -516,16 +516,15 @@ impl<'a> Parser<'a> {
token::BinOp(token::And) | token::AndAnd => {
make_it!(this, attrs, |this, _| this.parse_borrow_expr(lo))
}
token::BinOp(token::Plus) => {
token::BinOp(token::Plus) if this.look_ahead(1, |tok| tok.is_numeric_lit()) => {
let mut err = this.struct_span_err(lo, "leading `+` is not supported");
err.span_label(lo, "unexpected `+`");
// a block on the LHS might have been intended to be an expression instead
let sp = this.sess.source_map().start_point(lo);
if let Some(sp) = this.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
if let Some(sp) = this.sess.ambiguous_block_expr_parse.borrow().get(&lo) {
this.sess.expr_parentheses_needed(&mut err, *sp);
} else {
err.span_suggestion(
err.span_suggestion_verbose(
lo,
"try removing the `+`",
"".to_string(),