Skip to content

Commit

Permalink
Fix regression in parsing of trait object types
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jan 19, 2017
1 parent 74c42ac commit 853f697
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,10 +1277,17 @@ impl<'a> Parser<'a> {
"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);
Expand Down
15 changes: 15 additions & 0 deletions src/test/parse-fail/bounds-obj-parens.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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

0 comments on commit 853f697

Please sign in to comment.