Skip to content

no_effect_underscore_binding triggered in macro-generated code #17430

Description

@nazar-pc

Summary

I applied no_panic::no_panic macro on a method, which had some of the arguments ignored (it implemented a trait), which triggered this lint:

warning: binding to `_` prefixed variable with no side-effect
  --> ....rs:22:9
   |
22 |         _ext_state: &ExtState,
   |         ^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#no_effect_underscore_binding
   = note: `-W clippy::no-effect-underscore-binding` implied by `-W clippy::pedantic`
   = help: to override `-W clippy::pedantic` add `#[allow(clippy::no_effect_underscore_binding)]`

Macro generated this code (note let _ext_state = _ext_state;):

    fn prepare_csr_read(
        mut _ext_state: &ExtState,
        mut csr_index: u16,
        mut raw_value: Reg::Type,
        mut output_value: &mut Reg::Type,
    ) -> Result<bool, CsrError<CustomError>> {
        struct __NoPanic;
        unsafe extern "C" {
            #[link_name = "\n\nERROR[no-panic-const]: detected panic in function `prepare_csr_read`\n"]
            fn trigger() -> !;
        }
        impl ::core::ops::Drop for __NoPanic { fn drop(&mut self) { unsafe { trigger(); } } }
        let __guard = __NoPanic;
        let __result = (move || -> Result<bool, CsrError<CustomError>>   {
            let _ext_state = _ext_state;
            let csr_index = csr_index;
            let raw_value = raw_value;
            let output_value = output_value;
            let mut accepted_by_at_least_one = false;
            if {
                if VectorCsr::from_csr_index(csr_index).is_some() {
                    *output_value = raw_value;
                    Ok(true)
                } else {
                    Ok(false)
                }
            }? {
                accepted_by_at_least_one = true;
            }
            Ok(accepted_by_at_least_one)
        })();
        ::core::mem::forget(__guard);
        __result
    }

Since it is often impractical for proc macros to analyze which variables are actually use and which are not, I think this lint should be ignored in code generated by proc macros.

Lint Name

no_effect_underscore_binding

Reproducer

No response

Version

rustc 1.99.0-nightly (d0babd8b6 2026-07-15)
binary: rustc
commit-hash: d0babd8b6b05ef9bb65d42f928cef4129d64cf65
commit-date: 2026-07-15
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 22.1.8

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions