Skip to content

Commit

Permalink
[tests] Fix UI tests with missing imports (#706)
Browse files Browse the repository at this point in the history
Previously, some UI tests had missing imports which caused the
corresponding `.stderr` files to be populated with unhelpful "cannot
find ..." messages. This is another point in favor of #187 (switching to
the `ui-test` crate), which presumably would have made it much less
likely for this to slip under the radar.
  • Loading branch information
joshlf committed Dec 9, 2023
1 parent cd73b78 commit 0cdf0cb
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 311 deletions.
21 changes: 15 additions & 6 deletions tests/ui-msrv/transmute-mut-src-generic.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
error[E0405]: cannot find trait `FromBytes` in this scope
--> tests/ui-msrv/transmute-mut-src-generic.rs:15:31
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-msrv/transmute-mut-src-generic.rs:17:5
|
15 | fn transmute_mut<T: AsBytes + FromBytes + NoCell>(t: &mut T) -> &mut u8 {
| ^^^^^^^^^ not found in this scope
17 | transmute_mut!(t)
| ^^^^^^^^^^^^^^^^^
|
help: consider importing this trait
= note: source type: `T` (this type does not have a fixed size)
= note: target type: `u8` (8 bits)
= note: this error originates in the macro `$crate::assert_size_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-msrv/transmute-mut-src-generic.rs:17:5
|
11 | use zerocopy::FromBytes;
17 | transmute_mut!(t)
| ^^^^^^^^^^^^^^^^^
|
= note: source type: `AlignOf<T>` (size can vary because of T)
= note: target type: `MaxAlignsOf<T, u8>` (size can vary because of T)
= note: this error originates in the macro `$crate::assert_align_gt_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
2 changes: 1 addition & 1 deletion tests/ui-nightly/transmute-mut-src-generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

extern crate zerocopy;

use zerocopy::{transmute_mut, AsBytes, NoCell};
use zerocopy::{transmute_mut, AsBytes, FromBytes, NoCell};

fn main() {}

Expand Down
21 changes: 15 additions & 6 deletions tests/ui-nightly/transmute-mut-src-generic.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
error[E0405]: cannot find trait `FromBytes` in this scope
--> tests/ui-nightly/transmute-mut-src-generic.rs:15:31
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-nightly/transmute-mut-src-generic.rs:17:5
|
15 | fn transmute_mut<T: AsBytes + FromBytes + NoCell>(t: &mut T) -> &mut u8 {
| ^^^^^^^^^ not found in this scope
17 | transmute_mut!(t)
| ^^^^^^^^^^^^^^^^^
|
help: consider importing this trait
= note: source type: `T` (this type does not have a fixed size)
= note: target type: `u8` (8 bits)
= note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-nightly/transmute-mut-src-generic.rs:17:5
|
11 + use zerocopy::FromBytes;
17 | transmute_mut!(t)
| ^^^^^^^^^^^^^^^^^
|
= note: source type: `AlignOf<T>` (size can vary because of T)
= note: target type: `MaxAlignsOf<T, u8>` (size can vary because of T)
= note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
21 changes: 15 additions & 6 deletions tests/ui-stable/transmute-mut-src-generic.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
error[E0405]: cannot find trait `FromBytes` in this scope
--> tests/ui-stable/transmute-mut-src-generic.rs:15:31
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-stable/transmute-mut-src-generic.rs:17:5
|
15 | fn transmute_mut<T: AsBytes + FromBytes + NoCell>(t: &mut T) -> &mut u8 {
| ^^^^^^^^^ not found in this scope
17 | transmute_mut!(t)
| ^^^^^^^^^^^^^^^^^
|
help: consider importing this trait
= note: source type: `T` (this type does not have a fixed size)
= note: target type: `u8` (8 bits)
= note: this error originates in the macro `$crate::assert_size_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> tests/ui-stable/transmute-mut-src-generic.rs:17:5
|
11 + use zerocopy::FromBytes;
17 | transmute_mut!(t)
| ^^^^^^^^^^^^^^^^^
|
= note: source type: `AlignOf<T>` (size can vary because of T)
= note: target type: `MaxAlignsOf<T, u8>` (size can vary because of T)
= note: this error originates in the macro `$crate::assert_align_gt_eq` which comes from the expansion of the macro `transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
113 changes: 57 additions & 56 deletions zerocopy-derive/tests/ui-msrv/derive_transparent.stderr
Original file line number Diff line number Diff line change
@@ -1,88 +1,89 @@
<<<<<<< HEAD
error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
--> tests/ui-msrv/derive_transparent.rs:37:1
|
37 | assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeros);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy`
37 | assert_impl_all!(TransparentStruct<NotZerocopy>: TryFromBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
|
note: required because of the requirements on the impl of `FromZeroes` for `TransparentStruct<NotZerocopy>`
note: required because of the requirements on the impl of `TryFromBytes` for `TransparentStruct<NotZerocopy>`
--> tests/ui-msrv/derive_transparent.rs:27:19
|
27 | #[derive(AsBytes, FromZeros, FromBytes, Unaligned)]
| ^^^^^^^^^
27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)]
| ^^^^^^^^^^^^
note: required by a bound in `_::{closure#0}::assert_impl_all`
--> tests/ui-msrv/derive_transparent.rs:37:1
|
37 | assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeros);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `_::{closure#0}::assert_impl_all`
37 | assert_impl_all!(TransparentStruct<NotZerocopy>: TryFromBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `_::{closure#0}::assert_impl_all`
= note: this error originates in the macro `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied
--> tests/ui-msrv/derive_transparent.rs:38:1
=======
error: cannot find derive macro `TryFromBytes` in this scope
--> tests/ui-msrv/derive_transparent.rs:27:19
|
27 | #[derive(AsBytes, TryFromBytes, FromZeroes, FromBytes, Unaligned)]
| ^^^^^^^^^^^^ help: a derive macro with a similar name exists: `FromBytes`
>>>>>>> [derive] Support `derive(TryFromBytes)` for structs
|
::: src/lib.rs
38 | assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeros);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy`
|
<<<<<<< HEAD
note: required because of the requirements on the impl of `FromBytes` for `TransparentStruct<NotZerocopy>`
--> tests/ui-msrv/derive_transparent.rs:27:30
note: required because of the requirements on the impl of `FromZeroes` for `TransparentStruct<NotZerocopy>`
--> tests/ui-msrv/derive_transparent.rs:27:33
|
27 | #[derive(AsBytes, FromZeros, FromBytes, Unaligned)]
| ^^^^^^^^^
27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)]
| ^^^^^^^^^
note: required by a bound in `_::{closure#0}::assert_impl_all`
--> tests/ui-msrv/derive_transparent.rs:38:1
|
38 | assert_impl_all!(TransparentStruct<NotZerocopy>: FromBytes);
38 | assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeros);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `_::{closure#0}::assert_impl_all`
= note: this error originates in the macro `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
=======
| pub fn derive_from_bytes(ts: proc_macro::TokenStream) -> proc_macro::TokenStream {
| -------------------------------------------------------------------------------- similarly named derive macro `FromBytes` defined here
|
= note: consider importing one of these items:
zerocopy::TryFromBytes
zerocopy_derive::TryFromBytes
>>>>>>> [derive] Support `derive(TryFromBytes)` for structs

error[E0405]: cannot find trait `TryFromBytes` in this scope
--> tests/ui-msrv/derive_transparent.rs:37:50
error[E0277]: the trait bound `NotZerocopy: FromBytes` is not satisfied
--> tests/ui-msrv/derive_transparent.rs:39:1
|
37 | assert_impl_all!(TransparentStruct<NotZerocopy>: TryFromBytes);
| ^^^^^^^^^^^^
39 | assert_impl_all!(TransparentStruct<NotZerocopy>: FromBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromBytes` is not implemented for `NotZerocopy`
|
<<<<<<< HEAD
27 | #[derive(AsBytes, FromZeros, FromBytes, Unaligned)]
| ^^^^^^^
note: required because of the requirements on the impl of `FromBytes` for `TransparentStruct<NotZerocopy>`
--> tests/ui-msrv/derive_transparent.rs:27:44
|
27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)]
| ^^^^^^^^^
note: required by a bound in `_::{closure#0}::assert_impl_all`
--> tests/ui-msrv/derive_transparent.rs:39:1
=======
::: $WORKSPACE/src/lib.rs
>>>>>>> [derive] Support `derive(TryFromBytes)` for structs
|
| pub unsafe trait FromBytes: FromZeroes {
| -------------------------------------- similarly named trait `FromBytes` defined here
39 | assert_impl_all!(TransparentStruct<NotZerocopy>: FromBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `_::{closure#0}::assert_impl_all`
= note: this error originates in the macro `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `NotZerocopy: AsBytes` is not satisfied
--> tests/ui-msrv/derive_transparent.rs:40:1
|
help: a trait with a similar name exists
40 | assert_impl_all!(TransparentStruct<NotZerocopy>: AsBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `NotZerocopy`
|
<<<<<<< HEAD
note: required because of the requirements on the impl of `Unaligned` for `TransparentStruct<NotZerocopy>`
--> tests/ui-msrv/derive_transparent.rs:27:41
note: required because of the requirements on the impl of `AsBytes` for `TransparentStruct<NotZerocopy>`
--> tests/ui-msrv/derive_transparent.rs:27:10
|
27 | #[derive(AsBytes, FromZeros, FromBytes, Unaligned)]
| ^^^^^^^^^
27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)]
| ^^^^^^^
note: required by a bound in `_::{closure#0}::assert_impl_all`
--> tests/ui-msrv/derive_transparent.rs:40:1
=======
37 | assert_impl_all!(TransparentStruct<NotZerocopy>: FromBytes);
| ~~~~~~~~~
help: consider importing this trait
|
14 | use zerocopy::TryFromBytes;
>>>>>>> [derive] Support `derive(TryFromBytes)` for structs
40 | assert_impl_all!(TransparentStruct<NotZerocopy>: AsBytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `_::{closure#0}::assert_impl_all`
= note: this error originates in the macro `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `NotZerocopy: Unaligned` is not satisfied
--> tests/ui-msrv/derive_transparent.rs:41:1
|
41 | assert_impl_all!(TransparentStruct<NotZerocopy>: Unaligned);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Unaligned` is not implemented for `NotZerocopy`
|
note: required because of the requirements on the impl of `Unaligned` for `TransparentStruct<NotZerocopy>`
--> tests/ui-msrv/derive_transparent.rs:27:55
|
27 | #[derive(AsBytes, TryFromBytes, FromZeros, FromBytes, Unaligned)]
| ^^^^^^^^^
note: required by a bound in `_::{closure#0}::assert_impl_all`
--> tests/ui-msrv/derive_transparent.rs:41:1
|
41 | assert_impl_all!(TransparentStruct<NotZerocopy>: Unaligned);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `_::{closure#0}::assert_impl_all`
= note: this error originates in the macro `assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)
37 changes: 9 additions & 28 deletions zerocopy-derive/tests/ui-msrv/enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -67,54 +67,39 @@ error: TryFromBytes not supported on enum types
| |_^

error: must have a non-align #[repr(...)] attribute in order to guarantee this type's memory layout
<<<<<<< HEAD
--> tests/ui-msrv/enum.rs:42:21
--> tests/ui-msrv/enum.rs:42:35
|
42 | #[derive(FromZeros, FromBytes)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)

error: only C-like enums can implement FromZeros
=======
--> tests/ui-msrv/enum.rs:42:36
|
42 | #[derive(TryFromBytes, FromZeroes, FromBytes)]
| ^^^^^^^^^
42 | #[derive(TryFromBytes, FromZeros, FromBytes)]
| ^^^^^^^^^
|
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)

error: TryFromBytes not supported on enum types
--> tests/ui-msrv/enum.rs:70:1
|
70 | / enum FromZeroes1 {
70 | / enum FromZeros1 {
71 | | A(u8),
72 | | }
| |_^

error: only C-like enums can implement FromZeroes
>>>>>>> [derive] Support `derive(TryFromBytes)` for structs
error: only C-like enums can implement FromZeros
--> tests/ui-msrv/enum.rs:70:1
|
70 | / enum FromZeros1 {
71 | | A(u8),
72 | | }
| |_^

<<<<<<< HEAD
error: only C-like enums can implement FromZeros
=======
error: TryFromBytes not supported on enum types
--> tests/ui-msrv/enum.rs:75:1
|
75 | / enum FromZeroes2 {
75 | / enum FromZeros2 {
76 | | A,
77 | | B(u8),
78 | | }
| |_^

error: only C-like enums can implement FromZeroes
>>>>>>> [derive] Support `derive(TryFromBytes)` for structs
error: only C-like enums can implement FromZeros
--> tests/ui-msrv/enum.rs:75:1
|
75 | / enum FromZeros2 {
Expand All @@ -123,20 +108,16 @@ error: only C-like enums can implement FromZeroes
78 | | }
| |_^

<<<<<<< HEAD
error: FromZeros only supported on enums with a variant that has a discriminant of `0`
=======
error: TryFromBytes not supported on enum types
--> tests/ui-msrv/enum.rs:81:1
|
81 | / enum FromZeroes3 {
81 | / enum FromZeros3 {
82 | | A = 1,
83 | | B,
84 | | }
| |_^

error: FromZeroes only supported on enums with a variant that has a discriminant of `0`
>>>>>>> [derive] Support `derive(TryFromBytes)` for structs
error: FromZeros only supported on enums with a variant that has a discriminant of `0`
--> tests/ui-msrv/enum.rs:81:1
|
81 | / enum FromZeros3 {
Expand Down
9 changes: 2 additions & 7 deletions zerocopy-derive/tests/ui-msrv/late_compile_pass.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ warning: unused import: `zerocopy::KnownLayout`
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
--> tests/ui-msrv/late_compile_pass.rs:28:10
|
<<<<<<< HEAD
28 | #[derive(FromZeros)]
| ^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy`
=======
28 | #[derive(TryFromBytes)]
| ^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
|
Expand All @@ -22,9 +18,8 @@ error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: FromZeroes` is not satisfied
--> tests/ui-msrv/late_compile_pass.rs:37:10
|
37 | #[derive(FromZeroes)]
| ^^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy`
>>>>>>> [derive] Support `derive(TryFromBytes)` for structs
37 | #[derive(FromZeros)]
| ^^^^^^^^^ the trait `FromZeroes` is not implemented for `NotZerocopy`
|
= help: see issue #48214
= note: this error originates in the derive macro `FromZeros` (in Nightly builds, run with -Z macro-backtrace for more info)
Expand Down
2 changes: 1 addition & 1 deletion zerocopy-derive/tests/ui-nightly/derive_transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use core::marker::PhantomData;

use {
static_assertions::assert_impl_all,
zerocopy::{AsBytes, FromBytes, FromZeros, Unaligned},
zerocopy::{AsBytes, FromBytes, FromZeros, TryFromBytes, Unaligned},
};

use self::util::NotZerocopy;
Expand Down

0 comments on commit 0cdf0cb

Please sign in to comment.