summaryrefslogtreecommitdiffstats
path: root/vendor/bitflags/tests/compile-fail/non_integer_base
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/bitflags/tests/compile-fail/non_integer_base')
-rw-r--r--vendor/bitflags/tests/compile-fail/non_integer_base/all_defined.rs123
-rw-r--r--vendor/bitflags/tests/compile-fail/non_integer_base/all_defined.stderr.beta27
-rw-r--r--vendor/bitflags/tests/compile-fail/non_integer_base/all_missing.rs13
-rw-r--r--vendor/bitflags/tests/compile-fail/non_integer_base/all_missing.stderr.beta13
4 files changed, 176 insertions, 0 deletions
diff --git a/vendor/bitflags/tests/compile-fail/non_integer_base/all_defined.rs b/vendor/bitflags/tests/compile-fail/non_integer_base/all_defined.rs
new file mode 100644
index 000000000..c2856b108
--- /dev/null
+++ b/vendor/bitflags/tests/compile-fail/non_integer_base/all_defined.rs
@@ -0,0 +1,123 @@
+use std::{
+ fmt::{
+ self,
+ Debug,
+ Display,
+ LowerHex,
+ UpperHex,
+ Octal,
+ Binary,
+ },
+ ops::{
+ BitAnd,
+ BitOr,
+ BitXor,
+ BitAndAssign,
+ BitOrAssign,
+ BitXorAssign,
+ Not,
+ },
+};
+
+use bitflags::bitflags;
+
+// Ideally we'd actually want this to work, but currently need something like `num`'s `Zero`
+// With some design work it could be made possible
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+struct MyInt(u8);
+
+impl BitAnd for MyInt {
+ type Output = Self;
+
+ fn bitand(self, other: Self) -> Self {
+ MyInt(self.0 & other.0)
+ }
+}
+
+impl BitOr for MyInt {
+ type Output = Self;
+
+ fn bitor(self, other: Self) -> Self {
+ MyInt(self.0 | other.0)
+ }
+}
+
+impl BitXor for MyInt {
+ type Output = Self;
+
+ fn bitxor(self, other: Self) -> Self {
+ MyInt(self.0 ^ other.0)
+ }
+}
+
+impl BitAndAssign for MyInt {
+ fn bitand_assign(&mut self, other: Self) {
+ self.0 &= other.0
+ }
+}
+
+impl BitOrAssign for MyInt {
+ fn bitor_assign(&mut self, other: Self) {
+ self.0 |= other.0
+ }
+}
+
+impl BitXorAssign for MyInt {
+ fn bitxor_assign(&mut self, other: Self) {
+ self.0 ^= other.0
+ }
+}
+
+impl Debug for MyInt {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ Debug::fmt(&self.0, f)
+ }
+}
+
+impl Display for MyInt {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ Display::fmt(&self.0, f)
+ }
+}
+
+impl LowerHex for MyInt {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ LowerHex::fmt(&self.0, f)
+ }
+}
+
+impl UpperHex for MyInt {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ UpperHex::fmt(&self.0, f)
+ }
+}
+
+impl Octal for MyInt {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ Octal::fmt(&self.0, f)
+ }
+}
+
+impl Binary for MyInt {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ Binary::fmt(&self.0, f)
+ }
+}
+
+impl Not for MyInt {
+ type Output = MyInt;
+
+ fn not(self) -> Self {
+ MyInt(!self.0)
+ }
+}
+
+bitflags! {
+ struct Flags128: MyInt {
+ const A = MyInt(0b0000_0001u8);
+ const B = MyInt(0b0000_0010u8);
+ const C = MyInt(0b0000_0100u8);
+ }
+}
+
+fn main() {}
diff --git a/vendor/bitflags/tests/compile-fail/non_integer_base/all_defined.stderr.beta b/vendor/bitflags/tests/compile-fail/non_integer_base/all_defined.stderr.beta
new file mode 100644
index 000000000..1f0fb5cf7
--- /dev/null
+++ b/vendor/bitflags/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/vendor/bitflags/tests/compile-fail/non_integer_base/all_missing.rs b/vendor/bitflags/tests/compile-fail/non_integer_base/all_missing.rs
new file mode 100644
index 000000000..fff6b2cc1
--- /dev/null
+++ b/vendor/bitflags/tests/compile-fail/non_integer_base/all_missing.rs
@@ -0,0 +1,13 @@
+use bitflags::bitflags;
+
+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/vendor/bitflags/tests/compile-fail/non_integer_base/all_missing.stderr.beta b/vendor/bitflags/tests/compile-fail/non_integer_base/all_missing.stderr.beta
new file mode 100644
index 000000000..ee95f8365
--- /dev/null
+++ b/vendor/bitflags/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)