mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-02 10:18:25 +00:00

In order to expose edition dependent divergences in some tests in the test suite, add explicit `edition` annotations. Some of these tests might require additional work to *avoid* the divergences, as they might have been unintentional. These are not exhaustive changes, purely opportunistic while looking at something else.
37 lines
898 B
Rust
37 lines
898 B
Rust
//@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());
|
|
}
|