Skip to content

Commit

Permalink
Parse use<> precise capturing as Verbatim
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jul 13, 2024
1 parent f34dc7b commit bed32d2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,27 @@ pub(crate) mod parsing {

let begin = input.fork();

if cfg!(feature = "full") && input.peek(Token![use]) {
input.parse::<Token![use]>()?;
input.parse::<Token![<]>()?;
while !input.peek(Token![>]) {
if input.peek(Lifetime) {
input.parse::<Lifetime>()?;
} else if input.peek(Ident) {
input.parse::<Ident>()?;
} else {
break;
}
if input.peek(Token![,]) {
input.parse::<Token![,]>()?;
} else {
break;
}
}
input.parse::<Token![>]>()?;
return Ok(TypeParamBound::Verbatim(verbatim::between(&begin, input)));
}

let content;
let (paren_token, content) = if input.peek(token::Paren) {
(Some(parenthesized!(content in input)), &content)
Expand Down
47 changes: 47 additions & 0 deletions tests/test_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,50 @@ fn test_tuple_comma() {
}
"###);
}

#[test]
fn test_impl_trait_use() {
let tokens = quote! {
impl Sized + use<'_, 'a, A, Test>
};

snapshot!(tokens as Type, @r###"
Type::ImplTrait {
bounds: [
TypeParamBound::Trait(TraitBound {
path: Path {
segments: [
PathSegment {
ident: "Sized",
},
],
},
}),
Token![+],
TypeParamBound::Verbatim(`use < '_ , 'a , A , Test >`),
],
}
"###);

let trailing = quote! {
impl Sized + use<'_,>
};

snapshot!(trailing as Type, @r###"
Type::ImplTrait {
bounds: [
TypeParamBound::Trait(TraitBound {
path: Path {
segments: [
PathSegment {
ident: "Sized",
},
],
},
}),
Token![+],
TypeParamBound::Verbatim(`use < '_ , >`),
],
}
"###);
}

0 comments on commit bed32d2

Please sign in to comment.