]> git.proxmox.com Git - rustc.git/blob - tests/ui/dropck/issue-28498-ugeh-with-lifetime-param.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / dropck / issue-28498-ugeh-with-lifetime-param.rs
1 // run-pass
2
3 // Demonstrate the use of the unguarded escape hatch with a lifetime param
4 // to assert that destructor will not access any dead data.
5 //
6 // Compare with ui/span/issue28498-reject-lifetime-param.rs
7
8 #![feature(dropck_eyepatch)]
9
10 #[derive(Debug)]
11 struct ScribbleOnDrop(String);
12
13 impl Drop for ScribbleOnDrop {
14 fn drop(&mut self) {
15 self.0 = format!("DROPPED");
16 }
17 }
18
19 struct Foo<'a>(u32, &'a ScribbleOnDrop);
20
21 unsafe impl<#[may_dangle] 'a> Drop for Foo<'a> {
22 fn drop(&mut self) {
23 // Use of `may_dangle` is sound, because destructor never accesses `self.1`.
24 println!("Dropping Foo({}, _)", self.0);
25 }
26 }
27
28 fn main() {
29 let (last_dropped, foo0);
30 let (foo1, first_dropped);
31
32 last_dropped = ScribbleOnDrop(format!("last"));
33 first_dropped = ScribbleOnDrop(format!("first"));
34 foo0 = Foo(0, &last_dropped);
35 foo1 = Foo(1, &first_dropped);
36
37 println!("foo0.1: {:?} foo1.1: {:?}", foo0.1, foo1.1);
38 }