diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index fd6abc58b63..5dd772041e2 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1236,10 +1236,17 @@ pub fn parse_ty(&mut self) -> PResult<'a, P> { "at least one type parameter bound \ must be specified"); } - if let TyKind::Path(None, ref path) = lhs.node { + + let mut lhs = lhs.unwrap(); + if let TyKind::Paren(ty) = lhs.node { + // We have to accept the first bound in parens for backward compatibility. + // Example: `(Bound) + Bound + Bound` + lhs = ty.unwrap(); + } + if let TyKind::Path(None, path) = lhs.node { let poly_trait_ref = PolyTraitRef { bound_lifetimes: Vec::new(), - trait_ref: TraitRef { path: path.clone(), ref_id: lhs.id }, + trait_ref: TraitRef { path: path, ref_id: lhs.id }, span: lhs.span, }; let poly_trait_ref = TraitTyParamBound(poly_trait_ref, TraitBoundModifier::None); diff --git a/src/test/parse-fail/bounds-obj-parens.rs b/src/test/parse-fail/bounds-obj-parens.rs new file mode 100644 index 00000000000..cbdffb4a255 --- /dev/null +++ b/src/test/parse-fail/bounds-obj-parens.rs @@ -0,0 +1,15 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: -Z parse-only + +type A = Box<(Fn(D::Error) -> E) + 'static + Send + Sync>; // OK + +FAIL //~ ERROR