]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-21726.rs
09d1a3bca6901723076782e3c107d73cc7a771c2
[rust.git] / src / test / run-pass / issue-21726.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Regression test for #21726: an issue arose around the rules for
12 // subtyping of projection types that resulted in an unconstrained
13 // region, yielding region inference failures.
14
15 fn main() { }
16
17 fn foo<'a>(s: &'a str) {
18     let b: B<()> = B::new(s, ());
19     b.get_short();
20 }
21
22 trait IntoRef<'a> {
23     type T: Clone;
24     fn into_ref(self, &'a str) -> Self::T;
25 }
26
27 impl<'a> IntoRef<'a> for () {
28     type T = &'a str;
29     fn into_ref(self, s: &'a str) -> &'a str {
30         s
31     }
32 }
33
34 struct B<'a, P: IntoRef<'a>>(P::T);
35
36 impl<'a, P: IntoRef<'a>> B<'a, P> {
37     fn new(s: &'a str, i: P) -> B<'a, P> {
38         B(i.into_ref(s))
39     }
40
41     fn get_short(&self) -> P::T {
42         self.0.clone()
43     }
44 }