rust/tests/ui/trailing_empty_array.rs

187 lines
3.1 KiB
Rust
Raw Normal View History

2021-10-19 16:33:43 -05:00
#![warn(clippy::trailing_empty_array)]
2021-10-17 19:28:45 -05:00
#![feature(const_generics_defaults)]
2021-10-16 04:01:17 -05:00
// Do lint:
2021-10-14 22:08:38 -05:00
struct RarelyUseful {
2021-10-14 22:08:38 -05:00
field: i32,
2021-10-15 02:13:42 -05:00
last: [usize; 0],
2021-10-14 22:08:38 -05:00
}
struct OnlyField {
2021-10-15 02:13:42 -05:00
first_and_last: [usize; 0],
2021-10-14 22:08:38 -05:00
}
2021-10-16 04:01:17 -05:00
struct GenericArrayType<T> {
field: i32,
last: [T; 0],
}
2021-10-14 22:08:38 -05:00
#[must_use]
2021-10-18 06:59:03 -05:00
struct OnlyAnotherAttribute {
2021-10-16 04:01:17 -05:00
field: i32,
2021-10-16 18:13:14 -05:00
last: [usize; 0],
2021-10-16 04:01:17 -05:00
}
#[derive(Debug)]
2021-10-18 06:59:03 -05:00
struct OnlyADeriveAttribute {
2021-10-16 04:01:17 -05:00
field: i32,
2021-10-16 18:13:14 -05:00
last: [usize; 0],
2021-10-16 04:01:17 -05:00
}
const ZERO: usize = 0;
struct ZeroSizedWithConst {
2021-10-16 04:01:17 -05:00
field: i32,
last: [usize; ZERO],
2021-10-16 04:01:17 -05:00
}
#[allow(clippy::eq_op)]
2021-10-16 04:01:17 -05:00
const fn compute_zero() -> usize {
(4 + 6) - (2 * 5)
}
struct ZeroSizedWithConstFunction {
2021-10-16 04:01:17 -05:00
field: i32,
last: [usize; compute_zero()],
}
2021-10-18 19:41:27 -05:00
const fn compute_zero_from_arg(x: usize) -> usize {
x - 1
}
struct ZeroSizedWithConstFunction2 {
field: i32,
last: [usize; compute_zero_from_arg(1)],
}
2021-10-17 19:28:45 -05:00
struct ZeroSizedArrayWrapper([usize; 0]);
struct TupleStruct(i32, [usize; 0]);
struct LotsOfFields {
f1: u32,
f2: u32,
f3: u32,
f4: u32,
f5: u32,
f6: u32,
f7: u32,
f8: u32,
f9: u32,
f10: u32,
f11: u32,
f12: u32,
f13: u32,
f14: u32,
f15: u32,
f16: u32,
last: [usize; 0],
}
2021-10-16 04:26:08 -05:00
// Don't lint
#[repr(C)]
struct GoodReason {
field: i32,
last: [usize; 0],
}
#[repr(C)]
struct OnlyFieldWithReprC {
first_and_last: [usize; 0],
}
2021-10-16 18:13:14 -05:00
struct NonZeroSizedArray {
field: i32,
last: [usize; 1],
}
struct NotLastField {
f1: u32,
zero_sized: [usize; 0],
last: i32,
}
const ONE: usize = 1;
struct NonZeroSizedWithConst {
field: i32,
last: [usize; ONE],
}
2021-10-16 02:51:09 -05:00
#[derive(Debug)]
#[repr(C)]
2021-10-18 06:59:03 -05:00
struct AlsoADeriveAttribute {
field: i32,
last: [usize; 0],
}
#[must_use]
#[repr(C)]
2021-10-18 06:59:03 -05:00
struct AlsoAnotherAttribute {
field: i32,
last: [usize; 0],
}
2021-10-16 04:01:17 -05:00
#[repr(packed)]
struct ReprPacked {
field: i32,
last: [usize; 0],
}
#[repr(C, packed)]
struct ReprCPacked {
field: i32,
last: [usize; 0],
2021-10-16 04:01:17 -05:00
}
2021-10-16 02:51:09 -05:00
2021-10-16 04:01:17 -05:00
#[repr(align(64))]
struct ReprAlign {
field: i32,
last: [usize; 0],
}
#[repr(C, align(64))]
struct ReprCAlign {
field: i32,
last: [usize; 0],
}
2021-10-16 04:26:08 -05:00
// NOTE: because of https://doc.rust-lang.org/stable/reference/type-layout.html#primitive-representation-of-enums-with-fields and I'm not sure when in the compilation pipeline that would happen
2021-10-16 04:01:17 -05:00
#[repr(C)]
enum DontLintAnonymousStructsFromDesuraging {
A(u32),
B(f32, [u64; 0]),
C { x: u32, y: [u64; 0] },
}
2021-10-17 19:28:45 -05:00
#[repr(C)]
struct TupleStructReprC(i32, [usize; 0]);
type NamedTuple = (i32, [usize; 0]);
#[rustfmt::skip] // [rustfmt#4995](https://github.com/rust-lang/rustfmt/issues/4995)
struct ConstParamZeroDefault<const N: usize = 0> {
field: i32,
last: [usize; N],
}
struct ConstParamNoDefault<const N: usize> {
field: i32,
last: [usize; N],
}
#[rustfmt::skip]
struct ConstParamNonZeroDefault<const N: usize = 1> {
field: i32,
last: [usize; N],
}
2021-10-18 06:22:43 -05:00
struct TwoGenericParams<T, const N: usize> {
field: i32,
last: [T; N],
}
2021-10-17 19:28:45 -05:00
type A = ConstParamZeroDefault;
type B = ConstParamZeroDefault<0>;
type C = ConstParamNoDefault<0>;
type D = ConstParamNonZeroDefault<0>;
fn main() {}