Skip to content

Commit d2fd48f

Browse files
committed
add details
1 parent a2277f0 commit d2fd48f

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

clippy_lints/src/pointer_in_nomem_asm_block.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ fn yeet_lint(cx: &LateContext<'_>, asm: &InlineAsm<'_>, asm_span: Span, op_spans
3535

3636
span_lint_and_then(cx, POINTER_IN_NOMEM_ASM_BLOCK, op_spans, "passing pointer to nomem asm block", |diag| {
3737
if let Some(probably_asm_options_span) = probably_asm_options_span {
38-
diag.span_suggestion(probably_asm_options_span, "heeelppp", "suggg", Applicability::MaybeIncorrect);
38+
diag.span_note(probably_asm_options_span, "flags declared here");
3939
}
40-
// note_span.inspect(|s| { diag.span_note(*s, "declared here"); });
4140
});
4241
}
4342

@@ -58,21 +57,28 @@ fn check_asm(cx: &LateContext<'_>, asm: &InlineAsm<'_>, asm_span: Span) {
5857

5958
declare_clippy_lint! {
6059
/// ### What it does
60+
/// Checks if any pointer is being passed to an asm! block with `nomem` option.
6161
///
6262
/// ### Why is this bad?
63+
/// `nomem` forbids any reads or writes to memory and passing a pointer suggests
64+
/// that either of those will happen.
6365
///
6466
/// ### Example
6567
/// ```no_run
66-
/// // example code where clippy issues a warning
68+
/// fn f(p: *mut u32) {
69+
/// unsafe { core::arch::asm!("mov [{p}], 42", p = in(reg) p, options(nomem, nostack)); }
70+
/// }
6771
/// ```
6872
/// Use instead:
6973
/// ```no_run
70-
/// // example code which does not raise clippy warning
74+
/// fn f(p: *mut u32) {
75+
/// unsafe { core::arch::asm!("mov [{p}], 42", p = in(reg) p, options(nostack)); }
76+
/// }
7177
/// ```
7278
#[clippy::version = "1.81.0"]
7379
pub POINTER_IN_NOMEM_ASM_BLOCK,
7480
suspicious,
75-
"default lint description"
81+
"pointer in nomem asm block"
7682
}
7783

7884
declare_lint_pass!(PointerInNomemAsmBlock => [POINTER_IN_NOMEM_ASM_BLOCK]);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error: passing pointer to nomem asm block
2+
--> tests/ui/pointer_in_nomem_asm_block.rs:8:9
3+
|
4+
LL | p1 = in(reg) p,
5+
| ^^^^^^^^^^^^^^
6+
LL | p2 = in(reg) p as *const _ as usize,
7+
LL | p3 = in(reg) p,
8+
| ^^^^^^^^^^^^^^
9+
LL | / options(nomem, nostack, preserves_flags)
10+
LL | | );
11+
| |_____- help: remove `nomem`
12+
|
13+
= note: `-D clippy::pointer-in-nomem-asm-block` implied by `-D warnings`
14+
= help: to override `-D warnings` add `#[allow(clippy::pointer_in_nomem_asm_block)]`
15+
16+
error: passing pointer to nomem asm block
17+
--> tests/ui/pointer_in_nomem_asm_block.rs:33:34
18+
|
19+
LL | core::arch::asm!("asdf {p}", p = in(reg) p, options(nomem, nostack, preserves_flags));
20+
| ^^^^^^^^^^^^^ ----------------------------------------- help: remove `nomem`
21+
22+
error: aborting due to 2 previous errors
23+

0 commit comments

Comments
 (0)