diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-12-29 10:17:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-29 10:17:08 +0100 |
| commit | bee14712ab2993c0c6a8af9c72dbfa9b149b7f8d (patch) | |
| tree | 610e13cbefe6dfbb2fbb5b9a0e6688acf4172fd1 /src | |
| parent | e31314307f09cef0989e2e052b1cad75d0a9e723 (diff) | |
| parent | 4391a11537ce38c919058c292e91f059d658da94 (diff) | |
| download | rust-bee14712ab2993c0c6a8af9c72dbfa9b149b7f8d.tar.gz rust-bee14712ab2993c0c6a8af9c72dbfa9b149b7f8d.zip | |
Rollup merge of #92118 - jackh726:type-alias-position-error, r=petrochenkov
Parse and suggest moving where clauses after equals for type aliases ~Mostly the same as #90076, but doesn't make any syntax changes.~ Whether or not we want to land the syntax changes, we should parse the invalid where clause position and suggest moving. r? `@nikomatsakis` cc `@petrochenkov` you might have thoughts on implementation
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/parser/type-alias-where.rs | 37 | ||||
| -rw-r--r-- | src/test/ui/parser/type-alias-where.stderr | 40 |
2 files changed, 77 insertions, 0 deletions
diff --git a/src/test/ui/parser/type-alias-where.rs b/src/test/ui/parser/type-alias-where.rs new file mode 100644 index 00000000000..a9fa23dd95e --- /dev/null +++ b/src/test/ui/parser/type-alias-where.rs @@ -0,0 +1,37 @@ +// check-fail + +#![feature(generic_associated_types)] + +// Fine, but lints as unused +type Foo where u32: Copy = (); +// Not fine. +type Bar = () where u32: Copy; +//~^ ERROR where clause not allowed here +type Baz = () where; +//~^ ERROR where clause not allowed here + +trait Trait { + // Fine. + type Assoc where u32: Copy; + // Fine. + type Assoc2 where u32: Copy, i32: Copy; +} + +impl Trait for u32 { + // Fine. + type Assoc where u32: Copy = (); + // Not fine, suggests moving `i32: Copy` + type Assoc2 where u32: Copy = () where i32: Copy; + //~^ ERROR where clause not allowed here +} + +impl Trait for i32 { + // Not fine, suggests moving `u32: Copy` + type Assoc = () where u32: Copy; + //~^ ERROR where clause not allowed here + // Not fine, suggests moving both. + type Assoc2 = () where u32: Copy, i32: Copy; + //~^ ERROR where clause not allowed here +} + +fn main() {} diff --git a/src/test/ui/parser/type-alias-where.stderr b/src/test/ui/parser/type-alias-where.stderr new file mode 100644 index 00000000000..7ab0b28c864 --- /dev/null +++ b/src/test/ui/parser/type-alias-where.stderr @@ -0,0 +1,40 @@ +error: where clause not allowed here + --> $DIR/type-alias-where.rs:8:15 + | +LL | type Bar = () where u32: Copy; + | - ^^^^^^^^^^^^^^^ + | | + | help: move it here: `where u32: Copy` + +error: where clause not allowed here + --> $DIR/type-alias-where.rs:10:15 + | +LL | type Baz = () where; + | ^^^^^ + +error: where clause not allowed here + --> $DIR/type-alias-where.rs:24:38 + | +LL | type Assoc2 where u32: Copy = () where i32: Copy; + | - ^^^^^^^^^^^^^^^ + | | + | help: move it here: `, i32: Copy` + +error: where clause not allowed here + --> $DIR/type-alias-where.rs:30:21 + | +LL | type Assoc = () where u32: Copy; + | - ^^^^^^^^^^^^^^^ + | | + | help: move it here: `where u32: Copy` + +error: where clause not allowed here + --> $DIR/type-alias-where.rs:33:22 + | +LL | type Assoc2 = () where u32: Copy, i32: Copy; + | - ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | help: move it here: `where u32: Copy, i32: Copy` + +error: aborting due to 5 previous errors + |
