mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-01 12:24:29 +00:00
Improve asm support
Including:
- Infer `label {}` and `const` operands.
- Correctly handle unsafe check inside `label {}`.
- Fix an embarrassing parser typo that cause labels to never be part of the AST
This commit is contained in:
parent
f8e784353b
commit
5ed11234cc
10 changed files with 186 additions and 40 deletions
|
|
@ -381,10 +381,14 @@ fn parse_asm_expr(p: &mut Parser<'_>, m: Marker) -> Option<CompletedMarker> {
|
|||
op.complete(p, ASM_REG_OPERAND);
|
||||
op_n.complete(p, ASM_OPERAND_NAMED);
|
||||
} else if p.eat_contextual_kw(T![label]) {
|
||||
// test asm_label
|
||||
// fn foo() {
|
||||
// builtin#asm("", label {});
|
||||
// }
|
||||
dir_spec.abandon(p);
|
||||
block_expr(p);
|
||||
op.complete(p, ASM_OPERAND_NAMED);
|
||||
op_n.complete(p, ASM_LABEL);
|
||||
op.complete(p, ASM_LABEL);
|
||||
op_n.complete(p, ASM_OPERAND_NAMED);
|
||||
} else if p.eat(T![const]) {
|
||||
dir_spec.abandon(p);
|
||||
expr(p);
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ mod ok {
|
|||
#[test]
|
||||
fn asm_expr() { run_and_expect_no_errors("test_data/parser/inline/ok/asm_expr.rs"); }
|
||||
#[test]
|
||||
fn asm_label() { run_and_expect_no_errors("test_data/parser/inline/ok/asm_label.rs"); }
|
||||
#[test]
|
||||
fn assoc_const_eq() {
|
||||
run_and_expect_no_errors("test_data/parser/inline/ok/assoc_const_eq.rs");
|
||||
}
|
||||
|
|
|
|||
37
crates/parser/test_data/parser/inline/ok/asm_label.rast
Normal file
37
crates/parser/test_data/parser/inline/ok/asm_label.rast
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
SOURCE_FILE
|
||||
FN
|
||||
FN_KW "fn"
|
||||
WHITESPACE " "
|
||||
NAME
|
||||
IDENT "foo"
|
||||
PARAM_LIST
|
||||
L_PAREN "("
|
||||
R_PAREN ")"
|
||||
WHITESPACE " "
|
||||
BLOCK_EXPR
|
||||
STMT_LIST
|
||||
L_CURLY "{"
|
||||
WHITESPACE "\n "
|
||||
EXPR_STMT
|
||||
ASM_EXPR
|
||||
BUILTIN_KW "builtin"
|
||||
POUND "#"
|
||||
ASM_KW "asm"
|
||||
L_PAREN "("
|
||||
LITERAL
|
||||
STRING "\"\""
|
||||
COMMA ","
|
||||
WHITESPACE " "
|
||||
ASM_OPERAND_NAMED
|
||||
ASM_LABEL
|
||||
LABEL_KW "label"
|
||||
WHITESPACE " "
|
||||
BLOCK_EXPR
|
||||
STMT_LIST
|
||||
L_CURLY "{"
|
||||
R_CURLY "}"
|
||||
R_PAREN ")"
|
||||
SEMICOLON ";"
|
||||
WHITESPACE "\n"
|
||||
R_CURLY "}"
|
||||
WHITESPACE "\n"
|
||||
3
crates/parser/test_data/parser/inline/ok/asm_label.rs
Normal file
3
crates/parser/test_data/parser/inline/ok/asm_label.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fn foo() {
|
||||
builtin#asm("", label {});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue