From 967ebb9c3d21d1692b0fa51112eee71c1b4668c4 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 15 Feb 2023 11:41:33 +0100 Subject: [PATCH] add test for may_dangle and ManuallyDrop --- tests/ui/drop/dropck-eyepatch-manuallydrop.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/ui/drop/dropck-eyepatch-manuallydrop.rs diff --git a/tests/ui/drop/dropck-eyepatch-manuallydrop.rs b/tests/ui/drop/dropck-eyepatch-manuallydrop.rs new file mode 100644 index 00000000000..ff100cd941f --- /dev/null +++ b/tests/ui/drop/dropck-eyepatch-manuallydrop.rs @@ -0,0 +1,22 @@ +// check-pass +//! This test checks that dropck knows that ManuallyDrop does not drop its field. +#![feature(dropck_eyepatch)] + +use std::mem::ManuallyDrop; + +struct S(ManuallyDrop); + +unsafe impl<#[may_dangle] T> Drop for S { + fn drop(&mut self) {} +} + +struct NonTrivialDrop<'a>(&'a str); +impl<'a> Drop for NonTrivialDrop<'a> { + fn drop(&mut self) {} +} + +fn main() { + let s = String::from("string"); + let _t = S(ManuallyDrop::new(NonTrivialDrop(&s))); + drop(s); +}