Skip to content

transmute_undefined_repr fails to adjust argument types. #8501

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

Closed
llogiq opened this issue Mar 3, 2022 · 0 comments · Fixed by #8547
Closed

transmute_undefined_repr fails to adjust argument types. #8501

llogiq opened this issue Mar 3, 2022 · 0 comments · Fixed by #8547
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

@llogiq
Copy link
Contributor

llogiq commented Mar 3, 2022

Summary

If I have a mem::transmute<U, _>(v) where the type of v is autoderef-adjusted to U, the lint ignores this type adjustment and lints as if the concrete type of v would be transmuted.

Lint Name

No response

Reproducer

I tried this code:

#![warn(clippy::transmute_undefined_repr)]
struct Foo([u8]);
fn main() {
    let x = vec![0_u8, 1, 2, 3];
    // this makes the lint think it's transmuting `&Vec<u8> to &Foo`
    let _ = unsafe { std::mem::transmute::<&[u8], &Foo>(&x) };
}

I saw this happen:

warning: transmute from `&std::vec::Vec<u8>` which has an undefined layout
  --> src/test_transmute.rs:5:22
   |
55 |             unsafe { mem::transmute::<&[_], _>(&x) }
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: requested on the command line with `-W clippy::transmute-undefined-repr`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#transmute_undefined_repr

I expected to see this happen:

(nothing, the lint should not apply here).

Version

rustc 1.61.0-nightly (f0c4da499 2022-03-01)
binary: rustc
commit-hash: f0c4da49983aa699f715caf681e3154b445fb60b
commit-date: 2022-03-01
host: x86_64-unknown-linux-gnu
release: 1.61.0-nightly
LLVM version: 14.0.0

Additional Labels

No response

@llogiq llogiq 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 Mar 3, 2022
@bors bors closed this as completed in 2b0e730 Mar 16, 2022
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

Successfully merging a pull request may close this issue.

1 participant