Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7ec06fc

Browse files
committed
attempt to have rustfmt use the new logic
apparently it doesn't really use the asm parsing at present, so this may work?
1 parent de8e305 commit 7ec06fc

File tree

2 files changed

+14
-20
lines changed
  • compiler/rustc_builtin_macros/src
  • src/tools/rustfmt/src/parse/macros

2 files changed

+14
-20
lines changed

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_ast::ptr::P;
44
use rustc_ast::tokenstream::TokenStream;
55
use rustc_ast::{AsmMacro, token};
66
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
7-
use rustc_errors::{DiagCtxtHandle, PResult};
7+
use rustc_errors::PResult;
88
use rustc_expand::base::*;
99
use rustc_index::bit_set::GrowableBitSet;
1010
use rustc_parse::exp;
@@ -33,7 +33,7 @@ pub enum RawAsmArgKind {
3333
}
3434

3535
/// Validated assembly arguments, ready for macro expansion.
36-
pub struct AsmArgs {
36+
struct AsmArgs {
3737
pub templates: Vec<P<ast::Expr>>,
3838
pub operands: Vec<(ast::InlineAsmOperand, Span)>,
3939
named_args: FxIndexMap<Symbol, usize>,
@@ -261,26 +261,17 @@ fn parse_args<'a>(
261261
tts: TokenStream,
262262
asm_macro: AsmMacro,
263263
) -> PResult<'a, AsmArgs> {
264-
let mut p = ecx.new_parser_from_tts(tts);
265-
parse_asm_args(&mut p, sp, asm_macro)
264+
let raw_args = parse_raw_asm_args(&mut ecx.new_parser_from_tts(tts), sp, asm_macro)?;
265+
validate_raw_asm_args(ecx, asm_macro, raw_args)
266266
}
267267

268-
// public for use in rustfmt
269-
// FIXME: use `RawAsmArg` in the formatting code instead.
270-
pub fn parse_asm_args<'a>(
271-
p: &mut Parser<'a>,
272-
sp: Span,
273-
asm_macro: AsmMacro,
274-
) -> PResult<'a, AsmArgs> {
275-
let raw_args = parse_raw_asm_args(p, sp, asm_macro)?;
276-
validate_raw_asm_args(p.dcx(), asm_macro, raw_args)
277-
}
278-
279-
pub fn validate_raw_asm_args<'a>(
280-
dcx: DiagCtxtHandle<'a>,
268+
fn validate_raw_asm_args<'a>(
269+
ecx: &ExtCtxt<'a>,
281270
asm_macro: AsmMacro,
282271
raw_args: Vec<RawAsmArg>,
283272
) -> PResult<'a, AsmArgs> {
273+
let dcx = ecx.dcx();
274+
284275
let mut args = AsmArgs {
285276
templates: vec![],
286277
operands: vec![],
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
use rustc_ast::ast;
2-
use rustc_builtin_macros::asm::{AsmArgs, parse_asm_args};
2+
use rustc_builtin_macros::asm::{RawAsmArg, parse_raw_asm_args};
33

44
use crate::rewrite::RewriteContext;
55

66
#[allow(dead_code)]
7-
pub(crate) fn parse_asm(context: &RewriteContext<'_>, mac: &ast::MacCall) -> Option<AsmArgs> {
7+
pub(crate) fn parse_asm(
8+
context: &RewriteContext<'_>,
9+
mac: &ast::MacCall,
10+
) -> Option<Vec<RawAsmArg>> {
811
let ts = mac.args.tokens.clone();
912
let mut parser = super::build_parser(context, ts);
10-
parse_asm_args(&mut parser, mac.span(), ast::AsmMacro::Asm).ok()
13+
parse_raw_asm_args(&mut parser, mac.span(), ast::AsmMacro::Asm).ok()
1114
}

0 commit comments

Comments
 (0)