mirror of
https://gitee.com/openharmony/third_party_rust_bitflags
synced 2024-11-23 07:10:11 +00:00
Merge pull request #257 from KodrAus/chore/more-compile-tests
More work on compile tests
This commit is contained in:
commit
ac957a5876
27
tests/compile-fail/non_integer_base/all_defined.stderr.beta
Normal file
27
tests/compile-fail/non_integer_base/all_defined.stderr.beta
Normal file
@ -0,0 +1,27 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/all_defined.rs:115:1
|
||||
|
|
||||
115 | / bitflags! {
|
||||
116 | | struct Flags128: MyInt {
|
||||
117 | | const A = MyInt(0b0000_0001u8);
|
||||
118 | | const B = MyInt(0b0000_0010u8);
|
||||
119 | | const C = MyInt(0b0000_0100u8);
|
||||
120 | | }
|
||||
121 | | }
|
||||
| |_^ expected struct `MyInt`, found integer
|
||||
|
|
||||
= note: this error originates in the macro `__impl_all_bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/all_defined.rs:115:1
|
||||
|
|
||||
115 | / bitflags! {
|
||||
116 | | struct Flags128: MyInt {
|
||||
117 | | const A = MyInt(0b0000_0001u8);
|
||||
118 | | const B = MyInt(0b0000_0010u8);
|
||||
119 | | const C = MyInt(0b0000_0100u8);
|
||||
120 | | }
|
||||
121 | | }
|
||||
| |_^ expected struct `MyInt`, found integer
|
||||
|
|
||||
= note: this error originates in the macro `__impl_bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)
|
13
tests/compile-fail/non_integer_base/all_missing.stderr.beta
Normal file
13
tests/compile-fail/non_integer_base/all_missing.stderr.beta
Normal file
@ -0,0 +1,13 @@
|
||||
error[E0204]: the trait `Copy` may not be implemented for this type
|
||||
--> $DIR/all_missing.rs:5:1
|
||||
|
|
||||
5 | / bitflags! {
|
||||
6 | | struct Flags128: MyInt {
|
||||
7 | | const A = MyInt(0b0000_0001);
|
||||
8 | | const B = MyInt(0b0000_0010);
|
||||
9 | | const C = MyInt(0b0000_0100);
|
||||
10 | | }
|
||||
11 | | }
|
||||
| |_^ this field does not implement `Copy`
|
||||
|
|
||||
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
@ -1,14 +0,0 @@
|
||||
use bitflags::bitflags;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct MyInt(u8);
|
||||
|
||||
bitflags! {
|
||||
struct Flags128: MyInt {
|
||||
const A = MyInt(0b0000_0001);
|
||||
const B = MyInt(0b0000_0010);
|
||||
const C = MyInt(0b0000_0100);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
13
tests/compile-fail/visibility/private_field.rs
Normal file
13
tests/compile-fail/visibility/private_field.rs
Normal file
@ -0,0 +1,13 @@
|
||||
mod example {
|
||||
use bitflags::bitflags;
|
||||
|
||||
bitflags! {
|
||||
pub struct Flags1: u32 {
|
||||
const FLAG_A = 0b00000001;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let flag1 = example::Flags1::FLAG_A.bits;
|
||||
}
|
10
tests/compile-fail/visibility/private_field.stderr.beta
Normal file
10
tests/compile-fail/visibility/private_field.stderr.beta
Normal file
@ -0,0 +1,10 @@
|
||||
error[E0616]: field `bits` of struct `Flags1` is private
|
||||
--> $DIR/private_field.rs:12:41
|
||||
|
|
||||
12 | let flag1 = example::Flags1::FLAG_A.bits;
|
||||
| ^^^^ private field
|
||||
|
|
||||
help: a method `bits` also exists, call it with parentheses
|
||||
|
|
||||
12 | let flag1 = example::Flags1::FLAG_A.bits();
|
||||
| ^^
|
9
tests/compile-fail/visibility/pub_const.rs
Normal file
9
tests/compile-fail/visibility/pub_const.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use bitflags::bitflags;
|
||||
|
||||
bitflags! {
|
||||
pub struct Flags1: u32 {
|
||||
pub const FLAG_A = 0b00000001;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
5
tests/compile-fail/visibility/pub_const.stderr.beta
Normal file
5
tests/compile-fail/visibility/pub_const.stderr.beta
Normal file
@ -0,0 +1,5 @@
|
||||
error: no rules expected the token `pub`
|
||||
--> $DIR/pub_const.rs:5:9
|
||||
|
|
||||
5 | pub const FLAG_A = 0b00000001;
|
||||
| ^^^ no rules expected this token in macro call
|
17
tests/compile-pass/impls/convert.rs
Normal file
17
tests/compile-pass/impls/convert.rs
Normal file
@ -0,0 +1,17 @@
|
||||
use bitflags::bitflags;
|
||||
|
||||
bitflags! {
|
||||
struct Flags: u32 {
|
||||
const A = 0b00000001;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for Flags {
|
||||
fn from(v: u32) -> Flags {
|
||||
Flags::from_bits_truncate(v)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
15
tests/compile-pass/impls/inherent_methods.rs
Normal file
15
tests/compile-pass/impls/inherent_methods.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use bitflags::bitflags;
|
||||
|
||||
bitflags! {
|
||||
struct Flags: u32 {
|
||||
const A = 0b00000001;
|
||||
}
|
||||
}
|
||||
|
||||
impl Flags {
|
||||
pub fn new() -> Flags {
|
||||
Flags::A
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
11
tests/compile-pass/visibility/bits_field.rs
Normal file
11
tests/compile-pass/visibility/bits_field.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use bitflags::bitflags;
|
||||
|
||||
bitflags! {
|
||||
pub struct Flags1: u32 {
|
||||
const FLAG_A = 0b00000001;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(0b00000001, Flags1::FLAG_A.bits);
|
||||
}
|
19
tests/compile-pass/visibility/pub_in.rs
Normal file
19
tests/compile-pass/visibility/pub_in.rs
Normal file
@ -0,0 +1,19 @@
|
||||
mod a {
|
||||
mod b {
|
||||
use bitflags::bitflags;
|
||||
|
||||
bitflags! {
|
||||
pub(in crate::a) struct Flags: u32 {
|
||||
const FLAG_A = 0b00000001;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn flags() -> u32 {
|
||||
b::Flags::FLAG_A.bits()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(0b00000001, a::flags());
|
||||
}
|
Loading…
Reference in New Issue
Block a user