summaryrefslogtreecommitdiffstats
path: root/tests/ui/generics/issue-61631-default-type-param-cannot-reference-self.rs
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/generics/issue-61631-default-type-param-cannot-reference-self.rs
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/generics/issue-61631-default-type-param-cannot-reference-self.rs')
-rw-r--r--tests/ui/generics/issue-61631-default-type-param-cannot-reference-self.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/ui/generics/issue-61631-default-type-param-cannot-reference-self.rs b/tests/ui/generics/issue-61631-default-type-param-cannot-reference-self.rs
new file mode 100644
index 000000000..12db143e4
--- /dev/null
+++ b/tests/ui/generics/issue-61631-default-type-param-cannot-reference-self.rs
@@ -0,0 +1,45 @@
+#![crate_type="lib"]
+
+// rust-lang/rust#61631: Uses of `Self` in the defaults of generic
+// types for ADT's are not allowed. We justify this because the `Self`
+// type could be considered the "final" type parameter, that is only
+// well-defined after all of the other type parameters on the ADT have
+// been instantiated.
+//
+// These were previously were ICE'ing at the usage point anyway (see
+// `demo_usages` below), so there should not be any backwards
+// compatibility concern.
+
+struct Snobound<'a, P = Self> { x: Option<&'a P> }
+//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
+
+enum Enobound<'a, P = Self> { A, B(Option<&'a P>) }
+//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
+
+union Unobound<'a, P = Self> { x: i32, y: Option<&'a P> }
+//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
+
+// Disallowing `Self` in defaults sidesteps need to check the bounds
+// on the defaults in cases like these.
+
+struct Ssized<'a, P: Sized = [Self]> { x: Option<&'a P> }
+//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
+
+enum Esized<'a, P: Sized = [Self]> { A, B(Option<&'a P>) }
+//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
+
+union Usized<'a, P: Sized = [Self]> { x: i32, y: Option<&'a P> }
+//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
+
+fn demo_usages() {
+ // An ICE means you only get the error from the first line of the
+ // demo; comment each out to observe the other ICEs when trying
+ // this out on older versions of Rust.
+
+ let _ice: Snobound;
+ let _ice: Enobound;
+ let _ice: Unobound;
+ let _ice: Ssized;
+ let _ice: Esized;
+ let _ice: Usized;
+}