Skip to content

Commit

Permalink
Merge pull request #1707 from compiler-errors/precise-capturing
Browse files Browse the repository at this point in the history
Parse `use<'a, T>` precise capturing bounds as verbatim
  • Loading branch information
dtolnay authored Jul 21, 2024
2 parents f34dc7b + bed32d2 commit 11b2371
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 11b2371

Please sign in to comment.