mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-01 12:24:29 +00:00
Make global_asm!() work
Because apparently, we were not accepting inline asm in item position, completely breaking it.
This commit is contained in:
parent
bd8087e86e
commit
95c04c4503
13 changed files with 58 additions and 36 deletions
|
|
@ -4,7 +4,7 @@ use crate::grammar::attributes::ATTRIBUTE_FIRST;
|
|||
|
||||
use super::*;
|
||||
|
||||
pub(super) use atom::{EXPR_RECOVERY_SET, LITERAL_FIRST, literal};
|
||||
pub(super) use atom::{EXPR_RECOVERY_SET, LITERAL_FIRST, literal, parse_asm_expr};
|
||||
pub(crate) use atom::{block_expr, match_arm_list};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
|
|
|
|||
|
|
@ -328,7 +328,7 @@ fn builtin_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> {
|
|||
// tmp = out(reg) _,
|
||||
// );
|
||||
// }
|
||||
fn parse_asm_expr(p: &mut Parser<'_>, m: Marker) -> Option<CompletedMarker> {
|
||||
pub(crate) fn parse_asm_expr(p: &mut Parser<'_>, m: Marker) -> Option<CompletedMarker> {
|
||||
p.expect(T!['(']);
|
||||
if expr(p).is_none() {
|
||||
p.err_and_bump("expected asm template");
|
||||
|
|
|
|||
|
|
@ -261,6 +261,19 @@ fn opt_item_without_modifiers(p: &mut Parser<'_>, m: Marker) -> Result<(), Marke
|
|||
T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::konst(p, m),
|
||||
T![static] if (la == IDENT || la == T![_] || la == T![mut]) => consts::static_(p, m),
|
||||
|
||||
IDENT
|
||||
if p.at_contextual_kw(T![builtin])
|
||||
&& p.nth_at(1, T![#])
|
||||
&& p.nth_at_contextual_kw(2, T![global_asm]) =>
|
||||
{
|
||||
p.bump_remap(T![builtin]);
|
||||
p.bump(T![#]);
|
||||
p.bump_remap(T![global_asm]);
|
||||
// test global_asm
|
||||
// builtin#global_asm("")
|
||||
expressions::parse_asm_expr(p, m);
|
||||
}
|
||||
|
||||
_ => return Err(m),
|
||||
};
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -300,6 +300,8 @@ mod ok {
|
|||
run_and_expect_no_errors("test_data/parser/inline/ok/generic_param_list.rs");
|
||||
}
|
||||
#[test]
|
||||
fn global_asm() { run_and_expect_no_errors("test_data/parser/inline/ok/global_asm.rs"); }
|
||||
#[test]
|
||||
fn half_open_range_pat() {
|
||||
run_and_expect_no_errors("test_data/parser/inline/ok/half_open_range_pat.rs");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,16 +23,15 @@ SOURCE_FILE
|
|||
R_PAREN ")"
|
||||
SEMICOLON ";"
|
||||
WHITESPACE "\n "
|
||||
EXPR_STMT
|
||||
ASM_EXPR
|
||||
BUILTIN_KW "builtin"
|
||||
POUND "#"
|
||||
GLOBAL_ASM_KW "global_asm"
|
||||
L_PAREN "("
|
||||
LITERAL
|
||||
STRING "\"\""
|
||||
R_PAREN ")"
|
||||
SEMICOLON ";"
|
||||
ASM_EXPR
|
||||
BUILTIN_KW "builtin"
|
||||
POUND "#"
|
||||
GLOBAL_ASM_KW "global_asm"
|
||||
L_PAREN "("
|
||||
LITERAL
|
||||
STRING "\"\""
|
||||
R_PAREN ")"
|
||||
SEMICOLON ";"
|
||||
WHITESPACE "\n "
|
||||
EXPR_STMT
|
||||
ASM_EXPR
|
||||
|
|
|
|||
10
crates/parser/test_data/parser/inline/ok/global_asm.rast
Normal file
10
crates/parser/test_data/parser/inline/ok/global_asm.rast
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
SOURCE_FILE
|
||||
ASM_EXPR
|
||||
BUILTIN_KW "builtin"
|
||||
POUND "#"
|
||||
GLOBAL_ASM_KW "global_asm"
|
||||
L_PAREN "("
|
||||
LITERAL
|
||||
STRING "\"\""
|
||||
R_PAREN ")"
|
||||
WHITESPACE "\n"
|
||||
1
crates/parser/test_data/parser/inline/ok/global_asm.rs
Normal file
1
crates/parser/test_data/parser/inline/ok/global_asm.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
builtin#global_asm("")
|
||||
Loading…
Add table
Add a link
Reference in a new issue