about summary refs log tree commit diff
path: root/tests/ui/impl-trait/bound-normalization-pass.rs
diff options
context:
space:
mode:
authorAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-05 09:13:28 +0100
committerAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-11 09:32:08 +0000
commitcf2dff2b1e3fa55fa5415d524200070d0d7aacfe (patch)
tree40a88d9a46aaf3e8870676eb2538378b75a263eb /tests/ui/impl-trait/bound-normalization-pass.rs
parentca855e6e42787ecd062d81d53336fe6788ef51a9 (diff)
downloadrust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.tar.gz
rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.zip
Move /src/test to /tests
Diffstat (limited to 'tests/ui/impl-trait/bound-normalization-pass.rs')
-rw-r--r--tests/ui/impl-trait/bound-normalization-pass.rs87
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/bound-normalization-pass.rs b/tests/ui/impl-trait/bound-normalization-pass.rs
new file mode 100644
index 00000000000..51718079d2c
--- /dev/null
+++ b/tests/ui/impl-trait/bound-normalization-pass.rs
@@ -0,0 +1,87 @@
+// check-pass
+// edition:2018
+// revisions: default sa
+//[sa] compile-flags: -Z save-analysis
+//-^ To make this the regression test for #75962.
+
+#![feature(type_alias_impl_trait)]
+
+// See issue 60414
+
+// Reduction to `impl Trait`
+
+struct Foo<T>(T);
+
+trait FooLike {
+    type Output;
+}
+
+impl<T> FooLike for Foo<T> {
+    type Output = T;
+}
+
+mod impl_trait {
+    use super::*;
+
+    trait Trait {
+        type Assoc;
+    }
+
+    /// `T::Assoc` should be normalized to `()` here.
+    fn foo_pass<T: Trait<Assoc = ()>>() -> impl FooLike<Output = T::Assoc> {
+        Foo(())
+    }
+}
+
+// Same with lifetimes in the trait
+
+mod lifetimes {
+    use super::*;
+
+    trait Trait<'a> {
+        type Assoc;
+    }
+
+    /// Like above.
+    ///
+    /// FIXME(#51525) -- the shorter notation `T::Assoc` winds up referencing `'static` here
+    fn foo2_pass<'a, T: Trait<'a, Assoc = ()> + 'a>()
+    -> impl FooLike<Output = <T as Trait<'a>>::Assoc> + 'a {
+        Foo(())
+    }
+
+    /// Normalization to type containing bound region.
+    ///
+    /// FIXME(#51525) -- the shorter notation `T::Assoc` winds up referencing `'static` here
+    fn foo2_pass2<'a, T: Trait<'a, Assoc = &'a ()> + 'a>()
+    -> impl FooLike<Output = <T as Trait<'a>>::Assoc> + 'a {
+        Foo(&())
+    }
+}
+
+// The same applied to `type Foo = impl Bar`s
+
+mod opaque_types {
+    trait Implemented {
+        type Assoc;
+    }
+    impl<T> Implemented for T {
+        type Assoc = u8;
+    }
+
+    trait Trait {
+        type Out;
+    }
+
+    impl Trait for () {
+        type Out = u8;
+    }
+
+    type Ex = impl Trait<Out = <() as Implemented>::Assoc>;
+
+    fn define() -> Ex {
+        ()
+    }
+}
+
+fn main() {}