Skip to content

transmute_undefined_repr: False positive on tuples of size 1 #8503

Closed

Description

@dtolnay

Summary

I believe transmute_undefined_repr intentionally avoids linting on structs / tuple structs containing 1 field, but it currently does lint on tuples containing 1 field. These should be treated consistently with 1-field tuple structs: either lint both or neither.

Lint Name

transmute_undefined_repr

Reproducer

fn main() {
    let _ = unsafe { std::mem::transmute::<&i32, &(i32,)>(&0) };
}
$ cargo clippy

error: transmute into `&(i32,)` which has an undefined layout
 --> src/main.rs:2:22
  |
2 |     let _ = unsafe { std::mem::transmute::<&i32, &(i32,)>(&0) };
  |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[deny(clippy::transmute_undefined_repr)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#transmute_undefined_repr
fn main() {
    struct Tuple1(i32);
    let _ = unsafe { std::mem::transmute::<&i32, &Tuple1>(&0) };
}
$ cargo clippy
$ # (no lint)

Version

rustc 1.61.0-nightly (8769f4ef2 2022-03-02)
binary: rustc
commit-hash: 8769f4ef2fe1efddd1f072485f97f568e7328f79
commit-date: 2022-03-02
host: x86_64-unknown-linux-gnu
release: 1.61.0-nightly
LLVM version: 14.0.0

Additional Labels

No response

Activity

  1. added
    C-bugCategory: Clippy is not doing the correct thing
    I-false-positiveIssue: The lint was triggered on code it shouldn't have
    on Mar 3, 2022
  2. added a commit that references this issue on Mar 16, 2022
    2b0e730
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions