Skip to content

Commit

Permalink
Change &&/|| to &/| in assert_impl!
Browse files Browse the repository at this point in the history
  • Loading branch information
nvzqz committed Dec 30, 2019
1 parent 59a2335 commit 26090f2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
48 changes: 24 additions & 24 deletions src/assert_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ macro_rules! assert_impl_one {
#[macro_export(local_inner_macros)]
macro_rules! assert_impl_all {
($ty:ty: $($traits:path),+ $(,)?) => {
assert_impl!($ty: $( ($traits) )&&+);
assert_impl!($ty: $( ($traits) )&+);
};
}

Expand Down Expand Up @@ -152,7 +152,7 @@ macro_rules! assert_impl_all {
#[macro_export(local_inner_macros)]
macro_rules! assert_impl_any {
($ty:ty: $($traits:path),+ $(,)?) => {
assert_impl!($ty: $( ($traits) )||+);
assert_impl!($ty: $( ($traits) )|+);
};
}

Expand Down Expand Up @@ -207,7 +207,7 @@ macro_rules! assert_impl_any {
#[macro_export(local_inner_macros)]
macro_rules! assert_not_impl_all {
($ty:ty: $($traits:path),+ $(,)?) => {
assert_impl!($ty: !( $( ($traits) )&&+ ));
assert_impl!($ty: !( $( ($traits) )&+ ));
};
}

Expand Down Expand Up @@ -253,7 +253,7 @@ macro_rules! assert_not_impl_all {
#[macro_export(local_inner_macros)]
macro_rules! assert_not_impl_any {
($ty:ty: $($traits:path),+ $(,)?) => {
assert_impl!($ty: !( $( ($traits) )||+ ));
assert_impl!($ty: !( $( ($traits) )|+ ));
};
}

Expand All @@ -272,14 +272,14 @@ macro_rules! assert_not_impl_any {
/// where
/// - `<type>` is a type (that must not depend on a generic parameter)
/// - `<trait_expr>` is an expression made out of trait names, combined with
/// `!` for negation, `&&` for conjunction, `||` for disjunction and
/// `!` for negation, `&` for conjunction, `|` for disjunction and
/// parentheses for grouping.
/// - `<bounds>` is a trait bounds expression.
///
/// For technical reasons, traits like `Into<u8>` that are not a single identifier
/// must be surrounded by parentheses.
/// Note also that the usual operator priority is not respected: `x && y || z` is
/// parsed as `x && (y || z)`
/// Note also that the usual operator priority is not respected: `x & y | z` is
/// parsed as `x & (y | z)`
///
/// # Examples
///
Expand All @@ -288,7 +288,7 @@ macro_rules! assert_not_impl_any {
///
/// ```
/// # #[macro_use] extern crate static_assertions; fn main() {}
/// assert_impl!(u32: !((Into<usize>) && (Into<u8>)));
/// assert_impl!(u32: !((Into<usize>) & (Into<u8>)));
/// ```
///
/// Check that a type is [`Send`] bit not [`Sync`].
Expand All @@ -297,7 +297,7 @@ macro_rules! assert_not_impl_any {
/// # #[macro_use] extern crate static_assertions; fn main() {}
/// # struct Cell<T>(*mut T);
/// # unsafe impl<T> Send for Cell<T> {}
/// assert_impl!(Cell<u32>: Send && !Sync);
/// assert_impl!(Cell<u32>: Send & !Sync);
/// ```
///
/// This is also good for simple one-off cases:
Expand All @@ -320,7 +320,7 @@ macro_rules! assert_not_impl_any {
///
/// ```compile_fail
/// # #[macro_use] extern crate static_assertions; fn main() {}
/// assert_impl!(u64: (Into<u32>) || (Into<u16>));
/// assert_impl!(u64: (Into<u32>) | (Into<u16>));
/// ```
///
/// [`Send`]: https://doc.rust-lang.org/std/marker/trait.Send.html
Expand Down Expand Up @@ -358,33 +358,33 @@ macro_rules! _does_impl {
(@boolexpr($($args:tt)*) !($($expr:tt)*)) => {
_does_impl!(@boolexpr($($args)*) $($expr)*).not()
};
(@boolexpr($($args:tt)*) ($($left:tt)*) || $($right:tt)*) => {{
(@boolexpr($($args:tt)*) ($($left:tt)*) | $($right:tt)*) => {{
let left = _does_impl!(@boolexpr($($args)*) $($left)*);
let right = _does_impl!(@boolexpr($($args)*) $($right)*);
left.or(right)
}};
(@boolexpr($($args:tt)*) ($($left:tt)*) && $($right:tt)*) => {{
(@boolexpr($($args:tt)*) ($($left:tt)*) & $($right:tt)*) => {{
let left = _does_impl!(@boolexpr($($args)*) $($left)*);
let right = _does_impl!(@boolexpr($($args)*) $($right)*);
left.and(right)
}};
(@boolexpr($($args:tt)*) !($($left:tt)*) || $($right:tt)*) => {{
_does_impl!(@boolexpr($($args)*) (!($($left)*)) || $($right)*)
(@boolexpr($($args:tt)*) !($($left:tt)*) | $($right:tt)*) => {{
_does_impl!(@boolexpr($($args)*) (!($($left)*)) | $($right)*)
}};
(@boolexpr($($args:tt)*) !($($left:tt)*) && $($right:tt)*) => {{
_does_impl!(@boolexpr($($args)*) (!($($left)*)) && $($right)*)
(@boolexpr($($args:tt)*) !($($left:tt)*) & $($right:tt)*) => {{
_does_impl!(@boolexpr($($args)*) (!($($left)*)) & $($right)*)
}};
(@boolexpr($($args:tt)*) !$left:ident || $($right:tt)*) => {{
_does_impl!(@boolexpr($($args)*) !($left) || $($right)*)
(@boolexpr($($args:tt)*) !$left:ident | $($right:tt)*) => {{
_does_impl!(@boolexpr($($args)*) !($left) | $($right)*)
}};
(@boolexpr($($args:tt)*) !$left:ident && $($right:tt)*) => {{
_does_impl!(@boolexpr($($args)*) !($left) && $($right)*)
(@boolexpr($($args:tt)*) !$left:ident & $($right:tt)*) => {{
_does_impl!(@boolexpr($($args)*) !($left) & $($right)*)
}};
(@boolexpr($($args:tt)*) $left:ident || $($right:tt)*) => {
_does_impl!(@boolexpr($($args)*) ($left) || $($right)*)
(@boolexpr($($args:tt)*) $left:ident | $($right:tt)*) => {
_does_impl!(@boolexpr($($args)*) ($left) | $($right)*)
};
(@boolexpr($($args:tt)*) $left:ident && $($right:tt)*) => {{
_does_impl!(@boolexpr($($args)*) ($left) && $($right)*)
(@boolexpr($($args:tt)*) $left:ident & $($right:tt)*) => {{
_does_impl!(@boolexpr($($args)*) ($left) & $($right)*)
}};
(@boolexpr($($args:tt)*) !$expr:ident) => {
_does_impl!(@boolexpr($($args)*) !($expr))
Expand Down
4 changes: 2 additions & 2 deletions src/assert_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#[macro_export(local_inner_macros)]
macro_rules! assert_trait_sub_all {
($sub:path: $($super:path),+ $(,)?) => {
assert_impl!(for(T: $sub) T: $( ($super) )&&+);
assert_impl!(for(T: $sub) T: $( ($super) )&+);
};
}

Expand Down Expand Up @@ -134,6 +134,6 @@ macro_rules! assert_trait_super_all {
#[macro_export(local_inner_macros)]
macro_rules! assert_trait_sub_any {
($sub:path: $($super:path),+ $(,)?) => {
assert_impl!(for(T: $sub) T: $( ($super) )||+);
assert_impl!(for(T: $sub) T: $( ($super) )|+);
};
}
30 changes: 15 additions & 15 deletions tests/trait_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,26 @@ assert_impl_one!(Foo: C, A, B);
#[derive(Clone)]
struct Test;

assert_impl!(u8: (From<u16>) || (Into<u16>));
assert_impl!((): (From<u8>) || (From<u16>) || Send);
assert_impl!((): (!From<u8>) && !(From<u16>) && Send);
assert_impl!((): Copy || Clone);
assert_impl!((): Copy && Clone);
assert_impl!(Test: Copy || Clone);
assert_impl!(Test: !Copy || Clone);
assert_impl!(Test: !Copy && Clone);
assert_impl!(Test: !Copy && (Clone));
assert_impl!(Test: !(Copy) && Clone);
assert_impl!(u8: (From<u16>) | (Into<u16>));
assert_impl!((): (From<u8>) | (From<u16>) | Send);
assert_impl!((): (!From<u8>) & !(From<u16>) & Send);
assert_impl!((): Copy | Clone);
assert_impl!((): Copy & Clone);
assert_impl!(Test: Copy | Clone);
assert_impl!(Test: !Copy | Clone);
assert_impl!(Test: !Copy & Clone);
assert_impl!(Test: !Copy & (Clone));
assert_impl!(Test: !(Copy) & Clone);
assert_impl!(Test: !(!Clone));
assert_impl!(Test: !(Copy) && !(!Clone));
assert_impl!(Test: !(Copy && Clone));
assert_impl!(str: !Copy && !Clone);
assert_impl!(Test: !(Copy) & !(!Clone));
assert_impl!(Test: !(Copy & Clone));
assert_impl!(str: !Copy & !Clone);

#[derive(Clone)]
struct Box<T>(T);

assert_impl!(for(T: Clone) Box<T>: Clone);
assert_impl!(for(T: Clone + Send) Box<T>: Clone && Send);
assert_impl!(for(T: Clone + Send) Box<T>: Clone & Send);
assert_impl!(for(T) PhantomData<T>: Clone);
assert_impl!(for(T: Copy) T: Clone);
assert_impl!(for(T: ?Sized) T: Clone || !Clone);
assert_impl!(for(T: ?Sized) T: Clone | !Clone);

0 comments on commit 26090f2

Please sign in to comment.