summaryrefslogtreecommitdiffstats
path: root/tests/ui/associated-types/defaults-in-other-trait-items.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/associated-types/defaults-in-other-trait-items.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/associated-types/defaults-in-other-trait-items.rs')
-rw-r--r--tests/ui/associated-types/defaults-in-other-trait-items.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/ui/associated-types/defaults-in-other-trait-items.rs b/tests/ui/associated-types/defaults-in-other-trait-items.rs
new file mode 100644
index 000000000..505751969
--- /dev/null
+++ b/tests/ui/associated-types/defaults-in-other-trait-items.rs
@@ -0,0 +1,47 @@
+#![feature(associated_type_defaults)]
+
+// Associated type defaults may not be assumed inside the trait defining them.
+// ie. they only resolve to `<Self as Tr>::A`, not the actual type `()`
+trait Tr {
+ type A = (); //~ NOTE associated type defaults can't be assumed inside the trait defining them
+
+ fn f(p: Self::A) {
+ let () = p;
+ //~^ ERROR mismatched types
+ //~| NOTE expected associated type, found `()`
+ //~| NOTE expected associated type `<Self as Tr>::A`
+ //~| NOTE this expression has type `<Self as Tr>::A`
+ }
+}
+
+// An impl that doesn't override the type *can* assume the default.
+impl Tr for () {
+ fn f(p: Self::A) {
+ let () = p;
+ }
+}
+
+impl Tr for u8 {
+ type A = ();
+
+ fn f(p: Self::A) {
+ let () = p;
+ }
+}
+
+trait AssocConst {
+ type Ty = u8; //~ NOTE associated type defaults can't be assumed inside the trait defining them
+
+ // Assoc. consts also cannot assume that default types hold
+ const C: Self::Ty = 0u8;
+ //~^ ERROR mismatched types
+ //~| NOTE expected associated type, found `u8`
+ //~| NOTE expected associated type `<Self as AssocConst>::Ty`
+}
+
+// An impl can, however
+impl AssocConst for () {
+ const C: Self::Ty = 0u8;
+}
+
+fn main() {}