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

zst_offset lint broken #7395

Closed
ranweiler opened this issue Jun 23, 2021 · 0 comments · Fixed by #7396
Closed

zst_offset lint broken #7395

ranweiler opened this issue Jun 23, 2021 · 0 comments · Fixed by #7396
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@ranweiler
Copy link
Contributor

Summary

The zst_offset is broken, and only triggers on unrelated, valid code, which does not match the error described in #4813.

This is due to a refactoring regression in 2108387. In the invocation of the zst_offset check, we shadow the already-destructured receiver recv, and accidentally pass the first argument of the method as if it were the receiver.

This was not caught because the UI test expectation was never correct (a bad cast obscured the actual test result).

I tried this code:

This popped up in real life, in FFI wrapper code that interfaces with opaque pointers. An abstracted example:

// Raw pointer to ZST, modeling an opaque pointer.
pub type Opaque = *mut ();

// Suppose some type that e.g. wraps access to an FFI context.
pub struct Context();

impl Context {
    pub fn opaque(&self) -> Opaque {
        todo!()
    }

    pub fn add(&self, a: Opaque, b: Opaque) {
        todo!()
    }
}

fn main() {
    let ctx = Context();

    let a = ctx.opaque();
    let b = ctx.opaque();

    // Should pass linting.
    ctx.add(a, b);
}

I expected to see this happen:

No clippy warnings/errors.

Instead, this happened:

error: offset calculation on zero-sized value
  --> src\main.rs:73:5
   |
73 |     ctx.add(a, b);
   |     ^^^^^^^^^^^^^
   |
   = note: `#[deny(clippy::zst_offset)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#zst_offset

Meta

  • cargo clippy -V: clippy 0.1.53 (53cb7b09 2021-06-17)
  • rustc -Vv:
rustc 1.53.0 (53cb7b09b 2021-06-17)
binary: rustc
commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b
commit-date: 2021-06-17
host: x86_64-pc-windows-msvc
release: 1.53.0
LLVM version: 12.0.1
@ranweiler ranweiler added the C-bug Category: Clippy is not doing the correct thing label Jun 23, 2021
@bors bors closed this as completed in d568387 Jun 23, 2021
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant