-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[derive] Test with trivial_bounds feature
The nightly `trivial_bounds` causes some derive-emitted code to compile which is designed to fail compilation. This commit adds a test that ensures that the emitted code still triggers some compiler errors. Affects #61 Closes #500
- Loading branch information
Showing
2 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,74 @@ | ||
// 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. | ||
|
||
#![feature(trivial_bounds)] | ||
|
||
#[macro_use] | ||
extern crate zerocopy; | ||
|
||
#[path = "../util.rs"] | ||
mod util; | ||
|
||
use self::util::{NotZerocopy, AU16}; | ||
|
||
fn main() {} | ||
|
||
// These tests are compiled with the `trivial_bounds` feature enabled. We emit | ||
// code which is designed to fail compilation for types we wish to reject. | ||
// `trivial_bounds` causes some of this code to succeed. These tests exist to | ||
// ensure that at least *some* emitted code still fails compilation even when | ||
// `trivial_bounds` is enabled. | ||
|
||
// | ||
// FromZeroes errors | ||
// | ||
|
||
#[derive(FromZeroes)] | ||
struct FromZeroes1 { | ||
value: NotZerocopy, | ||
} | ||
|
||
// | ||
// FromBytes errors | ||
// | ||
|
||
#[derive(FromBytes)] | ||
struct FromBytes1 { | ||
value: NotZerocopy, | ||
} | ||
|
||
// | ||
// AsBytes errors | ||
// | ||
|
||
#[derive(AsBytes)] | ||
#[repr(C)] | ||
struct AsBytes1 { | ||
value: NotZerocopy, | ||
} | ||
|
||
// | ||
// Unaligned errors | ||
// | ||
|
||
#[derive(Unaligned)] | ||
#[repr(C)] | ||
struct Unaligned1 { | ||
aligned: AU16, | ||
} | ||
|
||
// This specifically tests a bug we had in an old version of the code in which | ||
// the trait bound would only be enforced for the first field's type. | ||
#[derive(Unaligned)] | ||
#[repr(C)] | ||
struct Unaligned2 { | ||
unaligned: u8, | ||
aligned: AU16, | ||
} | ||
|
||
#[derive(Unaligned)] | ||
#[repr(transparent)] | ||
struct Unaligned3 { | ||
aligned: 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,22 @@ | ||
error[E0277]: the trait bound `FromBytes1: FromZeroes` is not satisfied | ||
--> tests/ui-nightly/trivial_bounds.rs:36:10 | ||
| | ||
36 | #[derive(FromBytes)] | ||
| ^^^^^^^^^ the trait `FromZeroes` is not implemented for `FromBytes1` | ||
| | ||
= help: the following other types implement trait `FromZeroes`: | ||
bool | ||
char | ||
isize | ||
i8 | ||
i16 | ||
i32 | ||
i64 | ||
i128 | ||
and $N others | ||
note: required by a bound in `FromBytes` | ||
--> $WORKSPACE/src/lib.rs | ||
| | ||
| pub unsafe trait FromBytes: FromZeroes { | ||
| ^^^^^^^^^^ required by this bound in `FromBytes` | ||
= note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info) |