From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../2229_closure_analysis/run_pass/issue-88476.rs | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/test/ui/closures/2229_closure_analysis/run_pass/issue-88476.rs (limited to 'src/test/ui/closures/2229_closure_analysis/run_pass/issue-88476.rs') diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/issue-88476.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/issue-88476.rs new file mode 100644 index 000000000..f44c2af80 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/run_pass/issue-88476.rs @@ -0,0 +1,47 @@ +// check-pass +// edition:2021 + +use std::rc::Rc; + +// Test that we restrict precision when moving not-`Copy` types, if any of the parent paths +// implement `Drop`. This is to ensure that we don't move out of a type that implements Drop. +pub fn test1() { + struct Foo(Rc); + + impl Drop for Foo { + fn drop(self: &mut Foo) {} + } + + let f = Foo(Rc::new(1)); + let x = move || { + println!("{:?}", f.0); + }; + + x(); +} + + +// Test that we don't restrict precision when moving `Copy` types(i.e. when copying), +// even if any of the parent paths implement `Drop`. +pub fn test2() { + struct Character { + hp: u32, + name: String, + } + + impl Drop for Character { + fn drop(&mut self) {} + } + + let character = Character { hp: 100, name: format!("A") }; + + let c = move || { + println!("{}", character.hp) + }; + + c(); + + println!("{}", character.name); +} + +fn main() {} -- cgit v1.2.3