From 99560af0e7cac51c6482c56c89246bbbba3fdb33 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 13 Mar 2022 21:35:45 -0700 Subject: [PATCH] Parse trait bounds containing associated constant constraint Closes #1138. --- src/path.rs | 33 ++++++++++++++++++++++++++++++++- tests/repo/mod.rs | 5 ----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/path.rs b/src/path.rs index 48673177a3..3429a8537b 100644 --- a/src/path.rs +++ b/src/path.rs @@ -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::()?; + Type::Verbatim(verbatim::between(begin, input)) + } else if input.peek(token::Brace) { + let begin = input.fork(); + + #[cfg(feature = "full")] + { + input.parse::()?; + } + + #[cfg(not(feature = "full"))] + { + let content; + braced!(content in input); + content.parse::()?; + } + + Type::Verbatim(verbatim::between(begin, input)) + } else { + input.parse()? + }; + + return Ok(GenericArgument::Binding(Binding { + ident, + eq_token, + ty, + })); } #[cfg(feature = "full")] diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs index 9266d7705c..37f6e018d4 100644 --- a/tests/repo/mod.rs +++ b/tests/repo/mod.rs @@ -14,11 +14,6 @@ const REVISION: &str = "e95b10ba4ac4564ed25f7eef143e3182c33b3902"; #[rustfmt::skip] static EXCLUDE: &[&str] = &[ - // TODO: trait bound with associated constant constraint: - // where T: Trait - // https://github.com/dtolnay/syn/issues/1138 - "src/test/ui/associated-consts/assoc-const.rs", - // TODO: trailing where-clause on impl associated type: // impl Trait for Ty { type Assoc<'a> = T where T: 'a; } // https://github.com/dtolnay/syn/issues/1071