From a153bc946459ab8e15058850a3d3e4c0ca60f62d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 2 Oct 2021 18:08:43 -0700 Subject: [PATCH 1/2] Add regression test for issue 1073 --- tests/test_item.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/test_item.rs b/tests/test_item.rs index a991e62d33..96df4b1aad 100644 --- a/tests/test_item.rs +++ b/tests/test_item.rs @@ -299,3 +299,38 @@ fn test_impl_type_parameter_defaults() { self_ty: Type::Tuple, }"###); } + +#[test] +fn test_impl_trait_trailing_plus() { + let tokens = quote! { + fn f() -> impl Sized + {} + }; + + snapshot!(tokens as Item, @r###" + Item::Fn { + vis: Inherited, + sig: Signature { + ident: "f", + generics: Generics, + output: Type( + Type::ImplTrait { + bounds: [ + Trait(TraitBound { + modifier: None, + path: Path { + segments: [ + PathSegment { + ident: "Sized", + arguments: None, + }, + ], + }, + }), + ], + }, + ), + }, + block: Block, + } + "###); +} From caea567cd5692d5fe3eab353b4fd8ca8cbff1a8e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 2 Oct 2021 18:09:10 -0700 Subject: [PATCH 2/2] Support trailing plus on impl trait type --- src/ty.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ty.rs b/src/ty.rs index 3df340d5d7..6e9f1f4316 100644 --- a/src/ty.rs +++ b/src/ty.rs @@ -919,6 +919,14 @@ pub mod parsing { break; } bounds.push_punct(input.parse()?); + if !(input.peek(Ident::peek_any) + || input.peek(Token![::]) + || input.peek(Token![?]) + || input.peek(Lifetime) + || input.peek(token::Paren)) + { + break; + } } bounds },