Don't parse a plus sign when parsing a function type's return type.
diff --git a/src/path.rs b/src/path.rs
index 39edd11..9ad8e71 100644
--- a/src/path.rs
+++ b/src/path.rs
@@ -295,7 +295,7 @@
impl Synom for ParenthesizedGenericArguments {
named!(parse -> Self, do_parse!(
data: parens!(Punctuated::parse_terminated) >>
- output: syn!(ReturnType) >>
+ output: call!(ReturnType::without_plus) >>
(ParenthesizedGenericArguments {
paren_token: data.0,
inputs: data.1,
diff --git a/src/ty.rs b/src/ty.rs
index fa3900a..e0cbc31 100644
--- a/src/ty.rs
+++ b/src/ty.rs
@@ -394,7 +394,7 @@
variadic: option!(cond_reduce!(inputs.empty_or_trailing(), punct!(...))) >>
(inputs, variadic)
)) >>
- output: syn!(ReturnType) >>
+ output: call!(ReturnType::without_plus) >>
(TypeBareFn {
unsafety: unsafety,
abi: abi,
@@ -483,16 +483,21 @@
));
}
- impl Synom for ReturnType {
- named!(parse -> Self, alt!(
+ impl ReturnType {
+ named!(pub without_plus -> Self, call!(Self::parse, false));
+ named!(parse(allow_plus: bool) -> Self, alt!(
do_parse!(
arrow: punct!(->) >>
- ty: syn!(Type) >>
+ ty: call!(ambig_ty, allow_plus) >>
(ReturnType::Type(arrow, Box::new(ty)))
)
|
epsilon!() => { |_| ReturnType::Default }
));
+ }
+
+ impl Synom for ReturnType {
+ named!(parse -> Self, call!(Self::parse, true));
fn description() -> Option<&'static str> {
Some("return type")
diff --git a/tests/test_generics.rs b/tests/test_generics.rs
index bdeb171..4efa1b7 100644
--- a/tests/test_generics.rs
+++ b/tests/test_generics.rs
@@ -144,3 +144,21 @@
common::parse::syn::<TypeParamBound>(tokens.into())
);
}
+
+#[test]
+fn test_fn_precedence_in_where_clause() {
+ // This should parse as two separate bounds, `FnOnce() -> i32` and `Send` - not `FnOnce() -> (i32 + Send)`.
+ let sig = quote!(fn f<G>() where G: FnOnce() -> i32 + Send {});
+ let fun = common::parse::syn::<ItemFn>(sig.into());
+ let where_clause = fun.decl.generics.where_clause.as_ref().unwrap();
+ assert_eq!(where_clause.predicates.len(), 1);
+ let predicate = match where_clause.predicates[0] {
+ WherePredicate::Type(ref pred) => pred,
+ _ => panic!("wrong predicate kind"),
+ };
+ assert_eq!(predicate.bounds.len(), 2, "{:#?}", predicate.bounds);
+ let first_bound = &predicate.bounds[0];
+ assert_eq!(quote!(#first_bound).to_string(), "FnOnce ( ) -> i32");
+ let second_bound = &predicate.bounds[1];
+ assert_eq!(quote!(#second_bound).to_string(), "Send");
+}