rust/tests/ui/enum_clike_unportable_variant.rs

61 lines
1.6 KiB
Rust
Raw Normal View History

2024-08-17 14:38:10 -05:00
//@ignore-bitwidth: 32
2017-09-18 05:47:33 -05:00
#![warn(clippy::enum_clike_unportable_variant)]
#![allow(unused, non_upper_case_globals)]
#[repr(usize)]
enum NonPortable {
2017-02-08 07:58:07 -06:00
X = 0x1_0000_0000,
//~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets
//~| NOTE: `-D clippy::enum-clike-unportable-variant` implied by `-D warnings`
Y = 0,
Z = 0x7FFF_FFFF,
A = 0xFFFF_FFFF,
}
enum NonPortableNoHint {
2017-02-08 07:58:07 -06:00
X = 0x1_0000_0000,
//~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets
Y = 0,
Z = 0x7FFF_FFFF,
2017-02-08 07:58:07 -06:00
A = 0xFFFF_FFFF,
//~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets
}
#[repr(isize)]
enum NonPortableSigned {
X = -1,
Y = 0x7FFF_FFFF,
2017-02-08 07:58:07 -06:00
Z = 0xFFFF_FFFF,
//~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets
2017-02-08 07:58:07 -06:00
A = 0x1_0000_0000,
//~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets
B = i32::MIN as isize,
C = (i32::MIN as isize) - 1,
//~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets
}
enum NonPortableSignedNoHint {
X = -1,
Y = 0x7FFF_FFFF,
2017-02-08 07:58:07 -06:00
Z = 0xFFFF_FFFF,
//~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets
2017-02-08 07:58:07 -06:00
A = 0x1_0000_0000,
//~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets
}
#[repr(usize)]
enum NonPortable2 {
X = <usize as Trait>::Number,
//~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets
Y = 0,
}
trait Trait {
const Number: usize = 0x1_0000_0000;
}
impl Trait for usize {}
2018-12-09 16:26:16 -06:00
fn main() {}