diff options
| author | bors <bors@rust-lang.org> | 2020-03-28 11:13:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-03-28 11:13:09 +0000 |
| commit | b9d5ee567652cd342d9348c215009049551747b0 (patch) | |
| tree | 820b045d697c1263c497f442274d1a9aac952189 /src/test/ui/parser | |
| parent | b76238a3ee5ebffbad8a3aefd36012f3bceb7069 (diff) | |
| parent | 42c5cfdfda24529f424a6175fa1a48e5542cb824 (diff) | |
| download | rust-b9d5ee567652cd342d9348c215009049551747b0.tar.gz rust-b9d5ee567652cd342d9348c215009049551747b0.zip | |
Auto merge of #70261 - Centril:angle-args-partition, r=varkor
Move arg/constraint partition check to validation & improve recovery - In the first commit, we move the check rejecting e.g., `<'a, Item = u8, String>` from the parser into AST validation. - We then use this to improve the code for parsing generic arguments. - And we add recovery for e.g., `<Item = >` (missing), `<Item = 42>` (constant), and `<Item = 'a>` (lifetime). This is also preparatory work for supporting https://github.com/rust-lang/rust/issues/70256. r? @varkor
Diffstat (limited to 'src/test/ui/parser')
9 files changed, 82 insertions, 5 deletions
diff --git a/src/test/ui/parser/constraints-before-generic-args-syntactic-pass.rs b/src/test/ui/parser/constraints-before-generic-args-syntactic-pass.rs new file mode 100644 index 00000000000..afbd13e6fd9 --- /dev/null +++ b/src/test/ui/parser/constraints-before-generic-args-syntactic-pass.rs @@ -0,0 +1,9 @@ +// check-pass + +#[cfg(FALSE)] +fn syntax() { + foo::<T = u8, T: Ord, String>(); + foo::<T = u8, 'a, T: Ord>(); +} + +fn main() {} diff --git a/src/test/ui/parser/issue-32214.rs b/src/test/ui/parser/issue-32214.rs index 82f7ce62b94..1379eeb58e6 100644 --- a/src/test/ui/parser/issue-32214.rs +++ b/src/test/ui/parser/issue-32214.rs @@ -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 generic arguments must come before the first constraint fn main() { } diff --git a/src/test/ui/parser/issue-32214.stderr b/src/test/ui/parser/issue-32214.stderr index 08b230a14f5..742f4fdc38b 100644 --- a/src/test/ui/parser/issue-32214.stderr +++ b/src/test/ui/parser/issue-32214.stderr @@ -1,10 +1,10 @@ -error: associated type bindings must be declared after generic parameters - --> $DIR/issue-32214.rs:3:25 +error: generic arguments must come before the first constraint + --> $DIR/issue-32214.rs:3:34 | LL | pub fn test<W, I: Trait<Item=(), W> >() {} - | -------^^^ + | ------- ^ generic argument | | - | this associated type binding should be moved after the generic parameters + | the first constraint is provided here error: aborting due to previous error diff --git a/src/test/ui/parser/recover-assoc-const-constraint.rs b/src/test/ui/parser/recover-assoc-const-constraint.rs new file mode 100644 index 00000000000..06be3cdcc1a --- /dev/null +++ b/src/test/ui/parser/recover-assoc-const-constraint.rs @@ -0,0 +1,7 @@ +#[cfg(FALSE)] +fn syntax() { + bar::<Item = 42>(); //~ ERROR cannot constrain an associated constant to a value + bar::<Item = { 42 }>(); //~ ERROR cannot constrain an associated constant to a value +} + +fn main() {} diff --git a/src/test/ui/parser/recover-assoc-const-constraint.stderr b/src/test/ui/parser/recover-assoc-const-constraint.stderr new file mode 100644 index 00000000000..c6733b33faa --- /dev/null +++ b/src/test/ui/parser/recover-assoc-const-constraint.stderr @@ -0,0 +1,20 @@ +error: cannot constrain an associated constant to a value + --> $DIR/recover-assoc-const-constraint.rs:3:11 + | +LL | bar::<Item = 42>(); + | ----^^^-- + | | | + | | ...cannot be constrained to this value + | this associated constant... + +error: cannot constrain an associated constant to a value + --> $DIR/recover-assoc-const-constraint.rs:4:11 + | +LL | bar::<Item = { 42 }>(); + | ----^^^------ + | | | + | | ...cannot be constrained to this value + | this associated constant... + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/parser/recover-assoc-eq-missing-term.rs b/src/test/ui/parser/recover-assoc-eq-missing-term.rs new file mode 100644 index 00000000000..4b42c44dc64 --- /dev/null +++ b/src/test/ui/parser/recover-assoc-eq-missing-term.rs @@ -0,0 +1,6 @@ +#[cfg(FALSE)] +fn syntax() { + bar::<Item = >(); //~ ERROR missing type to the right of `=` +} + +fn main() {} diff --git a/src/test/ui/parser/recover-assoc-eq-missing-term.stderr b/src/test/ui/parser/recover-assoc-eq-missing-term.stderr new file mode 100644 index 00000000000..6e41e139220 --- /dev/null +++ b/src/test/ui/parser/recover-assoc-eq-missing-term.stderr @@ -0,0 +1,17 @@ +error: missing type to the right of `=` + --> $DIR/recover-assoc-eq-missing-term.rs:3:17 + | +LL | bar::<Item = >(); + | ^^^ + | +help: to constrain the associated type, add a type after `=` + | +LL | bar::<Item = TheType>(); + | ^^^^^^^ +help: remove the `=` if `Item` is a type + | +LL | bar::<Item >(); + | -- + +error: aborting due to previous error + diff --git a/src/test/ui/parser/recover-assoc-lifetime-constraint.rs b/src/test/ui/parser/recover-assoc-lifetime-constraint.rs new file mode 100644 index 00000000000..558fcdfe177 --- /dev/null +++ b/src/test/ui/parser/recover-assoc-lifetime-constraint.rs @@ -0,0 +1,6 @@ +#[cfg(FALSE)] +fn syntax() { + bar::<Item = 'a>(); //~ ERROR associated lifetimes are not supported +} + +fn main() {} diff --git a/src/test/ui/parser/recover-assoc-lifetime-constraint.stderr b/src/test/ui/parser/recover-assoc-lifetime-constraint.stderr new file mode 100644 index 00000000000..79437533d7c --- /dev/null +++ b/src/test/ui/parser/recover-assoc-lifetime-constraint.stderr @@ -0,0 +1,12 @@ +error: associated lifetimes are not supported + --> $DIR/recover-assoc-lifetime-constraint.rs:3:11 + | +LL | bar::<Item = 'a>(); + | ^^^^^^^-- + | | + | the lifetime is given here + | + = help: if you meant to specify a trait object, write `dyn Trait + 'lifetime` + +error: aborting due to previous error + |
