-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[derive] Fix handling of repr(packed)
While we're here, improve error messages and add tests for deriving `IntoBytes` on unions. Closes #1763
- Loading branch information
Showing
12 changed files
with
411 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2024 The Fuchsia Authors | ||
// | ||
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | ||
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | ||
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | ||
// This file may not be copied, modified, or distributed except according to | ||
// those terms. | ||
|
||
// This file contains tests which trigger errors on MSRV during a different | ||
// compiler pass compared to the stable or nightly toolchains. | ||
|
||
#[macro_use] | ||
extern crate zerocopy; | ||
|
||
#[path = "../include.rs"] | ||
mod util; | ||
|
||
use self::util::util::AU16; | ||
use zerocopy::IntoBytes; | ||
|
||
fn main() {} | ||
|
||
// `repr(C, packed(2))` is not equivalent to `repr(C, packed)`. | ||
#[derive(IntoBytes)] | ||
#[repr(C, packed(2))] | ||
struct IntoBytes1<T> { | ||
t0: T, | ||
// Add a second field to avoid triggering the "repr(C) struct with one | ||
// field" special case. | ||
t1: T, | ||
} | ||
|
||
fn is_into_bytes_1<T: IntoBytes>() { | ||
if false { | ||
is_into_bytes_1::<IntoBytes1<AU16>>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
warning: unused `#[macro_use]` import | ||
--> tests/ui-msrv/msrv_specific.rs:12:1 | ||
| | ||
12 | #[macro_use] | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(unused_imports)]` on by default | ||
|
||
error[E0277]: the trait bound `AU16: Unaligned` is not satisfied | ||
--> tests/ui-msrv/msrv_specific.rs:35:9 | ||
| | ||
35 | is_into_bytes_1::<IntoBytes1<AU16>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Unaligned` is not implemented for `AU16` | ||
| | ||
note: required because of the requirements on the impl of `zerocopy::IntoBytes` for `IntoBytes1<AU16>` | ||
--> tests/ui-msrv/msrv_specific.rs:24:10 | ||
| | ||
24 | #[derive(IntoBytes)] | ||
| ^^^^^^^^^ | ||
note: required by a bound in `is_into_bytes_1` | ||
--> tests/ui-msrv/msrv_specific.rs:33:23 | ||
| | ||
33 | fn is_into_bytes_1<T: IntoBytes>() { | ||
| ^^^^^^^^^ required by this bound in `is_into_bytes_1` | ||
= note: this error originates in the derive macro `IntoBytes` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.