Skip to content

Commit 967ebb9

Browse files
committed
add test for may_dangle and ManuallyDrop
1 parent 60a0782 commit 967ebb9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// check-pass
2+
//! This test checks that dropck knows that ManuallyDrop does not drop its field.
3+
#![feature(dropck_eyepatch)]
4+
5+
use std::mem::ManuallyDrop;
6+
7+
struct S<T>(ManuallyDrop<T>);
8+
9+
unsafe impl<#[may_dangle] T> Drop for S<T> {
10+
fn drop(&mut self) {}
11+
}
12+
13+
struct NonTrivialDrop<'a>(&'a str);
14+
impl<'a> Drop for NonTrivialDrop<'a> {
15+
fn drop(&mut self) {}
16+
}
17+
18+
fn main() {
19+
let s = String::from("string");
20+
let _t = S(ManuallyDrop::new(NonTrivialDrop(&s)));
21+
drop(s);
22+
}

0 commit comments

Comments
 (0)