rust/tests/ui/closures/2229_closure_analysis/destructure_patterns.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.7 KiB
Rust
Raw Normal View History

2021-06-27 01:22:46 -05:00
// edition:2021
2020-11-05 14:16:24 -06:00
#![feature(rustc_attrs)]
// Test to ensure Index projections are handled properly during capture analysis
// The array should be moved in entirety, even though only some elements are used.
fn arrays() {
let arr: [String; 5] = [format!("A"), format!("B"), format!("C"), format!("D"), format!("E")];
let c = #[rustc_capture_analysis]
//~^ ERROR: attributes on expressions are experimental
2020-11-13 00:51:19 -06:00
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
2024-01-10 00:39:02 -06:00
//~| NOTE: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020-11-05 14:16:24 -06:00
|| {
2020-11-13 00:51:19 -06:00
//~^ ERROR: First Pass analysis includes:
//~| ERROR: Min Capture analysis includes:
2020-11-05 14:16:24 -06:00
let [a, b, .., e] = arr;
2020-11-13 00:51:19 -06:00
//~^ NOTE: Capturing arr[Index] -> ByValue
//~| NOTE: Capturing arr[Index] -> ByValue
//~| NOTE: Capturing arr[Index] -> ByValue
2020-11-13 00:51:19 -06:00
//~| NOTE: Min Capture arr[] -> ByValue
2020-11-05 14:16:24 -06:00
assert_eq!(a, "A");
assert_eq!(b, "B");
assert_eq!(e, "E");
};
c();
}
struct Point {
x: i32,
y: i32,
id: String,
}
fn structs() {
let mut p = Point { x: 10, y: 10, id: String::new() };
let c = #[rustc_capture_analysis]
//~^ ERROR: attributes on expressions are experimental
2020-11-13 00:51:19 -06:00
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
2024-01-10 00:39:02 -06:00
//~| NOTE: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020-11-05 14:16:24 -06:00
|| {
2020-11-13 00:51:19 -06:00
//~^ ERROR: First Pass analysis includes:
//~| ERROR: Min Capture analysis includes:
2020-11-05 14:16:24 -06:00
let Point { x: ref mut x, y: _, id: moved_id } = p;
2020-11-13 00:51:19 -06:00
//~^ NOTE: Capturing p[(0, 0)] -> MutBorrow
//~| NOTE: Capturing p[(2, 0)] -> ByValue
//~| NOTE: Min Capture p[(0, 0)] -> MutBorrow
//~| NOTE: Min Capture p[(2, 0)] -> ByValue
2020-11-05 14:16:24 -06:00
println!("{}, {}", x, moved_id);
};
c();
}
fn tuples() {
let mut t = (10, String::new(), (String::new(), 42));
let c = #[rustc_capture_analysis]
//~^ ERROR: attributes on expressions are experimental
2020-11-13 00:51:19 -06:00
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
2024-01-10 00:39:02 -06:00
//~| NOTE: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020-11-05 14:16:24 -06:00
|| {
2020-11-13 00:51:19 -06:00
//~^ ERROR: First Pass analysis includes:
//~| ERROR: Min Capture analysis includes:
2020-11-05 14:16:24 -06:00
let (ref mut x, ref ref_str, (moved_s, _)) = t;
2020-11-13 00:51:19 -06:00
//~^ NOTE: Capturing t[(0, 0)] -> MutBorrow
//~| NOTE: Capturing t[(1, 0)] -> ImmBorrow
//~| NOTE: Capturing t[(2, 0),(0, 0)] -> ByValue
//~| NOTE: Min Capture t[(0, 0)] -> MutBorrow
//~| NOTE: Min Capture t[(1, 0)] -> ImmBorrow
//~| NOTE: Min Capture t[(2, 0),(0, 0)] -> ByValue
2020-11-05 14:16:24 -06:00
println!("{}, {} {}", x, ref_str, moved_s);
};
c();
}
fn main() {}