summaryrefslogtreecommitdiffstats
path: root/tests/ui/associated-inherent-types
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/associated-inherent-types
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/associated-inherent-types')
-rw-r--r--tests/ui/associated-inherent-types/assoc-inherent-no-body.rs10
-rw-r--r--tests/ui/associated-inherent-types/assoc-inherent-no-body.stderr10
-rw-r--r--tests/ui/associated-inherent-types/assoc-inherent-private.rs23
-rw-r--r--tests/ui/associated-inherent-types/assoc-inherent-private.stderr21
-rw-r--r--tests/ui/associated-inherent-types/assoc-inherent-unstable.rs6
-rw-r--r--tests/ui/associated-inherent-types/assoc-inherent-unstable.stderr11
-rw-r--r--tests/ui/associated-inherent-types/assoc-inherent-use.rs14
-rw-r--r--tests/ui/associated-inherent-types/auxiliary/assoc-inherent-unstable.rs11
-rw-r--r--tests/ui/associated-inherent-types/issue-104260.rs14
-rw-r--r--tests/ui/associated-inherent-types/normalize-projection-0.rs22
-rw-r--r--tests/ui/associated-inherent-types/normalize-projection-1.rs22
-rw-r--r--tests/ui/associated-inherent-types/struct-generics.rs15
-rw-r--r--tests/ui/associated-inherent-types/style.rs12
-rw-r--r--tests/ui/associated-inherent-types/style.stderr14
14 files changed, 205 insertions, 0 deletions
diff --git a/tests/ui/associated-inherent-types/assoc-inherent-no-body.rs b/tests/ui/associated-inherent-types/assoc-inherent-no-body.rs
new file mode 100644
index 000000000..71f65b92e
--- /dev/null
+++ b/tests/ui/associated-inherent-types/assoc-inherent-no-body.rs
@@ -0,0 +1,10 @@
+#![feature(inherent_associated_types)]
+#![allow(incomplete_features)]
+
+struct Foo;
+
+impl Foo {
+ type Baz; //~ ERROR associated type in `impl` without body
+}
+
+fn main() {}
diff --git a/tests/ui/associated-inherent-types/assoc-inherent-no-body.stderr b/tests/ui/associated-inherent-types/assoc-inherent-no-body.stderr
new file mode 100644
index 000000000..387a5658d
--- /dev/null
+++ b/tests/ui/associated-inherent-types/assoc-inherent-no-body.stderr
@@ -0,0 +1,10 @@
+error: associated type in `impl` without body
+ --> $DIR/assoc-inherent-no-body.rs:7:5
+ |
+LL | type Baz;
+ | ^^^^^^^^-
+ | |
+ | help: provide a definition for the type: `= <type>;`
+
+error: aborting due to previous error
+
diff --git a/tests/ui/associated-inherent-types/assoc-inherent-private.rs b/tests/ui/associated-inherent-types/assoc-inherent-private.rs
new file mode 100644
index 000000000..531581954
--- /dev/null
+++ b/tests/ui/associated-inherent-types/assoc-inherent-private.rs
@@ -0,0 +1,23 @@
+#![feature(inherent_associated_types)]
+#![allow(incomplete_features)]
+
+mod m {
+ pub struct T;
+ impl T {
+ type P = ();
+ }
+}
+type U = m::T::P; //~ ERROR associated type `P` is private
+
+mod n {
+ pub mod n {
+ pub struct T;
+ impl T {
+ pub(super) type P = bool;
+ }
+ }
+ type U = n::T::P;
+}
+type V = n::n::T::P; //~ ERROR associated type `P` is private
+
+fn main() {}
diff --git a/tests/ui/associated-inherent-types/assoc-inherent-private.stderr b/tests/ui/associated-inherent-types/assoc-inherent-private.stderr
new file mode 100644
index 000000000..d67b45dae
--- /dev/null
+++ b/tests/ui/associated-inherent-types/assoc-inherent-private.stderr
@@ -0,0 +1,21 @@
+error[E0624]: associated type `P` is private
+ --> $DIR/assoc-inherent-private.rs:10:10
+ |
+LL | type P = ();
+ | ------ associated type defined here
+...
+LL | type U = m::T::P;
+ | ^^^^^^^ private associated type
+
+error[E0624]: associated type `P` is private
+ --> $DIR/assoc-inherent-private.rs:21:10
+ |
+LL | pub(super) type P = bool;
+ | ----------------- associated type defined here
+...
+LL | type V = n::n::T::P;
+ | ^^^^^^^^^^ private associated type
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0624`.
diff --git a/tests/ui/associated-inherent-types/assoc-inherent-unstable.rs b/tests/ui/associated-inherent-types/assoc-inherent-unstable.rs
new file mode 100644
index 000000000..34b4e47bf
--- /dev/null
+++ b/tests/ui/associated-inherent-types/assoc-inherent-unstable.rs
@@ -0,0 +1,6 @@
+// aux-crate:aux=assoc-inherent-unstable.rs
+// edition: 2021
+
+type Data = aux::Owner::Data; //~ ERROR use of unstable library feature 'data'
+
+fn main() {}
diff --git a/tests/ui/associated-inherent-types/assoc-inherent-unstable.stderr b/tests/ui/associated-inherent-types/assoc-inherent-unstable.stderr
new file mode 100644
index 000000000..c0be8bfd7
--- /dev/null
+++ b/tests/ui/associated-inherent-types/assoc-inherent-unstable.stderr
@@ -0,0 +1,11 @@
+error[E0658]: use of unstable library feature 'data'
+ --> $DIR/assoc-inherent-unstable.rs:4:13
+ |
+LL | type Data = aux::Owner::Data;
+ | ^^^^^^^^^^^^^^^^
+ |
+ = help: add `#![feature(data)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/associated-inherent-types/assoc-inherent-use.rs b/tests/ui/associated-inherent-types/assoc-inherent-use.rs
new file mode 100644
index 000000000..7ae425e2a
--- /dev/null
+++ b/tests/ui/associated-inherent-types/assoc-inherent-use.rs
@@ -0,0 +1,14 @@
+// check-pass
+#![feature(inherent_associated_types)]
+#![allow(incomplete_features)]
+
+struct Foo;
+
+impl Foo {
+ type Bar = isize;
+}
+
+fn main() {
+ let x: Foo::Bar;
+ x = 0isize;
+}
diff --git a/tests/ui/associated-inherent-types/auxiliary/assoc-inherent-unstable.rs b/tests/ui/associated-inherent-types/auxiliary/assoc-inherent-unstable.rs
new file mode 100644
index 000000000..6b71ffc97
--- /dev/null
+++ b/tests/ui/associated-inherent-types/auxiliary/assoc-inherent-unstable.rs
@@ -0,0 +1,11 @@
+#![feature(staged_api)]
+#![feature(inherent_associated_types)]
+#![stable(feature = "main", since = "1.0.0")]
+
+#[stable(feature = "main", since = "1.0.0")]
+pub struct Owner;
+
+impl Owner {
+ #[unstable(feature = "data", issue = "none")]
+ pub type Data = ();
+}
diff --git a/tests/ui/associated-inherent-types/issue-104260.rs b/tests/ui/associated-inherent-types/issue-104260.rs
new file mode 100644
index 000000000..a73cd1775
--- /dev/null
+++ b/tests/ui/associated-inherent-types/issue-104260.rs
@@ -0,0 +1,14 @@
+// check-pass
+
+#![feature(inherent_associated_types)]
+#![allow(incomplete_features)]
+
+struct Foo;
+
+impl Foo {
+ type Bar<T> = u8;
+}
+
+fn main() {
+ let a: Foo::Bar<()>;
+}
diff --git a/tests/ui/associated-inherent-types/normalize-projection-0.rs b/tests/ui/associated-inherent-types/normalize-projection-0.rs
new file mode 100644
index 000000000..50763ecdd
--- /dev/null
+++ b/tests/ui/associated-inherent-types/normalize-projection-0.rs
@@ -0,0 +1,22 @@
+// check-pass
+
+#![feature(inherent_associated_types)]
+#![allow(incomplete_features)]
+
+struct S<T>(T);
+
+impl<T: O> S<T> {
+ type P = <T as O>::P;
+}
+
+trait O {
+ type P;
+}
+
+impl O for i32 {
+ type P = String;
+}
+
+fn main() {
+ let _: S<i32>::P = String::new();
+}
diff --git a/tests/ui/associated-inherent-types/normalize-projection-1.rs b/tests/ui/associated-inherent-types/normalize-projection-1.rs
new file mode 100644
index 000000000..2f7b2551a
--- /dev/null
+++ b/tests/ui/associated-inherent-types/normalize-projection-1.rs
@@ -0,0 +1,22 @@
+// check-pass
+
+#![feature(inherent_associated_types)]
+#![allow(incomplete_features)]
+
+struct S;
+
+impl S {
+ type P<T: O> = <T as O>::P;
+}
+
+trait O {
+ type P;
+}
+
+impl O for i32 {
+ type P = String;
+}
+
+fn main() {
+ let _: S::P<i32> = String::new();
+}
diff --git a/tests/ui/associated-inherent-types/struct-generics.rs b/tests/ui/associated-inherent-types/struct-generics.rs
new file mode 100644
index 000000000..8952b3791
--- /dev/null
+++ b/tests/ui/associated-inherent-types/struct-generics.rs
@@ -0,0 +1,15 @@
+// check-pass
+
+#![feature(inherent_associated_types)]
+#![allow(incomplete_features)]
+
+struct S<T>(T);
+
+impl<T> S<T> {
+ type P = T;
+}
+
+fn main() {
+ type A = S<()>::P;
+ let _: A = ();
+}
diff --git a/tests/ui/associated-inherent-types/style.rs b/tests/ui/associated-inherent-types/style.rs
new file mode 100644
index 000000000..8775bd19e
--- /dev/null
+++ b/tests/ui/associated-inherent-types/style.rs
@@ -0,0 +1,12 @@
+#![feature(inherent_associated_types)]
+#![allow(incomplete_features, dead_code)]
+#![deny(non_camel_case_types)]
+
+struct S;
+
+impl S {
+ type typ = ();
+ //~^ ERROR associated type `typ` should have an upper camel case name
+}
+
+fn main() {}
diff --git a/tests/ui/associated-inherent-types/style.stderr b/tests/ui/associated-inherent-types/style.stderr
new file mode 100644
index 000000000..f83061f8c
--- /dev/null
+++ b/tests/ui/associated-inherent-types/style.stderr
@@ -0,0 +1,14 @@
+error: associated type `typ` should have an upper camel case name
+ --> $DIR/style.rs:8:10
+ |
+LL | type typ = ();
+ | ^^^ help: convert the identifier to upper camel case: `Typ`
+ |
+note: the lint level is defined here
+ --> $DIR/style.rs:3:9
+ |
+LL | #![deny(non_camel_case_types)]
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+