Skip to content

Commit 465a0d1

Browse files
committed
Rollup merge of rust-lang#39179 - petrochenkov:objparen, r=eddyb
Fix regression in parsing of trait object types Fixes rust-lang#39169 Accepting parens in this position is a regression itself, introduced in Rust 1.6 by rust-lang#29870, so I hope to revert this in my next bounds refactoring patch (possibly with a warning, crater run, etc). r? @eddyb
2 parents f185265 + 853f697 commit 465a0d1

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,10 +1236,17 @@ impl<'a> Parser<'a> {
12361236
"at least one type parameter bound \
12371237
must be specified");
12381238
}
1239-
if let TyKind::Path(None, ref path) = lhs.node {
1239+
1240+
let mut lhs = lhs.unwrap();
1241+
if let TyKind::Paren(ty) = lhs.node {
1242+
// We have to accept the first bound in parens for backward compatibility.
1243+
// Example: `(Bound) + Bound + Bound`
1244+
lhs = ty.unwrap();
1245+
}
1246+
if let TyKind::Path(None, path) = lhs.node {
12401247
let poly_trait_ref = PolyTraitRef {
12411248
bound_lifetimes: Vec::new(),
1242-
trait_ref: TraitRef { path: path.clone(), ref_id: lhs.id },
1249+
trait_ref: TraitRef { path: path, ref_id: lhs.id },
12431250
span: lhs.span,
12441251
};
12451252
let poly_trait_ref = TraitTyParamBound(poly_trait_ref, TraitBoundModifier::None);
Lines changed: 15 additions & 0 deletions
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)