Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy::used_underscore_binding fires on an unused function parameter #12810

Open
Kriskras99 opened this issue May 16, 2024 · 1 comment
Open
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@Kriskras99
Copy link

Kriskras99 commented May 16, 2024

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

@Kriskras99 Kriskras99 added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels May 16, 2024
@AjithPanneerselvam
Copy link

I'd like to work on this issue if it is accepted :)

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants