diff options
| author | Nathaniel Hamovitz <18648574+nhamovitz@users.noreply.github.com> | 2021-10-16 22:03:08 -0700 |
|---|---|---|
| committer | Nathaniel Hamovitz <18648574+nhamovitz@users.noreply.github.com> | 2021-10-18 03:05:19 -0700 |
| commit | a3420f70043c19165a4e44639ef4e6f3c156a174 (patch) | |
| tree | 6c0207330fd89e69df14c2c27e9ade0776dc72d1 /tests | |
| parent | 9b3f55ee61e781ef3360ddfaa436746bb7e40df5 (diff) | |
| download | rust-a3420f70043c19165a4e44639ef4e6f3c156a174.tar.gz rust-a3420f70043c19165a4e44639ef4e6f3c156a174.zip | |
Tidy comments + tests; revert 'size-is-zero' detection
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/trailing_zero_sized_array_without_repr_c.rs | 36 | ||||
| -rw-r--r-- | tests/ui/trailing_zero_sized_array_without_repr_c.stderr | 91 |
2 files changed, 49 insertions, 78 deletions
diff --git a/tests/ui/trailing_zero_sized_array_without_repr_c.rs b/tests/ui/trailing_zero_sized_array_without_repr_c.rs index 6ab96c2ebf6..77b2c29b275 100644 --- a/tests/ui/trailing_zero_sized_array_without_repr_c.rs +++ b/tests/ui/trailing_zero_sized_array_without_repr_c.rs @@ -1,5 +1,4 @@ #![warn(clippy::trailing_zero_sized_array_without_repr_c)] -#![feature(const_generics_defaults)] // see below // Do lint: @@ -17,14 +16,16 @@ struct GenericArrayType<T> { last: [T; 0], } -#[derive(Debug)] -struct OnlyAnotherAttributeDerive { +#[must_use] +struct OnlyAnotherAttributeMustUse { field: i32, last: [usize; 0], } -#[must_use] -struct OnlyAnotherAttributeMustUse { +// NOTE: Unfortunately the attribute isn't included in the lint output. I'm not sure how to make it +// show up. +#[derive(Debug)] +struct OnlyAnotherAttributeDerive { field: i32, last: [usize; 0], } @@ -82,6 +83,12 @@ struct NonZeroSizedArray { last: [usize; 1], } +struct NotLastField { + f1: u32, + zero_sized: [usize; 0], + last: i32, +} + const ONE: usize = 1; struct NonZeroSizedWithConst { field: i32, @@ -133,21 +140,4 @@ enum DontLintAnonymousStructsFromDesuraging { C { x: u32, y: [u64; 0] }, } -// NOTE: including these (along with the required feature) triggers an ICE. Not sure why. Should -// make sure the const generics people are aware of that if they weren't already. - -// #[repr(C)] -// struct ConstParamOk<const N: usize = 0> { -// field: i32, -// last: [usize; N] -// } - -// struct ConstParamLint<const N: usize = 0> { -// field: i32, -// last: [usize; N] -// } - -fn main() { - let _ = OnlyAnotherAttributeMustUse { field: 0, last: [] }; - let _ = OtherAttributesMustUse { field: 0, last: [] }; -} +fn main() {} diff --git a/tests/ui/trailing_zero_sized_array_without_repr_c.stderr b/tests/ui/trailing_zero_sized_array_without_repr_c.stderr index 84606ed6185..ee8182cdc38 100644 --- a/tests/ui/trailing_zero_sized_array_without_repr_c.stderr +++ b/tests/ui/trailing_zero_sized_array_without_repr_c.stderr @@ -1,5 +1,5 @@ error: trailing zero-sized array in a struct which is not marked `#[repr(C)]` - --> $DIR/trailing_zero_sized_array_without_repr_c.rs:4:1 + --> $DIR/trailing_zero_sized_array_without_repr_c.rs:5:1 | LL | / struct RarelyUseful { LL | | field: i32, @@ -8,33 +8,20 @@ LL | | } | |_^ | = note: `-D clippy::trailing-zero-sized-array-without-repr-c` implied by `-D warnings` -help: try annotating the struct definition with `#[repr(C)]` (or another `repr` attribute): - | -LL + #[repr(C)] -LL + struct RarelyUseful { -LL + field: i32, -LL + last: [usize; 0], -LL + } - | + = help: consider annotating the struct definition with `#[repr(C)]` (or another `repr` attribute) error: trailing zero-sized array in a struct which is not marked `#[repr(C)]` - --> $DIR/trailing_zero_sized_array_without_repr_c.rs:15:1 + --> $DIR/trailing_zero_sized_array_without_repr_c.rs:10:1 | -LL | / struct OnlyFieldIsZeroSizeArray { +LL | / struct OnlyField { LL | | first_and_last: [usize; 0], LL | | } | |_^ | -help: try annotating the struct definition with `#[repr(C)]` (or another `repr` attribute): - | -LL + #[repr(C)] -LL + struct OnlyFieldIsZeroSizeArray { -LL + first_and_last: [usize; 0], -LL + } - | + = help: consider annotating the struct definition with `#[repr(C)]` (or another `repr` attribute) error: trailing zero-sized array in a struct which is not marked `#[repr(C)]` - --> $DIR/trailing_zero_sized_array_without_repr_c.rs:19:1 + --> $DIR/trailing_zero_sized_array_without_repr_c.rs:14:1 | LL | / struct GenericArrayType<T> { LL | | field: i32, @@ -42,53 +29,55 @@ LL | | last: [T; 0], LL | | } | |_^ | -help: try annotating the struct definition with `#[repr(C)]` (or another `repr` attribute): + = help: consider annotating the struct definition with `#[repr(C)]` (or another `repr` attribute) + +error: trailing zero-sized array in a struct which is not marked `#[repr(C)]` + --> $DIR/trailing_zero_sized_array_without_repr_c.rs:19:1 | -LL + #[repr(C)] -LL + struct GenericArrayType<T> { -LL + field: i32, -LL + last: [T; 0], -LL + } +LL | / #[must_use] +LL | | struct OnlyAnotherAttributeMustUse { +LL | | field: i32, +LL | | last: [usize; 0], +LL | | } + | |_^ | + = help: consider annotating the struct definition with `#[repr(C)]` (or another `repr` attribute) error: trailing zero-sized array in a struct which is not marked `#[repr(C)]` - --> $DIR/trailing_zero_sized_array_without_repr_c.rs:30:1 + --> $DIR/trailing_zero_sized_array_without_repr_c.rs:28:1 | -LL | / struct ZeroSizedFromExternalConst { +LL | / struct OnlyAnotherAttributeDerive { LL | | field: i32, -LL | | last: [usize; ZERO], +LL | | last: [usize; 0], LL | | } | |_^ | -help: try annotating the struct definition with `#[repr(C)]` (or another `repr` attribute): + = help: consider annotating the struct definition with `#[repr(C)]` (or another `repr` attribute) + +error: trailing zero-sized array in a struct which is not marked `#[repr(C)]` + --> $DIR/trailing_zero_sized_array_without_repr_c.rs:34:1 | -LL + #[repr(C)] -LL + struct ZeroSizedFromExternalConst { -LL + field: i32, -LL + last: [usize; ZERO], -LL + } +LL | / struct ZeroSizedWithConst { +LL | | field: i32, +LL | | last: [usize; ZERO], +LL | | } + | |_^ | + = help: consider annotating the struct definition with `#[repr(C)]` (or another `repr` attribute) error: trailing zero-sized array in a struct which is not marked `#[repr(C)]` - --> $DIR/trailing_zero_sized_array_without_repr_c.rs:45:1 + --> $DIR/trailing_zero_sized_array_without_repr_c.rs:43:1 | -LL | / struct UsingFunction { +LL | / struct ZeroSizedWithConstFunction { LL | | field: i32, LL | | last: [usize; compute_zero()], LL | | } | |_^ | -help: try annotating the struct definition with `#[repr(C)]` (or another `repr` attribute): - | -LL + #[repr(C)] -LL + struct UsingFunction { -LL + field: i32, -LL + last: [usize; compute_zero()], -LL + } - | + = help: consider annotating the struct definition with `#[repr(C)]` (or another `repr` attribute) error: trailing zero-sized array in a struct which is not marked `#[repr(C)]` - --> $DIR/trailing_zero_sized_array_without_repr_c.rs:94:1 + --> $DIR/trailing_zero_sized_array_without_repr_c.rs:48:1 | LL | / struct LotsOfFields { LL | | f1: u32, @@ -99,15 +88,7 @@ LL | | last: [usize; 0], LL | | } | |_^ | -help: try annotating the struct definition with `#[repr(C)]` (or another `repr` attribute): - | -LL + #[repr(C)] -LL + struct LotsOfFields { -LL + f1: u32, -LL + f2: u32, -LL + f3: u32, -LL + f4: u32, - ... + = help: consider annotating the struct definition with `#[repr(C)]` (or another `repr` attribute) -error: aborting due to 6 previous errors +error: aborting due to 8 previous errors |
