--- /dev/null
+#![feature(associated_type_defaults)]
+
+// Having a cycle in assoc. type defaults is okay...
+trait Tr {
+ type A = Self::B;
+ type B = Self::A;
+}
+
+// ...but is an error in any impl that doesn't override at least one of the defaults
+impl Tr for () {}
+//~^ ERROR overflow evaluating the requirement
+
+// As soon as at least one is redefined, it works:
+impl Tr for u8 {
+ type A = u8;
+}
+
+impl Tr for u16 {
+ type B = ();
+}
+
+impl Tr for u32 {
+ type A = ();
+ type B = u8;
+}
+
+// ...but only if this actually breaks the cycle
+impl Tr for bool {
+//~^ ERROR overflow evaluating the requirement
+ type A = Box<Self::B>;
+ //~^ ERROR overflow evaluating the requirement
+}
+// (the error is shown twice for some reason)
+
+impl Tr for usize {
+//~^ ERROR overflow evaluating the requirement
+ type B = &'static Self::A;
+ //~^ ERROR overflow evaluating the requirement
+}
+
+fn main() {
+ // We don't check that the types project correctly because the cycle errors stop compilation
+ // before `main` is type-checked.
+ // `defaults-cyclic-pass-1.rs` does this.
+}
--- /dev/null
+error[E0275]: overflow evaluating the requirement `<() as Tr>::B`
+ --> $DIR/defaults-cyclic-fail-1.rs:12:6
+ |
+LL | impl Tr for () {}
+ | ^^
+
+error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
+ --> $DIR/defaults-cyclic-fail-1.rs:30:6
+ |
+LL | impl Tr for bool {
+ | ^^
+
+error[E0275]: overflow evaluating the requirement `<usize as Tr>::B`
+ --> $DIR/defaults-cyclic-fail-1.rs:37:6
+ |
+LL | impl Tr for usize {
+ | ^^
+
+error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
+ --> $DIR/defaults-cyclic-fail-1.rs:32:5
+ |
+LL | type A = Box<Self::B>;
+ | ^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0275]: overflow evaluating the requirement `<usize as Tr>::A`
+ --> $DIR/defaults-cyclic-fail-1.rs:39:5
+ |
+LL | type B = &'static Self::A;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0275`.
--- /dev/null
+// compile-fail
+
+#![feature(associated_type_defaults)]
+
+// A more complex version of `defaults-cyclic-fail-1.rs`, with non-trivial defaults.
+
+// Having a cycle in assoc. type defaults is okay...
+trait Tr {
+ type A = Vec<Self::B>;
+ type B = Box<Self::A>;
+}
+
+// ...but is an error in any impl that doesn't override at least one of the defaults
+impl Tr for () {}
+//~^ ERROR overflow evaluating the requirement
+
+// As soon as at least one is redefined, it works:
+impl Tr for u8 {
+ type A = u8;
+}
+
+impl Tr for u16 {
+ type B = ();
+}
+
+impl Tr for u32 {
+ type A = ();
+ type B = u8;
+}
+
+// ...but only if this actually breaks the cycle
+impl Tr for bool {
+//~^ ERROR overflow evaluating the requirement
+ type A = Box<Self::B>;
+ //~^ ERROR overflow evaluating the requirement
+}
+// (the error is shown twice for some reason)
+
+impl Tr for usize {
+//~^ ERROR overflow evaluating the requirement
+ type B = &'static Self::A;
+ //~^ ERROR overflow evaluating the requirement
+}
+
+fn main() {
+ // We don't check that the types project correctly because the cycle errors stop compilation
+ // before `main` is type-checked.
+ // `defaults-cyclic-pass-2.rs` does this.
+}
--- /dev/null
+error[E0275]: overflow evaluating the requirement `<() as Tr>::B`
+ --> $DIR/defaults-cyclic-fail-2.rs:14:6
+ |
+LL | impl Tr for () {}
+ | ^^
+
+error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
+ --> $DIR/defaults-cyclic-fail-2.rs:32:6
+ |
+LL | impl Tr for bool {
+ | ^^
+
+error[E0275]: overflow evaluating the requirement `<usize as Tr>::B`
+ --> $DIR/defaults-cyclic-fail-2.rs:39:6
+ |
+LL | impl Tr for usize {
+ | ^^
+
+error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
+ --> $DIR/defaults-cyclic-fail-2.rs:34:5
+ |
+LL | type A = Box<Self::B>;
+ | ^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0275]: overflow evaluating the requirement `<usize as Tr>::A`
+ --> $DIR/defaults-cyclic-fail-2.rs:41:5
+ |
+LL | type B = &'static Self::A;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0275`.
+++ /dev/null
-#![feature(associated_type_defaults)]
-
-// Having a cycle in assoc. type defaults is okay...
-trait Tr {
- type A = Self::B;
- type B = Self::A;
-}
-
-// ...but is an error in any impl that doesn't override at least one of the defaults
-impl Tr for () {}
-//~^ ERROR overflow evaluating the requirement
-
-// As soon as at least one is redefined, it works:
-impl Tr for u8 {
- type A = u8;
-}
-
-impl Tr for u32 {
- type A = ();
- type B = u8;
-}
-
-// ...but only if this actually breaks the cycle
-impl Tr for bool {
-//~^ ERROR overflow evaluating the requirement
- type A = Box<Self::B>;
- //~^ ERROR overflow evaluating the requirement
-}
-// (the error is shown twice for some reason)
-
-fn main() {
- // Check that the overridden type propagates to the other
- let _a: <u8 as Tr>::A = 0u8;
- let _b: <u8 as Tr>::B = 0u8;
-}
+++ /dev/null
-error[E0275]: overflow evaluating the requirement `<() as Tr>::B`
- --> $DIR/defaults-cyclic-fail.rs:10:6
- |
-LL | impl Tr for () {}
- | ^^
-
-error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
- --> $DIR/defaults-cyclic-fail.rs:24:6
- |
-LL | impl Tr for bool {
- | ^^
-
-error[E0275]: overflow evaluating the requirement `<bool as Tr>::B`
- --> $DIR/defaults-cyclic-fail.rs:26:5
- |
-LL | type A = Box<Self::B>;
- | ^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to 3 previous errors
-
-For more information about this error, try `rustc --explain E0275`.
--- /dev/null
+// check-pass
+
+#![feature(associated_type_defaults)]
+
+// Having a cycle in assoc. type defaults is okay, as long as there's no impl
+// that retains it.
+trait Tr {
+ type A = Self::B;
+ type B = Self::A;
+
+ fn f();
+}
+
+// An impl has to break the cycle to be accepted.
+impl Tr for u8 {
+ type A = u8;
+
+ fn f() {
+ // Check that the type propagates as expected (seen from inside the impl)
+ let _: Self::A = 0u8;
+ let _: Self::B = 0u8;
+ }
+}
+
+impl Tr for String {
+ type B = ();
+
+ fn f() {
+ // Check that the type propagates as expected (seen from inside the impl)
+ let _: Self::A = ();
+ let _: Self::B = ();
+ }
+}
+
+impl Tr for () {
+ type A = Vec<()>;
+ type B = u8;
+
+ fn f() {
+ // Check that the type propagates as expected (seen from inside the impl)
+ let _: Self::A = Vec::<()>::new();
+ let _: Self::B = 0u8;
+ }
+}
+
+fn main() {
+ // Check that both impls now have the right types (seen from outside the impls)
+ let _: <u8 as Tr>::A = 0u8;
+ let _: <u8 as Tr>::B = 0u8;
+
+ let _: <String as Tr>::A = ();
+ let _: <String as Tr>::B = ();
+
+ let _: <() as Tr>::A = Vec::<()>::new();
+ let _: <() as Tr>::B = 0u8;
+}
--- /dev/null
+// check-pass
+
+#![feature(associated_type_defaults)]
+
+// Having a cycle in assoc. type defaults is okay, as long as there's no impl
+// that retains it.
+trait Tr {
+ type A = Vec<Self::B>;
+ type B = Box<Self::A>;
+
+ fn f();
+}
+
+// An impl has to break the cycle to be accepted.
+impl Tr for u8 {
+ type A = u8;
+
+ fn f() {
+ // Check that the type propagates as expected (seen from inside the impl)
+ let _: Self::A = 0u8;
+ let _: Self::B = Box::new(0u8);
+ }
+}
+
+impl Tr for String {
+ type B = ();
+
+ fn f() {
+ // Check that the type propagates as expected (seen from inside the impl)
+ let _: Self::A = Vec::<()>::new();
+ let _: Self::B = ();
+ }
+}
+
+impl Tr for () {
+ type A = Vec<()>;
+ type B = u8;
+
+ fn f() {
+ // Check that the type propagates as expected (seen from inside the impl)
+ let _: Self::A = Vec::<()>::new();
+ let _: Self::B = 0u8;
+ }
+}
+
+fn main() {
+ // Check that both impls now have the right types (seen from outside the impls)
+ let _: <u8 as Tr>::A = 0u8;
+ let _: <u8 as Tr>::B = Box::new(0u8);
+
+ let _: <String as Tr>::A = Vec::<()>::new();
+ let _: <String as Tr>::B = ();
+
+ let _: <() as Tr>::A = Vec::<()>::new();
+ let _: <() as Tr>::B = 0u8;
+}
+++ /dev/null
-// check-pass
-
-#![feature(associated_type_defaults)]
-
-// Having a cycle in assoc. type defaults is okay, as long as there's no impl
-// that retains it.
-trait Tr {
- type A = Self::B;
- type B = Self::A;
-}
-
-// An impl has to break the cycle to be accepted.
-impl Tr for u8 {
- type A = u8;
-}
-
-fn main() {}