about summary refs log tree commit diff
path: root/src/test/parse-fail
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-01-27 01:27:12 +0000
committerbors <bors@rust-lang.org>2017-01-27 01:27:12 +0000
commit23a94697c2fa67ec750a8fc09b2e86213b5e0af1 (patch)
tree453b69936662fd4b908e63a5366d005aa6cb730c /src/test/parse-fail
parent8430042a49bbd49bbb4fbc54f457feb5fb614f56 (diff)
parentbd4d5ec758cac866af2ca8fc09b27ce0d0112786 (diff)
downloadrust-23a94697c2fa67ec750a8fc09b2e86213b5e0af1.tar.gz
rust-23a94697c2fa67ec750a8fc09b2e86213b5e0af1.zip
Auto merge of #39158 - petrochenkov:bounds, r=nikomatsakis
Bounds parsing refactoring 2

See https://github.com/rust-lang/rust/pull/37511 for previous discussion.
cc @matklad

Relaxed parsing rules:
 - zero bounds after `:` are allowed in all contexts.
 - zero predicates are allowed after `where`.
- trailing separator `,` is allowed after predicates in `where` clauses not followed by `{`.

Other parsing rules:
 - trailing separator `+` is still allowed in all bound lists.

Code is also cleaned up and tests added.

I haven't touched parsing of trait object types yet, I'll do it later.
Diffstat (limited to 'src/test/parse-fail')
-rw-r--r--src/test/parse-fail/bounds-lifetime-1.rs15
-rw-r--r--src/test/parse-fail/bounds-lifetime-2.rs15
-rw-r--r--src/test/parse-fail/bounds-lifetime-where-1.rs15
-rw-r--r--src/test/parse-fail/bounds-lifetime-where.rs22
-rw-r--r--src/test/parse-fail/bounds-lifetime.rs24
-rw-r--r--src/test/parse-fail/bounds-type-where.rs23
-rw-r--r--src/test/parse-fail/bounds-type.rs23
-rw-r--r--src/test/parse-fail/issue-14303-path.rs1
-rw-r--r--src/test/parse-fail/issue-17904-2.rs (renamed from src/test/parse-fail/generic-non-trailing-defaults.rs)6
-rw-r--r--src/test/parse-fail/issue-17904.rs3
-rw-r--r--src/test/parse-fail/issue-32214.rs5
-rw-r--r--src/test/parse-fail/lifetime-semicolon.rs3
-rw-r--r--src/test/parse-fail/where-clauses-no-bounds-or-predicates.rs4
13 files changed, 144 insertions, 15 deletions
diff --git a/src/test/parse-fail/bounds-lifetime-1.rs b/src/test/parse-fail/bounds-lifetime-1.rs
new file mode 100644
index 00000000000..824d243d5f8
--- /dev/null
+++ b/src/test/parse-fail/bounds-lifetime-1.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 <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 = for<'a 'b> fn(); //~ ERROR expected one of `,`, `:`, or `>`, found `'b`
+
+fn main() {}
diff --git a/src/test/parse-fail/bounds-lifetime-2.rs b/src/test/parse-fail/bounds-lifetime-2.rs
new file mode 100644
index 00000000000..3c67dda70f5
--- /dev/null
+++ b/src/test/parse-fail/bounds-lifetime-2.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 <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 = for<'a + 'b> fn(); //~ ERROR expected one of `,`, `:`, or `>`, found `+`
+
+fn main() {}
diff --git a/src/test/parse-fail/bounds-lifetime-where-1.rs b/src/test/parse-fail/bounds-lifetime-where-1.rs
new file mode 100644
index 00000000000..aae9d729987
--- /dev/null
+++ b/src/test/parse-fail/bounds-lifetime-where-1.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 <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 where 'a; //~ ERROR expected `:`, found `;`
+
+fn main() {}
diff --git a/src/test/parse-fail/bounds-lifetime-where.rs b/src/test/parse-fail/bounds-lifetime-where.rs
new file mode 100644
index 00000000000..0a30818bc96
--- /dev/null
+++ b/src/test/parse-fail/bounds-lifetime-where.rs
@@ -0,0 +1,22 @@
+// 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 where 'a: 'b + 'c = u8; // OK
+type A where 'a: 'b, = u8; // OK
+type A where 'a: = u8; // OK
+type A where 'a:, = u8; // OK
+type A where 'a: 'b + 'c = u8; // OK
+type A where = u8; // OK
+type A where 'a: 'b + = u8; // OK
+type A where , = u8; //~ ERROR expected one of `=`, lifetime, or type, found `,`
+
+fn main() {}
diff --git a/src/test/parse-fail/bounds-lifetime.rs b/src/test/parse-fail/bounds-lifetime.rs
new file mode 100644
index 00000000000..5113a6b4803
--- /dev/null
+++ b/src/test/parse-fail/bounds-lifetime.rs
@@ -0,0 +1,24 @@
+// 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 -Z continue-parse-after-error
+
+type A = for<'a: 'b + 'c> fn(); // OK
+type A = for<'a: 'b,> fn(); // OK
+type A = for<'a:> fn(); // OK
+type A = for<'a:,> fn(); // OK
+type A = for<'a> fn(); // OK
+type A = for<> fn(); // OK
+type A = for<'a: 'b +> fn(); // OK
+
+type A = for<'a, T> fn(); //~ ERROR only lifetime parameters can be used in this context
+type A = for<,> fn(); //~ ERROR expected one of `>`, identifier, or lifetime, found `,`
+
+fn main() {}
diff --git a/src/test/parse-fail/bounds-type-where.rs b/src/test/parse-fail/bounds-type-where.rs
new file mode 100644
index 00000000000..9dc5d827744
--- /dev/null
+++ b/src/test/parse-fail/bounds-type-where.rs
@@ -0,0 +1,23 @@
+// 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 where for<'a> for<'b> Trait1 + ?Trait2: 'a + Trait = u8; // OK
+type A where T: Trait, = u8; // OK
+type A where T: = u8; // OK
+type A where T:, = u8; // OK
+type A where T: Trait + Trait = u8; // OK
+type A where = u8; // OK
+type A where T: Trait + = u8; // OK
+type A where T, = u8;
+//~^ ERROR expected one of `!`, `(`, `+`, `::`, `:`, `<`, `==`, or `=`, found `,`
+
+fn main() {}
diff --git a/src/test/parse-fail/bounds-type.rs b/src/test/parse-fail/bounds-type.rs
new file mode 100644
index 00000000000..c224b44a14b
--- /dev/null
+++ b/src/test/parse-fail/bounds-type.rs
@@ -0,0 +1,23 @@
+// 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 -Z continue-parse-after-error
+
+struct S<
+    T: 'a + Tr, // OK
+    T: Tr + 'a, // OK
+    T: 'a, // OK
+    T:, // OK
+    T: ?for<'a: 'b + 'c> Trait, // OK
+    T: Tr +, // OK
+    T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds
+>;
+
+fn main() {}
diff --git a/src/test/parse-fail/issue-14303-path.rs b/src/test/parse-fail/issue-14303-path.rs
index 431a917c2d9..f0d1feffec8 100644
--- a/src/test/parse-fail/issue-14303-path.rs
+++ b/src/test/parse-fail/issue-14303-path.rs
@@ -12,4 +12,3 @@
 
 fn bar<'a, T>(x: mymodule::X<'a, T, 'b, 'c>) {}
 //~^ ERROR lifetime parameters must be declared prior to type parameters
