Move inclusive range check to validation
This commit is contained in:
@@ -300,9 +300,6 @@ fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> (Option<CompletedMarker>,
|
|||||||
let has_trailing_expression =
|
let has_trailing_expression =
|
||||||
p.at_ts(EXPR_FIRST) && !(r.forbid_structs && p.at(T!['{']));
|
p.at_ts(EXPR_FIRST) && !(r.forbid_structs && p.at(T!['{']));
|
||||||
if !has_trailing_expression {
|
if !has_trailing_expression {
|
||||||
if op == T![..=] {
|
|
||||||
p.error("expected expression to end inclusive range");
|
|
||||||
}
|
|
||||||
// no RHS
|
// no RHS
|
||||||
lhs = m.complete(p, RANGE_EXPR);
|
lhs = m.complete(p, RANGE_EXPR);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ pub enum SyntaxErrorKind {
|
|||||||
InvalidMatchInnerAttr,
|
InvalidMatchInnerAttr,
|
||||||
InvalidTupleIndexFormat,
|
InvalidTupleIndexFormat,
|
||||||
VisibilityNotAllowed,
|
VisibilityNotAllowed,
|
||||||
|
InclusiveRangeMissingEnd,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for SyntaxErrorKind {
|
impl fmt::Display for SyntaxErrorKind {
|
||||||
@@ -103,6 +104,9 @@ impl fmt::Display for SyntaxErrorKind {
|
|||||||
VisibilityNotAllowed => {
|
VisibilityNotAllowed => {
|
||||||
write!(f, "unnecessary visibility qualifier")
|
write!(f, "unnecessary visibility qualifier")
|
||||||
}
|
}
|
||||||
|
InclusiveRangeMissingEnd => {
|
||||||
|
write!(f, "An inclusive range must have an end expression")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ pub(crate) fn validate(root: &SyntaxNode) -> Vec<SyntaxError> {
|
|||||||
ast::FieldExpr(it) => { validate_numeric_name(it.name_ref(), &mut errors) },
|
ast::FieldExpr(it) => { validate_numeric_name(it.name_ref(), &mut errors) },
|
||||||
ast::RecordField(it) => { validate_numeric_name(it.name_ref(), &mut errors) },
|
ast::RecordField(it) => { validate_numeric_name(it.name_ref(), &mut errors) },
|
||||||
ast::Visibility(it) => { validate_visibility(it, &mut errors) },
|
ast::Visibility(it) => { validate_visibility(it, &mut errors) },
|
||||||
|
ast::RangeExpr(it) => { validate_range_expr(it, &mut errors) },
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,3 +228,16 @@ fn validate_visibility(vis: ast::Visibility, errors: &mut Vec<SyntaxError>) {
|
|||||||
.push(SyntaxError::new(SyntaxErrorKind::VisibilityNotAllowed, vis.syntax.text_range()))
|
.push(SyntaxError::new(SyntaxErrorKind::VisibilityNotAllowed, vis.syntax.text_range()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn validate_range_expr(expr: ast::RangeExpr, errors: &mut Vec<SyntaxError>) {
|
||||||
|
let last_child = match expr.syntax().last_child_or_token() {
|
||||||
|
Some(it) => it,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
if last_child.kind() == T![..=] {
|
||||||
|
errors.push(SyntaxError::new(
|
||||||
|
SyntaxErrorKind::InclusiveRangeMissingEnd,
|
||||||
|
last_child.text_range(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
0..=;
|
0..=;
|
||||||
|
..=;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
SOURCE_FILE@[0; 24)
|
SOURCE_FILE@[0; 33)
|
||||||
FN_DEF@[0; 23)
|
FN_DEF@[0; 32)
|
||||||
FN_KW@[0; 2) "fn"
|
FN_KW@[0; 2) "fn"
|
||||||
WHITESPACE@[2; 3) " "
|
WHITESPACE@[2; 3) " "
|
||||||
NAME@[3; 7)
|
NAME@[3; 7)
|
||||||
@@ -8,8 +8,8 @@ SOURCE_FILE@[0; 24)
|
|||||||
L_PAREN@[7; 8) "("
|
L_PAREN@[7; 8) "("
|
||||||
R_PAREN@[8; 9) ")"
|
R_PAREN@[8; 9) ")"
|
||||||
WHITESPACE@[9; 10) " "
|
WHITESPACE@[9; 10) " "
|
||||||
BLOCK_EXPR@[10; 23)
|
BLOCK_EXPR@[10; 32)
|
||||||
BLOCK@[10; 23)
|
BLOCK@[10; 32)
|
||||||
L_CURLY@[10; 11) "{"
|
L_CURLY@[10; 11) "{"
|
||||||
WHITESPACE@[11; 16) "\n "
|
WHITESPACE@[11; 16) "\n "
|
||||||
EXPR_STMT@[16; 21)
|
EXPR_STMT@[16; 21)
|
||||||
@@ -18,7 +18,13 @@ SOURCE_FILE@[0; 24)
|
|||||||
INT_NUMBER@[16; 17) "0"
|
INT_NUMBER@[16; 17) "0"
|
||||||
DOTDOTEQ@[17; 20) "..="
|
DOTDOTEQ@[17; 20) "..="
|
||||||
SEMI@[20; 21) ";"
|
SEMI@[20; 21) ";"
|
||||||
WHITESPACE@[21; 22) "\n"
|
WHITESPACE@[21; 26) "\n "
|
||||||
R_CURLY@[22; 23) "}"
|
EXPR_STMT@[26; 30)
|
||||||
WHITESPACE@[23; 24) "\n"
|
RANGE_EXPR@[26; 29)
|
||||||
error 20: expected expression to end inclusive range
|
DOTDOTEQ@[26; 29) "..="
|
||||||
|
SEMI@[29; 30) ";"
|
||||||
|
WHITESPACE@[30; 31) "\n"
|
||||||
|
R_CURLY@[31; 32) "}"
|
||||||
|
WHITESPACE@[32; 33) "\n"
|
||||||
|
error [17; 20): An inclusive range must have an end expression
|
||||||
|
error [26; 29): An inclusive range must have an end expression
|
||||||
|
|||||||
Reference in New Issue
Block a user