summaryrefslogtreecommitdiffstats
path: root/tests/ui/generic-associated-types/parse
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/generic-associated-types/parse
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/generic-associated-types/parse')
-rw-r--r--tests/ui/generic-associated-types/parse/in-trait-impl.rs8
-rw-r--r--tests/ui/generic-associated-types/parse/in-trait.rs22
-rw-r--r--tests/ui/generic-associated-types/parse/trait-path-expected-token.rs8
-rw-r--r--tests/ui/generic-associated-types/parse/trait-path-expected-token.stderr10
-rw-r--r--tests/ui/generic-associated-types/parse/trait-path-expressions.rs20
-rw-r--r--tests/ui/generic-associated-types/parse/trait-path-expressions.stderr23
-rw-r--r--tests/ui/generic-associated-types/parse/trait-path-missing-gen_arg.rs18
-rw-r--r--tests/ui/generic-associated-types/parse/trait-path-missing-gen_arg.stderr43
-rw-r--r--tests/ui/generic-associated-types/parse/trait-path-segments.rs32
-rw-r--r--tests/ui/generic-associated-types/parse/trait-path-segments.stderr41
-rw-r--r--tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.rs11
-rw-r--r--tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr33
-rw-r--r--tests/ui/generic-associated-types/parse/trait-path-types.rs20
-rw-r--r--tests/ui/generic-associated-types/parse/trait-path-types.stderr41
14 files changed, 330 insertions, 0 deletions
diff --git a/tests/ui/generic-associated-types/parse/in-trait-impl.rs b/tests/ui/generic-associated-types/parse/in-trait-impl.rs
new file mode 100644
index 000000000..767098835
--- /dev/null
+++ b/tests/ui/generic-associated-types/parse/in-trait-impl.rs
@@ -0,0 +1,8 @@
+// check-pass
+// compile-flags: -Z parse-only
+
+impl<T> Baz for T where T: Foo {
+ type Quux<'a> = <T as Foo>::Bar<'a, 'static>;
+}
+
+fn main() {}
diff --git a/tests/ui/generic-associated-types/parse/in-trait.rs b/tests/ui/generic-associated-types/parse/in-trait.rs
new file mode 100644
index 000000000..6628aac37
--- /dev/null
+++ b/tests/ui/generic-associated-types/parse/in-trait.rs
@@ -0,0 +1,22 @@
+// check-pass
+// compile-flags: -Z parse-only
+
+use std::ops::Deref;
+use std::fmt::Debug;
+
+trait Foo {
+ type Bar<'a>;
+ type Bar<'a, 'b>;
+ type Bar<'a, 'b,>;
+ type Bar<'a, 'b, T>;
+ type Bar<'a, 'b, T, U>;
+ type Bar<'a, 'b, T, U,>;
+ type Bar<'a, 'b, T: Debug, U,>;
+ type Bar<'a, 'b, T: Debug, U,>: Debug;
+ type Bar<'a, 'b, T: Debug, U,>: Deref<Target = T> + Into<U>;
+ type Bar<'a, 'b, T: Debug, U,> where T: Deref<Target = U>, U: Into<T>;
+ type Bar<'a, 'b, T: Debug, U,>: Deref<Target = T> + Into<U>
+ where T: Deref<Target = U>, U: Into<T>;
+}
+
+fn main() {}
diff --git a/tests/ui/generic-associated-types/parse/trait-path-expected-token.rs b/tests/ui/generic-associated-types/parse/trait-path-expected-token.rs
new file mode 100644
index 000000000..cbb051892
--- /dev/null
+++ b/tests/ui/generic-associated-types/parse/trait-path-expected-token.rs
@@ -0,0 +1,8 @@
+trait X {
+ type Y<'a>;
+}
+
+fn f1<'a>(arg : Box<dyn X<Y = B = &'a ()>>) {}
+ //~^ ERROR: expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `=`
+
+fn main() {}
diff --git a/tests/ui/generic-associated-types/parse/trait-path-expected-token.stderr b/tests/ui/generic-associated-types/parse/trait-path-expected-token.stderr
new file mode 100644
index 000000000..53d5f9de6
--- /dev/null
+++ b/tests/ui/generic-associated-types/parse/trait-path-expected-token.stderr
@@ -0,0 +1,10 @@
+error: expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `=`
+ --> $DIR/trait-path-expected-token.rs:5:33
+ |
+LL | fn f1<'a>(arg : Box<dyn X<Y = B = &'a ()>>) {}
+ | - ^ expected one of 7 possible tokens
+ | |
+ | maybe try to close unmatched angle bracket
+
+error: aborting due to previous error
+
diff --git a/tests/ui/generic-associated-types/parse/trait-path-expressions.rs b/tests/ui/generic-associated-types/parse/trait-path-expressions.rs
new file mode 100644
index 000000000..9183ec497
--- /dev/null
+++ b/tests/ui/generic-associated-types/parse/trait-path-expressions.rs
@@ -0,0 +1,20 @@
+mod error1 {
+ trait X {
+ type Y<'a>;
+ }
+
+ fn f1<'a>(arg : Box<dyn X< 1 = 32 >>) {}
+ //~^ ERROR: expected expression, found `)`
+}
+
+mod error2 {
+
+ trait X {
+ type Y<'a>;
+ }
+
+ fn f2<'a>(arg : Box<dyn X< { 1 } = 32 >>) {}
+ //~^ ERROR: expected one of
+}
+
+fn main() {}
diff --git a/tests/ui/generic-associated-types/parse/trait-path-expressions.stderr b/tests/ui/generic-associated-types/parse/trait-path-expressions.stderr
new file mode 100644
index 000000000..cf2b1763f
--- /dev/null
+++ b/tests/ui/generic-associated-types/parse/trait-path-expressions.stderr
@@ -0,0 +1,23 @@
+error: expected expression, found `)`
+ --> $DIR/trait-path-expressions.rs:6:39
+ |
+LL | fn f1<'a>(arg : Box<dyn X< 1 = 32 >>) {}
+ | - ^ expected expression
+ | |
+ | while parsing a const generic argument starting here
+
+error: expected one of `,`, `:`, or `>`, found `=`
+ --> $DIR/trait-path-expressions.rs:16:36
+ |
+LL | fn f2<'a>(arg : Box<dyn X< { 1 } = 32 >>) {}
+ | - ^ expected one of `,`, `:`, or `>`
+ | |
+ | maybe try to close unmatched angle bracket
+ |
+help: you might have meant to end the type parameters here
+ |
+LL | fn f2<'a>(arg : Box<dyn X< { 1 }> = 32 >>) {}
+ | +
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/generic-associated-types/parse/trait-path-missing-gen_arg.rs b/tests/ui/generic-associated-types/parse/trait-path-missing-gen_arg.rs
new file mode 100644
index 000000000..ecabf8943
--- /dev/null
+++ b/tests/ui/generic-associated-types/parse/trait-path-missing-gen_arg.rs
@@ -0,0 +1,18 @@
+trait X {
+ type Y<'a>;
+}
+
+const _: () = {
+ fn f1<'a>(arg : Box<dyn X< : 32 >>) {}
+ //~^ ERROR: expected one of `>`, a const expression, lifetime, or type, found `:`
+ //~| ERROR: expected parameter name, found `>`
+ //~| ERROR: expected one of `!`, `)`, `+`, `,`, or `::`, found `>`
+ //~| ERROR: constant provided when a type was expected
+};
+
+const _: () = {
+ fn f1<'a>(arg : Box<dyn X< = 32 >>) {}
+ //~^ ERROR: expected one of `>`, a const expression, lifetime, or type, found `=`
+};
+
+fn main() {}
diff --git a/tests/ui/generic-associated-types/parse/trait-path-missing-gen_arg.stderr b/tests/ui/generic-associated-types/parse/trait-path-missing-gen_arg.stderr
new file mode 100644
index 000000000..10ceccedc
--- /dev/null
+++ b/tests/ui/generic-associated-types/parse/trait-path-missing-gen_arg.stderr
@@ -0,0 +1,43 @@
+error: expected one of `>`, a const expression, lifetime, or type, found `:`
+ --> $DIR/trait-path-missing-gen_arg.rs:6:30
+ |
+LL | fn f1<'a>(arg : Box<dyn X< : 32 >>) {}
+ | ^ expected one of `>`, a const expression, lifetime, or type
+ |
+help: expressions must be enclosed in braces to be used as const generic arguments
+ |
+LL | fn f1<'a>(arg : Box<{ dyn X< : 32 } >>) {}
+ | + +
+
+error: expected parameter name, found `>`
+ --> $DIR/trait-path-missing-gen_arg.rs:6:36
+ |
+LL | fn f1<'a>(arg : Box<dyn X< : 32 >>) {}
+ | ^ expected parameter name
+
+error: expected one of `!`, `)`, `+`, `,`, or `::`, found `>`
+ --> $DIR/trait-path-missing-gen_arg.rs:6:36
+ |
+LL | fn f1<'a>(arg : Box<dyn X< : 32 >>) {}
+ | ^
+ | |
+ | expected one of `!`, `)`, `+`, `,`, or `::`
+ | help: missing `,`
+
+error: expected one of `>`, a const expression, lifetime, or type, found `=`
+ --> $DIR/trait-path-missing-gen_arg.rs:14:30
+ |
+LL | fn f1<'a>(arg : Box<dyn X< = 32 >>) {}
+ | - ^ expected one of `>`, a const expression, lifetime, or type
+ | |
+ | maybe try to close unmatched angle bracket
+
+error[E0747]: constant provided when a type was expected
+ --> $DIR/trait-path-missing-gen_arg.rs:6:23
+ |
+LL | fn f1<'a>(arg : Box<dyn X< : 32 >>) {}
+ | ^^^^^^^^^^^
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0747`.
diff --git a/tests/ui/generic-associated-types/parse/trait-path-segments.rs b/tests/ui/generic-associated-types/parse/trait-path-segments.rs
new file mode 100644
index 000000000..458e203eb
--- /dev/null
+++ b/tests/ui/generic-associated-types/parse/trait-path-segments.rs
@@ -0,0 +1,32 @@
+const _: () = {
+ trait X {
+ type Y<'a>;
+ }
+
+ fn f1<'a>(arg : Box<dyn X<X::Y = u32>>) {}
+ //~^ ERROR: expected one of
+ };
+
+const _: () = {
+ trait X {
+ type Y<'a>;
+ }
+
+ trait Z {}
+
+ impl<T : X<<Self as X>::Y<'a> = &'a u32>> Z for T {}
+ //~^ ERROR: expected one of
+};
+
+const _: () = {
+ trait X {
+ type Y<'a>;
+ }
+
+ trait Z {}
+
+ impl<T : X<X::Y<'a> = &'a u32>> Z for T {}
+ //~^ ERROR: expected one of
+};
+
+fn main() {}
diff --git a/tests/ui/generic-associated-types/parse/trait-path-segments.stderr b/tests/ui/generic-associated-types/parse/trait-path-segments.stderr
new file mode 100644
index 000000000..8bc737d67
--- /dev/null
+++ b/tests/ui/generic-associated-types/parse/trait-path-segments.stderr
@@ -0,0 +1,41 @@
+error: expected one of `!`, `(`, `+`, `,`, `::`, `:`, `<`, or `>`, found `=`
+ --> $DIR/trait-path-segments.rs:6:36
+ |
+LL | fn f1<'a>(arg : Box<dyn X<X::Y = u32>>) {}
+ | - ^ expected one of 8 possible tokens
+ | |
+ | maybe try to close unmatched angle bracket
+ |
+help: you might have meant to end the type parameters here
+ |
+LL | fn f1<'a>(arg : Box<dyn X<X::Y> = u32>>) {}
+ | +
+
+error: expected one of `,`, `::`, `:`, or `>`, found `=`
+ --> $DIR/trait-path-segments.rs:17:35
+ |
+LL | impl<T : X<<Self as X>::Y<'a> = &'a u32>> Z for T {}
+ | - ^ expected one of `,`, `::`, `:`, or `>`
+ | |
+ | maybe try to close unmatched angle bracket
+ |
+help: you might have meant to end the type parameters here
+ |
+LL | impl<T : X<<Self as X>::Y<'a>> = &'a u32>> Z for T {}
+ | +
+
+error: expected one of `!`, `+`, `,`, `::`, `:`, or `>`, found `=`
+ --> $DIR/trait-path-segments.rs:28:25
+ |
+LL | impl<T : X<X::Y<'a> = &'a u32>> Z for T {}
+ | - ^ expected one of `!`, `+`, `,`, `::`, `:`, or `>`
+ | |
+ | maybe try to close unmatched angle bracket
+ |
+help: you might have meant to end the type parameters here
+ |
+LL | impl<T : X<X::Y<'a>> = &'a u32>> Z for T {}
+ | +
+
+error: aborting due to 3 previous errors
+
diff --git a/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.rs b/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.rs
new file mode 100644
index 000000000..1622b92aa
--- /dev/null
+++ b/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.rs
@@ -0,0 +1,11 @@
+trait X {
+ type Y<'a>;
+}
+
+const _: () = {
+ fn f2<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
+ //~^ ERROR this associated type takes 1 lifetime argument but 0 lifetime arguments
+ //~| ERROR this associated type takes 0 generic arguments but 1 generic argument
+};
+
+fn main() {}
diff --git a/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr b/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr
new file mode 100644
index 000000000..0a09ec5dc
--- /dev/null
+++ b/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr
@@ -0,0 +1,33 @@
+error[E0107]: this associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
+ --> $DIR/trait-path-type-error-once-implemented.rs:6:29
+ |
+LL | fn f2<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
+ | ^ expected 1 lifetime argument
+ |
+note: associated type defined here, with 1 lifetime parameter: `'a`
+ --> $DIR/trait-path-type-error-once-implemented.rs:2:10
+ |
+LL | type Y<'a>;
+ | ^ --
+help: add missing lifetime argument
+ |
+LL | fn f2<'a>(arg : Box<dyn X<Y<'_, 1> = &'a ()>>) {}
+ | +++
+
+error[E0107]: this associated type takes 0 generic arguments but 1 generic argument was supplied
+ --> $DIR/trait-path-type-error-once-implemented.rs:6:29
+ |
+LL | fn f2<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
+ | ^--- help: remove these generics
+ | |
+ | expected 0 generic arguments
+ |
+note: associated type defined here, with 0 generic parameters
+ --> $DIR/trait-path-type-error-once-implemented.rs:2:10
+ |
+LL | type Y<'a>;
+ | ^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0107`.
diff --git a/tests/ui/generic-associated-types/parse/trait-path-types.rs b/tests/ui/generic-associated-types/parse/trait-path-types.rs
new file mode 100644
index 000000000..74a00342f
--- /dev/null
+++ b/tests/ui/generic-associated-types/parse/trait-path-types.rs
@@ -0,0 +1,20 @@
+trait X {
+ type Y<'a>;
+}
+
+const _: () = {
+ fn f<'a>(arg : Box<dyn X< [u8; 1] = u32>>) {}
+ //~^ ERROR: expected one of
+};
+
+const _: () = {
+ fn f1<'a>(arg : Box<dyn X<(Y<'a>) = &'a ()>>) {}
+ //~^ ERROR: expected one of
+};
+
+const _: () = {
+ fn f1<'a>(arg : Box<dyn X< 'a = u32 >>) {}
+ //~^ ERROR: expected one of
+};
+
+fn main() {}
diff --git a/tests/ui/generic-associated-types/parse/trait-path-types.stderr b/tests/ui/generic-associated-types/parse/trait-path-types.stderr
new file mode 100644
index 000000000..8f7a73c95
--- /dev/null
+++ b/tests/ui/generic-associated-types/parse/trait-path-types.stderr
@@ -0,0 +1,41 @@
+error: expected one of `,`, `:`, or `>`, found `=`
+ --> $DIR/trait-path-types.rs:6:37
+ |
+LL | fn f<'a>(arg : Box<dyn X< [u8; 1] = u32>>) {}
+ | - ^ expected one of `,`, `:`, or `>`
+ | |
+ | maybe try to close unmatched angle bracket
+ |
+help: you might have meant to end the type parameters here
+ |
+LL | fn f<'a>(arg : Box<dyn X< [u8; 1]> = u32>>) {}
+ | +
+
+error: expected one of `,`, `:`, or `>`, found `=`
+ --> $DIR/trait-path-types.rs:11:37
+ |
+LL | fn f1<'a>(arg : Box<dyn X<(Y<'a>) = &'a ()>>) {}
+ | - ^ expected one of `,`, `:`, or `>`
+ | |
+ | maybe try to close unmatched angle bracket
+ |
+help: you might have meant to end the type parameters here
+ |
+LL | fn f1<'a>(arg : Box<dyn X<(Y<'a>)> = &'a ()>>) {}
+ | +
+
+error: expected one of `,`, `:`, or `>`, found `=`
+ --> $DIR/trait-path-types.rs:16:33
+ |
+LL | fn f1<'a>(arg : Box<dyn X< 'a = u32 >>) {}
+ | -- ^ expected one of `,`, `:`, or `>`
+ | |
+ | maybe try to close unmatched angle bracket
+ |
+help: you might have meant to end the type parameters here
+ |
+LL | fn f1<'a>(arg : Box<dyn X< 'a> = u32 >>) {}
+ | +
+
+error: aborting due to 3 previous errors
+