-//~^^ ERROR expected pattern, found `'c`
diff --git a/src/test/parse-fail/generic-non-trailing-defaults.rs b/src/test/parse-fail/issue-17904-2.rs
index 2bb593258ae..3f41c0edd2e 100644
--- a/src/test/parse-fail/generic-non-trailing-defaults.rs
+++ b/src/test/parse-fail/issue-17904-2.rs
@@ -10,10 +10,6 @@
 
 // compile-flags: -Z parse-only -Z continue-parse-after-error
 
-struct Heap;
-
-struct Vec<A = Heap, T>; //~ ERROR type parameters with a default must be trailing
-
-struct Foo<A, B = Vec<C>, C>; //~ ERROR type parameters with a default must be trailing
+struct Bar<T> { x: T } where T: Copy //~ ERROR expected item, found `where`
 
 fn main() {}
diff --git a/src/test/parse-fail/issue-17904.rs b/src/test/parse-fail/issue-17904.rs
index de5aeb02ab7..ae28ac76acb 100644
--- a/src/test/parse-fail/issue-17904.rs
+++ b/src/test/parse-fail/issue-17904.rs
@@ -13,7 +13,6 @@
 struct Baz<U> where U: Eq(U); //This is parsed as the new Fn* style parenthesis syntax.
 struct Baz<U> where U: Eq(U) -> R; // Notice this parses as well.
 struct Baz<U>(U) where U: Eq; // This rightfully signals no error as well.
