1
- use hir_expand:: name:: Name ;
2
1
use intern:: Symbol ;
3
2
use rustc_hash:: { FxHashMap , FxHashSet } ;
4
3
use syntax:: {
@@ -25,7 +24,7 @@ impl ExprCollector<'_> {
25
24
let mut named_pos: FxHashMap < usize , Symbol > = Default :: default ( ) ;
26
25
let mut named_args: FxHashMap < Symbol , usize > = Default :: default ( ) ;
27
26
let mut reg_args: FxHashSet < usize > = Default :: default ( ) ;
28
- for operand in asm. asm_operands ( ) {
27
+ for piece in asm. asm_pieces ( ) {
29
28
let slot = operands. len ( ) ;
30
29
let mut lower_reg = |reg : Option < ast:: AsmRegSpec > | {
31
30
let reg = reg?;
@@ -39,14 +38,14 @@ impl ExprCollector<'_> {
39
38
}
40
39
} ;
41
40
42
- let op = match operand {
43
- ast:: AsmOperand :: AsmClobberAbi ( clobber_abi) => {
41
+ let op = match piece {
42
+ ast:: AsmPiece :: AsmClobberAbi ( clobber_abi) => {
44
43
if let Some ( abi_name) = clobber_abi. string_token ( ) {
45
44
clobber_abis. insert ( Symbol :: intern ( abi_name. text ( ) ) ) ;
46
45
}
47
46
continue ;
48
47
}
49
- ast:: AsmOperand :: AsmOptions ( opt) => {
48
+ ast:: AsmPiece :: AsmOptions ( opt) => {
50
49
opt. asm_options ( ) . for_each ( |opt| {
51
50
options |= match opt. syntax ( ) . first_token ( ) . map_or ( T ! [ $] , |it| it. kind ( ) ) {
52
51
T ! [ att_syntax] => AsmOptions :: ATT_SYNTAX ,
@@ -63,71 +62,82 @@ impl ExprCollector<'_> {
63
62
} ) ;
64
63
continue ;
65
64
}
66
- ast:: AsmOperand :: AsmRegOperand ( op) => {
67
- let Some ( dir_spec) = op. asm_dir_spec ( ) else {
68
- continue ;
69
- } ;
70
- let Some ( reg) = lower_reg ( op. asm_reg_spec ( ) ) else {
71
- continue ;
72
- } ;
65
+ ast:: AsmPiece :: AsmOperandNamed ( op) => {
73
66
if let Some ( name) = op. name ( ) {
74
67
let sym = Symbol :: intern ( & name. text ( ) ) ;
75
68
named_args. insert ( sym. clone ( ) , slot) ;
76
69
named_pos. insert ( slot, sym) ;
77
70
}
78
- if dir_spec. in_token ( ) . is_some ( ) {
79
- let expr = self
80
- . collect_expr_opt ( op. asm_operand_expr ( ) . and_then ( |it| it. in_expr ( ) ) ) ;
81
- AsmOperand :: In { reg, expr }
82
- } else if dir_spec. out_token ( ) . is_some ( ) {
83
- let expr = self
84
- . collect_expr_opt ( op. asm_operand_expr ( ) . and_then ( |it| it. in_expr ( ) ) ) ;
85
- AsmOperand :: Out { reg, expr : Some ( expr) , late : false }
86
- } else if dir_spec. lateout_token ( ) . is_some ( ) {
87
- let expr = self
88
- . collect_expr_opt ( op. asm_operand_expr ( ) . and_then ( |it| it. in_expr ( ) ) ) ;
89
- AsmOperand :: Out { reg, expr : Some ( expr) , late : true }
90
- } else if dir_spec. inout_token ( ) . is_some ( ) {
91
- let Some ( op_expr) = op. asm_operand_expr ( ) else { continue } ;
92
- let in_expr = self . collect_expr_opt ( op_expr. in_expr ( ) ) ;
93
- let out_expr = op_expr. out_expr ( ) . map ( |it| self . collect_expr ( it) ) ;
94
- match out_expr {
95
- Some ( out_expr) => AsmOperand :: SplitInOut {
96
- reg,
97
- in_expr,
98
- out_expr : Some ( out_expr) ,
99
- late : false ,
100
- } ,
101
- None => AsmOperand :: InOut { reg, expr : in_expr, late : false } ,
71
+ let Some ( op) = op. asm_operand ( ) else { continue } ;
72
+ match op {
73
+ ast:: AsmOperand :: AsmRegOperand ( op) => {
74
+ let Some ( dir_spec) = op. asm_dir_spec ( ) else {
75
+ continue ;
76
+ } ;
77
+ let Some ( reg) = lower_reg ( op. asm_reg_spec ( ) ) else {
78
+ continue ;
79
+ } ;
80
+ if dir_spec. in_token ( ) . is_some ( ) {
81
+ let expr = self . collect_expr_opt (
82
+ op. asm_operand_expr ( ) . and_then ( |it| it. in_expr ( ) ) ,
83
+ ) ;
84
+ AsmOperand :: In { reg, expr }
85
+ } else if dir_spec. out_token ( ) . is_some ( ) {
86
+ let expr = self . collect_expr_opt (
87
+ op. asm_operand_expr ( ) . and_then ( |it| it. in_expr ( ) ) ,
88
+ ) ;
89
+ AsmOperand :: Out { reg, expr : Some ( expr) , late : false }
90
+ } else if dir_spec. lateout_token ( ) . is_some ( ) {
91
+ let expr = self . collect_expr_opt (
92
+ op. asm_operand_expr ( ) . and_then ( |it| it. in_expr ( ) ) ,
93
+ ) ;
94
+ AsmOperand :: Out { reg, expr : Some ( expr) , late : true }
95
+ } else if dir_spec. inout_token ( ) . is_some ( ) {
96
+ let Some ( op_expr) = op. asm_operand_expr ( ) else { continue } ;
97
+ let in_expr = self . collect_expr_opt ( op_expr. in_expr ( ) ) ;
98
+ let out_expr = op_expr. out_expr ( ) . map ( |it| self . collect_expr ( it) ) ;
99
+ match out_expr {
100
+ Some ( out_expr) => AsmOperand :: SplitInOut {
101
+ reg,
102
+ in_expr,
103
+ out_expr : Some ( out_expr) ,
104
+ late : false ,
105
+ } ,
106
+ None => AsmOperand :: InOut { reg, expr : in_expr, late : false } ,
107
+ }
108
+ } else if dir_spec. inlateout_token ( ) . is_some ( ) {
109
+ let Some ( op_expr) = op. asm_operand_expr ( ) else { continue } ;
110
+ let in_expr = self . collect_expr_opt ( op_expr. in_expr ( ) ) ;
111
+ let out_expr = op_expr. out_expr ( ) . map ( |it| self . collect_expr ( it) ) ;
112
+ match out_expr {
113
+ Some ( out_expr) => AsmOperand :: SplitInOut {
114
+ reg,
115
+ in_expr,
116
+ out_expr : Some ( out_expr) ,
117
+ late : false ,
118
+ } ,
119
+ None => AsmOperand :: InOut { reg, expr : in_expr, late : false } ,
120
+ }
121
+ } else {
122
+ continue ;
123
+ }
102
124
}
103
- } else if dir_spec. inlateout_token ( ) . is_some ( ) {
104
- let Some ( op_expr) = op. asm_operand_expr ( ) else { continue } ;
105
- let in_expr = self . collect_expr_opt ( op_expr. in_expr ( ) ) ;
106
- let out_expr = op_expr. out_expr ( ) . map ( |it| self . collect_expr ( it) ) ;
107
- match out_expr {
108
- Some ( out_expr) => AsmOperand :: SplitInOut {
109
- reg,
110
- in_expr,
111
- out_expr : Some ( out_expr) ,
112
- late : false ,
113
- } ,
114
- None => AsmOperand :: InOut { reg, expr : in_expr, late : false } ,
125
+ ast:: AsmOperand :: AsmLabel ( l) => {
126
+ AsmOperand :: Label ( self . collect_block_opt ( l. block_expr ( ) ) )
127
+ }
128
+ ast:: AsmOperand :: AsmConst ( c) => {
129
+ AsmOperand :: Const ( self . collect_expr_opt ( c. expr ( ) ) )
130
+ }
131
+ ast:: AsmOperand :: AsmSym ( s) => {
132
+ let Some ( path) =
133
+ s. path ( ) . and_then ( |p| self . expander . parse_path ( self . db , p) )
134
+ else {
135
+ continue ;
136
+ } ;
137
+ AsmOperand :: Sym ( path)
115
138
}
116
- } else {
117
- continue ;
118
139
}
119
140
}
120
- ast:: AsmOperand :: AsmLabel ( l) => {
121
- AsmOperand :: Label ( self . collect_block_opt ( l. block_expr ( ) ) )
122
- }
123
- ast:: AsmOperand :: AsmConst ( c) => AsmOperand :: Const ( self . collect_expr_opt ( c. expr ( ) ) ) ,
124
- ast:: AsmOperand :: AsmSym ( s) => {
125
- let Some ( path) = s. path ( ) . and_then ( |p| self . expander . parse_path ( self . db , p) )
126
- else {
127
- continue ;
128
- } ;
129
- AsmOperand :: Sym ( path)
130
- }
131
141
} ;
132
142
operands. push ( op) ;
133
143
}
@@ -192,7 +202,7 @@ impl ExprCollector<'_> {
192
202
rustc_parse_format:: Piece :: NextArgument ( arg) => {
193
203
// let span = arg_spans.next();
194
204
195
- let _operand_idx = match arg. position {
205
+ let operand_idx = match arg. position {
196
206
rustc_parse_format:: ArgumentIs ( idx)
197
207
| rustc_parse_format:: ArgumentImplicitlyIs ( idx) => {
198
208
if idx >= operands. len ( )
@@ -206,15 +216,15 @@ impl ExprCollector<'_> {
206
216
}
207
217
rustc_parse_format:: ArgumentNamed ( name) => {
208
218
let name = Symbol :: intern ( name) ;
209
- if let Some ( position_span) = to_span ( arg. position_span ) {
210
- mappings. push ( (
211
- position_span,
212
- Name :: new_symbol_root ( name. clone ( ) ) ,
213
- ) ) ;
214
- }
215
219
named_args. get ( & name) . copied ( )
216
220
}
217
221
} ;
222
+
223
+ if let Some ( operand_idx) = operand_idx {
224
+ if let Some ( position_span) = to_span ( arg. position_span ) {
225
+ mappings. push ( ( position_span, operand_idx) ) ;
226
+ }
227
+ }
218
228
}
219
229
}
220
230
}
@@ -224,7 +234,7 @@ impl ExprCollector<'_> {
224
234
Expr :: InlineAsm ( InlineAsm { operands : operands. into_boxed_slice ( ) , options } ) ,
225
235
syntax_ptr,
226
236
) ;
227
- self . source_map . format_args_template_map . insert ( idx, mappings) ;
237
+ self . source_map . template_map . get_or_insert_with ( Default :: default ) . 1 . insert ( idx, mappings) ;
228
238
idx
229
239
}
230
240
}
0 commit comments