Skip to content

Commit d3b0276

Browse files
committed
Parse generic associated type equality constraint
1 parent 1a31fb2 commit d3b0276

File tree

2 files changed

+57
-23
lines changed

2 files changed

+57
-23
lines changed

src/path.rs

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,44 @@ pub mod parsing {
245245
return const_argument(input).map(GenericArgument::Const);
246246
}
247247

248-
input.parse().map(GenericArgument::Type)
248+
#[cfg(feature = "full")]
249+
let begin = input.fork();
250+
251+
let argument: Type = input.parse()?;
252+
253+
#[cfg(feature = "full")]
254+
{
255+
if match &argument {
256+
Type::Path(argument)
257+
if argument.qself.is_none()
258+
&& argument.path.leading_colon.is_none()
259+
&& argument.path.segments.len() == 1 =>
260+
{
261+
match argument.path.segments[0].arguments {
262+
PathArguments::AngleBracketed(_) => true,
263+
_ => false,
264+
}
265+
}
266+
_ => false,
267+
} {
268+
if if input.peek(Token![=]) {
269+
input.parse::<Token![=]>()?;
270+
input.parse::<Type>()?;
271+
true
272+
} else if input.peek(Token![:]) {
273+
input.parse::<Token![:]>()?;
274+
input.call(constraint_bounds)?;
275+
true
276+
} else {
277+
false
278+
} {
279+
let verbatim = verbatim::between(begin, input);
280+
return Ok(GenericArgument::Type(Type::Verbatim(verbatim)));
281+
}
282+
}
283+
}
284+
285+
Ok(GenericArgument::Type(argument))
249286
}
250287
}
251288

@@ -368,26 +405,29 @@ pub mod parsing {
368405
Ok(Constraint {
369406
ident: input.parse()?,
370407
colon_token: input.parse()?,
371-
bounds: {
372-
let mut bounds = Punctuated::new();
373-
loop {
374-
if input.peek(Token![,]) || input.peek(Token![>]) {
375-
break;
376-
}
377-
let value = input.parse()?;
378-
bounds.push_value(value);
379-
if !input.peek(Token![+]) {
380-
break;
381-
}
382-
let punct = input.parse()?;
383-
bounds.push_punct(punct);
384-
}
385-
bounds
386-
},
408+
bounds: constraint_bounds(input)?,
387409
})
388410
}
389411
}
390412

413+
#[cfg(feature = "full")]
414+
fn constraint_bounds(input: ParseStream) -> Result<Punctuated<TypeParamBound, Token![+]>> {
415+
let mut bounds = Punctuated::new();
416+
loop {
417+
if input.peek(Token![,]) || input.peek(Token![>]) {
418+
break;
419+
}
420+
let value = input.parse()?;
421+
bounds.push_value(value);
422+
if !input.peek(Token![+]) {
423+
break;
424+
}
425+
let punct = input.parse()?;
426+
bounds.push_punct(punct);
427+
}
428+
Ok(bounds)
429+
}
430+
391431
impl Path {
392432
/// Parse a `Path` containing no path arguments on any of its segments.
393433
///

tests/repo/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ const REVISION: &str = "52e3dffa50cfffdcfa145c0cc0ba48b49abc0c07";
1212

1313
#[rustfmt::skip]
1414
static EXCLUDE: &[&str] = &[
15-
// TODO: generic associated type equality constraint
16-
// https://github.com/dtolnay/syn/issues/979
17-
"src/test/pretty/gat-bounds.rs",
18-
"src/test/ui/generic-associated-types/generic-associated-type-bounds.rs",
19-
"src/test/ui/generic-associated-types/issue-80433-reduced.rs",
20-
2115
// Compile-fail expr parameter in const generic position: f::<1 + 2>()
2216
"src/test/ui/const-generics/closing-args-token.rs",
2317
"src/test/ui/const-generics/const-expression-parameter.rs",

0 commit comments

Comments
 (0)