Use verbose suggestions and only match if the + is seen before a numeric literal
This commit is contained in:
parent
bc9877c5af
commit
65eb7e516c
9 changed files with 58 additions and 95 deletions
|
@ -586,6 +586,10 @@ impl Token {
|
||||||
self.is_non_raw_ident_where(|id| id.name.is_bool_lit())
|
self.is_non_raw_ident_where(|id| id.name.is_bool_lit())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_numeric_lit(&self) -> bool {
|
||||||
|
matches!(self.kind, Literal(Lit { kind: LitKind::Integer, ..}) | Literal(Lit { kind: LitKind::Float, ..}))
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns `true` if the token is a non-raw identifier for which `pred` holds.
|
/// Returns `true` if the token is a non-raw identifier for which `pred` holds.
|
||||||
pub fn is_non_raw_ident_where(&self, pred: impl FnOnce(Ident) -> bool) -> bool {
|
pub fn is_non_raw_ident_where(&self, pred: impl FnOnce(Ident) -> bool) -> bool {
|
||||||
match self.ident() {
|
match self.ident() {
|
||||||
|
|
|
@ -516,16 +516,15 @@ impl<'a> Parser<'a> {
|
||||||
token::BinOp(token::And) | token::AndAnd => {
|
token::BinOp(token::And) | token::AndAnd => {
|
||||||
make_it!(this, attrs, |this, _| this.parse_borrow_expr(lo))
|
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");
|
let mut err = this.struct_span_err(lo, "leading `+` is not supported");
|
||||||
err.span_label(lo, "unexpected `+`");
|
err.span_label(lo, "unexpected `+`");
|
||||||
|
|
||||||
// a block on the LHS might have been intended to be an expression instead
|
// 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(&lo) {
|
||||||
if let Some(sp) = this.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
|
|
||||||
this.sess.expr_parentheses_needed(&mut err, *sp);
|
this.sess.expr_parentheses_needed(&mut err, *sp);
|
||||||
} else {
|
} else {
|
||||||
err.span_suggestion(
|
err.span_suggestion_verbose(
|
||||||
lo,
|
lo,
|
||||||
"try removing the `+`",
|
"try removing the `+`",
|
||||||
"".to_string(),
|
"".to_string(),
|
||||||
|
|
|
@ -2,10 +2,13 @@ error: leading `+` is not supported
|
||||||
--> $DIR/issue-36499.rs:4:9
|
--> $DIR/issue-36499.rs:4:9
|
||||||
|
|
|
|
||||||
LL | 2 + +2;
|
LL | 2 + +2;
|
||||||
| ^
|
| ^ unexpected `+`
|
||||||
| |
|
|
|
||||||
| unexpected `+`
|
help: try removing the `+`
|
||||||
| help: try removing the `+`
|
|
|
||||||
|
LL - 2 + +2;
|
||||||
|
LL + 2 + 2;
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#![allow(unused_must_use)]
|
#![allow(unused_must_use)]
|
||||||
|
|
||||||
fn foo() -> i32 {
|
fn foo() -> i32 {
|
||||||
({2}) + {2} //~ ERROR leading `+` is not supported
|
({2}) + {2} //~ ERROR expected expression, found `+`
|
||||||
//~^ ERROR mismatched types
|
//~^ ERROR mismatched types
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ fn bar() -> i32 {
|
||||||
|
|
||||||
fn zul() -> u32 {
|
fn zul() -> u32 {
|
||||||
let foo = 3;
|
let foo = 3;
|
||||||
({ 42 }) + foo; //~ ERROR leading `+` is not supported
|
({ 42 }) + foo; //~ ERROR expected expression, found `+`
|
||||||
//~^ ERROR mismatched types
|
//~^ ERROR mismatched types
|
||||||
32
|
32
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#![allow(unused_must_use)]
|
#![allow(unused_must_use)]
|
||||||
|
|
||||||
fn foo() -> i32 {
|
fn foo() -> i32 {
|
||||||
{2} + {2} //~ ERROR leading `+` is not supported
|
{2} + {2} //~ ERROR expected expression, found `+`
|
||||||
//~^ ERROR mismatched types
|
//~^ ERROR mismatched types
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ fn bar() -> i32 {
|
||||||
|
|
||||||
fn zul() -> u32 {
|
fn zul() -> u32 {
|
||||||
let foo = 3;
|
let foo = 3;
|
||||||
{ 42 } + foo; //~ ERROR leading `+` is not supported
|
{ 42 } + foo; //~ ERROR expected expression, found `+`
|
||||||
//~^ ERROR mismatched types
|
//~^ ERROR mismatched types
|
||||||
32
|
32
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
error: leading `+` is not supported
|
error: expected expression, found `+`
|
||||||
--> $DIR/expr-as-stmt.rs:8:9
|
--> $DIR/expr-as-stmt.rs:8:9
|
||||||
|
|
|
|
||||||
LL | {2} + {2}
|
LL | {2} + {2}
|
||||||
| ^ unexpected `+`
|
| ^ expected expression
|
||||||
|
|
|
|
||||||
help: parentheses are required to parse this as an expression
|
help: parentheses are required to parse this as an expression
|
||||||
|
|
|
|
||||||
|
@ -20,11 +20,11 @@ help: parentheses are required to parse this as an expression
|
||||||
LL | ({2}) + 2
|
LL | ({2}) + 2
|
||||||
| + +
|
| + +
|
||||||
|
|
||||||
error: leading `+` is not supported
|
error: expected expression, found `+`
|
||||||
--> $DIR/expr-as-stmt.rs:19:12
|
--> $DIR/expr-as-stmt.rs:19:12
|
||||||
|
|
|
|
||||||
LL | { 42 } + foo;
|
LL | { 42 } + foo;
|
||||||
| ^ unexpected `+`
|
| ^ expected expression
|
||||||
|
|
|
|
||||||
help: parentheses are required to parse this as an expression
|
help: parentheses are required to parse this as an expression
|
||||||
|
|
|
|
||||||
|
|
|
@ -2,12 +2,7 @@
|
||||||
#[allow(unused_parens)]
|
#[allow(unused_parens)]
|
||||||
fn main() {
|
fn main() {
|
||||||
let _ = 1; //~ ERROR leading `+` is not supported
|
let _ = 1; //~ ERROR leading `+` is not supported
|
||||||
let _ = -(1+2)*3; //~ ERROR leading `+` is not supported
|
let _ = (1.0 + 2.0) * 3.0; //~ ERROR leading `+` is not supported
|
||||||
let _ = --(1+2)*3; //~ ERROR leading `+` is not supported
|
|
||||||
//~| ERROR leading `+` is not supported
|
|
||||||
let _ = (1 + 2) * 3; //~ ERROR leading `+` is not supported
|
|
||||||
//~| ERROR leading `+` is not supported
|
//~| ERROR leading `+` is not supported
|
||||||
let _ = (&"hello"); //~ ERROR leading `+` is not supported
|
|
||||||
let _ = [3, 4+6]; //~ ERROR leading `+` is not supported
|
let _ = [3, 4+6]; //~ ERROR leading `+` is not supported
|
||||||
//~| ERROR leading `+` is not supported
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,7 @@
|
||||||
#[allow(unused_parens)]
|
#[allow(unused_parens)]
|
||||||
fn main() {
|
fn main() {
|
||||||
let _ = +1; //~ ERROR leading `+` is not supported
|
let _ = +1; //~ ERROR leading `+` is not supported
|
||||||
let _ = -+(1+2)*3; //~ ERROR leading `+` is not supported
|
let _ = (1.0 + +2.0) * +3.0; //~ ERROR leading `+` is not supported
|
||||||
let _ = -+-+(1+2)*3; //~ ERROR leading `+` is not supported
|
|
||||||
//~| ERROR leading `+` is not supported
|
|
||||||
let _ = (1 + +2) * +3; //~ ERROR leading `+` is not supported
|
|
||||||
//~| ERROR leading `+` is not supported
|
//~| ERROR leading `+` is not supported
|
||||||
let _ = (+&"hello"); //~ ERROR leading `+` is not supported
|
let _ = [+3, 4+6]; //~ ERROR leading `+` is not supported
|
||||||
let _ = +[+3, 4+6]; //~ ERROR leading `+` is not supported
|
|
||||||
//~| ERROR leading `+` is not supported
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,82 +2,49 @@ error: leading `+` is not supported
|
||||||
--> $DIR/issue-88276-unary-plus.rs:4:13
|
--> $DIR/issue-88276-unary-plus.rs:4:13
|
||||||
|
|
|
|
||||||
LL | let _ = +1;
|
LL | let _ = +1;
|
||||||
| ^
|
| ^ unexpected `+`
|
||||||
| |
|
|
|
||||||
| unexpected `+`
|
help: try removing the `+`
|
||||||
| help: try removing the `+`
|
|
|
||||||
|
LL - let _ = +1;
|
||||||
|
LL + let _ = 1;
|
||||||
|
|
|
||||||
|
|
||||||
error: leading `+` is not supported
|
error: leading `+` is not supported
|
||||||
--> $DIR/issue-88276-unary-plus.rs:5:14
|
--> $DIR/issue-88276-unary-plus.rs:5:20
|
||||||
|
|
|
|
||||||
LL | let _ = -+(1+2)*3;
|
LL | let _ = (1.0 + +2.0) * +3.0;
|
||||||
| ^
|
| ^ unexpected `+`
|
||||||
| |
|
|
|
||||||
| unexpected `+`
|
help: try removing the `+`
|
||||||
| help: try removing the `+`
|
|
|
||||||
|
LL - let _ = (1.0 + +2.0) * +3.0;
|
||||||
|
LL + let _ = (1.0 + 2.0) * +3.0;
|
||||||
|
|
|
||||||
|
|
||||||
error: leading `+` is not supported
|
error: leading `+` is not supported
|
||||||
--> $DIR/issue-88276-unary-plus.rs:6:14
|
--> $DIR/issue-88276-unary-plus.rs:5:28
|
||||||
|
|
|
|
||||||
LL | let _ = -+-+(1+2)*3;
|
LL | let _ = (1.0 + +2.0) * +3.0;
|
||||||
| ^
|
| ^ unexpected `+`
|
||||||
| |
|
|
|
||||||
| unexpected `+`
|
help: try removing the `+`
|
||||||
| help: try removing the `+`
|
|
|
||||||
|
LL - let _ = (1.0 + +2.0) * +3.0;
|
||||||
|
LL + let _ = (1.0 + +2.0) * 3.0;
|
||||||
|
|
|
||||||
|
|
||||||
error: leading `+` is not supported
|
error: leading `+` is not supported
|
||||||
--> $DIR/issue-88276-unary-plus.rs:6:16
|
--> $DIR/issue-88276-unary-plus.rs:7:14
|
||||||
|
|
|
|
||||||
LL | let _ = -+-+(1+2)*3;
|
LL | let _ = [+3, 4+6];
|
||||||
| ^
|
| ^ unexpected `+`
|
||||||
| |
|
|
||||||
| unexpected `+`
|
|
||||||
| help: try removing the `+`
|
|
||||||
|
|
||||||
error: leading `+` is not supported
|
|
||||||
--> $DIR/issue-88276-unary-plus.rs:8:18
|
|
||||||
|
|
|
|
||||||
LL | let _ = (1 + +2) * +3;
|
help: try removing the `+`
|
||||||
| ^
|
|
||||||
| |
|
|
||||||
| unexpected `+`
|
|
||||||
| help: try removing the `+`
|
|
||||||
|
|
||||||
error: leading `+` is not supported
|
|
||||||
--> $DIR/issue-88276-unary-plus.rs:8:24
|
|
||||||
|
|
|
|
||||||
LL | let _ = (1 + +2) * +3;
|
LL - let _ = [+3, 4+6];
|
||||||
| ^
|
LL + let _ = [3, 4+6];
|
||||||
| |
|
|
|
||||||
| unexpected `+`
|
|
||||||
| help: try removing the `+`
|
|
||||||
|
|
||||||
error: leading `+` is not supported
|
error: aborting due to 4 previous errors
|
||||||
--> $DIR/issue-88276-unary-plus.rs:10:14
|
|
||||||
|
|
|
||||||
LL | let _ = (+&"hello");
|
|
||||||
| ^
|
|
||||||
| |
|
|
||||||
| unexpected `+`
|
|
||||||
| help: try removing the `+`
|
|
||||||
|
|
||||||
error: leading `+` is not supported
|
|
||||||
--> $DIR/issue-88276-unary-plus.rs:11:13
|
|
||||||
|
|
|
||||||
LL | let _ = +[+3, 4+6];
|
|
||||||
| ^
|
|
||||||
| |
|
|
||||||
| unexpected `+`
|
|
||||||
| help: try removing the `+`
|
|
||||||
|
|
||||||
error: leading `+` is not supported
|
|
||||||
--> $DIR/issue-88276-unary-plus.rs:11:15
|
|
||||||
|
|
|
||||||
LL | let _ = +[+3, 4+6];
|
|
||||||
| ^
|
|
||||||
| |
|
|
||||||
| unexpected `+`
|
|
||||||
| help: try removing the `+`
|
|
||||||
|
|
||||||
error: aborting due to 9 previous errors
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue