From df838ab816f855e18ba27799c4c8f7b5d8f09bd8 Mon Sep 17 00:00:00 2001 From: KodrAus Date: Mon, 16 Aug 2021 14:00:53 +1000 Subject: [PATCH] more work on compile tests --- tests/compile-fail/{derive => impls}/copy.rs | 0 .../{derive => impls}/copy.stderr.beta | 0 tests/compile-fail/{derive => impls}/eq.rs | 0 .../{derive => impls}/eq.stderr.beta | 0 .../non_integer_base/all_defined.stderr.beta | 27 +++++++++++++++++++ .../{missing_copy.rs => all_missing.rs} | 0 .../non_integer_base/all_missing.stderr.beta | 13 +++++++++ .../non_integer_base/missing_bitops.rs | 14 ---------- .../compile-fail/visibility/private_field.rs | 13 +++++++++ .../visibility/private_field.stderr.beta | 10 +++++++ .../{ => visibility}/private_flags.rs | 0 .../private_flags.stderr.beta | 0 tests/compile-fail/visibility/pub_const.rs | 9 +++++++ .../visibility/pub_const.stderr.beta | 5 ++++ tests/compile-pass/impls/convert.rs | 17 ++++++++++++ .../compile-pass/{derive => impls}/default.rs | 0 tests/compile-pass/impls/inherent_methods.rs | 15 +++++++++++ tests/compile-pass/visibility/bits_field.rs | 11 ++++++++ tests/compile-pass/visibility/pub_in.rs | 19 +++++++++++++ 19 files changed, 139 insertions(+), 14 deletions(-) rename tests/compile-fail/{derive => impls}/copy.rs (100%) rename tests/compile-fail/{derive => impls}/copy.stderr.beta (100%) rename tests/compile-fail/{derive => impls}/eq.rs (100%) rename tests/compile-fail/{derive => impls}/eq.stderr.beta (100%) create mode 100644 tests/compile-fail/non_integer_base/all_defined.stderr.beta rename tests/compile-fail/non_integer_base/{missing_copy.rs => all_missing.rs} (100%) create mode 100644 tests/compile-fail/non_integer_base/all_missing.stderr.beta delete mode 100644 tests/compile-fail/non_integer_base/missing_bitops.rs create mode 100644 tests/compile-fail/visibility/private_field.rs create mode 100644 tests/compile-fail/visibility/private_field.stderr.beta rename tests/compile-fail/{ => visibility}/private_flags.rs (100%) rename tests/compile-fail/{ => visibility}/private_flags.stderr.beta (100%) create mode 100644 tests/compile-fail/visibility/pub_const.rs create mode 100644 tests/compile-fail/visibility/pub_const.stderr.beta create mode 100644 tests/compile-pass/impls/convert.rs rename tests/compile-pass/{derive => impls}/default.rs (100%) create mode 100644 tests/compile-pass/impls/inherent_methods.rs create mode 100644 tests/compile-pass/visibility/bits_field.rs create mode 100644 tests/compile-pass/visibility/pub_in.rs diff --git a/tests/compile-fail/derive/copy.rs b/tests/compile-fail/impls/copy.rs similarity index 100% rename from tests/compile-fail/derive/copy.rs rename to tests/compile-fail/impls/copy.rs diff --git a/tests/compile-fail/derive/copy.stderr.beta b/tests/compile-fail/impls/copy.stderr.beta similarity index 100% rename from tests/compile-fail/derive/copy.stderr.beta rename to tests/compile-fail/impls/copy.stderr.beta diff --git a/tests/compile-fail/derive/eq.rs b/tests/compile-fail/impls/eq.rs similarity index 100% rename from tests/compile-fail/derive/eq.rs rename to tests/compile-fail/impls/eq.rs diff --git a/tests/compile-fail/derive/eq.stderr.beta b/tests/compile-fail/impls/eq.stderr.beta similarity index 100% rename from tests/compile-fail/derive/eq.stderr.beta rename to tests/compile-fail/impls/eq.stderr.beta diff --git a/tests/compile-fail/non_integer_base/all_defined.stderr.beta b/tests/compile-fail/non_integer_base/all_defined.stderr.beta new file mode 100644 index 00000000..1f0fb5cf --- /dev/null +++ b/tests/compile-fail/non_integer_base/all_defined.stderr.beta @@ -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) diff --git a/tests/compile-fail/non_integer_base/missing_copy.rs b/tests/compile-fail/non_integer_base/all_missing.rs similarity index 100% rename from tests/compile-fail/non_integer_base/missing_copy.rs rename to tests/compile-fail/non_integer_base/all_missing.rs diff --git a/tests/compile-fail/non_integer_base/all_missing.stderr.beta b/tests/compile-fail/non_integer_base/all_missing.stderr.beta new file mode 100644 index 00000000..ee95f836 --- /dev/null +++ b/tests/compile-fail/non_integer_base/all_missing.stderr.beta @@ -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) diff --git a/tests/compile-fail/non_integer_base/missing_bitops.rs b/tests/compile-fail/non_integer_base/missing_bitops.rs deleted file mode 100644 index 8d6f2288..00000000 --- a/tests/compile-fail/non_integer_base/missing_bitops.rs +++ /dev/null @@ -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() {} diff --git a/tests/compile-fail/visibility/private_field.rs b/tests/compile-fail/visibility/private_field.rs new file mode 100644 index 00000000..a6a3912a --- /dev/null +++ b/tests/compile-fail/visibility/private_field.rs @@ -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; +} diff --git a/tests/compile-fail/visibility/private_field.stderr.beta b/tests/compile-fail/visibility/private_field.stderr.beta new file mode 100644 index 00000000..58a04660 --- /dev/null +++ b/tests/compile-fail/visibility/private_field.stderr.beta @@ -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(); + | ^^ diff --git a/tests/compile-fail/private_flags.rs b/tests/compile-fail/visibility/private_flags.rs similarity index 100% rename from tests/compile-fail/private_flags.rs rename to tests/compile-fail/visibility/private_flags.rs diff --git a/tests/compile-fail/private_flags.stderr.beta b/tests/compile-fail/visibility/private_flags.stderr.beta similarity index 100% rename from tests/compile-fail/private_flags.stderr.beta rename to tests/compile-fail/visibility/private_flags.stderr.beta diff --git a/tests/compile-fail/visibility/pub_const.rs b/tests/compile-fail/visibility/pub_const.rs new file mode 100644 index 00000000..b90f0ce9 --- /dev/null +++ b/tests/compile-fail/visibility/pub_const.rs @@ -0,0 +1,9 @@ +use bitflags::bitflags; + +bitflags! { + pub struct Flags1: u32 { + pub const FLAG_A = 0b00000001; + } +} + +fn main() {} diff --git a/tests/compile-fail/visibility/pub_const.stderr.beta b/tests/compile-fail/visibility/pub_const.stderr.beta new file mode 100644 index 00000000..b01122c7 --- /dev/null +++ b/tests/compile-fail/visibility/pub_const.stderr.beta @@ -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 diff --git a/tests/compile-pass/impls/convert.rs b/tests/compile-pass/impls/convert.rs new file mode 100644 index 00000000..1f02982a --- /dev/null +++ b/tests/compile-pass/impls/convert.rs @@ -0,0 +1,17 @@ +use bitflags::bitflags; + +bitflags! { + struct Flags: u32 { + const A = 0b00000001; + } +} + +impl From for Flags { + fn from(v: u32) -> Flags { + Flags::from_bits_truncate(v) + } +} + +fn main() { + +} diff --git a/tests/compile-pass/derive/default.rs b/tests/compile-pass/impls/default.rs similarity index 100% rename from tests/compile-pass/derive/default.rs rename to tests/compile-pass/impls/default.rs diff --git a/tests/compile-pass/impls/inherent_methods.rs b/tests/compile-pass/impls/inherent_methods.rs new file mode 100644 index 00000000..3052c460 --- /dev/null +++ b/tests/compile-pass/impls/inherent_methods.rs @@ -0,0 +1,15 @@ +use bitflags::bitflags; + +bitflags! { + struct Flags: u32 { + const A = 0b00000001; + } +} + +impl Flags { + pub fn new() -> Flags { + Flags::A + } +} + +fn main() {} diff --git a/tests/compile-pass/visibility/bits_field.rs b/tests/compile-pass/visibility/bits_field.rs new file mode 100644 index 00000000..33a7967e --- /dev/null +++ b/tests/compile-pass/visibility/bits_field.rs @@ -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); +} diff --git a/tests/compile-pass/visibility/pub_in.rs b/tests/compile-pass/visibility/pub_in.rs new file mode 100644 index 00000000..c11050e3 --- /dev/null +++ b/tests/compile-pass/visibility/pub_in.rs @@ -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()); +}