Skip to content

Commit

Permalink
Merge pull request #199 from dtolnay/bracket
Browse files Browse the repository at this point in the history
Handle parsing unseparated right angle brackets in generics
  • Loading branch information
dtolnay committed Nov 27, 2021
2 parents a5a98e0 + fa70762 commit 3f33b89
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
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

0 comments on commit 3f33b89

Please sign in to comment.