mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-30 11:37:31 +00:00
Merge pull request #20210 from ChayimFriedman2/naked-asm-safe
fix: Inline asm fixes
This commit is contained in:
commit
e9968fc555
28 changed files with 303 additions and 84 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)]
|
||||
|
|
|
|||
|
|
@ -253,8 +253,7 @@ fn builtin_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> {
|
|||
let m = p.start();
|
||||
p.bump_remap(T![builtin]);
|
||||
p.bump(T![#]);
|
||||
if p.at_contextual_kw(T![offset_of]) {
|
||||
p.bump_remap(T![offset_of]);
|
||||
if p.eat_contextual_kw(T![offset_of]) {
|
||||
p.expect(T!['(']);
|
||||
type_(p);
|
||||
p.expect(T![,]);
|
||||
|
|
@ -278,8 +277,7 @@ fn builtin_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> {
|
|||
p.expect(T![')']);
|
||||
}
|
||||
Some(m.complete(p, OFFSET_OF_EXPR))
|
||||
} else if p.at_contextual_kw(T![format_args]) {
|
||||
p.bump_remap(T![format_args]);
|
||||
} else if p.eat_contextual_kw(T![format_args]) {
|
||||
p.expect(T!['(']);
|
||||
expr(p);
|
||||
if p.eat(T![,]) {
|
||||
|
|
@ -302,7 +300,16 @@ fn builtin_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> {
|
|||
}
|
||||
p.expect(T![')']);
|
||||
Some(m.complete(p, FORMAT_ARGS_EXPR))
|
||||
} else if p.at_contextual_kw(T![asm]) {
|
||||
} else if p.eat_contextual_kw(T![asm])
|
||||
|| p.eat_contextual_kw(T![global_asm])
|
||||
|| p.eat_contextual_kw(T![naked_asm])
|
||||
{
|
||||
// test asm_kinds
|
||||
// fn foo() {
|
||||
// builtin#asm("");
|
||||
// builtin#global_asm("");
|
||||
// builtin#naked_asm("");
|
||||
// }
|
||||
parse_asm_expr(p, m)
|
||||
} else {
|
||||
m.abandon(p);
|
||||
|
|
@ -321,8 +328,7 @@ fn builtin_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> {
|
|||
// tmp = out(reg) _,
|
||||
// );
|
||||
// }
|
||||
fn parse_asm_expr(p: &mut Parser<'_>, m: Marker) -> Option<CompletedMarker> {
|
||||
p.bump_remap(T![asm]);
|
||||
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(())
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue