rust-lang / rust-lang/rust-clippy

`clippy::used_underscore_binding` fires on an unused function parameter

Open
#12,810 2 comments 0 reactions 1 assignee View on GitHub

@AjithPanneerselvam is already working on this.

Since May 21, 2024.

C-bug I-false-positive T-macros
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

clippy::used_underscore_binding fires on an unused function parameter.

To reproduce:

git clone https://github.com/Kriskras99/ferris_dancing.git
cd ferris_dancing
git checkout acd683a
cargo +nightly clippy

You don't need the submodule to reproduce, and you can ignore the dead_code warning from another crate in the workspace

Lint Name

used_underscore_binding

Reproducer

I tried this code:

impl BinaryDeserialize<'_> for Xtx {
    type Ctx = ();
    type Output = Self;

    #[tracing::instrument(skip(reader))]
    fn deserialize_at_with_ctx(
        reader: &(impl ReadAtExt + ?Sized),
        position: &mut u64,
        _ctx: (),
    ) -> Result<Self, ReadError> {
        let start = *position;
        let magic = reader.read_at::<u32le>(position)?;
        test_eq(&magic, &0x4E76_4644)?;

        let size = reader.read_at::<u32le>(position)?;
        test_eq(&size, &0x10)?;

        let major_version = reader.read_at::<u32le>(position)?;
        test_eq(&major_version, &0x1)?;

        let minor_version = reader.read_at::<u32le>(position)?;

        let mut blocks = Vec::new();

        loop {
            match reader.read_at::<u32le>(position) {
                Ok(magic) => {
                    *position -= 4;
                    if magic != 0x4E76_4248 {
                        break;
                    }
                }
                Err(ReadError::IoError {
                    error: _,
                    backtrace: _,
                }) => break,
                Err(error) => return Err(error),
            }
            tracing::trace!("Block start: {}", *position - start);
            let block = reader.read_at::<Block>(position)?;
            blocks.push(block);
        }

        let mut images = Vec::new();

        let mut index = 0;
        while index < blocks.len() {
            let block = blocks.get(index).unwrap_or_else(|| unreachable!());
            match &block.data {
                BlockData::TextureHeader(hdr) => {
                    let second_block = blocks.get(index + 1);
                    let data = match second_block {
                        Some(block) => match &block.data {
                            BlockData::Data(data) => Ok(data),
                            _ => Err(ReadError::custom("Found header without data".to_string())),
                        },
                        None => Err(ReadError::custom("Found header without data".to_string())),
                    }?;

                    images.push(parse_data_block_to_image(hdr, data)?);

                    index += 2;

                    Ok(())
                }
                BlockData::Data(_) => {
                    Err(ReadError::custom("Found data without a header".to_string()))
                }
                BlockData::Three(_) => {
                    index += 1;
                    Ok(())
                }
            }?;
        }

        Ok(Self {
            major_version,
            minor_version,
            images,
        })
    }
}

I saw this happen:

warning: used binding `_ctx` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
  --> ubiart_toolkit/src/cooked/xtx/parser.rs:30:9
   |
30 |         _ctx: (),
   |         ^^^^
   |
note: `_ctx` is defined here
  --> ubiart_toolkit/src/cooked/xtx/parser.rs:30:9
   |
30 |         _ctx: (),
   |         ^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding
   = note: `-W clippy::used-underscore-binding` implied by `-W clippy::pedantic`
   = help: to override `-W clippy::pedantic` add `#[allow(clippy::used_underscore_binding)]`

I expected to see this happen:
No output as _ctx is not used

Version
rustc 1.80.0-nightly (1871252fc 2024-05-15)
binary: rustc
commit-hash: 1871252fc8bb672d40787e67404e6eaae7059369
commit-date: 2024-05-15
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4
Additional Labels

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.