-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make more fns/macros const, update MSRV to 1.61.0
Make more functions and the `transmute!` macro const. This requires updating our MSRV to 1.61.0. While we're doing this, document our MSRV in the crate root and our `README.md`.
- Loading branch information
Showing
13 changed files
with
172 additions
and
19 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
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 |
---|---|---|
@@ -1,9 +1,29 @@ | ||
// Copyright 2022 The Fuchsia Authors. All rights reserved. | ||
// Copyright 2019 The Fuchsia Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// UI tests depend on the exact error messages emitted by rustc, but those error | ||
// messages are not stable, and sometimes change between Rust versions. Thus, we | ||
// maintain one set of UI tests for each Rust version that we test in CI, and we | ||
// pin to specific versions in CI (a specific stable version, a specific date of | ||
// the nightly compiler, and a specific MSRV). Updating those pinned versions | ||
// may also require updating these tests. | ||
// - `tests/ui` - Contains the source of truth for our UI test source files | ||
// (`.rs`), and contains `.err` and `.out` files for nightly and beta | ||
// - `tests/ui-stable` - Contains symlinks to the `.rs` files in `tests/ui`, and | ||
// contains `.err` and `.out` files for stable | ||
// - `tests/ui-msrv` - Contains symlinks to the `.rs` files in `tests/ui`, and | ||
// contains `.err` and `.out` files for MSRV | ||
|
||
#[rustversion::any(nightly, beta)] | ||
const SOURCE_FILES_GLOB: &str = "tests/ui/*.rs"; | ||
#[rustversion::all(stable, not(stable(1.61.0)))] | ||
const SOURCE_FILES_GLOB: &str = "tests/ui-stable/*.rs"; | ||
#[rustversion::stable(1.61.0)] | ||
const SOURCE_FILES_GLOB: &str = "tests/ui-msrv/*.rs"; | ||
|
||
#[test] | ||
fn ui() { | ||
let t = trybuild::TestCases::new(); | ||
t.compile_fail("tests/ui/*.rs"); | ||
t.compile_fail(SOURCE_FILES_GLOB); | ||
} |
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/transmute-illegal.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[E0601]: `main` function not found in crate `$CRATE` | ||
--> tests/ui-msrv/transmute-illegal.rs:8:76 | ||
| | ||
8 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); | ||
| ^ consider adding a `main` function to `$DIR/tests/ui-msrv/transmute-illegal.rs` | ||
|
||
error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied | ||
--> tests/ui-msrv/transmute-illegal.rs:8:30 | ||
| | ||
8 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `*const usize` | ||
| | ||
= help: the following implementations were found: | ||
<usize as AsBytes> | ||
<f32 as AsBytes> | ||
<f64 as AsBytes> | ||
<i128 as AsBytes> | ||
and 10 others | ||
note: required by a bound in `POINTER_VALUE::transmute` | ||
--> tests/ui-msrv/transmute-illegal.rs:8:30 | ||
| | ||
8 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `POINTER_VALUE::transmute` | ||
= note: this error originates in the macro `zerocopy::transmute` (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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../ui/transmute-illegal.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,28 @@ | ||
error[E0601]: `main` function not found in crate `$CRATE` | ||
--> tests/ui-stable/transmute-illegal.rs:8:76 | ||
| | ||
8 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); | ||
| ^ consider adding a `main` function to `$DIR/tests/ui-stable/transmute-illegal.rs` | ||
|
||
error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied | ||
--> tests/ui-stable/transmute-illegal.rs:8:30 | ||
| | ||
8 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsBytes` is not implemented for `*const usize` | ||
| | ||
= help: the following other types implement trait `AsBytes`: | ||
f32 | ||
f64 | ||
i128 | ||
i16 | ||
i32 | ||
i64 | ||
i8 | ||
isize | ||
and 6 others | ||
note: required by a bound in `POINTER_VALUE::transmute` | ||
--> tests/ui-stable/transmute-illegal.rs:8:30 | ||
| | ||
8 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `POINTER_VALUE::transmute` | ||
= note: this error originates in the macro `zerocopy::transmute` (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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright 2022 The Fuchsia Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
extern crate zerocopy; | ||
|
||
// It is unsound to inspect the usize value of a pointer during const eval. | ||
const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); |
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,31 @@ | ||
error[E0601]: `main` function not found in crate `$CRATE` | ||
--> tests/ui/transmute-illegal.rs:8:76 | ||
| | ||
8 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); | ||
| ^ consider adding a `main` function to `$DIR/tests/ui/transmute-illegal.rs` | ||
|
||
error[E0277]: the trait bound `*const usize: AsBytes` is not satisfied | ||
--> tests/ui/transmute-illegal.rs:8:30 | ||
| | ||
8 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| the trait `AsBytes` is not implemented for `*const usize` | ||
| required by a bound introduced by this call | ||
| | ||
= help: the following other types implement trait `AsBytes`: | ||
f32 | ||
f64 | ||
i128 | ||
i16 | ||
i32 | ||
i64 | ||
i8 | ||
isize | ||
and 6 others | ||
note: required by a bound in `POINTER_VALUE::transmute` | ||
--> tests/ui/transmute-illegal.rs:8:30 | ||
| | ||
8 | const POINTER_VALUE: usize = zerocopy::transmute!(&0usize as *const usize); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `POINTER_VALUE::transmute` | ||
= note: this error originates in the macro `zerocopy::transmute` (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