Skip to content

Commit bed32d2

Browse files
Parse use<> precise capturing as Verbatim
1 parent f34dc7b commit bed32d2

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

src/generics.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,27 @@ pub(crate) mod parsing {
772772

773773
let begin = input.fork();
774774

775+
if cfg!(feature = "full") && input.peek(Token![use]) {
776+
input.parse::<Token![use]>()?;
777+
input.parse::<Token![<]>()?;
778+
while !input.peek(Token![>]) {
779+
if input.peek(Lifetime) {
780+
input.parse::<Lifetime>()?;
781+
} else if input.peek(Ident) {
782+
input.parse::<Ident>()?;
783+
} else {
784+
break;
785+
}
786+
if input.peek(Token![,]) {
787+
input.parse::<Token![,]>()?;
788+
} else {
789+
break;
790+
}
791+
}
792+
input.parse::<Token![>]>()?;
793+
return Ok(TypeParamBound::Verbatim(verbatim::between(&begin, input)));
794+
}
795+
775796
let content;
776797
let (paren_token, content) = if input.peek(token::Paren) {
777798
(Some(parenthesized!(content in input)), &content)

tests/test_ty.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,50 @@ fn test_tuple_comma() {
395395
}
396396
"###);
397397
}
398+
399+
#[test]
400+
fn test_impl_trait_use() {
401+
let tokens = quote! {
402+
impl Sized + use<'_, 'a, A, Test>
403+
};
404+
405+
snapshot!(tokens as Type, @r###"
406+
Type::ImplTrait {
407+
bounds: [
408+
TypeParamBound::Trait(TraitBound {
409+
path: Path {
410+
segments: [
411+
PathSegment {
412+
ident: "Sized",
413+
},
414+
],
415+
},
416+
}),
417+
Token![+],
418+
TypeParamBound::Verbatim(`use < '_ , 'a , A , Test >`),
419+
],
420+
}
421+
"###);
422+
423+
let trailing = quote! {
424+
impl Sized + use<'_,>
425+
};
426+
427+
snapshot!(trailing as Type, @r###"
428+
Type::ImplTrait {
429+
bounds: [
430+
TypeParamBound::Trait(TraitBound {
431+
path: Path {
432+
segments: [
433+
PathSegment {
434+
ident: "Sized",
435+
},
436+
],
437+
},
438+
}),
439+
Token![+],
440+
TypeParamBound::Verbatim(`use < '_ , >`),
441+
],
442+
}
443+
"###);
444+
}

0 commit comments

Comments
 (0)