Skip to content

Commit 0de314b

Browse files
committed
Reimplement lowering of sym operands for asm! so that it also works with global_asm!
1 parent a377ebc commit 0de314b

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

clippy_lints/src/loops/never_loop.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,14 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
169169
.iter()
170170
.map(|(o, _)| match o {
171171
InlineAsmOperand::In { expr, .. }
172-
| InlineAsmOperand::InOut { expr, .. }
173-
| InlineAsmOperand::Sym { expr } => never_loop_expr(expr, main_loop_id),
172+
| InlineAsmOperand::InOut { expr, .. } => never_loop_expr(expr, main_loop_id),
174173
InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter(), main_loop_id),
175174
InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
176175
never_loop_expr_all(&mut once(in_expr).chain(out_expr.iter()), main_loop_id)
177176
},
178-
InlineAsmOperand::Const { .. } => NeverLoopResult::Otherwise,
177+
InlineAsmOperand::Const { .. }
178+
| InlineAsmOperand::SymFn { .. }
179+
| InlineAsmOperand::SymStatic { .. } => NeverLoopResult::Otherwise,
179180
})
180181
.fold(NeverLoopResult::Otherwise, combine_both),
181182
ExprKind::Struct(_, _, None)

clippy_lints/src/utils/inspector.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,9 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
281281
for (op, _op_sp) in asm.operands {
282282
match op {
283283
hir::InlineAsmOperand::In { expr, .. }
284-
| hir::InlineAsmOperand::InOut { expr, .. }
285-
| hir::InlineAsmOperand::Sym { expr } => print_expr(cx, expr, indent + 1),
284+
| hir::InlineAsmOperand::InOut { expr, .. } => {
285+
print_expr(cx, expr, indent + 1);
286+
}
286287
hir::InlineAsmOperand::Out { expr, .. } => {
287288
if let Some(expr) = expr {
288289
print_expr(cx, expr, indent + 1);
@@ -294,10 +295,26 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
294295
print_expr(cx, out_expr, indent + 1);
295296
}
296297
},
297-
hir::InlineAsmOperand::Const { anon_const } => {
298+
hir::InlineAsmOperand::Const { anon_const }
299+
| hir::InlineAsmOperand::SymFn { anon_const } => {
298300
println!("{}anon_const:", ind);
299301
print_expr(cx, &cx.tcx.hir().body(anon_const.body).value, indent + 1);
300302
},
303+
hir::InlineAsmOperand::SymStatic { path, .. } => {
304+
match path {
305+
hir::QPath::Resolved(ref ty, path) => {
306+
println!("{}Resolved Path, {:?}", ind, ty);
307+
println!("{}path: {:?}", ind, path);
308+
},
309+
hir::QPath::TypeRelative(ty, seg) => {
310+
println!("{}Relative Path, {:?}", ind, ty);
311+
println!("{}seg: {:?}", ind, seg);
312+
},
313+
hir::QPath::LangItem(lang_item, ..) => {
314+
println!("{}Lang Item Path, {:?}", ind, lang_item.name());
315+
},
316+
}
317+
}
301318
}
302319
}
303320
},

clippy_utils/src/hir_utils.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,8 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
675675
}
676676
},
677677
InlineAsmOperand::Const { anon_const } => self.hash_body(anon_const.body),
678-
InlineAsmOperand::Sym { expr } => self.hash_expr(expr),
678+
InlineAsmOperand::SymFn { anon_const } => self.hash_body(anon_const.body),
679+
InlineAsmOperand::SymStatic { path, def_id: _ } => self.hash_qpath(path),
679680
}
680681
}
681682
},

0 commit comments

Comments
 (0)