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