Skip to content

Commit

Permalink
Merge pull request #1025 from taiki-e/impl-type-parameter-defaults
Browse files Browse the repository at this point in the history
Parse type parameter defaults on impl blocks
  • Loading branch information
dtolnay committed Apr 28, 2021
2 parents 6dc5c73 + 70f8b8e commit bc383c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2469,7 +2469,8 @@ pub mod parsing {
|| (input.peek2(Ident) || input.peek2(Lifetime))
&& (input.peek3(Token![:])
|| input.peek3(Token![,])
|| input.peek3(Token![>]))
|| input.peek3(Token![>])
|| input.peek3(Token![=]))
|| input.peek2(Token![const]));
let mut generics: Generics = if has_generics {
input.parse()?
Expand Down
24 changes: 24 additions & 0 deletions tests/test_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,27 @@ fn test_impl_visibility() {

snapshot!(tokens as Item, @"Verbatim(`pub default unsafe impl union { }`)");
}

#[test]
fn test_impl_type_parameter_defaults() {
#[cfg(any())]
impl<T = ()> () {}
let tokens = quote! {
impl<T = ()> () {}
};
snapshot!(tokens as Item, @r###"
Item::Impl {
generics: Generics {
lt_token: Some,
params: [
Type(TypeParam {
ident: "T",
eq_token: Some,
default: Some(Type::Tuple),
}),
],
gt_token: Some,
},
self_ty: Type::Tuple,
}"###);
}

0 comments on commit bc383c5

Please sign in to comment.