-struct Foo<T> where T: Copy, (T); //~ ERROR unexpected token in `where` clause
-struct Bar<T> { x: T } where T: Copy //~ ERROR expected item, found `where`
+struct Foo<T> where T: Copy, (T); //~ ERROR expected one of `+`, `:`, `==`, or `=`, found `;`
 
 fn main() {}
diff --git a/src/test/parse-fail/issue-32214.rs b/src/test/parse-fail/issue-32214.rs
index 3ba59c8ee94..9e200094093 100644
--- a/src/test/parse-fail/issue-32214.rs
+++ b/src/test/parse-fail/issue-32214.rs
@@ -10,8 +10,7 @@
 
 // compile-flags: -Z parse-only -Z continue-parse-after-error
 
-pub fn test<W, I: Iterator<Item=(), W> >() {
-    //~^ ERROR expected `=`, found `>`
-}
+pub fn test<W, I: Iterator<Item=(), W> >() {}
+//~^ ERROR type parameters must be declared prior to associated type bindings
 
 fn main() { }
diff --git a/src/test/parse-fail/lifetime-semicolon.rs b/src/test/parse-fail/lifetime-semicolon.rs
index 7010d0e7deb..e1975952fca 100644
--- a/src/test/parse-fail/lifetime-semicolon.rs
+++ b/src/test/parse-fail/lifetime-semicolon.rs
@@ -15,5 +15,4 @@ struct Foo<'a, 'b> {
 }
 
 fn foo<'a, 'b>(x: &mut Foo<'a; 'b>) {}
-//~^ ERROR expected `,` or `>` after lifetime name, found `;`
-//~^^ NOTE did you mean a single argument type &'a Type, or did you mean the comma-separated
+//~^ ERROR expected one of `,` or `>`, found `;`
diff --git a/src/test/parse-fail/where-clauses-no-bounds-or-predicates.rs b/src/test/parse-fail/where-clauses-no-bounds-or-predicates.rs
index 78d97454087..cf67b518fff 100644
--- a/src/test/parse-fail/where-clauses-no-bounds-or-predicates.rs
+++ b/src/test/parse-fail/where-clauses-no-bounds-or-predicates.rs
@@ -10,13 +10,13 @@
 
 // compile-flags: -Z parse-only -Z continue-parse-after-error
 
+// Empty predicate list is OK
 fn equal1<T>(_: &T, _: &T) -> bool where {
-//~^ ERROR a `where` clause must have at least one predicate in it
     true
 }
 
+// Empty bound list is OK
 fn equal2<T>(_: &T, _: &T) -> bool where T: {
-//~^ ERROR each predicate in a `where` clause must have at least one bound
     true
 }