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