parse: move constraint/arg restriction to ast_validation.

This commit is contained in:
Mazdak Farrokhzad 2020-03-22 04:40:05 +01:00
parent 6c19a10e24
commit 91194f795c
17 changed files with 246 additions and 199 deletions

View file

@ -0,0 +1,9 @@
// check-pass
#[cfg(FALSE)]
fn syntax() {
foo::<T = u8, T: Ord, String>();
foo::<T = u8, 'a, T: Ord>();
}
fn main() {}

View file

@ -1,6 +1,6 @@
trait Trait<T> { type Item; }
pub fn test<W, I: Trait<Item=(), W> >() {}
//~^ ERROR associated type bindings must be declared after generic parameters
//~^ ERROR constraints in a path segment must come after generic arguments
fn main() { }

View file

@ -1,10 +1,11 @@
error: associated type bindings must be declared after generic parameters
--> $DIR/issue-32214.rs:3:25
error: constraints in a path segment must come after generic arguments
--> $DIR/issue-32214.rs:3:24
|
LL | pub fn test<W, I: Trait<Item=(), W> >() {}
| -------^^^
| |
| this associated type binding should be moved after the generic parameters
| ^-------^^-^
| | |
| | this generic argument must come before the first constraint
| the first constraint is provided here
error: aborting due to previous error

View file

