| //@revisions: edition2015 edition2024 |
| //@[edition2015] edition:2015 |
| //@[edition2024] edition:2024 |
| // This test should never pass! |
| |
| use std::cell::RefCell; |
| use std::rc::Rc; |
| |
| trait Swap: Sized { |
| fn swap(self, other: Self); |
| } |
| |
| impl<T> Swap for Rc<RefCell<T>> { |
| fn swap(self, other: Self) { |
| <RefCell<T>>::swap(&self, &other); |
| } |
| } |
| |
| fn hide<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a { |
| x |
| //[edition2015]~^ ERROR hidden type for `impl Swap + 'a` captures lifetime that does not appear in bounds |
| } |
| |
| fn dangle() -> &'static [i32; 3] { |
| let long = Rc::new(RefCell::new(&[4, 5, 6])); |
| let x = [1, 2, 3]; |
| let short = Rc::new(RefCell::new(&x)); |
| //[edition2024]~^ ERROR `x` does not live long enough |
| hide(long.clone()).swap(hide(short)); |
| let res: &'static [i32; 3] = *long.borrow(); |
| res |
| } |
| |
| fn main() { |
| println!("{:?}", dangle()); |
| } |