mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
enforce parsing invariant for patterns
This commit is contained in:
parent
7989d567e2
commit
e78424846e
4 changed files with 42 additions and 2 deletions
|
@ -141,7 +141,7 @@ macro_rules! m1 { () => (Some(x) left overs) }
|
||||||
macro_rules! m2 { () => ($) }
|
macro_rules! m2 { () => ($) }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let Some(x) = ();
|
let Some(x)left overs = ();
|
||||||
let /* parse error: expected pattern */
|
let /* parse error: expected pattern */
|
||||||
$ = ();
|
$ = ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,19 @@ pub(crate) mod entry {
|
||||||
items::mod_contents(p, false);
|
items::mod_contents(p, false);
|
||||||
m.complete(p, MACRO_ITEMS);
|
m.complete(p, MACRO_ITEMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn pattern(p: &mut Parser) {
|
||||||
|
let m = p.start();
|
||||||
|
patterns::pattern_single(p);
|
||||||
|
if p.at(EOF) {
|
||||||
|
m.abandon(p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while !p.at(EOF) {
|
||||||
|
p.bump_any();
|
||||||
|
}
|
||||||
|
m.complete(p, ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,8 +119,8 @@ impl TopEntryPoint {
|
||||||
TopEntryPoint::SourceFile => grammar::entry::top::source_file,
|
TopEntryPoint::SourceFile => grammar::entry::top::source_file,
|
||||||
TopEntryPoint::MacroStmts => grammar::entry::top::macro_stmts,
|
TopEntryPoint::MacroStmts => grammar::entry::top::macro_stmts,
|
||||||
TopEntryPoint::MacroItems => grammar::entry::top::macro_items,
|
TopEntryPoint::MacroItems => grammar::entry::top::macro_items,
|
||||||
|
TopEntryPoint::Pattern => grammar::entry::top::pattern,
|
||||||
// FIXME
|
// FIXME
|
||||||
TopEntryPoint::Pattern => grammar::entry::prefix::pat,
|
|
||||||
TopEntryPoint::Type => grammar::entry::prefix::ty,
|
TopEntryPoint::Type => grammar::entry::prefix::ty,
|
||||||
TopEntryPoint::Expr => grammar::entry::prefix::expr,
|
TopEntryPoint::Expr => grammar::entry::prefix::expr,
|
||||||
TopEntryPoint::MetaItem => grammar::entry::prefix::meta_item,
|
TopEntryPoint::MetaItem => grammar::entry::prefix::meta_item,
|
||||||
|
|
|
@ -146,6 +146,33 @@ fn macro_pattern() {
|
||||||
R_PAREN ")"
|
R_PAREN ")"
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
check(
|
||||||
|
TopEntryPoint::Pattern,
|
||||||
|
"None leftover tokens",
|
||||||
|
expect![[r#"
|
||||||
|
ERROR
|
||||||
|
IDENT_PAT
|
||||||
|
NAME
|
||||||
|
IDENT "None"
|
||||||
|
WHITESPACE " "
|
||||||
|
IDENT "leftover"
|
||||||
|
WHITESPACE " "
|
||||||
|
IDENT "tokens"
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
|
||||||
|
check(
|
||||||
|
TopEntryPoint::Pattern,
|
||||||
|
"@err",
|
||||||
|
expect![[r#"
|
||||||
|
ERROR
|
||||||
|
ERROR
|
||||||
|
AT "@"
|
||||||
|
IDENT "err"
|
||||||
|
error 0: expected pattern
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue