mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-03 21:25:25 +00:00
Improve parsing error for static and const
Example --- ```rust static C<i32>: u32 = 0; ``` -> ```diff -error 8: missing type for `const` or `static` +error 8: `static` may not have generic parameters ``` --- ```rust const C = 0; ``` -> ```diff -error 7: missing type for `const` or `static` +error 7: missing type for `const` ``` --- ```rust static C = 0; ``` -> ```diff -error 8: missing type for `const` or `static` +error 8: missing type for `static` ```
This commit is contained in:
parent
a2e6043bfa
commit
216db6d5b4
8 changed files with 50 additions and 4 deletions
|
|
@ -32,14 +32,22 @@ fn const_or_static(p: &mut Parser<'_>, m: Marker, is_const: bool) {
|
||||||
// const C<'a>: &'a () = &();
|
// const C<'a>: &'a () = &();
|
||||||
// }
|
// }
|
||||||
generic_params::opt_generic_param_list(p);
|
generic_params::opt_generic_param_list(p);
|
||||||
|
} else if p.at(T![<]) {
|
||||||
|
p.error("`static` may not have generic parameters");
|
||||||
}
|
}
|
||||||
// test_err generic_static
|
// test_err generic_static
|
||||||
// static C<i32>: u32 = 0;
|
// static C<i32>: u32 = 0;
|
||||||
|
|
||||||
if p.at(T![:]) {
|
if p.at(T![:]) {
|
||||||
types::ascription(p);
|
types::ascription(p);
|
||||||
} else {
|
} else if is_const {
|
||||||
p.error("missing type for `const` or `static`");
|
// test_err missing_const_type
|
||||||
|
// const C = 0;
|
||||||
|
p.error("missing type for `const`");
|
||||||
|
} else if !p.at(T![<]) {
|
||||||
|
// 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
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ SOURCE_FILE
|
||||||
ERROR
|
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 SEMICOLON
|
||||||
error 8: expected an item
|
error 8: expected an item
|
||||||
error 12: expected an item
|
error 12: 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