Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle parsing unseparated right angle brackets in generics #199

Merged
merged 3 commits into from Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/ensure.rs
Expand Up @@ -319,6 +319,10 @@ macro_rules! __parse_ensure {
$crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $rangle) $($parse)*} ($($rest)*) $($rest)*)
};

(generic ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt >> $($rest:tt)*) => {
$crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* >) $($parse)*} (> $($rest)*) > $($rest)*)
};

(generic $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt $lit:literal $($rest:tt)*) => {
$crate::__parse_ensure!(arglist $stack $bail ($($fuel)*) {($($buf)* $lit) $($parse)*} ($($rest)*) $($rest)*)
};
Expand All @@ -339,6 +343,10 @@ macro_rules! __parse_ensure {
$crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $ty >) $($parse)*} ($($rest)*) $($rest)*)
};

(generic ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt $ty:ty >> $($rest:tt)*) => {
$crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $ty >) $($parse)*} (> $($rest)*) > $($rest)*)
};

(arglist $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($comma:tt $($dup:tt)*) , $($rest:tt)*) => {
$crate::__parse_ensure!(generic $stack $bail ($($fuel)*) {($($buf)* $comma) $($parse)*} ($($rest)*) $($rest)*)
};
Expand All @@ -347,6 +355,10 @@ macro_rules! __parse_ensure {
$crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* $rangle) $($parse)*} ($($rest)*) $($rest)*)
};

(arglist ($pop:ident $stack:tt) $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt >> $($rest:tt)*) => {
$crate::__parse_ensure!($pop $stack $bail ($($fuel)*) {($($buf)* >) $($parse)*} (> $($rest)*) > $($rest)*)
};

// high precedence binary operators

(atom $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($add:tt $($dup:tt)*) + $($rest:tt)*) => {
Expand Down
20 changes: 20 additions & 0 deletions tests/test_ensure.rs
Expand Up @@ -2,6 +2,7 @@
clippy::diverging_sub_expression,
clippy::if_same_then_else,
clippy::ifs_same_cond,
clippy::items_after_statements,
clippy::let_and_return,
clippy::let_underscore_drop,
clippy::match_bool,
Expand Down Expand Up @@ -319,6 +320,25 @@ fn test_path() {
test,
"Condition failed: `Chain::<'static>::new.t(1) == 2` (1 vs 2)",
);

#[derive(PartialOrd, PartialEq, Debug)]
enum E<'a, T> {
#[allow(dead_code)]
T(&'a T),
U,
}

#[rustfmt::skip]
let test = || Ok(ensure!(E::U::<>>E::U::<u8>));
assert_err(test, "Condition failed: `E::U::<> > E::U::<u8>` (U vs U)");

#[rustfmt::skip]
let test = || Ok(ensure!(E::U::<u8>>E::U));
assert_err(test, "Condition failed: `E::U::<u8> > E::U` (U vs U)");

#[rustfmt::skip]
let test = || Ok(ensure!(E::U::<u8,>>E::U));
assert_err(test, "Condition failed: `E::U::<u8> > E::U` (U vs U)");
}

#[test]
Expand Down