File tree 2 files changed +96
-0
lines changed
zerocopy-derive/tests/ui-nightly
2 files changed +96
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2019 The Fuchsia Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #![ feature( trivial_bounds) ]
6
+
7
+ #[ macro_use]
8
+ extern crate zerocopy;
9
+
10
+ #[ path = "../util.rs" ]
11
+ mod util;
12
+
13
+ use self :: util:: { NotZerocopy , AU16 } ;
14
+
15
+ fn main ( ) { }
16
+
17
+ // These tests are compiled with the `trivial_bounds` feature enabled. We emit
18
+ // code which is designed to fail compilation for types we wish to reject.
19
+ // `trivial_bounds` causes some of this code to succeed. These tests exist to
20
+ // ensure that at least *some* emitted code still fails compilation even when
21
+ // `trivial_bounds` is enabled.
22
+
23
+ //
24
+ // FromZeroes errors
25
+ //
26
+
27
+ #[ derive( FromZeroes ) ]
28
+ struct FromZeroes1 {
29
+ value : NotZerocopy ,
30
+ }
31
+
32
+ //
33
+ // FromBytes errors
34
+ //
35
+
36
+ #[ derive( FromBytes ) ]
37
+ struct FromBytes1 {
38
+ value : NotZerocopy ,
39
+ }
40
+
41
+ //
42
+ // AsBytes errors
43
+ //
44
+
45
+ #[ derive( AsBytes ) ]
46
+ #[ repr( C ) ]
47
+ struct AsBytes1 {
48
+ value : NotZerocopy ,
49
+ }
50
+
51
+ //
52
+ // Unaligned errors
53
+ //
54
+
55
+ #[ derive( Unaligned ) ]
56
+ #[ repr( C ) ]
57
+ struct Unaligned1 {
58
+ aligned : AU16 ,
59
+ }
60
+
61
+ // This specifically tests a bug we had in an old version of the code in which
62
+ // the trait bound would only be enforced for the first field's type.
63
+ #[ derive( Unaligned ) ]
64
+ #[ repr( C ) ]
65
+ struct Unaligned2 {
66
+ unaligned : u8 ,
67
+ aligned : AU16 ,
68
+ }
69
+
70
+ #[ derive( Unaligned ) ]
71
+ #[ repr( transparent) ]
72
+ struct Unaligned3 {
73
+ aligned : AU16 ,
74
+ }
Original file line number Diff line number Diff line change
1
+ error[E0277]: the trait bound `FromBytes1: FromZeroes` is not satisfied
2
+ --> tests/ui-nightly/trivial_bounds.rs:36:10
3
+ |
4
+ 36 | #[derive(FromBytes)]
5
+ | ^^^^^^^^^ the trait `FromZeroes` is not implemented for `FromBytes1`
6
+ |
7
+ = help: the following other types implement trait `FromZeroes`:
8
+ bool
9
+ char
10
+ isize
11
+ i8
12
+ i16
13
+ i32
14
+ i64
15
+ i128
16
+ and $N others
17
+ note: required by a bound in `FromBytes`
18
+ --> $WORKSPACE/src/lib.rs
19
+ |
20
+ | pub unsafe trait FromBytes: FromZeroes {
21
+ | ^^^^^^^^^^ required by this bound in `FromBytes`
22
+ = note: this error originates in the derive macro `FromBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
You can’t perform that action at this time.
0 commit comments