2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2015-01-05 06:26:29 -06:00
|
|
|
// This is a regression test for something that only came up while
|
2020-02-29 11:16:26 -06:00
|
|
|
// attempting to bootstrap librustc_ast; it is adapted from
|
2020-02-29 11:37:32 -06:00
|
|
|
// `rustc_ast::ext::tt::generic_extension`.
|
2015-01-05 06:26:29 -06:00
|
|
|
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2015-01-05 06:26:29 -06:00
|
|
|
pub struct E<'a> {
|
|
|
|
pub f: &'a u8,
|
|
|
|
}
|
|
|
|
impl<'b> E<'b> {
|
|
|
|
pub fn m(&self) -> &'b u8 { self.f }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct P<'c> {
|
|
|
|
pub g: &'c u8,
|
|
|
|
}
|
|
|
|
pub trait M {
|
|
|
|
fn n(&self) -> u8;
|
|
|
|
}
|
|
|
|
impl<'d> M for P<'d> {
|
|
|
|
fn n(&self) -> u8 { *self.g }
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:47:21 -05:00
|
|
|
fn extension<'e>(x: &'e E<'e>) -> Box<dyn M+'e> {
|
2015-01-05 06:26:29 -06:00
|
|
|
loop {
|
|
|
|
let p = P { g: x.m() };
|
2019-05-28 13:47:21 -05:00
|
|
|
return Box::new(p) as Box<dyn M+'e>;
|
2015-01-05 06:26:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2015-03-03 02:42:26 -06:00
|
|
|
let w = E { f: &10 };
|
2015-01-05 06:26:29 -06:00
|
|
|
let o = extension(&w);
|
2015-03-03 02:42:26 -06:00
|
|
|
assert_eq!(o.n(), 10);
|
2015-01-05 06:26:29 -06:00
|
|
|
}
|