]> git.lizzy.rs Git - rust.git/blob - tests/ui/traits/object/with-lifetime-bound.rs
Auto merge of #105716 - chriswailes:ndk-update-redux, r=pietroalbini
[rust.git] / tests / ui / traits / object / with-lifetime-bound.rs
1 // run-pass
2 // Uncovered during work on new scoping rules for safe destructors
3 // as an important use case to support properly.
4
5
6 pub struct E<'a> {
7     pub f: &'a u8,
8 }
9 impl<'b> E<'b> {
10     pub fn m(&self) -> &'b u8 { self.f }
11 }
12
13 pub struct P<'c> {
14     pub g: &'c u8,
15 }
16 pub trait M {
17     fn n(&self) -> u8;
18 }
19 impl<'d> M for P<'d> {
20     fn n(&self) -> u8 { *self.g }
21 }
22
23 fn extension<'e>(x: &'e E<'e>) -> Box<dyn M+'e> {
24     loop {
25         let p = P { g: x.m() };
26         return Box::new(p) as Box<dyn M+'e>;
27     }
28 }
29
30 fn main() {
31     let w = E { f: &10 };
32     let o = extension(&w);
33     assert_eq!(o.n(), 10);
34 }