mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-15 04:49:51 +00:00
Merge pull request #20805 from A4-Tacks/improve-static-const-parse-error
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
Improve parsing error for `static` and `const`
This commit is contained in:
commit
f8fdf544e4
8 changed files with 72 additions and 42 deletions
|
@ -25,21 +25,28 @@ fn const_or_static(p: &mut Parser<'_>, m: Marker, is_const: bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Recover on statics with generic params/where clause.
|
// FIXME: Recover on statics with generic params/where clause.
|
||||||
if is_const {
|
if !is_const && p.at(T![<]) {
|
||||||
// test generic_const
|
// test_err generic_static
|
||||||
// const C<i32>: u32 = 0;
|
// static C<i32>: u32 = 0;
|
||||||
// impl Foo {
|
p.error("`static` may not have generic parameters");
|
||||||
// const C<'a>: &'a () = &();
|
|
||||||
// }
|
|
||||||
generic_params::opt_generic_param_list(p);
|
|
||||||
}
|
}
|
||||||
// test_err generic_static
|
// test generic_const
|
||||||
// static C<i32>: u32 = 0;
|
// const C<i32>: u32 = 0;
|
||||||
|
// impl Foo {
|
||||||
|
// const C<'a>: &'a () = &();
|
||||||
|
// }
|
||||||
|
generic_params::opt_generic_param_list(p);
|
||||||
|
|
||||||
if p.at(T![:]) {
|
if p.at(T![:]) {
|
||||||
types::ascription(p);
|
types::ascription(p);
|
||||||
|
} else if is_const {
|
||||||
|
// test_err missing_const_type
|
||||||
|
// const C = 0;
|
||||||
|
p.error("missing type for `const`");
|
||||||
} else {
|
} else {
|
||||||
p.error("missing type for `const` or `static`");
|
// test_err missing_static_type
|
||||||
|
// static C = 0;
|
||||||
|
p.error("missing type for `static`");
|
||||||
}
|
}
|
||||||
if p.eat(T![=]) {
|
if p.eat(T![=]) {
|
||||||
expressions::expr(p);
|
expressions::expr(p);
|
||||||
|
|
|
@ -824,10 +824,18 @@ mod err {
|
||||||
run_and_expect_errors("test_data/parser/inline/err/misplaced_label_err.rs");
|
run_and_expect_errors("test_data/parser/inline/err/misplaced_label_err.rs");
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
|
fn missing_const_type() {
|
||||||
|
run_and_expect_errors("test_data/parser/inline/err/missing_const_type.rs");
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
fn missing_fn_param_type() {
|
fn missing_fn_param_type() {
|
||||||
run_and_expect_errors("test_data/parser/inline/err/missing_fn_param_type.rs");
|
run_and_expect_errors("test_data/parser/inline/err/missing_fn_param_type.rs");
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
|
fn missing_static_type() {
|
||||||
|
run_and_expect_errors("test_data/parser/inline/err/missing_static_type.rs");
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
fn path_item_without_excl() {
|
fn path_item_without_excl() {
|
||||||
run_and_expect_errors("test_data/parser/inline/err/path_item_without_excl.rs");
|
run_and_expect_errors("test_data/parser/inline/err/path_item_without_excl.rs");
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ SOURCE_FILE
|
||||||
WHITESPACE "\n"
|
WHITESPACE "\n"
|
||||||
error 6: expected fn, trait or impl
|
error 6: expected fn, trait or impl
|
||||||
error 38: expected a name
|
error 38: expected a name
|
||||||
error 40: missing type for `const` or `static`
|
error 40: missing type for `const`
|
||||||
error 40: expected SEMICOLON
|
error 40: expected SEMICOLON
|
||||||
error 44: expected an item
|
error 44: expected an item
|
||||||
error 44: expected an item
|
error 44: expected an item
|
||||||
|
|
|
@ -4,39 +4,24 @@ SOURCE_FILE
|
||||||
WHITESPACE " "
|
WHITESPACE " "
|
||||||
NAME
|
NAME
|
||||||
IDENT "C"
|
IDENT "C"
|
||||||
ERROR
|
GENERIC_PARAM_LIST
|
||||||
L_ANGLE "<"
|
L_ANGLE "<"
|
||||||
ERROR
|
TYPE_PARAM
|
||||||
PATH
|
NAME
|
||||||
PATH_SEGMENT
|
|
||||||
NAME_REF
|
|
||||||
IDENT "i32"
|
IDENT "i32"
|
||||||
ERROR
|
R_ANGLE ">"
|
||||||
R_ANGLE ">"
|
|
||||||
ERROR
|
|
||||||
COLON ":"
|
COLON ":"
|
||||||
WHITESPACE " "
|
WHITESPACE " "
|
||||||
ERROR
|
PATH_TYPE
|
||||||
PATH
|
PATH
|
||||||
PATH_SEGMENT
|
PATH_SEGMENT
|
||||||
NAME_REF
|
NAME_REF
|
||||||
IDENT "u32"
|
IDENT "u32"
|
||||||
WHITESPACE " "
|
WHITESPACE " "
|
||||||
ERROR
|
|
||||||
EQ "="
|
EQ "="
|
||||||
WHITESPACE " "
|
WHITESPACE " "
|
||||||
ERROR
|
LITERAL
|
||||||
INT_NUMBER "0"
|
INT_NUMBER "0"
|
||||||
ERROR
|
|
||||||
SEMICOLON ";"
|
SEMICOLON ";"
|
||||||
WHITESPACE "\n"
|
WHITESPACE "\n"
|
||||||
error 8: missing type for `const` or `static`
|
error 8: `static` may not have generic parameters
|
||||||
error 8: expected SEMICOLON
|
|
||||||
error 8: expected an item
|
|
||||||
error 12: expected an item
|
|
||||||
error 12: expected an item
|
|
||||||
error 13: expected an item
|
|
||||||
error 18: expected an item
|
|
||||||
error 19: expected an item
|
|
||||||
error 21: expected an item
|
|
||||||
error 22: expected an item
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
SOURCE_FILE
|
||||||
|
CONST
|
||||||
|
CONST_KW "const"
|
||||||
|
WHITESPACE " "
|
||||||
|
NAME
|
||||||
|
IDENT "C"
|
||||||
|
WHITESPACE " "
|
||||||
|
EQ "="
|
||||||
|
WHITESPACE " "
|
||||||
|
LITERAL
|
||||||
|
INT_NUMBER "0"
|
||||||
|
SEMICOLON ";"
|
||||||
|
WHITESPACE "\n"
|
||||||
|
error 7: missing type for `const`
|
|
@ -0,0 +1 @@
|
||||||
|
const C = 0;
|
|
@ -0,0 +1,14 @@
|
||||||
|
SOURCE_FILE
|
||||||
|
STATIC
|
||||||
|
STATIC_KW "static"
|
||||||
|
WHITESPACE " "
|
||||||
|
NAME
|
||||||
|
IDENT "C"
|
||||||
|
WHITESPACE " "
|
||||||
|
EQ "="
|
||||||
|
WHITESPACE " "
|
||||||
|
LITERAL
|
||||||
|
INT_NUMBER "0"
|
||||||
|
SEMICOLON ";"
|
||||||
|
WHITESPACE "\n"
|
||||||
|
error 8: missing type for `static`
|
|
@ -0,0 +1 @@
|
||||||
|
static C = 0;
|
Loading…
Add table
Add a link
Reference in a new issue