Skip to content

Commit 853f697

Browse files
committed
Fix regression in parsing of trait object types
1 parent 74c42ac commit 853f697

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/libsyntax/parse/parser.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1277,10 +1277,17 @@ impl<'a> Parser<'a> {
12771277
"at least one type parameter bound \
12781278
must be specified");
12791279
}
1280-
if let TyKind::Path(None, ref path) = lhs.node {
1280+
1281+
let mut lhs = lhs.unwrap();
1282+
if let TyKind::Paren(ty) = lhs.node {
1283+
// We have to accept the first bound in parens for backward compatibility.
1284+
// Example: `(Bound) + Bound + Bound`
1285+
lhs = ty.unwrap();
1286+
}
1287+
if let TyKind::Path(None, path) = lhs.node {
12811288
let poly_trait_ref = PolyTraitRef {
12821289
bound_lifetimes: Vec::new(),
1283-
trait_ref: TraitRef { path: path.clone(), ref_id: lhs.id },
1290+
trait_ref: TraitRef { path: path, ref_id: lhs.id },
12841291
span: lhs.span,
12851292
};
12861293
let poly_trait_ref = TraitTyParamBound(poly_trait_ref, TraitBoundModifier::None);
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -Z parse-only
12+
13+
type A = Box<(Fn(D::Error) -> E) + 'static + Send + Sync>; // OK
14+
15+
FAIL //~ ERROR

0 commit comments

Comments
 (0)