Skip to content

Commit d30124a

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 7935e87 commit d30124a

File tree

2 files changed

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

2 files changed

+15
-20
lines changed

compiler/rustc_builtin_macros/src/asm.rs

+9-17
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>,
@@ -144,6 +144,7 @@ fn parse_asm_operand<'a>(
144144
}))
145145
}
146146

147+
// Public for rustfmt
147148
pub fn parse_raw_asm_args<'a>(
148149
p: &mut Parser<'a>,
149150
sp: Span,
@@ -258,26 +259,17 @@ fn parse_args<'a>(
258259
tts: TokenStream,
259260
asm_macro: AsmMacro,
260261
) -> PResult<'a, AsmArgs> {
261-
let mut p = ecx.new_parser_from_tts(tts);
262-
parse_asm_args(&mut p, sp, asm_macro)
262+
let raw_args = parse_raw_asm_args(&mut ecx.new_parser_from_tts(tts), sp, asm_macro)?;
263+
validate_raw_asm_args(ecx, asm_macro, raw_args)
263264
}
264265

265-
// public for use in rustfmt
266-
// FIXME: use `RawAsmArg` in the formatting code instead.
267-
pub fn parse_asm_args<'a>(
268-
p: &mut Parser<'a>,
269-
sp: Span,
270-
asm_macro: AsmMacro,
271-
) -> PResult<'a, AsmArgs> {
272-
let raw_args = parse_raw_asm_args(p, sp, asm_macro)?;
273-
validate_raw_asm_args(p.dcx(), asm_macro, raw_args)
274-
}
275-
276-
pub fn validate_raw_asm_args<'a>(
277-
dcx: DiagCtxtHandle<'a>,
266+
fn validate_raw_asm_args<'a>(
267+
ecx: &ExtCtxt<'a>,
278268
asm_macro: AsmMacro,
279269
raw_args: Vec<RawAsmArg>,
280270
) -> PResult<'a, AsmArgs> {
271+
let dcx = ecx.dcx();
272+
281273
let mut args = AsmArgs {
282274
templates: vec![],
283275
operands: vec![],
+6-3
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)