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

Parse associated type constraints in dyn trait object types #204

Merged
merged 1 commit 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
4 changes: 4 additions & 0 deletions src/ensure.rs
Expand Up @@ -503,6 +503,10 @@ macro_rules! __parse_ensure {
$crate::__parse_ensure!(arglist $stack $bail ($($fuel)*) {($($buf)* $life) $($parse)*} ($($rest)*) $($rest)*)
};

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

(generic $stack:tt $bail:tt (~$($fuel:tt)*) $parse:tt $dup:tt $($rest:tt)*) => {
$crate::__parse_ensure!(type (arglist $stack) $bail ($($fuel)*) $parse $dup $($rest)*)
};
Expand Down
16 changes: 12 additions & 4 deletions tests/test_ensure.rs
Expand Up @@ -536,13 +536,21 @@ fn test_as() {
"Condition failed: `f as fn() -> ! as usize * 0 != 0` (0 vs 0)",
);

trait EqDebug<T>: PartialEq<T> + Debug {}
impl<S, T> EqDebug<T> for S where S: PartialEq<T> + Debug {}
trait EqDebug<T>: PartialEq<T> + Debug {
type Assoc;
}

impl<S, T> EqDebug<T> for S
where
S: PartialEq<T> + Debug,
{
type Assoc = bool;
}

let test = || Ok(ensure!(&0 as &dyn EqDebug<i32> != &0));
let test = || Ok(ensure!(&0 as &dyn EqDebug<i32, Assoc = bool> != &0));
assert_err(
test,
"Condition failed: `&0 as &dyn EqDebug<i32> != &0` (0 vs 0)",
"Condition failed: `&0 as &dyn EqDebug<i32, Assoc = bool> != &0` (0 vs 0)",
);

let test = || {
Expand Down