diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
commit | 218caa410aa38c29984be31a5229b9fa717560ee (patch) | |
tree | c54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/closures/2229_closure_analysis/issue-88476.rs | |
parent | Releasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/closures/2229_closure_analysis/issue-88476.rs')
-rw-r--r-- | tests/ui/closures/2229_closure_analysis/issue-88476.rs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/ui/closures/2229_closure_analysis/issue-88476.rs b/tests/ui/closures/2229_closure_analysis/issue-88476.rs new file mode 100644 index 000000000..f5906d306 --- /dev/null +++ b/tests/ui/closures/2229_closure_analysis/issue-88476.rs @@ -0,0 +1,62 @@ +// edition:2021 + +#![feature(rustc_attrs)] + +// Test that we can't move out of struct that impls `Drop`. + + +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<i32>); + + impl Drop for Foo { + fn drop(self: &mut Foo) {} + } + + let f = Foo(Rc::new(1)); + let x = #[rustc_capture_analysis] move || { + //~^ ERROR: attributes on expressions are experimental + //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> + //~| ERROR: First Pass analysis includes: + //~| ERROR: Min Capture analysis includes: + println!("{:?}", f.0); + //~^ NOTE: Capturing f[(0, 0)] -> ImmBorrow + //~| NOTE: Min Capture f[] -> ByValue + }; + + 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`. +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 = #[rustc_capture_analysis] move || { + //~^ ERROR: attributes on expressions are experimental + //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> + //~| ERROR: First Pass analysis includes: + //~| ERROR: Min Capture analysis includes: + println!("{}", character.hp) + //~^ NOTE: Capturing character[(0, 0)] -> ImmBorrow + //~| NOTE: Min Capture character[(0, 0)] -> ByValue + }; + + c(); + + println!("{}", character.name); +} + +fn main() {} |