about summary refs log tree commit diff
path: root/src/libsyntax/parse/parser.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2017-01-19 15:49:49 -0800
committerAlex Crichton <alex@alexcrichton.com>2017-01-20 08:35:49 -0800
commit465a0d12b9777dde1e10e758924ce1d4837a4517 (patch)
tree764532478d4454379b80b175bc4ef720ce4c6fc3 /src/libsyntax/parse/parser.rs
parentf1852650d91ca09e78fca2b6b24758bdbc521f5e (diff)
parent853f6974767243e2e5defb43f5f7195ce1fb1cc7 (diff)
downloadrust-465a0d12b9777dde1e10e758924ce1d4837a4517.tar.gz
rust-465a0d12b9777dde1e10e758924ce1d4837a4517.zip
Rollup merge of #39179 - petrochenkov:objparen, r=eddyb
Fix regression in parsing of trait object types

Fixes https://github.com/rust-lang/rust/issues/39169

Accepting parens in this position is a regression itself, introduced in Rust 1.6 by https://github.com/rust-lang/rust/pull/29870, so I hope to revert this in my next bounds refactoring patch (possibly with a warning,  crater run, etc).

r? @eddyb
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
-rw-r--r--src/libsyntax/parse/parser.rs11
1 files changed, 9 insertions, 2 deletions
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 @@ 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);