forked from google/zerocopy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Inline Size Assertion Annotations
Implem the procedural macro `inline_assert_size_eq` to check the size of a type at compile time. Additionally, add the test file `inline_assert_size_eq_failed.rs` to ensure that the macro tirggers a compile-time error when the size is not as expected Fixes google#1329
- Loading branch information
Showing
5 changed files
with
96 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![allow(unused)] | ||
extern crate zerocopy_derive; | ||
extern crate static_assertions; | ||
use zerocopy_derive::*; | ||
use static_assertions; | ||
|
||
#[zerocopy_derive::inline_assert_size_eq(1)] | ||
struct test_size_neq_struct { | ||
i: i8, | ||
} |
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,24 @@ | ||
error[E0254]: the name `static_assertions` is defined multiple times | ||
--> tests/ui-stable/inline_assert_size_eq_failed.rs:5:5 | ||
| | ||
3 | extern crate static_assertions; | ||
| ------------------------------- previous import of the extern crate `static_assertions` here | ||
4 | use zerocopy_derive::*; | ||
5 | use static_assertions; | ||
| ^^^^^^^^^^^^^^^^^ `static_assertions` reimported here | ||
| | ||
= note: `static_assertions` must be defined only once in the type namespace of this module | ||
|
||
warning: type `test_size_neq_struct` should have an upper camel case name | ||
--> tests/ui-stable/inline_assert_size_eq_failed.rs:8:8 | ||
| | ||
8 | struct test_size_neq_struct { | ||
| ^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to upper camel case: `TestSizeNeqStruct` | ||
| | ||
= note: `#[warn(non_camel_case_types)]` on by default | ||
|
||
error[E0601]: `main` function not found in crate `$CRATE` | ||
--> tests/ui-stable/inline_assert_size_eq_failed.rs:10:2 | ||
| | ||
10 | } | ||
| ^ consider adding a `main` function to `$DIR/tests/ui-stable/inline_assert_size_eq_failed.rs` |
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 @@ | ||
../ui-nightly/inline_assert_size_eq_failed.rs |
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,24 @@ | ||
error[E0254]: the name `static_assertions` is defined multiple times | ||
--> tests/ui-stable/inline_assert_size_eq_failed.rs:5:5 | ||
| | ||
3 | extern crate static_assertions; | ||
| ------------------------------- previous import of the extern crate `static_assertions` here | ||
4 | use zerocopy_derive::*; | ||
5 | use static_assertions; | ||
| ^^^^^^^^^^^^^^^^^ `static_assertions` reimported here | ||
| | ||
= note: `static_assertions` must be defined only once in the type namespace of this module | ||
|
||
warning: type `test_size_neq_struct` should have an upper camel case name | ||
--> tests/ui-stable/inline_assert_size_eq_failed.rs:8:8 | ||
| | ||
8 | struct test_size_neq_struct { | ||
| ^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to upper camel case: `TestSizeNeqStruct` | ||
| | ||
= note: `#[warn(non_camel_case_types)]` on by default | ||
|
||
error[E0601]: `main` function not found in crate `$CRATE` | ||
--> tests/ui-stable/inline_assert_size_eq_failed.rs:10:2 | ||
| | ||
10 | } | ||
| ^ consider adding a `main` function to `$DIR/tests/ui-stable/inline_assert_size_eq_failed.rs` |
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