Skip to content

Commit 91fe548

Browse files
committed
Retain assembly operands span when lowering AST to HIR
1 parent 0f6f2d6 commit 91fe548

File tree

13 files changed

+18
-20
lines changed

13 files changed

+18
-20
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13071307
hir::InlineAsmOperand::Sym { expr: self.lower_expr_mut(expr) }
13081308
}
13091309
};
1310-
Some(op)
1310+
Some((op, *op_sp))
13111311
})
13121312
.collect();
13131313

@@ -1326,7 +1326,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13261326
} = *p
13271327
{
13281328
let op_sp = asm.operands[operand_idx].1;
1329-
match &operands[operand_idx] {
1329+
match &operands[operand_idx].0 {
13301330
hir::InlineAsmOperand::In { reg, .. }
13311331
| hir::InlineAsmOperand::Out { reg, .. }
13321332
| hir::InlineAsmOperand::InOut { reg, .. }
@@ -1385,8 +1385,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13851385
let mut used_input_regs = FxHashMap::default();
13861386
let mut used_output_regs = FxHashMap::default();
13871387
let mut required_features: Vec<&str> = vec![];
1388-
for (idx, op) in operands.iter().enumerate() {
1389-
let op_sp = asm.operands[idx].1;
1388+
for (idx, &(ref op, op_sp)) in operands.iter().enumerate() {
13901389
if let Some(reg) = op.reg() {
13911390
// Make sure we don't accidentally carry features from the
13921391
// previous iteration.
@@ -1458,8 +1457,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14581457
skip = true;
14591458

14601459
let idx2 = *o.get();
1461-
let op2 = &operands[idx2];
1462-
let op_sp2 = asm.operands[idx2].1;
1460+
let &(ref op2, op_sp2) = &operands[idx2];
14631461
let reg2 = match op2.reg() {
14641462
Some(asm::InlineAsmRegOrRegClass::Reg(r)) => r,
14651463
_ => unreachable!(),

compiler/rustc_hir/src/arena.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ macro_rules! arena_types {
1414
// HIR types
1515
[few] hir_krate: rustc_hir::Crate<$tcx>,
1616
[] arm: rustc_hir::Arm<$tcx>,
17-
[] asm_operand: rustc_hir::InlineAsmOperand<$tcx>,
17+
[] asm_operand: (rustc_hir::InlineAsmOperand<$tcx>, Span),
1818
[] asm_template: rustc_ast::InlineAsmTemplatePiece,
1919
[] attribute: rustc_ast::Attribute,
2020
[] block: rustc_hir::Block<$tcx>,

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,7 @@ impl<'hir> InlineAsmOperand<'hir> {
21432143
#[derive(Debug, HashStable_Generic)]
21442144
pub struct InlineAsm<'hir> {
21452145
pub template: &'hir [InlineAsmTemplatePiece],
2146-
pub operands: &'hir [InlineAsmOperand<'hir>],
2146+
pub operands: &'hir [(InlineAsmOperand<'hir>, Span)],
21472147
pub options: InlineAsmOptions,
21482148
pub line_spans: &'hir [Span],
21492149
}

compiler/rustc_hir/src/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
11911191
walk_list!(visitor, visit_expr, optional_expression);
11921192
}
11931193
ExprKind::InlineAsm(ref asm) => {
1194-
for op in asm.operands {
1194+
for (op, _op_sp) in asm.operands {
11951195
match op {
11961196
InlineAsmOperand::In { expr, .. }
11971197
| InlineAsmOperand::InOut { expr, .. }

compiler/rustc_hir_pretty/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ impl<'a> State<'a> {
14621462

14631463
let mut args = vec![];
14641464
args.push(AsmArg::Template(ast::InlineAsmTemplatePiece::to_string(&a.template)));
1465-
args.extend(a.operands.iter().map(|o| AsmArg::Operand(o)));
1465+
args.extend(a.operands.iter().map(|(o, _)| AsmArg::Operand(o)));
14661466
if !a.options.is_empty() {
14671467
args.push(AsmArg::Options(a.options));
14681468
}

compiler/rustc_mir_build/src/thir/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
408408
operands: asm
409409
.operands
410410
.iter()
411-
.map(|op| {
411+
.map(|(op, _op_sp)| {
412412
match *op {
413413
hir::InlineAsmOperand::In { reg, ref expr } => {
414414
InlineAsmOperand::In { reg, expr: expr.to_ref() }

compiler/rustc_passes/src/intrinsicck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl ExprVisitor<'tcx> {
347347
}
348348

349349
fn check_asm(&self, asm: &hir::InlineAsm<'tcx>) {
350-
for (idx, op) in asm.operands.iter().enumerate() {
350+
for (idx, (op, _op_sp)) in asm.operands.iter().enumerate() {
351351
match *op {
352352
hir::InlineAsmOperand::In { reg, ref expr } => {
353353
self.check_asm_operand_type(idx, reg, expr, asm.template, None);

compiler/rustc_passes/src/liveness.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
11741174
};
11751175

11761176
// Do a first pass for writing outputs only
1177-
for op in asm.operands.iter().rev() {
1177+
for (op, _op_sp) in asm.operands.iter().rev() {
11781178
match op {
11791179
hir::InlineAsmOperand::In { .. }
11801180
| hir::InlineAsmOperand::Const { .. }
@@ -1197,7 +1197,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
11971197

11981198
// Then do a second pass for inputs
11991199
let mut succ = succ;
1200-
for op in asm.operands.iter().rev() {
1200+
for (op, _op_sp) in asm.operands.iter().rev() {
12011201
match op {
12021202
hir::InlineAsmOperand::In { expr, .. }
12031203
| hir::InlineAsmOperand::Const { expr, .. }
@@ -1454,7 +1454,7 @@ fn check_expr<'tcx>(this: &mut Liveness<'_, 'tcx>, expr: &'tcx Expr<'tcx>) {
14541454
}
14551455

14561456
hir::ExprKind::InlineAsm(ref asm) => {
1457-
for op in asm.operands {
1457+
for (op, _op_sp) in asm.operands {
14581458
match op {
14591459
hir::InlineAsmOperand::Out { expr, .. } => {
14601460
if let Some(expr) = expr {

compiler/rustc_typeck/src/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19291929
}
19301930

19311931
fn check_expr_asm(&self, asm: &'tcx hir::InlineAsm<'tcx>) -> Ty<'tcx> {
1932-
for op in asm.operands {
1932+
for (op, _op_sp) in asm.operands {
19331933
match op {
19341934
hir::InlineAsmOperand::In { expr, .. } | hir::InlineAsmOperand::Const { expr } => {
19351935
self.check_expr_asm_operand(expr, true);

compiler/rustc_typeck/src/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
243243
}
244244

245245
hir::ExprKind::InlineAsm(ref asm) => {
246-
for op in asm.operands {
246+
for (op, _op_sp) in asm.operands {
247247
match op {
248248
hir::InlineAsmOperand::In { expr, .. }
249249
| hir::InlineAsmOperand::Const { expr, .. }

src/tools/clippy/clippy_lints/src/loops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
768768
ExprKind::InlineAsm(ref asm) => asm
769769
.operands
770770
.iter()
771-
.map(|o| match o {
771+
.map(|(o, _)| match o {
772772
InlineAsmOperand::In { expr, .. }
773773
| InlineAsmOperand::InOut { expr, .. }
774774
| InlineAsmOperand::Const { expr }

src/tools/clippy/clippy_lints/src/utils/hir_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
517517
}
518518
}
519519
asm.options.hash(&mut self.s);
520-
for op in asm.operands {
520+
for (op, _op_sp) in asm.operands {
521521
match op {
522522
InlineAsmOperand::In { reg, expr } => {
523523
reg.hash(&mut self.s);

src/tools/clippy/clippy_lints/src/utils/inspector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
293293
println!("{}template: {}", ind, InlineAsmTemplatePiece::to_string(asm.template));
294294
println!("{}options: {:?}", ind, asm.options);
295295
println!("{}operands:", ind);
296-
for op in asm.operands {
296+
for (op, _op_sp) in asm.operands {
297297
match op {
298298
hir::InlineAsmOperand::In { expr, .. }
299299
| hir::InlineAsmOperand::InOut { expr, .. }

0 commit comments

Comments
 (0)