You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.pubtypeOpaque = *mut();// Suppose some type that e.g. wraps access to an FFI context.pubstructContext();implContext{pubfnopaque(&self) -> Opaque{todo!()}pubfnadd(&self,a:Opaque,b:Opaque){todo!()}}fnmain(){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
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 receiverrecv
, 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:
I expected to see this happen:
No clippy warnings/errors.
Instead, this happened:
Meta
cargo clippy -V
: clippy 0.1.53 (53cb7b09 2021-06-17)rustc -Vv
:The text was updated successfully, but these errors were encountered: