]> git.lizzy.rs Git - rust.git/blob - tests/ui/associated-types/issue-21726.rs
Rollup merge of #103236 - tspiteri:redoc-int-adc-sbb, r=m-ou-se
[rust.git] / tests / ui / associated-types / issue-21726.rs
1 // check-pass
2 #![allow(dead_code)]
3 // Regression test for #21726: an issue arose around the rules for
4 // subtyping of projection types that resulted in an unconstrained
5 // region, yielding region inference failures.
6
7 // pretty-expanded FIXME #23616
8
9 fn main() { }
10
11 fn foo<'a>(s: &'a str) {
12     let b: B<()> = B::new(s, ());
13     b.get_short();
14 }
15
16 trait IntoRef<'a> {
17     type T: Clone;
18     fn into_ref(self, _: &'a str) -> Self::T;
19 }
20
21 impl<'a> IntoRef<'a> for () {
22     type T = &'a str;
23     fn into_ref(self, s: &'a str) -> &'a str {
24         s
25     }
26 }
27
28 struct B<'a, P: IntoRef<'a>>(P::T);
29
30 impl<'a, P: IntoRef<'a>> B<'a, P> {
31     fn new(s: &'a str, i: P) -> B<'a, P> {
32         B(i.into_ref(s))
33     }
34
35     fn get_short(&self) -> P::T {
36         self.0.clone()
37     }
38 }