mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-14 00:47:16 +00:00
069957a8ad
* Late Lint pass, catches: * One liner: 0 -> null -> transmute * One liner: std:null() -> transmute * Const (which resolves to null) -> transmute * UI Test case for Lint * Updated test for issue 3849, because now the lint that code generated is in Clippy. * Expanded `const.rs` miri-based Constant Folding code, to cover raw pointers
30 lines
735 B
Rust
30 lines
735 B
Rust
#![allow(dead_code)]
|
|
#![warn(clippy::transmuting_null)]
|
|
#![allow(clippy::zero_ptr)]
|
|
#![allow(clippy::transmute_ptr_to_ref)]
|
|
#![allow(clippy::eq_op)]
|
|
|
|
// Easy to lint because these only span one line.
|
|
fn one_liners() {
|
|
unsafe {
|
|
let _: &u64 = std::mem::transmute(0 as *const u64);
|
|
let _: &u64 = std::mem::transmute(std::ptr::null::<u64>());
|
|
}
|
|
}
|
|
|
|
pub const ZPTR: *const usize = 0 as *const _;
|
|
pub const NOT_ZPTR: *const usize = 1 as *const _;
|
|
|
|
fn transmute_const() {
|
|
unsafe {
|
|
// Should raise a lint.
|
|
let _: &u64 = std::mem::transmute(ZPTR);
|
|
// Should NOT raise a lint.
|
|
let _: &u64 = std::mem::transmute(NOT_ZPTR);
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
one_liners();
|
|
transmute_const();
|
|
}
|