Skip to content

Commit

Permalink
Parse trait bounds containing associated constant constraint
Browse files Browse the repository at this point in the history
Closes #1138.
  • Loading branch information
dtolnay committed Mar 14, 2022
1 parent 6fc1da9 commit 99560af
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
33 changes: 32 additions & 1 deletion src/path.rs
Expand Up @@ -231,7 +231,38 @@ pub mod parsing {
}

if input.peek(Ident) && input.peek2(Token![=]) {
return Ok(GenericArgument::Binding(input.parse()?));
let ident: Ident = input.parse()?;
let eq_token: Token![=] = input.parse()?;

let ty = if input.peek(Lit) {
let begin = input.fork();
input.parse::<Lit>()?;
Type::Verbatim(verbatim::between(begin, input))
} else if input.peek(token::Brace) {
let begin = input.fork();

#[cfg(feature = "full")]
{
input.parse::<ExprBlock>()?;
}

#[cfg(not(feature = "full"))]
{
let content;
braced!(content in input);
content.parse::<Expr>()?;
}

Type::Verbatim(verbatim::between(begin, input))
} else {
input.parse()?
};

return Ok(GenericArgument::Binding(Binding {
ident,
eq_token,
ty,
}));
}

#[cfg(feature = "full")]
Expand Down
5 changes: 0 additions & 5 deletions tests/repo/mod.rs
Expand Up @@ -14,11 +14,6 @@ const REVISION: &str = "e95b10ba4ac4564ed25f7eef143e3182c33b3902";

#[rustfmt::skip]
static EXCLUDE: &[&str] = &[
// TODO: trait bound with associated constant constraint:
// where T: Trait<N = 3usize>
// https://github.com/dtolnay/syn/issues/1138
"src/test/ui/associated-consts/assoc-const.rs",

// TODO: trailing where-clause on impl associated type:
// impl<T> Trait for Ty<T> { type Assoc<'a> = T where T: 'a; }
// https://github.com/dtolnay/syn/issues/1071
Expand Down

0 comments on commit 99560af

Please sign in to comment.