@ -1,5 +1,3 @@
// ignore-tidy-linelength
#![allow(warnings)]
// This test verifies that the suggestion to move types before associated type bindings
@ -25,20 +23,22 @@ trait ThreeWithLifetime<'a, 'b, 'c, T, U, V> {
type C;
}
struct A<T, M: One<A=(), T>> { //~ ERROR associated type bindings must be declared after generic parameters
struct A<T, M: One<A=(), T>> {
//~^ ERROR constraints in a path segment must come after generic arguments
m: M,
t: T,
}
struct Al<'a, T, M: OneWithLifetime<A=(), T, 'a>> {
//~^ ERROR associated type bindings must be declared after generic parameters
//~^ ERROR constraints in a path segment must come after generic arguments
//~^^ ERROR type provided when a lifetime was expected
m: M,
t: &'a T,
}
struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> { //~ ERROR associated type bindings must be declared after generic parameters
struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> {
//~^ ERROR constraints in a path segment must come after generic arguments
m: M,
t: T,
u: U,
@ -46,7 +46,7 @@ struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> { //~ ERROR associated ty
}
struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, 'a, 'b, 'c>> {
//~^ ERROR associated type bindings must be declared after generic parameters
//~^ ERROR constraints in a path segment must come after generic arguments
//~^^ ERROR type provided when a lifetime was expected
m: M,
t: &'a T,
@ -54,7 +54,8 @@ struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, '
v: &'c V,
}
struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> { //~ ERROR associated type bindings must be declared after generic parameters
struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> {
//~^ ERROR constraints in a path segment must come after generic arguments
m: M,
t: T,
u: U,
@ -62,7 +63,7 @@ struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> { //~ ERROR associated ty
}
struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
//~^ ERROR associated type bindings must be declared after generic parameters
//~^ ERROR constraints in a path segment must come after generic arguments
//~^^ ERROR lifetime provided when a type was expected
m: M,
t: &'a T,
@ -70,7 +71,8 @@ struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U,
v: &'c V,
}
struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> { //~ ERROR associated type bindings must be declared after generic parameters
struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> {
//~^ ERROR constraints in a path segment must come after generic arguments
m: M,
t: T,
u: U,
@ -78,7 +80,7 @@ struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> { //~ ERROR associated ty
}
struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
//~^ ERROR associated type bindings must be declared after generic parameters
//~^ ERROR constraints in a path segment must come after generic arguments
//~^^ ERROR lifetime provided when a type was expected
m: M,
t: &'a T,

View file

@ -1,81 +1,93 @@
error: associated type bindings must be declared after generic parameters
--> $DIR/suggest-move-types.rs:28:20
error: constraints in a path segment must come after generic arguments
--> $DIR/suggest-move-types.rs:26:19
|
LL | struct A<T, M: One<A=(), T>> {
| ----^^^
| |
| this associated type binding should be moved after the generic parameters
| ^----^^-^
| | |
| | this generic argument must come before the first constraint
| the first constraint is provided here
error: associated type bindings must be declared after generic parameters
--> $DIR/suggest-move-types.rs:34:37
error: constraints in a path segment must come after generic arguments
--> $DIR/suggest-move-types.rs:33:36
|
LL | struct Al<'a, T, M: OneWithLifetime<A=(), T, 'a>> {
| ----^^^^^^^
| |
| this associated type binding should be moved after the generic parameters
| ^----^^-^^--^
| | | |
| | | this generic argument must come before the first constraint
| | this generic argument must come before the first constraint
| the first constraint is provided here
error: associated type bindings must be declared after generic parameters
--> $DIR/suggest-move-types.rs:41:28
error: constraints in a path segment must come after generic arguments
--> $DIR/suggest-move-types.rs:40:27
|
LL | struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> {
| ----^^----^^----^^^^^^^^^
| | | |
| | | this associated type binding should be moved after the generic parameters
| | this associated type binding should be moved after the generic parameters
| this associated type binding should be moved after the generic parameters
| ^----^^^^^^^^^^^^^^-^^-^^-^
| | | | |
| | | | this generic argument must come before the first constraint
| | | this generic argument must come before the first constraint
| | this generic argument must come before the first constraint
| the first constraint is provided here
error: associated type bindings must be declared after generic parameters
--> $DIR/suggest-move-types.rs:48:53
error: constraints in a path segment must come after generic arguments
--> $DIR/suggest-move-types.rs:48:52
|
LL | struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, 'a, 'b, 'c>> {
| ----^^----^^----^^^^^^^^^^^^^^^^^^^^^
| | | |
| | | this associated type binding should be moved after the generic parameters
| | this associated type binding should be moved after the generic parameters
| this associated type binding should be moved after the generic parameters
| ^----^^^^^^^^^^^^^^-^^-^^-^^--^^--^^--^
| | | | | | | |
| | | | | | | this generic argument must come before the first constraint
| | | | | | this generic argument must come before the first constraint
| | | | | this generic argument must come before the first constraint
| | | | this generic argument must come before the first constraint
| | | this generic argument must come before the first constraint
| | this generic argument must come before the first constraint
| the first constraint is provided here
error: associated type bindings must be declared after generic parameters
--> $DIR/suggest-move-types.rs:57:28
error: constraints in a path segment must come after generic arguments
--> $DIR/suggest-move-types.rs:57:27
|
LL | struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> {
| ^^^----^^----^^----^^^^^^
| | | |
| | | this associated type binding should be moved after the generic parameters
| | this associated type binding should be moved after the generic parameters
| this associated type binding should be moved after the generic parameters
| ^^^^----^^^^^^^^^^^^^^-^^-^
| | | |
| | | this generic argument must come before the first constraint
| | this generic argument must come before the first constraint
| the first constraint is provided here
error: associated type bindings must be declared after generic parameters
--> $DIR/suggest-move-types.rs:64:53
error: constraints in a path segment must come after generic arguments
--> $DIR/suggest-move-types.rs:65:52
|
LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
| ^^^^^^^----^^----^^----^^^^^^^^^^^^^^
| | | |
| | | this associated type binding should be moved after the generic parameters
| | this associated type binding should be moved after the generic parameters
| this associated type binding should be moved after the generic parameters
| ^^^^^^^^----^^^^^^^^^^^^^^-^^--^^-^^--^
| | | | | |
| | | | | this generic argument must come before the first constraint
| | | | this generic argument must come before the first constraint
| | | this generic argument must come before the first constraint
| | this generic argument must come before the first constraint
| the first constraint is provided here
error: associated type bindings must be declared after generic parameters
--> $DIR/suggest-move-types.rs:73:28
error: constraints in a path segment must come after generic arguments
--> $DIR/suggest-move-types.rs:74:27
|
LL | struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> {
| ^^^----^^----^^^^^----^^^
| | | |
| | | this associated type binding should be moved after the generic parameters
| | this associated type binding should be moved after the generic parameters
| this associated type binding should be moved after the generic parameters
| ^^^^----^^^^^^^^-^^^^^^^^-^
| | | |
| | | this generic argument must come before the first constraint
| | this generic argument must come before the first constraint
| the first constraint is provided here
error: associated type bindings must be declared after generic parameters
--> $DIR/suggest-move-types.rs:80:53
error: constraints in a path segment must come after generic arguments
--> $DIR/suggest-move-types.rs:82:52
|
LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
| ^^^^^^^----^^----^^^^^^^^^----^^^^^^^
| | | |
| | | this associated type binding should be moved after the generic parameters
| | this associated type binding should be moved after the generic parameters
| this associated type binding should be moved after the generic parameters
| ^^^^^^^^----^^^^^^^^-^^--^^^^^^^^-^^--^
| | | | | |
| | | | | this generic argument must come before the first constraint
| | | | this generic argument must come before the first constraint
| | | this generic argument must come before the first constraint
| | this generic argument must come before the first constraint
| the first constraint is provided here
error[E0747]: type provided when a lifetime was expected
--> $DIR/suggest-move-types.rs:34:43
--> $DIR/suggest-move-types.rs:33:43
|
LL | struct Al<'a, T, M: OneWithLifetime<A=(), T, 'a>> {
| ^
@ -91,7 +103,7 @@ LL | struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U,
= note: lifetime arguments must be provided before type arguments
error[E0747]: lifetime provided when a type was expected
--> $DIR/suggest-move-types.rs:64:56
--> $DIR/suggest-move-types.rs:65:56
|
LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
| ^^
@ -99,7 +111,7 @@ LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=()
= note: type arguments must be provided before lifetime arguments
error[E0747]: lifetime provided when a type was expected
--> $DIR/suggest-move-types.rs:80:56
--> $DIR/suggest-move-types.rs:82:56
|
LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
| ^^