]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/lint-strict-provenance-lossy-casts.rs
Merge commit 'e9d1a0a7b0b28dd422f1a790ccde532acafbf193' into sync_cg_clif-2022-08-24
[rust.git] / src / test / ui / lint / lint-strict-provenance-lossy-casts.rs
1 #![feature(strict_provenance)]
2 #![deny(lossy_provenance_casts)]
3
4 fn main() {
5     let x: u8 = 37;
6     let addr: usize = &x as *const u8 as usize;
7     //~^ ERROR under strict provenance it is considered bad style to cast pointer `*const u8` to integer `usize`
8
9     let addr_32bit = &x as *const u8 as u32;
10     //~^ ERROR under strict provenance it is considered bad style to cast pointer `*const u8` to integer `u32`
11
12     // don't add unnecessary parens in the suggestion
13     let ptr = &x as *const u8;
14     let ptr_addr = ptr as usize;
15     //~^ ERROR under strict provenance it is considered bad style to cast pointer `*const u8` to integer `usize`
16     let ptr_addr_32bit = ptr as u32;
17     //~^ ERROR under strict provenance it is considered bad style to cast pointer `*const u8` to integer `u32`
18 }