]> git.lizzy.rs Git - rust.git/blob - tests/ui/generic-associated-types/bugs/issue-87735.rs
Rollup merge of #105172 - alexs-sh:issue-98861-fix-next, r=scottmcm
[rust.git] / tests / ui / generic-associated-types / bugs / issue-87735.rs
1 // check-fail
2 // known-bug: #87735, #88526
3
4 // This should pass, but we need an extension of implied bounds (probably).
5
6 pub trait AsRef2 {
7   type Output<'a> where Self: 'a;
8
9   fn as_ref2<'a>(&'a self) -> Self::Output<'a>;
10 }
11
12 impl<T> AsRef2 for Vec<T> {
13   type Output<'a> = &'a [T] where Self: 'a;
14
15   fn as_ref2<'a>(&'a self) -> Self::Output<'a> {
16     &self[..]
17   }
18 }
19
20 #[derive(Debug)]
21 struct Foo<T>(T);
22 #[derive(Debug)]
23 struct FooRef<'a, U>(&'a [U]);
24
25 impl<'b, T, U> AsRef2 for Foo<T>
26 where
27     // * `for<'b, 'c> T: AsRef2<Output<'b> = &'c [U]>>` does not work
28     //
29     // * `U` is unconstrained but should be allowed in this context because `Output` is
30     // an associated type
31     T: AsRef2<Output<'b> = &'b [U]>,
32     U: 'b
33 {
34   type Output<'a> = FooRef<'a, U> where Self: 'a;
35
36   fn as_ref2<'a>(&'a self) -> Self::Output<'a> {
37     FooRef(self.0.as_ref2())
38   }
39 }
40
41 fn main() {
42     let foo = Foo(vec![1, 2, 3]);
43     dbg!(foo.as_ref2());
44 }