diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs index bedb8b1c58b82..33dd374c38ceb 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs @@ -219,7 +219,6 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>( // We won't be building MIR if the closure wasn't local let closure_hir_id = tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local()); - let closure_span = tcx.hir().span(closure_hir_id); let (capture_index, capture) = if let Some(capture_details) = find_capture_matching_projections( @@ -230,7 +229,7 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>( ) { capture_details } else { - if !enable_precise_capture(tcx, closure_span) { + if !tcx.features().capture_disjoint_fields { bug!( "No associated capture found for {:?}[{:#?}] even though \ capture_disjoint_fields isn't enabled", @@ -783,9 +782,3 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } } - -/// Precise capture is enabled if the feature gate `capture_disjoint_fields` is enabled or if -/// user is using Rust Edition 2021 or higher. -fn enable_precise_capture(tcx: TyCtxt<'_>, closure_span: Span) -> bool { - tcx.features().capture_disjoint_fields || closure_span.rust_2021() -} diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index 6e6d4778b269c..869594c34adc1 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -179,7 +179,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // We now fake capture information for all variables that are mentioned within the closure // We do this after handling migrations so that min_captures computes before - if !enable_precise_capture(self.tcx, span) { + if !self.tcx.features().capture_disjoint_fields { let mut capture_information: InferredCaptureInformation<'tcx> = Default::default(); if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) { @@ -216,7 +216,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // If we have an origin, store it. if let Some(origin) = delegate.current_origin.clone() { - let origin = if enable_precise_capture(self.tcx, span) { + let origin = if self.tcx.features().capture_disjoint_fields { (origin.0, restrict_capture_precision(capture_clause, origin.1)) } else { (origin.0, Place { projections: vec![], ..origin.1 }) @@ -1979,13 +1979,3 @@ fn determine_place_ancestry_relation( PlaceAncestryRelation::Divergent } } - -/// Precise capture is enabled if the feature gate `capture_disjoint_fields` is enabled or if -/// user is using Rust Edition 2021 or higher. -/// -/// `span` is the span of the closure. -fn enable_precise_capture(tcx: TyCtxt<'_>, span: Span) -> bool { - // We use span here to ensure that if the closure was generated by a macro with a different - // edition. - tcx.features().capture_disjoint_fields || span.rust_2021() -} diff --git a/src/test/ui/closures/2229_closure_analysis/arrays-completely-captured.rs b/src/test/ui/closures/2229_closure_analysis/arrays-completely-captured.rs deleted file mode 100644 index 7a4b21f022365..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/arrays-completely-captured.rs +++ /dev/null @@ -1,21 +0,0 @@ -// edition:2021 -#![feature(rustc_attrs)] - -// Ensure that capture analysis results in arrays being completely captured. -fn main() { - let mut m = [1, 2, 3, 4, 5]; - - let mut c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - m[0] += 10; - //~^ NOTE: Capturing m[] -> MutBorrow - //~| NOTE: Min Capture m[] -> MutBorrow - m[1] += 40; - }; - - c(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/arrays-completely-captured.stderr b/src/test/ui/closures/2229_closure_analysis/arrays-completely-captured.stderr deleted file mode 100644 index 69ec53447b8a6..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/arrays-completely-captured.stderr +++ /dev/null @@ -1,48 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/arrays-completely-captured.rs:8:17 - | -LL | let mut c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/arrays-completely-captured.rs:11:5 - | -LL | / || { -LL | | -LL | | -LL | | m[0] += 10; -... | -LL | | m[1] += 40; -LL | | }; - | |_____^ - | -note: Capturing m[] -> MutBorrow - --> $DIR/arrays-completely-captured.rs:14:9 - | -LL | m[0] += 10; - | ^ - -error: Min Capture analysis includes: - --> $DIR/arrays-completely-captured.rs:11:5 - | -LL | / || { -LL | | -LL | | -LL | | m[0] += 10; -... | -LL | | m[1] += 40; -LL | | }; - | |_____^ - | -note: Min Capture m[] -> MutBorrow - --> $DIR/arrays-completely-captured.rs:14:9 - | -LL | m[0] += 10; - | ^ - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/by_value.rs b/src/test/ui/closures/2229_closure_analysis/by_value.rs deleted file mode 100644 index 02a243e050646..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/by_value.rs +++ /dev/null @@ -1,38 +0,0 @@ -// edition:2021 - -// Test that we handle derferences properly when only some of the captures are being moved with -// `capture_disjoint_fields` enabled. -#![feature(rustc_attrs)] - -#[derive(Debug, Default)] -struct SomeLargeType; -struct MuchLargerType([SomeLargeType; 32]); - -// Ensure that we don't capture any derefs when moving captures into the closures, -// i.e. only data from the enclosing stack is moved. -fn big_box() { - let s = MuchLargerType(Default::default()); - let b = Box::new(s); - let t = (b, 10); - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ First Pass analysis includes: - //~| Min Capture analysis includes: - let p = t.0.0; - //~^ NOTE: Capturing t[(0, 0),Deref,(0, 0)] -> ImmBorrow - //~| NOTE: Capturing t[(0, 0)] -> ByValue - //~| NOTE: Min Capture t[(0, 0)] -> ByValue - println!("{} {:?}", t.1, p); - //~^ NOTE: Capturing t[(1, 0)] -> ImmBorrow - //~| NOTE: Min Capture t[(1, 0)] -> ImmBorrow - }; - - c(); -} - -fn main() { - big_box(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/by_value.stderr b/src/test/ui/closures/2229_closure_analysis/by_value.stderr deleted file mode 100644 index 7014ae6a5e6af..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/by_value.stderr +++ /dev/null @@ -1,63 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/by_value.rs:18:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/by_value.rs:21:5 - | -LL | / || { -LL | | -LL | | -LL | | let p = t.0.0; -... | -LL | | -LL | | }; - | |_____^ - | -note: Capturing t[(0, 0),Deref,(0, 0)] -> ImmBorrow - --> $DIR/by_value.rs:24:17 - | -LL | let p = t.0.0; - | ^^^^^ -note: Capturing t[(0, 0)] -> ByValue - --> $DIR/by_value.rs:24:17 - | -LL | let p = t.0.0; - | ^^^^^ -note: Capturing t[(1, 0)] -> ImmBorrow - --> $DIR/by_value.rs:28:29 - | -LL | println!("{} {:?}", t.1, p); - | ^^^ - -error: Min Capture analysis includes: - --> $DIR/by_value.rs:21:5 - | -LL | / || { -LL | | -LL | | -LL | | let p = t.0.0; -... | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture t[(0, 0)] -> ByValue - --> $DIR/by_value.rs:24:17 - | -LL | let p = t.0.0; - | ^^^^^ -note: Min Capture t[(1, 0)] -> ImmBorrow - --> $DIR/by_value.rs:28:29 - | -LL | println!("{} {:?}", t.1, p); - | ^^^ - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/capture-analysis-1.rs b/src/test/ui/closures/2229_closure_analysis/capture-analysis-1.rs deleted file mode 100644 index dc53b31768ec5..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/capture-analysis-1.rs +++ /dev/null @@ -1,33 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] - -#[derive(Debug)] -struct Point { - x: i32, - y: i32, -} - -fn main() { - let p = Point { x: 10, y: 10 }; - let q = Point { x: 10, y: 10 }; - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ First Pass analysis includes: - //~| Min Capture analysis includes: - println!("{:?}", p); - //~^ NOTE: Capturing p[] -> ImmBorrow - //~| NOTE: Min Capture p[] -> ImmBorrow - println!("{:?}", p.x); - //~^ NOTE: Capturing p[(0, 0)] -> ImmBorrow - - println!("{:?}", q.x); - //~^ NOTE: Capturing q[(0, 0)] -> ImmBorrow - println!("{:?}", q); - //~^ NOTE: Capturing q[] -> ImmBorrow - //~| NOTE: Min Capture q[] -> ImmBorrow - }; -} diff --git a/src/test/ui/closures/2229_closure_analysis/capture-analysis-1.stderr b/src/test/ui/closures/2229_closure_analysis/capture-analysis-1.stderr deleted file mode 100644 index fceafb9c84eeb..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/capture-analysis-1.stderr +++ /dev/null @@ -1,68 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/capture-analysis-1.rs:15:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/capture-analysis-1.rs:18:5 - | -LL | / || { -LL | | -LL | | -LL | | println!("{:?}", p); -... | -LL | | -LL | | }; - | |_____^ - | -note: Capturing p[] -> ImmBorrow - --> $DIR/capture-analysis-1.rs:21:26 - | -LL | println!("{:?}", p); - | ^ -note: Capturing p[(0, 0)] -> ImmBorrow - --> $DIR/capture-analysis-1.rs:24:26 - | -LL | println!("{:?}", p.x); - | ^^^ -note: Capturing q[(0, 0)] -> ImmBorrow - --> $DIR/capture-analysis-1.rs:27:26 - | -LL | println!("{:?}", q.x); - | ^^^ -note: Capturing q[] -> ImmBorrow - --> $DIR/capture-analysis-1.rs:29:26 - | -LL | println!("{:?}", q); - | ^ - -error: Min Capture analysis includes: - --> $DIR/capture-analysis-1.rs:18:5 - | -LL | / || { -LL | | -LL | | -LL | | println!("{:?}", p); -... | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture p[] -> ImmBorrow - --> $DIR/capture-analysis-1.rs:21:26 - | -LL | println!("{:?}", p); - | ^ -note: Min Capture q[] -> ImmBorrow - --> $DIR/capture-analysis-1.rs:29:26 - | -LL | println!("{:?}", q); - | ^ - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/capture-analysis-2.rs b/src/test/ui/closures/2229_closure_analysis/capture-analysis-2.rs deleted file mode 100644 index 99d12f8d8f1db..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/capture-analysis-2.rs +++ /dev/null @@ -1,28 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] - -#[derive(Debug)] -struct Point { - x: String, - y: i32, -} - -fn main() { - let mut p = Point { x: String::new(), y: 10 }; - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ First Pass analysis includes: - //~| Min Capture analysis includes: - let _x = p.x; - //~^ NOTE: Capturing p[(0, 0)] -> ByValue - //~| NOTE: p[] captured as ByValue here - println!("{:?}", p); - //~^ NOTE: Capturing p[] -> ImmBorrow - //~| NOTE: Min Capture p[] -> ByValue - //~| NOTE: p[] used here - }; -} diff --git a/src/test/ui/closures/2229_closure_analysis/capture-analysis-2.stderr b/src/test/ui/closures/2229_closure_analysis/capture-analysis-2.stderr deleted file mode 100644 index cb44ca2665293..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/capture-analysis-2.stderr +++ /dev/null @@ -1,56 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/capture-analysis-2.rs:14:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/capture-analysis-2.rs:17:5 - | -LL | / || { -LL | | -LL | | -LL | | let _x = p.x; -... | -LL | | -LL | | }; - | |_____^ - | -note: Capturing p[(0, 0)] -> ByValue - --> $DIR/capture-analysis-2.rs:20:18 - | -LL | let _x = p.x; - | ^^^ -note: Capturing p[] -> ImmBorrow - --> $DIR/capture-analysis-2.rs:23:26 - | -LL | println!("{:?}", p); - | ^ - -error: Min Capture analysis includes: - --> $DIR/capture-analysis-2.rs:17:5 - | -LL | / || { -LL | | -LL | | -LL | | let _x = p.x; -... | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture p[] -> ByValue - --> $DIR/capture-analysis-2.rs:20:18 - | -LL | let _x = p.x; - | ^^^ p[] captured as ByValue here -... -LL | println!("{:?}", p); - | ^ p[] used here - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/capture-analysis-3.rs b/src/test/ui/closures/2229_closure_analysis/capture-analysis-3.rs deleted file mode 100644 index 3f337097dbd2f..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/capture-analysis-3.rs +++ /dev/null @@ -1,33 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] - -#[derive(Debug)] -struct Child { - c: String, - d: String, -} - -#[derive(Debug)] -struct Parent { - b: Child, -} - -fn main() { - let mut a = Parent { b: Child {c: String::new(), d: String::new()} }; - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ First Pass analysis includes: - //~| Min Capture analysis includes: - let _x = a.b.c; - //~^ NOTE: Capturing a[(0, 0),(0, 0)] -> ByValue - //~| NOTE: a[(0, 0)] captured as ByValue here - println!("{:?}", a.b); - //~^ NOTE: Capturing a[(0, 0)] -> ImmBorrow - //~| NOTE: Min Capture a[(0, 0)] -> ByValue - //~| NOTE: a[(0, 0)] used here - }; -} diff --git a/src/test/ui/closures/2229_closure_analysis/capture-analysis-3.stderr b/src/test/ui/closures/2229_closure_analysis/capture-analysis-3.stderr deleted file mode 100644 index 71e7bdc354fb2..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/capture-analysis-3.stderr +++ /dev/null @@ -1,56 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/capture-analysis-3.rs:19:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/capture-analysis-3.rs:22:5 - | -LL | / || { -LL | | -LL | | -LL | | let _x = a.b.c; -... | -LL | | -LL | | }; - | |_____^ - | -note: Capturing a[(0, 0),(0, 0)] -> ByValue - --> $DIR/capture-analysis-3.rs:25:18 - | -LL | let _x = a.b.c; - | ^^^^^ -note: Capturing a[(0, 0)] -> ImmBorrow - --> $DIR/capture-analysis-3.rs:28:26 - | -LL | println!("{:?}", a.b); - | ^^^ - -error: Min Capture analysis includes: - --> $DIR/capture-analysis-3.rs:22:5 - | -LL | / || { -LL | | -LL | | -LL | | let _x = a.b.c; -... | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture a[(0, 0)] -> ByValue - --> $DIR/capture-analysis-3.rs:25:18 - | -LL | let _x = a.b.c; - | ^^^^^ a[(0, 0)] captured as ByValue here -... -LL | println!("{:?}", a.b); - | ^^^ a[(0, 0)] used here - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/capture-analysis-4.rs b/src/test/ui/closures/2229_closure_analysis/capture-analysis-4.rs deleted file mode 100644 index bc46ec997360b..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/capture-analysis-4.rs +++ /dev/null @@ -1,31 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] - -#[derive(Debug)] -struct Child { - c: String, - d: String, -} - -#[derive(Debug)] -struct Parent { - b: Child, -} - -fn main() { - let mut a = Parent { b: Child {c: String::new(), d: String::new()} }; - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ First Pass analysis includes: - //~| Min Capture analysis includes: - let _x = a.b; - //~^ NOTE: Capturing a[(0, 0)] -> ByValue - //~| NOTE: Min Capture a[(0, 0)] -> ByValue - println!("{:?}", a.b.c); - //~^ NOTE: Capturing a[(0, 0),(0, 0)] -> ImmBorrow - }; -} diff --git a/src/test/ui/closures/2229_closure_analysis/capture-analysis-4.stderr b/src/test/ui/closures/2229_closure_analysis/capture-analysis-4.stderr deleted file mode 100644 index 7e6e625bc7d48..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/capture-analysis-4.stderr +++ /dev/null @@ -1,53 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/capture-analysis-4.rs:19:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/capture-analysis-4.rs:22:5 - | -LL | / || { -LL | | -LL | | -LL | | let _x = a.b; -... | -LL | | -LL | | }; - | |_____^ - | -note: Capturing a[(0, 0)] -> ByValue - --> $DIR/capture-analysis-4.rs:25:18 - | -LL | let _x = a.b; - | ^^^ -note: Capturing a[(0, 0),(0, 0)] -> ImmBorrow - --> $DIR/capture-analysis-4.rs:28:26 - | -LL | println!("{:?}", a.b.c); - | ^^^^^ - -error: Min Capture analysis includes: - --> $DIR/capture-analysis-4.rs:22:5 - | -LL | / || { -LL | | -LL | | -LL | | let _x = a.b; -... | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture a[(0, 0)] -> ByValue - --> $DIR/capture-analysis-4.rs:25:18 - | -LL | let _x = a.b; - | ^^^ - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-struct.rs b/src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-struct.rs deleted file mode 100644 index 6fd1515533160..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-struct.rs +++ /dev/null @@ -1,29 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] - -struct Point { - x: i32, - y: i32, -} - -fn main() { - let mut p = Point { x: 10, y: 10 }; - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ First Pass analysis includes: - //~| Min Capture analysis includes: - println!("{}", p.x); - //~^ NOTE: Capturing p[(0, 0)] -> ImmBorrow - //~| NOTE: Min Capture p[(0, 0)] -> ImmBorrow - }; - - // `c` should only capture `p.x`, therefore mutating `p.y` is allowed. - let py = &mut p.y; - - c(); - *py = 20; -} diff --git a/src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-struct.stderr b/src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-struct.stderr deleted file mode 100644 index 0f64ecf3a0ccb..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-struct.stderr +++ /dev/null @@ -1,48 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/capture-disjoint-field-struct.rs:13:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/capture-disjoint-field-struct.rs:16:5 - | -LL | / || { -LL | | -LL | | -LL | | println!("{}", p.x); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Capturing p[(0, 0)] -> ImmBorrow - --> $DIR/capture-disjoint-field-struct.rs:19:24 - | -LL | println!("{}", p.x); - | ^^^ - -error: Min Capture analysis includes: - --> $DIR/capture-disjoint-field-struct.rs:16:5 - | -LL | / || { -LL | | -LL | | -LL | | println!("{}", p.x); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture p[(0, 0)] -> ImmBorrow - --> $DIR/capture-disjoint-field-struct.rs:19:24 - | -LL | println!("{}", p.x); - | ^^^ - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-tuple.rs b/src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-tuple.rs deleted file mode 100644 index 8d3bb3262fb2b..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-tuple.rs +++ /dev/null @@ -1,24 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] - -fn main() { - let mut t = (10, 10); - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ First Pass analysis includes: - //~| Min Capture analysis includes: - println!("{}", t.0); - //~^ NOTE: Capturing t[(0, 0)] -> ImmBorrow - //~| NOTE: Min Capture t[(0, 0)] -> ImmBorrow - }; - - // `c` only captures t.0, therefore mutating t.1 is allowed. - let t1 = &mut t.1; - - c(); - *t1 = 20; -} diff --git a/src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-tuple.stderr b/src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-tuple.stderr deleted file mode 100644 index a8ca9622a6a68..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-tuple.stderr +++ /dev/null @@ -1,48 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/capture-disjoint-field-tuple.rs:8:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/capture-disjoint-field-tuple.rs:11:5 - | -LL | / || { -LL | | -LL | | -LL | | println!("{}", t.0); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Capturing t[(0, 0)] -> ImmBorrow - --> $DIR/capture-disjoint-field-tuple.rs:14:24 - | -LL | println!("{}", t.0); - | ^^^ - -error: Min Capture analysis includes: - --> $DIR/capture-disjoint-field-tuple.rs:11:5 - | -LL | / || { -LL | | -LL | | -LL | | println!("{}", t.0); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture t[(0, 0)] -> ImmBorrow - --> $DIR/capture-disjoint-field-tuple.rs:14:24 - | -LL | println!("{}", t.0); - | ^^^ - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/capture-enums.rs b/src/test/ui/closures/2229_closure_analysis/capture-enums.rs deleted file mode 100644 index 322ae99b86138..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/capture-enums.rs +++ /dev/null @@ -1,62 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] - -enum Info { - Point(i32, i32, String), - Meta(String, Vec<(i32, i32)>) -} - -fn multi_variant_enum() { - let point = Info::Point(10, -10, "1".into()); - - let vec = Vec::new(); - let meta = Info::Meta("meta".into(), vec); - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ First Pass analysis includes: - //~| Min Capture analysis includes: - if let Info::Point(_, _, str) = point { - //~^ NOTE: Capturing point[] -> ImmBorrow - //~| NOTE: Capturing point[(2, 0)] -> ByValue - //~| NOTE: Min Capture point[] -> ByValue - println!("{}", str); - } - - if let Info::Meta(_, v) = meta { - //~^ NOTE: Capturing meta[] -> ImmBorrow - //~| NOTE: Capturing meta[(1, 1)] -> ByValue - //~| NOTE: Min Capture meta[] -> ByValue - println!("{:?}", v); - } - }; - - c(); -} - -enum SingleVariant { - Point(i32, i32, String), -} - -fn single_variant_enum() { - let point = SingleVariant::Point(10, -10, "1".into()); - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ First Pass analysis includes: - //~| Min Capture analysis includes: - let SingleVariant::Point(_, _, str) = point; - //~^ NOTE: Capturing point[(2, 0)] -> ByValue - //~| NOTE: Min Capture point[(2, 0)] -> ByValue - println!("{}", str); - }; - - c(); -} - -fn main() {} diff --git a/src/test/ui/closures/2229_closure_analysis/capture-enums.stderr b/src/test/ui/closures/2229_closure_analysis/capture-enums.stderr deleted file mode 100644 index 8a6ba8444a80a..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/capture-enums.stderr +++ /dev/null @@ -1,113 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/capture-enums.rs:16:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/capture-enums.rs:47:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/capture-enums.rs:19:5 - | -LL | / || { -LL | | -LL | | -LL | | if let Info::Point(_, _, str) = point { -... | -LL | | } -LL | | }; - | |_____^ - | -note: Capturing point[] -> ImmBorrow - --> $DIR/capture-enums.rs:22:41 - | -LL | if let Info::Point(_, _, str) = point { - | ^^^^^ -note: Capturing point[(2, 0)] -> ByValue - --> $DIR/capture-enums.rs:22:41 - | -LL | if let Info::Point(_, _, str) = point { - | ^^^^^ -note: Capturing meta[] -> ImmBorrow - --> $DIR/capture-enums.rs:29:35 - | -LL | if let Info::Meta(_, v) = meta { - | ^^^^ -note: Capturing meta[(1, 1)] -> ByValue - --> $DIR/capture-enums.rs:29:35 - | -LL | if let Info::Meta(_, v) = meta { - | ^^^^ - -error: Min Capture analysis includes: - --> $DIR/capture-enums.rs:19:5 - | -LL | / || { -LL | | -LL | | -LL | | if let Info::Point(_, _, str) = point { -... | -LL | | } -LL | | }; - | |_____^ - | -note: Min Capture point[] -> ByValue - --> $DIR/capture-enums.rs:22:41 - | -LL | if let Info::Point(_, _, str) = point { - | ^^^^^ -note: Min Capture meta[] -> ByValue - --> $DIR/capture-enums.rs:29:35 - | -LL | if let Info::Meta(_, v) = meta { - | ^^^^ - -error: First Pass analysis includes: - --> $DIR/capture-enums.rs:50:5 - | -LL | / || { -LL | | -LL | | -LL | | let SingleVariant::Point(_, _, str) = point; -... | -LL | | println!("{}", str); -LL | | }; - | |_____^ - | -note: Capturing point[(2, 0)] -> ByValue - --> $DIR/capture-enums.rs:53:47 - | -LL | let SingleVariant::Point(_, _, str) = point; - | ^^^^^ - -error: Min Capture analysis includes: - --> $DIR/capture-enums.rs:50:5 - | -LL | / || { -LL | | -LL | | -LL | | let SingleVariant::Point(_, _, str) = point; -... | -LL | | println!("{}", str); -LL | | }; - | |_____^ - | -note: Min Capture point[(2, 0)] -> ByValue - --> $DIR/capture-enums.rs:53:47 - | -LL | let SingleVariant::Point(_, _, str) = point; - | ^^^^^ - -error: aborting due to 6 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/deep-multilevel-struct.rs b/src/test/ui/closures/2229_closure_analysis/deep-multilevel-struct.rs deleted file mode 100644 index 3341166e22b92..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/deep-multilevel-struct.rs +++ /dev/null @@ -1,50 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] -#![allow(unused)] - -#[derive(Debug)] -struct Point { - x: i32, - y: i32, -} -#[derive(Debug)] -struct Line { - p: Point, - q: Point -} -#[derive(Debug)] -struct Plane { - a: Line, - b: Line, -} - -fn main() { - let mut p = Plane { - a: Line { - p: Point { x: 1,y: 2 }, - q: Point { x: 3,y: 4 }, - }, - b: Line { - p: Point { x: 1,y: 2 }, - q: Point { x: 3,y: 4 }, - } - }; - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - let x = &p.a.p.x; - //~^ NOTE: Capturing p[(0, 0),(0, 0),(0, 0)] -> ImmBorrow - p.b.q.y = 9; - //~^ NOTE: Capturing p[(1, 0),(1, 0),(1, 0)] -> MutBorrow - //~| NOTE: p[] captured as MutBorrow here - println!("{:?}", p); - //~^ NOTE: Capturing p[] -> ImmBorrow - //~| NOTE: Min Capture p[] -> MutBorrow - //~| NOTE: p[] used here - }; -} diff --git a/src/test/ui/closures/2229_closure_analysis/deep-multilevel-struct.stderr b/src/test/ui/closures/2229_closure_analysis/deep-multilevel-struct.stderr deleted file mode 100644 index 29e1af0431ec6..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/deep-multilevel-struct.stderr +++ /dev/null @@ -1,61 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/deep-multilevel-struct.rs:34:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/deep-multilevel-struct.rs:37:5 - | -LL | / || { -LL | | -LL | | -LL | | let x = &p.a.p.x; -... | -LL | | -LL | | }; - | |_____^ - | -note: Capturing p[(0, 0),(0, 0),(0, 0)] -> ImmBorrow - --> $DIR/deep-multilevel-struct.rs:40:18 - | -LL | let x = &p.a.p.x; - | ^^^^^^^ -note: Capturing p[(1, 0),(1, 0),(1, 0)] -> MutBorrow - --> $DIR/deep-multilevel-struct.rs:42:9 - | -LL | p.b.q.y = 9; - | ^^^^^^^ -note: Capturing p[] -> ImmBorrow - --> $DIR/deep-multilevel-struct.rs:45:26 - | -LL | println!("{:?}", p); - | ^ - -error: Min Capture analysis includes: - --> $DIR/deep-multilevel-struct.rs:37:5 - | -LL | / || { -LL | | -LL | | -LL | | let x = &p.a.p.x; -... | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture p[] -> MutBorrow - --> $DIR/deep-multilevel-struct.rs:42:9 - | -LL | p.b.q.y = 9; - | ^^^^^^^ p[] captured as MutBorrow here -... -LL | println!("{:?}", p); - | ^ p[] used here - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/deep-multilevel-tuple.rs b/src/test/ui/closures/2229_closure_analysis/deep-multilevel-tuple.rs deleted file mode 100644 index 34b0132f3cb0b..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/deep-multilevel-tuple.rs +++ /dev/null @@ -1,24 +0,0 @@ -// edition:2021 -#![feature(rustc_attrs)] -#![allow(unused)] - -fn main() { - let mut t = (((1,2),(3,4)),((5,6),(7,8))); - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - let x = &t.0.0.0; - //~^ NOTE: Capturing t[(0, 0),(0, 0),(0, 0)] -> ImmBorrow - t.1.1.1 = 9; - //~^ NOTE: Capturing t[(1, 0),(1, 0),(1, 0)] -> MutBorrow - //~| NOTE: t[] captured as MutBorrow here - println!("{:?}", t); - //~^ NOTE: Min Capture t[] -> MutBorrow - //~| NOTE: Capturing t[] -> ImmBorrow - //~| NOTE: t[] used here - }; -} diff --git a/src/test/ui/closures/2229_closure_analysis/deep-multilevel-tuple.stderr b/src/test/ui/closures/2229_closure_analysis/deep-multilevel-tuple.stderr deleted file mode 100644 index e917516765c8f..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/deep-multilevel-tuple.stderr +++ /dev/null @@ -1,61 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/deep-multilevel-tuple.rs:8:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/deep-multilevel-tuple.rs:11:5 - | -LL | / || { -LL | | -LL | | -LL | | let x = &t.0.0.0; -... | -LL | | -LL | | }; - | |_____^ - | -note: Capturing t[(0, 0),(0, 0),(0, 0)] -> ImmBorrow - --> $DIR/deep-multilevel-tuple.rs:14:18 - | -LL | let x = &t.0.0.0; - | ^^^^^^^ -note: Capturing t[(1, 0),(1, 0),(1, 0)] -> MutBorrow - --> $DIR/deep-multilevel-tuple.rs:16:9 - | -LL | t.1.1.1 = 9; - | ^^^^^^^ -note: Capturing t[] -> ImmBorrow - --> $DIR/deep-multilevel-tuple.rs:19:26 - | -LL | println!("{:?}", t); - | ^ - -error: Min Capture analysis includes: - --> $DIR/deep-multilevel-tuple.rs:11:5 - | -LL | / || { -LL | | -LL | | -LL | | let x = &t.0.0.0; -... | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture t[] -> MutBorrow - --> $DIR/deep-multilevel-tuple.rs:16:9 - | -LL | t.1.1.1 = 9; - | ^^^^^^^ t[] captured as MutBorrow here -... -LL | println!("{:?}", t); - | ^ t[] used here - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/destructure_patterns.rs b/src/test/ui/closures/2229_closure_analysis/destructure_patterns.rs deleted file mode 100644 index 9918802334ecc..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/destructure_patterns.rs +++ /dev/null @@ -1,75 +0,0 @@ -// edition:2021 - -#![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 - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - let [a, b, .., e] = arr; - //~^ NOTE: Capturing arr[Index] -> ByValue - //~| NOTE: Min Capture arr[] -> ByValue - 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 - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - let Point { x: ref mut x, y: _, id: moved_id } = p; - //~^ 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 - - 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 - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - let (ref mut x, ref ref_str, (moved_s, _)) = t; - //~^ 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 - - println!("{}, {} {}", x, ref_str, moved_s); - }; - c(); -} - -fn main() {} diff --git a/src/test/ui/closures/2229_closure_analysis/destructure_patterns.stderr b/src/test/ui/closures/2229_closure_analysis/destructure_patterns.stderr deleted file mode 100644 index b53adb5248161..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/destructure_patterns.stderr +++ /dev/null @@ -1,168 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/destructure_patterns.rs:10:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/destructure_patterns.rs:36:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/destructure_patterns.rs:56:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/destructure_patterns.rs:13:5 - | -LL | / || { -LL | | -LL | | -LL | | let [a, b, .., e] = arr; -... | -LL | | assert_eq!(e, "E"); -LL | | }; - | |_____^ - | -note: Capturing arr[Index] -> ByValue - --> $DIR/destructure_patterns.rs:16:29 - | -LL | let [a, b, .., e] = arr; - | ^^^ - -error: Min Capture analysis includes: - --> $DIR/destructure_patterns.rs:13:5 - | -LL | / || { -LL | | -LL | | -LL | | let [a, b, .., e] = arr; -... | -LL | | assert_eq!(e, "E"); -LL | | }; - | |_____^ - | -note: Min Capture arr[] -> ByValue - --> $DIR/destructure_patterns.rs:16:29 - | -LL | let [a, b, .., e] = arr; - | ^^^ - -error: First Pass analysis includes: - --> $DIR/destructure_patterns.rs:39:5 - | -LL | / || { -LL | | -LL | | -LL | | let Point { x: ref mut x, y: _, id: moved_id } = p; -... | -LL | | println!("{}, {}", x, moved_id); -LL | | }; - | |_____^ - | -note: Capturing p[(0, 0)] -> MutBorrow - --> $DIR/destructure_patterns.rs:42:58 - | -LL | let Point { x: ref mut x, y: _, id: moved_id } = p; - | ^ -note: Capturing p[(2, 0)] -> ByValue - --> $DIR/destructure_patterns.rs:42:58 - | -LL | let Point { x: ref mut x, y: _, id: moved_id } = p; - | ^ - -error: Min Capture analysis includes: - --> $DIR/destructure_patterns.rs:39:5 - | -LL | / || { -LL | | -LL | | -LL | | let Point { x: ref mut x, y: _, id: moved_id } = p; -... | -LL | | println!("{}, {}", x, moved_id); -LL | | }; - | |_____^ - | -note: Min Capture p[(0, 0)] -> MutBorrow - --> $DIR/destructure_patterns.rs:42:58 - | -LL | let Point { x: ref mut x, y: _, id: moved_id } = p; - | ^ -note: Min Capture p[(2, 0)] -> ByValue - --> $DIR/destructure_patterns.rs:42:58 - | -LL | let Point { x: ref mut x, y: _, id: moved_id } = p; - | ^ - -error: First Pass analysis includes: - --> $DIR/destructure_patterns.rs:59:5 - | -LL | / || { -LL | | -LL | | -LL | | let (ref mut x, ref ref_str, (moved_s, _)) = t; -... | -LL | | println!("{}, {} {}", x, ref_str, moved_s); -LL | | }; - | |_____^ - | -note: Capturing t[(0, 0)] -> MutBorrow - --> $DIR/destructure_patterns.rs:62:54 - | -LL | let (ref mut x, ref ref_str, (moved_s, _)) = t; - | ^ -note: Capturing t[(1, 0)] -> ImmBorrow - --> $DIR/destructure_patterns.rs:62:54 - | -LL | let (ref mut x, ref ref_str, (moved_s, _)) = t; - | ^ -note: Capturing t[(2, 0),(0, 0)] -> ByValue - --> $DIR/destructure_patterns.rs:62:54 - | -LL | let (ref mut x, ref ref_str, (moved_s, _)) = t; - | ^ - -error: Min Capture analysis includes: - --> $DIR/destructure_patterns.rs:59:5 - | -LL | / || { -LL | | -LL | | -LL | | let (ref mut x, ref ref_str, (moved_s, _)) = t; -... | -LL | | println!("{}, {} {}", x, ref_str, moved_s); -LL | | }; - | |_____^ - | -note: Min Capture t[(0, 0)] -> MutBorrow - --> $DIR/destructure_patterns.rs:62:54 - | -LL | let (ref mut x, ref ref_str, (moved_s, _)) = t; - | ^ -note: Min Capture t[(1, 0)] -> ImmBorrow - --> $DIR/destructure_patterns.rs:62:54 - | -LL | let (ref mut x, ref ref_str, (moved_s, _)) = t; - | ^ -note: Min Capture t[(2, 0),(0, 0)] -> ByValue - --> $DIR/destructure_patterns.rs:62:54 - | -LL | let (ref mut x, ref ref_str, (moved_s, _)) = t; - | ^ - -error: aborting due to 9 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/arrays.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/arrays.rs deleted file mode 100644 index 93131b2ac4e4d..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/arrays.rs +++ /dev/null @@ -1,85 +0,0 @@ -// edition:2021 - -// Test that arrays are completely captured by closures by relying on the borrow check diagnostics - -fn arrays_1() { - let mut arr = [1, 2, 3, 4, 5]; - - let mut c = || { - arr[0] += 10; - }; - - // c will capture `arr` completely, therefore another index into the - // array can't be modified here - arr[1] += 10; - //~^ ERROR: cannot use `arr` because it was mutably borrowed - //~| ERROR: cannot use `arr[_]` because it was mutably borrowed - c(); -} - -fn arrays_2() { - let mut arr = [1, 2, 3, 4, 5]; - - let c = || { - println!("{:#?}", &arr[3..4]); - }; - - // c will capture `arr` completely, therefore another index into the - // array can't be modified here - arr[1] += 10; - //~^ ERROR: cannot assign to `arr[_]` because it is borrowed - c(); -} - -fn arrays_3() { - let mut arr = [1, 2, 3, 4, 5]; - - let c = || { - println!("{}", arr[3]); - }; - - // c will capture `arr` completely, therefore another index into the - // array can't be modified here - arr[1] += 10; - //~^ ERROR: cannot assign to `arr[_]` because it is borrowed - c(); -} - -fn arrays_4() { - let mut arr = [1, 2, 3, 4, 5]; - - let mut c = || { - arr[1] += 10; - }; - - // c will capture `arr` completely, therefore we cannot borrow another index - // into the array. - println!("{}", arr[3]); - //~^ ERROR: cannot use `arr` because it was mutably borrowed - //~| ERROR: cannot borrow `arr[_]` as immutable because it is also borrowed as mutable - - c(); -} - -fn arrays_5() { - let mut arr = [1, 2, 3, 4, 5]; - - let mut c = || { - arr[1] += 10; - }; - - // c will capture `arr` completely, therefore we cannot borrow other indecies - // into the array. - println!("{:#?}", &arr[3..2]); - //~^ ERROR: cannot borrow `arr` as immutable because it is also borrowed as mutable - - c(); -} - -fn main() { - arrays_1(); - arrays_2(); - arrays_3(); - arrays_4(); - arrays_5(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/arrays.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/arrays.stderr deleted file mode 100644 index a3f2f25e447e1..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/arrays.stderr +++ /dev/null @@ -1,102 +0,0 @@ -error[E0503]: cannot use `arr` because it was mutably borrowed - --> $DIR/arrays.rs:14:5 - | -LL | let mut c = || { - | -- borrow of `arr` occurs here -LL | arr[0] += 10; - | --- borrow occurs due to use of `arr` in closure -... -LL | arr[1] += 10; - | ^^^^^^ use of borrowed `arr` -... -LL | c(); - | - borrow later used here - -error[E0503]: cannot use `arr[_]` because it was mutably borrowed - --> $DIR/arrays.rs:14:5 - | -LL | let mut c = || { - | -- borrow of `arr` occurs here -LL | arr[0] += 10; - | --- borrow occurs due to use of `arr` in closure -... -LL | arr[1] += 10; - | ^^^^^^^^^^^^ use of borrowed `arr` -... -LL | c(); - | - borrow later used here - -error[E0506]: cannot assign to `arr[_]` because it is borrowed - --> $DIR/arrays.rs:29:5 - | -LL | let c = || { - | -- borrow of `arr[_]` occurs here -LL | println!("{:#?}", &arr[3..4]); - | --- borrow occurs due to use in closure -... -LL | arr[1] += 10; - | ^^^^^^^^^^^^ assignment to borrowed `arr[_]` occurs here -LL | -LL | c(); - | - borrow later used here - -error[E0506]: cannot assign to `arr[_]` because it is borrowed - --> $DIR/arrays.rs:43:5 - | -LL | let c = || { - | -- borrow of `arr[_]` occurs here -LL | println!("{}", arr[3]); - | --- borrow occurs due to use in closure -... -LL | arr[1] += 10; - | ^^^^^^^^^^^^ assignment to borrowed `arr[_]` occurs here -LL | -LL | c(); - | - borrow later used here - -error[E0503]: cannot use `arr` because it was mutably borrowed - --> $DIR/arrays.rs:57:20 - | -LL | let mut c = || { - | -- borrow of `arr` occurs here -LL | arr[1] += 10; - | --- borrow occurs due to use of `arr` in closure -... -LL | println!("{}", arr[3]); - | ^^^^^^ use of borrowed `arr` -... -LL | c(); - | - borrow later used here - -error[E0502]: cannot borrow `arr[_]` as immutable because it is also borrowed as mutable - --> $DIR/arrays.rs:57:20 - | -LL | let mut c = || { - | -- mutable borrow occurs here -LL | arr[1] += 10; - | --- first borrow occurs due to use of `arr` in closure -... -LL | println!("{}", arr[3]); - | ^^^^^^ immutable borrow occurs here -... -LL | c(); - | - mutable borrow later used here - -error[E0502]: cannot borrow `arr` as immutable because it is also borrowed as mutable - --> $DIR/arrays.rs:73:24 - | -LL | let mut c = || { - | -- mutable borrow occurs here -LL | arr[1] += 10; - | --- first borrow occurs due to use of `arr` in closure -... -LL | println!("{:#?}", &arr[3..2]); - | ^^^ immutable borrow occurs here -... -LL | c(); - | - mutable borrow later used here - -error: aborting due to 7 previous errors - -Some errors have detailed explanations: E0502, E0503, E0506. -For more information about an error, try `rustc --explain E0502`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-1.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-1.rs deleted file mode 100644 index 3664d76c2038f..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-1.rs +++ /dev/null @@ -1,19 +0,0 @@ -// edition:2021 - -#[derive(Debug)] -struct Point { - x: i32, - y: i32, -} -fn main() { - let mut p = Point {x: 1, y: 2 }; - - let y = &mut p.y; - let mut c = || { - //~^ ERROR cannot borrow `p` as mutable more than once at a time - let x = &mut p.x; - println!("{:?}", p); - }; - c(); - *y+=1; -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-1.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-1.stderr deleted file mode 100644 index 341d2bc65634b..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-1.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0499]: cannot borrow `p` as mutable more than once at a time - --> $DIR/borrowck-1.rs:12:17 - | -LL | let y = &mut p.y; - | -------- first mutable borrow occurs here -LL | let mut c = || { - | ^^ second mutable borrow occurs here -LL | -LL | let x = &mut p.x; - | --- capture is mutable because of use here -LL | println!("{:?}", p); - | - second borrow occurs due to use of `p` in closure -... -LL | *y+=1; - | ----- first borrow later used here - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0499`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-2.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-2.rs deleted file mode 100644 index ae416bab65ea5..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-2.rs +++ /dev/null @@ -1,19 +0,0 @@ -// edition:2021 - -#[derive(Debug)] -struct Point { - x: i32, - y: i32, -} -fn main() { - let mut p = Point {x: 1, y: 2 }; - - let y = &p.y; - let mut c = || { - //~^ ERROR cannot borrow `p` as mutable because it is also borrowed as immutable - println!("{:?}", p); - let x = &mut p.x; - }; - c(); - println!("{}", y); -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-2.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-2.stderr deleted file mode 100644 index 584bb862b2c0a..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-2.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0502]: cannot borrow `p` as mutable because it is also borrowed as immutable - --> $DIR/borrowck-2.rs:12:17 - | -LL | let y = &p.y; - | ---- immutable borrow occurs here -LL | let mut c = || { - | ^^ mutable borrow occurs here -LL | -LL | println!("{:?}", p); - | - second borrow occurs due to use of `p` in closure -LL | let x = &mut p.x; - | --- capture is mutable because of use here -... -LL | println!("{}", y); - | - immutable borrow later used here - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0502`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-3.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-3.rs deleted file mode 100644 index bdd6cb79b60b0..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-3.rs +++ /dev/null @@ -1,18 +0,0 @@ -// edition:2021 - -#[derive(Debug)] -struct Point { - x: String, - y: String, -} -fn main() { - let mut c = { - let mut p = Point {x: "1".to_string(), y: "2".to_string() }; - || { - let x = &mut p.x; - println!("{:?}", p); - //~^ ERROR `p` does not live long enough - } - }; - c(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-3.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-3.stderr deleted file mode 100644 index dab1809a381ee..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-3.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error[E0597]: `p` does not live long enough - --> $DIR/borrowck-3.rs:13:29 - | -LL | let mut c = { - | ----- borrow later stored here -LL | let mut p = Point {x: "1".to_string(), y: "2".to_string() }; -LL | || { - | -- value captured here -LL | let x = &mut p.x; -LL | println!("{:?}", p); - | ^ borrowed value does not live long enough -... -LL | }; - | - `p` dropped here while still borrowed - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.rs deleted file mode 100644 index a2290d850207d..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.rs +++ /dev/null @@ -1,20 +0,0 @@ -// edition:2021 - -#[derive(Debug)] -struct Point { - x: i32, - y: i32, -} -fn foo () -> impl FnMut()->() { - let mut p = Point {x: 1, y: 2 }; - let mut c = || { - //~^ ERROR closure may outlive the current function, but it borrows `p` - p.x+=5; - println!("{:?}", p); - }; - c -} -fn main() { - let c = foo(); - c(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.stderr deleted file mode 100644 index 29bd4b27d6b07..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error[E0373]: closure may outlive the current function, but it borrows `p`, which is owned by the current function - --> $DIR/borrowck-4.rs:10:17 - | -LL | let mut c = || { - | ^^ may outlive borrowed value `p` -... -LL | println!("{:?}", p); - | - `p` is borrowed here - | -note: closure is returned here - --> $DIR/borrowck-4.rs:8:14 - | -LL | fn foo () -> impl FnMut()->() { - | ^^^^^^^^^^^^^^^^ -help: to force the closure to take ownership of `p` (and any other referenced variables), use the `move` keyword - | -LL | let mut c = move || { - | ^^^^^^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0373`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-closures-mut-and-imm.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-closures-mut-and-imm.rs deleted file mode 100644 index 6a8c9664051df..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-closures-mut-and-imm.rs +++ /dev/null @@ -1,26 +0,0 @@ -// edition:2021 - -// Tests that two closures cannot simultaneously have mutable -// and immutable access to the variable. Issue #6801. - -#![feature(box_syntax)] - -#[derive(Debug)] -struct Point { - x: i32, - y: i32, -} - -fn a() { - let mut p = Point {x: 3, y:4}; - let c2 = || p.y * 5; - let c1 = || { - //~^ ERROR cannot borrow `p` as mutable because it is also borrowed as immutable - dbg!(&p); - p.x = 4; - }; - drop(c2); -} - -fn main() { -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-closures-mut-and-imm.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-closures-mut-and-imm.stderr deleted file mode 100644 index 5f1dae2972f9e..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-closures-mut-and-imm.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0502]: cannot borrow `p` as mutable because it is also borrowed as immutable - --> $DIR/borrowck-closures-mut-and-imm.rs:17:14 - | -LL | let c2 = || p.y * 5; - | -- --- first borrow occurs due to use of `p.y` in closure - | | - | immutable borrow occurs here -LL | let c1 = || { - | ^^ mutable borrow occurs here -LL | -LL | dbg!(&p); - | - second borrow occurs due to use of `p` in closure -LL | p.x = 4; - | --- capture is mutable because of use here -LL | }; -LL | drop(c2); - | -- immutable borrow later used here - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0502`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/box.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/box.rs deleted file mode 100644 index a110fa4e2cb3e..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/box.rs +++ /dev/null @@ -1,64 +0,0 @@ -// edition:2021 - -// Test borrow checker when we precise capture when using boxes - -struct MetaData { x: String, name: String } -struct Data { m: MetaData } -struct BoxedData(Box); -struct EvenMoreBoxedData(Box); - -// Check diagnostics when the same path is mutated both inside and outside the closure -fn box_1() { - let m = MetaData { x: format!("x"), name: format!("name") }; - let d = Data { m }; - let b = BoxedData(Box::new(d)); - let mut e = EvenMoreBoxedData(Box::new(b)); - - let mut c = || { - e.0.0.m.x = format!("not-x"); - }; - - e.0.0.m.x = format!("not-x"); - //~^ ERROR: cannot assign to `e.0.0.m.x` because it is borrowed - c(); -} - -// Check diagnostics when a path is mutated inside a closure while attempting to read it outside -// the closure. -fn box_2() { - let m = MetaData { x: format!("x"), name: format!("name") }; - let d = Data { m }; - let b = BoxedData(Box::new(d)); - let mut e = EvenMoreBoxedData(Box::new(b)); - - let mut c = || { - e.0.0.m.x = format!("not-x"); - }; - - println!("{}", e.0.0.m.x); - //~^ ERROR: cannot borrow `e.0.0.m.x` as immutable because it is also borrowed as mutable - c(); -} - -// Check diagnostics when a path is read inside a closure while attempting to mutate it outside -// the closure. -fn box_3() { - let m = MetaData { x: format!("x"), name: format!("name") }; - let d = Data { m }; - let b = BoxedData(Box::new(d)); - let mut e = EvenMoreBoxedData(Box::new(b)); - - let c = || { - println!("{}", e.0.0.m.x); - }; - - e.0.0.m.x = format!("not-x"); - //~^ ERROR: cannot assign to `e.0.0.m.x` because it is borrowed - c(); -} - -fn main() { - box_1(); - box_2(); - box_3(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/box.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/box.stderr deleted file mode 100644 index 2badf0514187e..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/box.stderr +++ /dev/null @@ -1,46 +0,0 @@ -error[E0506]: cannot assign to `e.0.0.m.x` because it is borrowed - --> $DIR/box.rs:21:5 - | -LL | let mut c = || { - | -- borrow of `e.0.0.m.x` occurs here -LL | e.0.0.m.x = format!("not-x"); - | --------- borrow occurs due to use in closure -... -LL | e.0.0.m.x = format!("not-x"); - | ^^^^^^^^^ assignment to borrowed `e.0.0.m.x` occurs here -LL | -LL | c(); - | - borrow later used here - -error[E0502]: cannot borrow `e.0.0.m.x` as immutable because it is also borrowed as mutable - --> $DIR/box.rs:38:20 - | -LL | let mut c = || { - | -- mutable borrow occurs here -LL | e.0.0.m.x = format!("not-x"); - | --------- first borrow occurs due to use of `e.0.0.m.x` in closure -... -LL | println!("{}", e.0.0.m.x); - | ^^^^^^^^^ immutable borrow occurs here -LL | -LL | c(); - | - mutable borrow later used here - -error[E0506]: cannot assign to `e.0.0.m.x` because it is borrowed - --> $DIR/box.rs:55:5 - | -LL | let c = || { - | -- borrow of `e.0.0.m.x` occurs here -LL | println!("{}", e.0.0.m.x); - | --------- borrow occurs due to use in closure -... -LL | e.0.0.m.x = format!("not-x"); - | ^^^^^^^^^ assignment to borrowed `e.0.0.m.x` occurs here -LL | -LL | c(); - | - borrow later used here - -error: aborting due to 3 previous errors - -Some errors have detailed explanations: E0502, E0506. -For more information about an error, try `rustc --explain E0502`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm-borrow.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm-borrow.rs deleted file mode 100644 index a5b4a19d8c3ff..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm-borrow.rs +++ /dev/null @@ -1,19 +0,0 @@ -// edition:2021 - -// Test that if we deref an immutable borrow to access a Place, -// then we can't mutate the final place. - -fn main() { - let mut x = (format!(""), format!("X2")); - let mut y = (&x, "Y"); - let z = (&mut y, "Z"); - - // `x.0` is mutable but we access `x` via `z.0.0`, which is an immutable reference and - // therefore can't be mutated. - let mut c = || { - //~^ ERROR: cannot borrow `z.0.0.0` as mutable, as it is behind a `&` reference - z.0.0.0 = format!("X1"); - }; - - c(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm-borrow.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm-borrow.stderr deleted file mode 100644 index cfe531e17d3d7..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm-borrow.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0596]: cannot borrow `z.0.0.0` as mutable, as it is behind a `&` reference - --> $DIR/cant-mutate-imm-borrow.rs:13:17 - | -LL | let mut c = || { - | ^^ cannot borrow as mutable -LL | -LL | z.0.0.0 = format!("X1"); - | ------- mutable borrow occurs due to use of `z.0.0.0` in closure - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0596`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.rs deleted file mode 100644 index 25ee9a1490e0c..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.rs +++ /dev/null @@ -1,34 +0,0 @@ -// edition:2021 - -// Ensure that diagnostics for mutability error (because the root variable -// isn't mutable) work with `capture_disjoint_fields` enabled. - -fn mut_error_struct() { - let x = (10, 10); - let y = (x, 10); - let z = (y, 10); - - let mut c = || { - z.0.0.0 = 20; - //~^ ERROR: cannot assign to `z.0.0.0`, as it is not declared as mutable - }; - - c(); -} - -fn mut_error_box() { - let x = (10, 10); - let bx = Box::new(x); - - let mut c = || { - bx.0 = 20; - //~^ ERROR: cannot assign to `*bx.0`, as it is not declared as mutable - }; - - c(); -} - -fn main() { - mut_error_struct(); - mut_error_box(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.stderr deleted file mode 100644 index 98414fa8a3d5f..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0594]: cannot assign to `z.0.0.0`, as it is not declared as mutable - --> $DIR/cant-mutate-imm.rs:12:9 - | -LL | let z = (y, 10); - | - help: consider changing this to be mutable: `mut z` -... -LL | z.0.0.0 = 20; - | ^^^^^^^^^^^^ cannot assign - -error[E0594]: cannot assign to `*bx.0`, as it is not declared as mutable - --> $DIR/cant-mutate-imm.rs:24:9 - | -LL | let bx = Box::new(x); - | -- help: consider changing this to be mutable: `mut bx` -... -LL | bx.0 = 20; - | ^^^^^^^^^ cannot assign - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-array-diagnostics.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-array-diagnostics.rs deleted file mode 100644 index f3be542e40d7a..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-array-diagnostics.rs +++ /dev/null @@ -1,13 +0,0 @@ -// edition:2021 - -// Test that array access is not stored as part of closure kind origin - -fn expect_fn(_f: F) {} - -fn main() { - let s = [format!("s"), format!("s")]; - let c = || { //~ ERROR expected a closure that implements the `Fn` - let [_, _s] = s; - }; - expect_fn(c); -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-array-diagnostics.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-array-diagnostics.stderr deleted file mode 100644 index bcde35983fc4c..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-array-diagnostics.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnOnce` - --> $DIR/closure-origin-array-diagnostics.rs:9:13 - | -LL | let c = || { - | ^^ this closure implements `FnOnce`, not `Fn` -LL | let [_, _s] = s; - | - closure is `FnOnce` because it moves the variable `s` out of its environment -LL | }; -LL | expect_fn(c); - | --------- the requirement to implement `Fn` derives from here - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0525`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-multi-variant-diagnostics.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-multi-variant-diagnostics.rs deleted file mode 100644 index aa85b55b15cc7..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-multi-variant-diagnostics.rs +++ /dev/null @@ -1,27 +0,0 @@ -// edition:2021 - -// Check that precise paths are being reported back in the error message. - -enum MultiVariant { - Point(i32, i32), - Meta(i32) -} - -fn main() { - let mut point = MultiVariant::Point(10, -10,); - - let mut meta = MultiVariant::Meta(1); - - let c = || { - if let MultiVariant::Point(ref mut x, _) = point { - *x += 1; - } - - if let MultiVariant::Meta(ref mut v) = meta { - *v += 1; - } - }; - - let a = c; - let b = c; //~ ERROR use of moved value: `c` [E0382] -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-multi-variant-diagnostics.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-multi-variant-diagnostics.stderr deleted file mode 100644 index 066c000c832d8..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-multi-variant-diagnostics.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error[E0382]: use of moved value: `c` - --> $DIR/closure-origin-multi-variant-diagnostics.rs:26:13 - | -LL | let a = c; - | - value moved here -LL | let b = c; - | ^ value used here after move - | -note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `point.0` out of its environment - --> $DIR/closure-origin-multi-variant-diagnostics.rs:16:52 - | -LL | if let MultiVariant::Point(ref mut x, _) = point { - | ^^^^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-single-variant-diagnostics.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-single-variant-diagnostics.rs deleted file mode 100644 index bedb103cc4c7b..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-single-variant-diagnostics.rs +++ /dev/null @@ -1,18 +0,0 @@ -// edition:2021 - - -enum SingleVariant { - Point(i32, i32), -} - -fn main() { - let mut point = SingleVariant::Point(10, -10); - - let c = || { - let SingleVariant::Point(ref mut x, _) = point; - *x += 1; - }; - - let b = c; - let a = c; //~ ERROR use of moved value: `c` [E0382] -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-single-variant-diagnostics.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-single-variant-diagnostics.stderr deleted file mode 100644 index 2a6e00850fa8a..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-single-variant-diagnostics.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error[E0382]: use of moved value: `c` - --> $DIR/closure-origin-single-variant-diagnostics.rs:17:13 - | -LL | let b = c; - | - value moved here -LL | let a = c; - | ^ value used here after move - | -note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `point.0` out of its environment - --> $DIR/closure-origin-single-variant-diagnostics.rs:12:50 - | -LL | let SingleVariant::Point(ref mut x, _) = point; - | ^^^^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-struct-diagnostics.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-struct-diagnostics.rs deleted file mode 100644 index 3277a83c4e147..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-struct-diagnostics.rs +++ /dev/null @@ -1,22 +0,0 @@ -// edition:2021 - -// Check that precise paths are being reported back in the error message. - -struct Y { - y: X -} - -struct X { - a: u32, - b: u32, -} - -fn main() { - let mut x = Y { y: X { a: 5, b: 0 } }; - let hello = || { - x.y.a += 1; - }; - - let b = hello; - let c = hello; //~ ERROR use of moved value: `hello` [E0382] -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-struct-diagnostics.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-struct-diagnostics.stderr deleted file mode 100644 index d7fc51c55eae3..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-struct-diagnostics.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error[E0382]: use of moved value: `hello` - --> $DIR/closure-origin-struct-diagnostics.rs:21:13 - | -LL | let b = hello; - | ----- value moved here -LL | let c = hello; - | ^^^^^ value used here after move - | -note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `x.y.a` out of its environment - --> $DIR/closure-origin-struct-diagnostics.rs:17:9 - | -LL | x.y.a += 1; - | ^^^^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-tuple-diagnostics-1.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-tuple-diagnostics-1.rs deleted file mode 100644 index dc3a57ae793e7..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-tuple-diagnostics-1.rs +++ /dev/null @@ -1,13 +0,0 @@ -// edition:2021 - -// Check that precise paths are being reported back in the error message. - -fn main() { - let mut x = (5, 0); - let hello = || { - x.0 += 1; - }; - - let b = hello; - let c = hello; //~ ERROR use of moved value: `hello` [E0382] -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-tuple-diagnostics-1.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-tuple-diagnostics-1.stderr deleted file mode 100644 index 63e2d300eb06a..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-tuple-diagnostics-1.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error[E0382]: use of moved value: `hello` - --> $DIR/closure-origin-tuple-diagnostics-1.rs:12:13 - | -LL | let b = hello; - | ----- value moved here -LL | let c = hello; - | ^^^^^ value used here after move - | -note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `x.0` out of its environment - --> $DIR/closure-origin-tuple-diagnostics-1.rs:8:9 - | -LL | x.0 += 1; - | ^^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-tuple-diagnostics.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-tuple-diagnostics.rs deleted file mode 100644 index fa1328013db45..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-tuple-diagnostics.rs +++ /dev/null @@ -1,13 +0,0 @@ -// edition:2021 - -struct S(String, String); - -fn expect_fn(_f: F) {} - -fn main() { - let s = S(format!("s"), format!("s")); - let c = || { //~ ERROR expected a closure that implements the `Fn` - let s = s.1; - }; - expect_fn(c); -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-tuple-diagnostics.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-tuple-diagnostics.stderr deleted file mode 100644 index df33c4f1fd6d4..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-tuple-diagnostics.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnOnce` - --> $DIR/closure-origin-tuple-diagnostics.rs:9:13 - | -LL | let c = || { - | ^^ this closure implements `FnOnce`, not `Fn` -LL | let s = s.1; - | --- closure is `FnOnce` because it moves the variable `s.1` out of its environment -LL | }; -LL | expect_fn(c); - | --------- the requirement to implement `Fn` derives from here - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0525`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.rs deleted file mode 100644 index 1cc22fac35282..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.rs +++ /dev/null @@ -1,91 +0,0 @@ -// edition:2021 - -// check-pass -#![allow(unreachable_code)] -#![warn(unused)] - -#[derive(Debug)] -struct Point { - x: i32, - y: i32, -} - -pub fn f() { - let mut a = 1; - let mut c = Point{ x:1, y:0 }; - - // Captured by value, but variable is dead on entry. - (move || { - // This will not trigger a warning for unused variable as - // c.x will be treated as a Non-tracked place - c.x = 1; - println!("{}", c.x); - a = 1; //~ WARN value captured by `a` is never read - println!("{}", a); - })(); - - // Read and written to, but never actually used. - (move || { - // This will not trigger a warning for unused variable as - // c.x will be treated as a Non-tracked place - c.x += 1; - a += 1; //~ WARN unused variable: `a` - })(); - - (move || { - println!("{}", c.x); - // Value is read by closure itself on later invocations. - // This will not trigger a warning for unused variable as - // c.x will be treated as a Non-tracked place - c.x += 1; - println!("{}", a); - a += 1; - })(); - let b = Box::new(42); - (move || { - println!("{}", c.x); - // Never read because this is FnOnce closure. - // This will not trigger a warning for unused variable as - // c.x will be treated as a Non-tracked place - c.x += 1; - println!("{}", a); - a += 1; //~ WARN value assigned to `a` is never read - drop(b); - })(); -} - -#[derive(Debug)] -struct MyStruct<'a> { - x: Option<& 'a str>, - y: i32, -} - -pub fn nested() { - let mut a : Option<& str>; - a = None; - let mut b : Option<& str>; - b = None; - let mut d = MyStruct{ x: None, y: 1}; - let mut e = MyStruct{ x: None, y: 1}; - (|| { - (|| { - // This will not trigger a warning for unused variable as - // d.x will be treated as a Non-tracked place - d.x = Some("d1"); - d.x = Some("d2"); - a = Some("d1"); //~ WARN value assigned to `a` is never read - a = Some("d2"); - })(); - (move || { - // This will not trigger a warning for unused variable as - //e.x will be treated as a Non-tracked place - e.x = Some("e1"); - e.x = Some("e2"); - b = Some("e1"); //~ WARN value assigned to `b` is never read - //~| WARN unused variable: `b` - b = Some("e2"); //~ WARN value assigned to `b` is never read - })(); - })(); -} - -fn main() {} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr deleted file mode 100644 index 4eac5a2d282b0..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr +++ /dev/null @@ -1,70 +0,0 @@ -warning: value captured by `a` is never read - --> $DIR/liveness.rs:23:9 - | -LL | a = 1; - | ^ - | -note: the lint level is defined here - --> $DIR/liveness.rs:5:9 - | -LL | #![warn(unused)] - | ^^^^^^ - = note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]` - = help: did you mean to capture by reference instead? - -warning: unused variable: `a` - --> $DIR/liveness.rs:32:9 - | -LL | a += 1; - | ^ - | -note: the lint level is defined here - --> $DIR/liveness.rs:5:9 - | -LL | #![warn(unused)] - | ^^^^^^ - = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]` - = help: did you mean to capture by reference instead? - -warning: value assigned to `a` is never read - --> $DIR/liveness.rs:52:9 - | -LL | a += 1; - | ^ - | - = help: maybe it is overwritten before being read? - -warning: value assigned to `a` is never read - --> $DIR/liveness.rs:76:13 - | -LL | a = Some("d1"); - | ^ - | - = help: maybe it is overwritten before being read? - -warning: value assigned to `b` is never read - --> $DIR/liveness.rs:84:13 - | -LL | b = Some("e1"); - | ^ - | - = help: maybe it is overwritten before being read? - -warning: value assigned to `b` is never read - --> $DIR/liveness.rs:86:13 - | -LL | b = Some("e2"); - | ^ - | - = help: maybe it is overwritten before being read? - -warning: unused variable: `b` - --> $DIR/liveness.rs:84:13 - | -LL | b = Some("e1"); - | ^ - | - = help: did you mean to capture by reference instead? - -warning: 7 warnings emitted - diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.rs deleted file mode 100644 index 10a7d07a1df99..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.rs +++ /dev/null @@ -1,42 +0,0 @@ -// edition:2021 - -// check-pass -#![warn(unused)] - -#[derive(Debug)] -struct MyStruct { - a: i32, - b: i32, -} - -pub fn unintentional_copy_one() { - let mut a = 1; - let mut last = MyStruct{ a: 1, b: 1}; - let mut f = move |s| { - // This will not trigger a warning for unused variable - // as last.a will be treated as a Non-tracked place - last.a = s; - a = s; - //~^ WARN value assigned to `a` is never read - //~| WARN unused variable: `a` - }; - f(2); - f(3); - f(4); -} - -pub fn unintentional_copy_two() { - let mut a = 1; - let mut sum = MyStruct{ a: 1, b: 0}; - (1..10).for_each(move |x| { - // This will not trigger a warning for unused variable - // as sum.b will be treated as a Non-tracked place - sum.b += x; - a += x; //~ WARN unused variable: `a` - }); -} - -fn main() { - unintentional_copy_one(); - unintentional_copy_two(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr deleted file mode 100644 index f74303e3dd682..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr +++ /dev/null @@ -1,38 +0,0 @@ -warning: value assigned to `a` is never read - --> $DIR/liveness_unintentional_copy.rs:19:9 - | -LL | a = s; - | ^ - | -note: the lint level is defined here - --> $DIR/liveness_unintentional_copy.rs:4:9 - | -LL | #![warn(unused)] - | ^^^^^^ - = note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]` - = help: maybe it is overwritten before being read? - -warning: unused variable: `a` - --> $DIR/liveness_unintentional_copy.rs:19:9 - | -LL | a = s; - | ^ - | -note: the lint level is defined here - --> $DIR/liveness_unintentional_copy.rs:4:9 - | -LL | #![warn(unused)] - | ^^^^^^ - = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]` - = help: did you mean to capture by reference instead? - -warning: unused variable: `a` - --> $DIR/liveness_unintentional_copy.rs:35:9 - | -LL | a += x; - | ^ - | - = help: did you mean to capture by reference instead? - -warning: 3 warnings emitted - diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/multilevel-path.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/multilevel-path.rs deleted file mode 100644 index fa73ff23f9cd3..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/multilevel-path.rs +++ /dev/null @@ -1,28 +0,0 @@ -// edition:2021 - -// Test that when a borrow checker diagnostics are emitted, it's as precise -// as the capture by the closure. - -#![allow(unused)] - -struct Point { - x: i32, - y: i32, -} -struct Wrapper { - p: Point, -} - -fn main() { - let mut w = Wrapper { p: Point { x: 10, y: 10 } }; - - let mut c = || { - w.p.x += 20; - }; - - let py = &mut w.p.x; - //~^ ERROR: cannot borrow `w.p.x` as mutable more than once at a time - c(); - - *py = 20 -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/multilevel-path.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/multilevel-path.stderr deleted file mode 100644 index ac4c9c93769ce..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/multilevel-path.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error[E0499]: cannot borrow `w.p.x` as mutable more than once at a time - --> $DIR/multilevel-path.rs:23:14 - | -LL | let mut c = || { - | -- first mutable borrow occurs here -LL | w.p.x += 20; - | ----- first borrow occurs due to use of `w.p.x` in closure -... -LL | let py = &mut w.p.x; - | ^^^^^^^^^^ second mutable borrow occurs here -LL | -LL | c(); - | - first borrow later used here - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0499`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/mut_ref.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/mut_ref.rs deleted file mode 100644 index 3d5a31e8b8e49..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/mut_ref.rs +++ /dev/null @@ -1,37 +0,0 @@ -// edition:2021 - -// Test that we can't mutate a place if we need to deref an imm-borrow -// to reach it. - -fn imm_mut_ref() { - let mut x = String::new(); - let y = String::new(); - let mref_x = &mut x; - let ref_mref_x = &mref_x; - - let c = || { - //~^ ERROR: cannot borrow `**ref_mref_x` as mutable, as it is behind a `&` reference - **ref_mref_x = y; - }; - - c(); -} - -fn mut_imm_ref() { - let x = String::new(); - let y = String::new(); - let mut ref_x = &x; - let mref_ref_x = &mut ref_x; - - let c = || { - //~^ ERROR: cannot borrow `**mref_ref_x` as mutable, as it is behind a `&` reference - **mref_ref_x = y; - }; - - c(); -} - -fn main() { - imm_mut_ref(); - mut_imm_ref(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr deleted file mode 100644 index dbf8523a3bae1..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr +++ /dev/null @@ -1,24 +0,0 @@ -error[E0596]: cannot borrow `**ref_mref_x` as mutable, as it is behind a `&` reference - --> $DIR/mut_ref.rs:12:13 - | -LL | let ref_mref_x = &mref_x; - | ------- help: consider changing this to be a mutable reference: `&mut mref_x` -LL | -LL | let c = || { - | ^^ `ref_mref_x` is a `&` reference, so the data it refers to cannot be borrowed as mutable -LL | -LL | **ref_mref_x = y; - | ------------ mutable borrow occurs due to use of `**ref_mref_x` in closure - -error[E0596]: cannot borrow `**mref_ref_x` as mutable, as it is behind a `&` reference - --> $DIR/mut_ref.rs:26:13 - | -LL | let c = || { - | ^^ cannot borrow as mutable -LL | -LL | **mref_ref_x = y; - | ------------ mutable borrow occurs due to use of `**mref_ref_x` in closure - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0596`. diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.rs deleted file mode 100644 index 4799f488d7d52..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.rs +++ /dev/null @@ -1,35 +0,0 @@ -// edition:2021 - -// check-pass - -// Given how the closure desugaring is implemented (at least at the time of writing this test), -// we don't need to truncate the captured path to a reference into a packed-struct if the field -// being referenced will be moved into the closure, since it's safe to move out a field from a -// packed-struct. -// -// However to avoid surprises for the user, or issues when the closure is -// inlined we will truncate the capture to access just the struct regardless of if the field -// might get moved into the closure. -// -// It is possible for someone to try writing the code that relies on the desugaring to access a ref -// into a packed-struct without explicity using unsafe. Here we test that the compiler warns the -// user that such an access is still unsafe. -fn test_missing_unsafe_warning_on_repr_packed() { - #[repr(packed)] - struct Foo { x: String } - - let foo = Foo { x: String::new() }; - - let c = || { - println!("{}", foo.x); - //~^ WARNING: reference to packed field is unaligned - //~| WARNING: this was previously accepted by the compiler but is being phased out - let _z = foo.x; - }; - - c(); -} - -fn main() { - test_missing_unsafe_warning_on_repr_packed(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr deleted file mode 100644 index d2466681a0877..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr +++ /dev/null @@ -1,13 +0,0 @@ -warning: reference to packed field is unaligned - --> $DIR/repr_packed.rs:24:24 - | -LL | println!("{}", foo.x); - | ^^^^^ - | - = note: `#[warn(unaligned_references)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #82523 - = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced) - -warning: 1 warning emitted - diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/simple-struct-min-capture.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/simple-struct-min-capture.rs deleted file mode 100644 index ed2d9a3de00f8..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/simple-struct-min-capture.rs +++ /dev/null @@ -1,25 +0,0 @@ -// edition:2021 - -// Test that borrow checker error is accurate and that min capture pass of the -// closure analysis is working as expected. - -#[derive(Debug)] -struct Point { - x: i32, - y: i32, -} - -fn main() { - let mut p = Point { x: 10, y: 20 }; - - // `p` is captured via mutable borrow. - let mut c = || { - p.x += 10; - println!("{:?}", p); - }; - - - println!("{:?}", p); - //~^ ERROR: cannot borrow `p` as immutable because it is also borrowed as mutable - c(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/simple-struct-min-capture.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/simple-struct-min-capture.stderr deleted file mode 100644 index 32705af3d0166..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/simple-struct-min-capture.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0502]: cannot borrow `p` as immutable because it is also borrowed as mutable - --> $DIR/simple-struct-min-capture.rs:22:22 - | -LL | let mut c = || { - | -- mutable borrow occurs here -LL | p.x += 10; - | --- capture is mutable because of use here -LL | println!("{:?}", p); - | - first borrow occurs due to use of `p` in closure -... -LL | println!("{:?}", p); - | ^ immutable borrow occurs here -LL | -LL | c(); - | - mutable borrow later used here - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0502`. diff --git a/src/test/ui/closures/2229_closure_analysis/feature-gate-capture_disjoint_fields.rs b/src/test/ui/closures/2229_closure_analysis/feature-gate-capture_disjoint_fields.rs index 269cf76e67351..7c7cda89827a9 100644 --- a/src/test/ui/closures/2229_closure_analysis/feature-gate-capture_disjoint_fields.rs +++ b/src/test/ui/closures/2229_closure_analysis/feature-gate-capture_disjoint_fields.rs @@ -1,4 +1,7 @@ -// edition:2021 +#![feature(capture_disjoint_fields)] +//~^ WARNING: the feature `capture_disjoint_fields` is incomplete +//~| NOTE: `#[warn(incomplete_features)]` on by default +//~| NOTE: see issue #53488 #![feature(rustc_attrs)] diff --git a/src/test/ui/closures/2229_closure_analysis/feature-gate-capture_disjoint_fields.stderr b/src/test/ui/closures/2229_closure_analysis/feature-gate-capture_disjoint_fields.stderr index b936c5ee35a4d..13be309b4f895 100644 --- a/src/test/ui/closures/2229_closure_analysis/feature-gate-capture_disjoint_fields.stderr +++ b/src/test/ui/closures/2229_closure_analysis/feature-gate-capture_disjoint_fields.stderr @@ -1,5 +1,5 @@ error[E0658]: attributes on expressions are experimental - --> $DIR/feature-gate-capture_disjoint_fields.rs:8:13 + --> $DIR/feature-gate-capture_disjoint_fields.rs:11:13 | LL | let c = #[rustc_capture_analysis] | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,8 +7,17 @@ LL | let c = #[rustc_capture_analysis] = note: see issue #15701 for more information = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable +warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/feature-gate-capture_disjoint_fields.rs:1:12 + | +LL | #![feature(capture_disjoint_fields)] + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #53488 for more information + error: First Pass analysis includes: - --> $DIR/feature-gate-capture_disjoint_fields.rs:11:5 + --> $DIR/feature-gate-capture_disjoint_fields.rs:14:5 | LL | / || { LL | | @@ -20,13 +29,13 @@ LL | | }; | |_____^ | note: Capturing s[] -> ImmBorrow - --> $DIR/feature-gate-capture_disjoint_fields.rs:14:69 + --> $DIR/feature-gate-capture_disjoint_fields.rs:17:69 | LL | println!("This uses new capture analyysis to capture s={}", s); | ^ error: Min Capture analysis includes: - --> $DIR/feature-gate-capture_disjoint_fields.rs:11:5 + --> $DIR/feature-gate-capture_disjoint_fields.rs:14:5 | LL | / || { LL | | @@ -38,11 +47,11 @@ LL | | }; | |_____^ | note: Min Capture s[] -> ImmBorrow - --> $DIR/feature-gate-capture_disjoint_fields.rs:14:69 + --> $DIR/feature-gate-capture_disjoint_fields.rs:17:69 | LL | println!("This uses new capture analyysis to capture s={}", s); | ^ -error: aborting due to 3 previous errors +error: aborting due to 3 previous errors; 1 warning emitted For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/filter-on-struct-member.rs b/src/test/ui/closures/2229_closure_analysis/filter-on-struct-member.rs deleted file mode 100644 index bfa3ebcd6d286..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/filter-on-struct-member.rs +++ /dev/null @@ -1,41 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] - -struct Filter { - div: i32, -} -impl Filter { - fn allowed(&self, x: i32) -> bool { - x % self.div == 1 - } -} - -struct Data { - filter: Filter, - list: Vec, -} -impl Data { - fn update(&mut self) { - // The closure passed to filter only captures self.filter, - // therefore mutating self.list is allowed. - self.list.retain( - #[rustc_capture_analysis] - |v| self.filter.allowed(*v), - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - //~| NOTE: Capturing self[Deref,(0, 0)] -> ImmBorrow - //~| NOTE: Min Capture self[Deref,(0, 0)] -> ImmBorrow - ); - } -} - -fn main() { - let mut d = Data { filter: Filter { div: 3 }, list: Vec::new() }; - - for i in 1..10 { - d.list.push(i); - } - - d.update(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/filter-on-struct-member.stderr b/src/test/ui/closures/2229_closure_analysis/filter-on-struct-member.stderr deleted file mode 100644 index 10e0d076b4276..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/filter-on-struct-member.stderr +++ /dev/null @@ -1,26 +0,0 @@ -error: First Pass analysis includes: - --> $DIR/filter-on-struct-member.rs:24:13 - | -LL | |v| self.filter.allowed(*v), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: Capturing self[Deref,(0, 0)] -> ImmBorrow - --> $DIR/filter-on-struct-member.rs:24:17 - | -LL | |v| self.filter.allowed(*v), - | ^^^^^^^^^^^ - -error: Min Capture analysis includes: - --> $DIR/filter-on-struct-member.rs:24:13 - | -LL | |v| self.filter.allowed(*v), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: Min Capture self[Deref,(0, 0)] -> ImmBorrow - --> $DIR/filter-on-struct-member.rs:24:17 - | -LL | |v| self.filter.allowed(*v), - | ^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.fixed b/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.fixed deleted file mode 100644 index 134d07c400b3a..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.fixed +++ /dev/null @@ -1,67 +0,0 @@ -// run-rustfix -#![deny(rust_2021_incompatible_closure_captures)] - -use std::thread; - -/* Test Send Trait Migration */ -struct SendPointer(*mut i32); -unsafe impl Send for SendPointer {} - -fn test_send_trait() { - let mut f = 10; - let fptr = SendPointer(&mut f as *mut i32); - thread::spawn(move || { let _ = &fptr; unsafe { - //~^ ERROR: `Send` trait implementation - //~| HELP: add a dummy let to cause `fptr` to be fully captured - *fptr.0 = 20; - } }); -} - -/* Test Sync Trait Migration */ -struct CustomInt(*mut i32); -struct SyncPointer(CustomInt); -unsafe impl Sync for SyncPointer {} -unsafe impl Send for CustomInt {} - -fn test_sync_trait() { - let mut f = 10; - let f = CustomInt(&mut f as *mut i32); - let fptr = SyncPointer(f); - thread::spawn(move || { let _ = &fptr; unsafe { - //~^ ERROR: `Sync`, `Send` trait implementation - //~| HELP: add a dummy let to cause `fptr` to be fully captured - *fptr.0.0 = 20; - } }); -} - -/* Test Clone Trait Migration */ -struct S(String); -struct T(i32); - -struct U(S, T); - -impl Clone for U { - fn clone(&self) -> Self { - U(S(String::from("Hello World")), T(0)) - } -} - -fn test_clone_trait() { - let f = U(S(String::from("Hello World")), T(0)); - let c = || { let _ = &f; - //~^ ERROR: `Clone` trait implementation, and drop order - //~| HELP: add a dummy let to cause `f` to be fully captured - let f_1 = f.1; - println!("{:?}", f_1.0); - }; - - let c_clone = c.clone(); - - c_clone(); -} - -fn main() { - test_send_trait(); - test_sync_trait(); - test_clone_trait(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.rs b/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.rs deleted file mode 100644 index b48a724f052f0..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.rs +++ /dev/null @@ -1,67 +0,0 @@ -// run-rustfix -#![deny(rust_2021_incompatible_closure_captures)] - -use std::thread; - -/* Test Send Trait Migration */ -struct SendPointer(*mut i32); -unsafe impl Send for SendPointer {} - -fn test_send_trait() { - let mut f = 10; - let fptr = SendPointer(&mut f as *mut i32); - thread::spawn(move || unsafe { - //~^ ERROR: `Send` trait implementation - //~| HELP: add a dummy let to cause `fptr` to be fully captured - *fptr.0 = 20; - }); -} - -/* Test Sync Trait Migration */ -struct CustomInt(*mut i32); -struct SyncPointer(CustomInt); -unsafe impl Sync for SyncPointer {} -unsafe impl Send for CustomInt {} - -fn test_sync_trait() { - let mut f = 10; - let f = CustomInt(&mut f as *mut i32); - let fptr = SyncPointer(f); - thread::spawn(move || unsafe { - //~^ ERROR: `Sync`, `Send` trait implementation - //~| HELP: add a dummy let to cause `fptr` to be fully captured - *fptr.0.0 = 20; - }); -} - -/* Test Clone Trait Migration */ -struct S(String); -struct T(i32); - -struct U(S, T); - -impl Clone for U { - fn clone(&self) -> Self { - U(S(String::from("Hello World")), T(0)) - } -} - -fn test_clone_trait() { - let f = U(S(String::from("Hello World")), T(0)); - let c = || { - //~^ ERROR: `Clone` trait implementation, and drop order - //~| HELP: add a dummy let to cause `f` to be fully captured - let f_1 = f.1; - println!("{:?}", f_1.0); - }; - - let c_clone = c.clone(); - - c_clone(); -} - -fn main() { - test_send_trait(); - test_sync_trait(); - test_clone_trait(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr deleted file mode 100644 index 3d3dde15412bf..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr +++ /dev/null @@ -1,72 +0,0 @@ -error: `Send` trait implementation will change in Rust 2021 - --> $DIR/auto_traits.rs:13:19 - | -LL | thread::spawn(move || unsafe { - | ___________________^ -LL | | -LL | | -LL | | *fptr.0 = 20; -LL | | }); - | |_____^ - | -note: the lint level is defined here - --> $DIR/auto_traits.rs:2:9 - | -LL | #![deny(rust_2021_incompatible_closure_captures)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: for more information, see -help: add a dummy let to cause `fptr` to be fully captured - | -LL | thread::spawn(move || { let _ = &fptr; unsafe { -LL | -LL | -LL | *fptr.0 = 20; -LL | } }); - | - -error: `Sync`, `Send` trait implementation will change in Rust 2021 - --> $DIR/auto_traits.rs:30:19 - | -LL | thread::spawn(move || unsafe { - | ___________________^ -LL | | -LL | | -LL | | *fptr.0.0 = 20; -LL | | }); - | |_____^ - | - = note: for more information, see -help: add a dummy let to cause `fptr` to be fully captured - | -LL | thread::spawn(move || { let _ = &fptr; unsafe { -LL | -LL | -LL | *fptr.0.0 = 20; -LL | } }); - | - -error: `Clone` trait implementation, and drop order will change in Rust 2021 - --> $DIR/auto_traits.rs:51:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | let f_1 = f.1; -LL | | println!("{:?}", f_1.0); -LL | | }; - | |_____^ - | - = note: for more information, see -help: add a dummy let to cause `f` to be fully captured - | -LL | let c = || { let _ = &f; -LL | -LL | -LL | let f_1 = f.1; -LL | println!("{:?}", f_1.0); -LL | }; - | - -error: aborting due to 3 previous errors - diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop.fixed b/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop.fixed deleted file mode 100644 index 51d9c4881af3f..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop.fixed +++ /dev/null @@ -1,140 +0,0 @@ -// run-rustfix - -#![deny(rust_2021_incompatible_closure_captures)] -//~^ NOTE: the lint level is defined here - -// Test cases for types that implement a insignificant drop (stlib defined) - -// `t` needs Drop because one of its elements needs drop, -// therefore precise capture might affect drop ordering -fn test1_all_need_migration() { - let t = (String::new(), String::new()); - let t1 = (String::new(), String::new()); - let t2 = (String::new(), String::new()); - - let c = || { let _ = (&t, &t1, &t2); - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t`, `t1`, `t2` to be fully captured - - let _t = t.0; - let _t1 = t1.0; - let _t2 = t2.0; - }; - - c(); -} - -// String implements drop and therefore should be migrated. -// But in this test cases, `t2` is completely captured and when it is dropped won't be affected -fn test2_only_precise_paths_need_migration() { - let t = (String::new(), String::new()); - let t1 = (String::new(), String::new()); - let t2 = (String::new(), String::new()); - - let c = || { let _ = (&t, &t1); - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t`, `t1` to be fully captured - let _t = t.0; - let _t1 = t1.0; - let _t2 = t2; - }; - - c(); -} - -// If a variable would've not been captured by value then it would've not been -// dropped with the closure and therefore doesn't need migration. -fn test3_only_by_value_need_migration() { - let t = (String::new(), String::new()); - let t1 = (String::new(), String::new()); - let c = || { let _ = &t; - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - println!("{}", t1.1); - }; - - c(); -} - -// Copy types get copied into the closure instead of move. Therefore we don't need to -// migrate then as their drop order isn't tied to the closure. -fn test4_only_non_copy_types_need_migration() { - let t = (String::new(), String::new()); - - // `t1` is Copy because all of its elements are Copy - let t1 = (0i32, 0i32); - - let c = || { let _ = &t; - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - let _t1 = t1.0; - }; - - c(); -} - -fn test5_only_drop_types_need_migration() { - struct S(i32, i32); - - let t = (String::new(), String::new()); - - // `s` doesn't implement Drop or any elements within it, and doesn't need migration - let s = S(0i32, 0i32); - - let c = || { let _ = &t; - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - let _s = s.0; - }; - - c(); -} - -// Since we are using a move closure here, both `t` and `t1` get moved -// even though they are being used by ref inside the closure. -fn test6_move_closures_non_copy_types_might_need_migration() { - let t = (String::new(), String::new()); - let t1 = (String::new(), String::new()); - let c = move || { let _ = (&t1, &t); - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t1`, `t` to be fully captured - println!("{} {}", t1.1, t.1); - }; - - c(); -} - -// Test migration analysis in case of Drop + Non Drop aggregates. -// Note we need migration here only because the non-copy (because Drop type) is captured, -// otherwise we won't need to, since we can get away with just by ref capture in that case. -fn test7_drop_non_drop_aggregate_need_migration() { - let t = (String::new(), String::new(), 0i32); - - let c = || { let _ = &t; - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - }; - - c(); -} - -fn main() { - test1_all_need_migration(); - test2_only_precise_paths_need_migration(); - test3_only_by_value_need_migration(); - test4_only_non_copy_types_need_migration(); - test5_only_drop_types_need_migration(); - test6_move_closures_non_copy_types_might_need_migration(); - test7_drop_non_drop_aggregate_need_migration(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop.rs b/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop.rs deleted file mode 100644 index c732cbb4fa51e..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop.rs +++ /dev/null @@ -1,140 +0,0 @@ -// run-rustfix - -#![deny(rust_2021_incompatible_closure_captures)] -//~^ NOTE: the lint level is defined here - -// Test cases for types that implement a insignificant drop (stlib defined) - -// `t` needs Drop because one of its elements needs drop, -// therefore precise capture might affect drop ordering -fn test1_all_need_migration() { - let t = (String::new(), String::new()); - let t1 = (String::new(), String::new()); - let t2 = (String::new(), String::new()); - - let c = || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t`, `t1`, `t2` to be fully captured - - let _t = t.0; - let _t1 = t1.0; - let _t2 = t2.0; - }; - - c(); -} - -// String implements drop and therefore should be migrated. -// But in this test cases, `t2` is completely captured and when it is dropped won't be affected -fn test2_only_precise_paths_need_migration() { - let t = (String::new(), String::new()); - let t1 = (String::new(), String::new()); - let t2 = (String::new(), String::new()); - - let c = || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t`, `t1` to be fully captured - let _t = t.0; - let _t1 = t1.0; - let _t2 = t2; - }; - - c(); -} - -// If a variable would've not been captured by value then it would've not been -// dropped with the closure and therefore doesn't need migration. -fn test3_only_by_value_need_migration() { - let t = (String::new(), String::new()); - let t1 = (String::new(), String::new()); - let c = || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - println!("{}", t1.1); - }; - - c(); -} - -// Copy types get copied into the closure instead of move. Therefore we don't need to -// migrate then as their drop order isn't tied to the closure. -fn test4_only_non_copy_types_need_migration() { - let t = (String::new(), String::new()); - - // `t1` is Copy because all of its elements are Copy - let t1 = (0i32, 0i32); - - let c = || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - let _t1 = t1.0; - }; - - c(); -} - -fn test5_only_drop_types_need_migration() { - struct S(i32, i32); - - let t = (String::new(), String::new()); - - // `s` doesn't implement Drop or any elements within it, and doesn't need migration - let s = S(0i32, 0i32); - - let c = || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - let _s = s.0; - }; - - c(); -} - -// Since we are using a move closure here, both `t` and `t1` get moved -// even though they are being used by ref inside the closure. -fn test6_move_closures_non_copy_types_might_need_migration() { - let t = (String::new(), String::new()); - let t1 = (String::new(), String::new()); - let c = move || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t1`, `t` to be fully captured - println!("{} {}", t1.1, t.1); - }; - - c(); -} - -// Test migration analysis in case of Drop + Non Drop aggregates. -// Note we need migration here only because the non-copy (because Drop type) is captured, -// otherwise we won't need to, since we can get away with just by ref capture in that case. -fn test7_drop_non_drop_aggregate_need_migration() { - let t = (String::new(), String::new(), 0i32); - - let c = || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - }; - - c(); -} - -fn main() { - test1_all_need_migration(); - test2_only_precise_paths_need_migration(); - test3_only_by_value_need_migration(); - test4_only_non_copy_types_need_migration(); - test5_only_drop_types_need_migration(); - test6_move_closures_non_copy_types_might_need_migration(); - test7_drop_non_drop_aggregate_need_migration(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop.stderr deleted file mode 100644 index 89a2b0eb95366..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop.stderr +++ /dev/null @@ -1,173 +0,0 @@ -error: drop order will change in Rust 2021 - --> $DIR/insignificant_drop.rs:15:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | -... | -LL | | let _t2 = t2.0; -LL | | }; - | |_____^ - | -note: the lint level is defined here - --> $DIR/insignificant_drop.rs:3:9 - | -LL | #![deny(rust_2021_incompatible_closure_captures)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: for more information, see -help: add a dummy let to cause `t`, `t1`, `t2` to be fully captured - | -LL | let c = || { let _ = (&t, &t1, &t2); -LL | -LL | -LL | -LL | -LL | let _t = t.0; - ... - -error: drop order will change in Rust 2021 - --> $DIR/insignificant_drop.rs:35:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | -... | -LL | | let _t2 = t2; -LL | | }; - | |_____^ - | - = note: for more information, see -help: add a dummy let to cause `t`, `t1` to be fully captured - | -LL | let c = || { let _ = (&t, &t1); -LL | -LL | -LL | -LL | let _t = t.0; -LL | let _t1 = t1.0; - ... - -error: drop order will change in Rust 2021 - --> $DIR/insignificant_drop.rs:52:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | -LL | | let _t = t.0; -LL | | println!("{}", t1.1); -LL | | }; - | |_____^ - | - = note: for more information, see -help: add a dummy let to cause `t` to be fully captured - | -LL | let c = || { let _ = &t; -LL | -LL | -LL | -LL | let _t = t.0; -LL | println!("{}", t1.1); - ... - -error: drop order will change in Rust 2021 - --> $DIR/insignificant_drop.rs:71:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | -LL | | let _t = t.0; -LL | | let _t1 = t1.0; -LL | | }; - | |_____^ - | - = note: for more information, see -help: add a dummy let to cause `t` to be fully captured - | -LL | let c = || { let _ = &t; -LL | -LL | -LL | -LL | let _t = t.0; -LL | let _t1 = t1.0; - ... - -error: drop order will change in Rust 2021 - --> $DIR/insignificant_drop.rs:90:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | -LL | | let _t = t.0; -LL | | let _s = s.0; -LL | | }; - | |_____^ - | - = note: for more information, see -help: add a dummy let to cause `t` to be fully captured - | -LL | let c = || { let _ = &t; -LL | -LL | -LL | -LL | let _t = t.0; -LL | let _s = s.0; - ... - -error: drop order will change in Rust 2021 - --> $DIR/insignificant_drop.rs:106:13 - | -LL | let c = move || { - | _____________^ -LL | | -LL | | -LL | | -LL | | println!("{} {}", t1.1, t.1); -LL | | }; - | |_____^ - | - = note: for more information, see -help: add a dummy let to cause `t1`, `t` to be fully captured - | -LL | let c = move || { let _ = (&t1, &t); -LL | -LL | -LL | -LL | println!("{} {}", t1.1, t.1); -LL | }; - | - -error: drop order will change in Rust 2021 - --> $DIR/insignificant_drop.rs:122:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | -LL | | let _t = t.0; -LL | | }; - | |_____^ - | - = note: for more information, see -help: add a dummy let to cause `t` to be fully captured - | -LL | let c = || { let _ = &t; -LL | -LL | -LL | -LL | let _t = t.0; -LL | }; - | - -error: aborting due to 7 previous errors - diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.fixed b/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.fixed deleted file mode 100644 index 8c85cd990d308..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.fixed +++ /dev/null @@ -1,68 +0,0 @@ -// run-rustfix - -#![deny(rust_2021_incompatible_closure_captures)] -//~^ NOTE: the lint level is defined here -#![feature(rustc_attrs)] -#![allow(unused)] - -struct InsignificantDropPoint { - x: i32, - y: i32, -} - -impl Drop for InsignificantDropPoint { - #[rustc_insignificant_dtor] - fn drop(&mut self) {} -} - -struct SigDrop; - -impl Drop for SigDrop { - fn drop(&mut self) {} -} - -struct GenericStruct(T, T); - -struct Wrapper(GenericStruct, i32); - -impl Drop for GenericStruct { - #[rustc_insignificant_dtor] - fn drop(&mut self) {} -} - -// `SigDrop` implements drop and therefore needs to be migrated. -fn significant_drop_needs_migration() { - let t = (SigDrop {}, SigDrop {}); - - let c = || { let _ = &t; - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - }; - - c(); -} - -// Even if a type implements an insignificant drop, if it's -// elements have a significant drop then the overall type is -// consdered to have an significant drop. Since the elements -// of `GenericStruct` implement drop, migration is required. -fn generic_struct_with_significant_drop_needs_migration() { - let t = Wrapper(GenericStruct(SigDrop {}, SigDrop {}), 5); - - // move is used to force i32 to be copied instead of being a ref - let c = move || { let _ = &t; - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.1; - }; - - c(); -} - -fn main() { - significant_drop_needs_migration(); - generic_struct_with_significant_drop_needs_migration(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.rs b/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.rs deleted file mode 100644 index 17cee28e31117..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.rs +++ /dev/null @@ -1,68 +0,0 @@ -// run-rustfix - -#![deny(rust_2021_incompatible_closure_captures)] -//~^ NOTE: the lint level is defined here -#![feature(rustc_attrs)] -#![allow(unused)] - -struct InsignificantDropPoint { - x: i32, - y: i32, -} - -impl Drop for InsignificantDropPoint { - #[rustc_insignificant_dtor] - fn drop(&mut self) {} -} - -struct SigDrop; - -impl Drop for SigDrop { - fn drop(&mut self) {} -} - -struct GenericStruct(T, T); - -struct Wrapper(GenericStruct, i32); - -impl Drop for GenericStruct { - #[rustc_insignificant_dtor] - fn drop(&mut self) {} -} - -// `SigDrop` implements drop and therefore needs to be migrated. -fn significant_drop_needs_migration() { - let t = (SigDrop {}, SigDrop {}); - - let c = || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - }; - - c(); -} - -// Even if a type implements an insignificant drop, if it's -// elements have a significant drop then the overall type is -// consdered to have an significant drop. Since the elements -// of `GenericStruct` implement drop, migration is required. -fn generic_struct_with_significant_drop_needs_migration() { - let t = Wrapper(GenericStruct(SigDrop {}, SigDrop {}), 5); - - // move is used to force i32 to be copied instead of being a ref - let c = move || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.1; - }; - - c(); -} - -fn main() { - significant_drop_needs_migration(); - generic_struct_with_significant_drop_needs_migration(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.stderr deleted file mode 100644 index 1d3bda03d0e16..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.stderr +++ /dev/null @@ -1,53 +0,0 @@ -error: drop order will change in Rust 2021 - --> $DIR/insignificant_drop_attr_migrations.rs:37:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | -LL | | let _t = t.0; -LL | | }; - | |_____^ - | -note: the lint level is defined here - --> $DIR/insignificant_drop_attr_migrations.rs:3:9 - | -LL | #![deny(rust_2021_incompatible_closure_captures)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: for more information, see -help: add a dummy let to cause `t` to be fully captured - | -LL | let c = || { let _ = &t; -LL | -LL | -LL | -LL | let _t = t.0; -LL | }; - | - -error: drop order will change in Rust 2021 - --> $DIR/insignificant_drop_attr_migrations.rs:55:13 - | -LL | let c = move || { - | _____________^ -LL | | -LL | | -LL | | -LL | | let _t = t.1; -LL | | }; - | |_____^ - | - = note: for more information, see -help: add a dummy let to cause `t` to be fully captured - | -LL | let c = move || { let _ = &t; -LL | -LL | -LL | -LL | let _t = t.1; -LL | }; - | - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_no_migrations.rs b/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_no_migrations.rs deleted file mode 100644 index a527bf42e574a..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_no_migrations.rs +++ /dev/null @@ -1,45 +0,0 @@ -// run-pass - -#![deny(rust_2021_incompatible_closure_captures)] -#![feature(rustc_attrs)] -#![allow(unused)] - -struct InsignificantDropPoint { - x: i32, - y: i32, -} - -impl Drop for InsignificantDropPoint { - #[rustc_insignificant_dtor] - fn drop(&mut self) {} -} - -struct GenericStruct(T, T); - -// No drop reordering is required as the elements of `t` implement insignificant drop -fn insignificant_drop_does_not_need_migration() { - let t = (InsignificantDropPoint { x: 4, y: 9 }, InsignificantDropPoint { x: 4, y: 9 }); - - let c = || { - let _t = t.0; - }; - - c(); -} - -// Generic struct whose elements don't have significant drops don't need drop reordering -fn generic_struct_with_insignificant_drop_does_not_need_migration() { - let t = - GenericStruct(InsignificantDropPoint { x: 4, y: 9 }, InsignificantDropPoint { x: 4, y: 9 }); - - let c = || { - let _t = t.0; - }; - - c(); -} - -fn main() { - insignificant_drop_does_not_need_migration(); - generic_struct_with_insignificant_drop_does_not_need_migration(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.rs b/src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.rs deleted file mode 100644 index ff5d284614bf1..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.rs +++ /dev/null @@ -1,10 +0,0 @@ -// run-pass - -#![warn(rust_2021_incompatible_closure_captures)] - -fn main() { - if let a = "" { - //~^ WARNING: irrefutable `if let` pattern - drop(|_: ()| drop(a)); - } -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr deleted file mode 100644 index 7e5da949cb299..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr +++ /dev/null @@ -1,15 +0,0 @@ -warning: irrefutable `if let` pattern - --> $DIR/issue-78720.rs:6:5 - | -LL | / if let a = "" { -LL | | -LL | | drop(|_: ()| drop(a)); -LL | | } - | |_____^ - | - = note: `#[warn(irrefutable_let_patterns)]` on by default - = note: this pattern will always match, so the `if let` is useless - = help: consider replacing the `if let` with a `let` - -warning: 1 warning emitted - diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/issue-86753.rs b/src/test/ui/closures/2229_closure_analysis/migrations/issue-86753.rs deleted file mode 100644 index fce9cac627b5e..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/issue-86753.rs +++ /dev/null @@ -1,34 +0,0 @@ -// edition:2018 -// check-pass - -#![warn(rust_2021_compatibility)] - -use std::future::Future; - -struct Runtime; - -impl Runtime { - pub fn block_on(&self, _future: F) -> F::Output { - unimplemented!() - } -} - -pub fn http(_func: F) -where - F: Fn() -> Fut, - Fut: Future, -{ - let rt = Runtime {}; - let srv = rt.block_on(async move { serve(move || async move { unimplemented!() }) }); - let _ = || rt.block_on(async { srv }); -} - -pub struct Server { - _marker: std::marker::PhantomData, -} - -pub fn serve(_new_service: S) -> Server { - unimplemented!() -} - -fn main() { } diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/migrations_rustfix.fixed b/src/test/ui/closures/2229_closure_analysis/migrations/migrations_rustfix.fixed deleted file mode 100644 index c974299c1536b..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/migrations_rustfix.fixed +++ /dev/null @@ -1,42 +0,0 @@ -// run-rustfix -#![deny(rust_2021_incompatible_closure_captures)] -//~^ NOTE: the lint level is defined here - -// Test the two possible cases for automated migartion using rustfix -// - Closure contains a block i.e. `|| { .. };` -// - Closure contains just an expr `|| ..;` - -#[derive(Debug)] -struct Foo(i32); -impl Drop for Foo { - fn drop(&mut self) { - println!("{:?} dropped", self.0); - } -} - -fn closure_contains_block() { - let t = (Foo(0), Foo(0)); - let c = || { let _ = &t; - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - }; - - c(); -} - -fn closure_doesnt_contain_block() { - let t = (Foo(0), Foo(0)); - let c = || { let _ = &t; t.0 }; - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - - c(); -} - -fn main() { - closure_contains_block(); - closure_doesnt_contain_block(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/migrations_rustfix.rs b/src/test/ui/closures/2229_closure_analysis/migrations/migrations_rustfix.rs deleted file mode 100644 index dd9556aa56784..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/migrations_rustfix.rs +++ /dev/null @@ -1,42 +0,0 @@ -// run-rustfix -#![deny(rust_2021_incompatible_closure_captures)] -//~^ NOTE: the lint level is defined here - -// Test the two possible cases for automated migartion using rustfix -// - Closure contains a block i.e. `|| { .. };` -// - Closure contains just an expr `|| ..;` - -#[derive(Debug)] -struct Foo(i32); -impl Drop for Foo { - fn drop(&mut self) { - println!("{:?} dropped", self.0); - } -} - -fn closure_contains_block() { - let t = (Foo(0), Foo(0)); - let c = || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - }; - - c(); -} - -fn closure_doesnt_contain_block() { - let t = (Foo(0), Foo(0)); - let c = || t.0; - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - - c(); -} - -fn main() { - closure_contains_block(); - closure_doesnt_contain_block(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/migrations_rustfix.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/migrations_rustfix.stderr deleted file mode 100644 index 2d5e5e5e55c14..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/migrations_rustfix.stderr +++ /dev/null @@ -1,42 +0,0 @@ -error: drop order will change in Rust 2021 - --> $DIR/migrations_rustfix.rs:19:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | -LL | | let _t = t.0; -LL | | }; - | |_____^ - | -note: the lint level is defined here - --> $DIR/migrations_rustfix.rs:2:9 - | -LL | #![deny(rust_2021_incompatible_closure_captures)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: for more information, see -help: add a dummy let to cause `t` to be fully captured - | -LL | let c = || { let _ = &t; -LL | -LL | -LL | -LL | let _t = t.0; -LL | }; - | - -error: drop order will change in Rust 2021 - --> $DIR/migrations_rustfix.rs:31:13 - | -LL | let c = || t.0; - | ^^^^^^ - | - = note: for more information, see -help: add a dummy let to cause `t` to be fully captured - | -LL | let c = || { let _ = &t; t.0 }; - | ^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.fixed b/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.fixed deleted file mode 100644 index 7f49b460ef63a..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.fixed +++ /dev/null @@ -1,44 +0,0 @@ -// run-rustfix - -#![deny(rust_2021_incompatible_closure_captures)] -// ignore-wasm32-bare compiled with panic=abort by default -#![feature(fn_traits)] -#![feature(never_type)] - -use std::panic; - -fn foo_diverges() -> ! { - panic!() -} - -fn assert_panics(f: F) -where - F: FnOnce(), -{ - let f = panic::AssertUnwindSafe(f); - let result = panic::catch_unwind(move || { let _ = &f; - //~^ ERROR: `UnwindSafe`, `RefUnwindSafe` trait implementation - //~| HELP: add a dummy let to cause `f` to be fully captured - f.0() - }); - if let Ok(..) = result { - panic!("diverging function returned"); - } -} - -fn test_fn_ptr_panic(mut t: T) -where - T: Fn() -> !, -{ - let as_fn = >::call; - assert_panics(|| as_fn(&t, ())); - let as_fn_mut = >::call_mut; - assert_panics(|| as_fn_mut(&mut t, ())); - let as_fn_once = >::call_once; - assert_panics(|| as_fn_once(t, ())); -} - -fn main() { - test_fn_ptr_panic(foo_diverges); - test_fn_ptr_panic(foo_diverges as fn() -> !); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs b/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs deleted file mode 100644 index 3c654bec52605..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs +++ /dev/null @@ -1,44 +0,0 @@ -// run-rustfix - -#![deny(rust_2021_incompatible_closure_captures)] -// ignore-wasm32-bare compiled with panic=abort by default -#![feature(fn_traits)] -#![feature(never_type)] - -use std::panic; - -fn foo_diverges() -> ! { - panic!() -} - -fn assert_panics(f: F) -where - F: FnOnce(), -{ - let f = panic::AssertUnwindSafe(f); - let result = panic::catch_unwind(move || { - //~^ ERROR: `UnwindSafe`, `RefUnwindSafe` trait implementation - //~| HELP: add a dummy let to cause `f` to be fully captured - f.0() - }); - if let Ok(..) = result { - panic!("diverging function returned"); - } -} - -fn test_fn_ptr_panic(mut t: T) -where - T: Fn() -> !, -{ - let as_fn = >::call; - assert_panics(|| as_fn(&t, ())); - let as_fn_mut = >::call_mut; - assert_panics(|| as_fn_mut(&mut t, ())); - let as_fn_once = >::call_once; - assert_panics(|| as_fn_once(t, ())); -} - -fn main() { - test_fn_ptr_panic(foo_diverges); - test_fn_ptr_panic(foo_diverges as fn() -> !); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.stderr deleted file mode 100644 index dca5c454b83be..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: `UnwindSafe`, `RefUnwindSafe` trait implementation will change in Rust 2021 - --> $DIR/mir_calls_to_shims.rs:19:38 - | -LL | let result = panic::catch_unwind(move || { - | ______________________________________^ -LL | | -LL | | -LL | | f.0() -LL | | }); - | |_____^ - | -note: the lint level is defined here - --> $DIR/mir_calls_to_shims.rs:3:9 - | -LL | #![deny(rust_2021_incompatible_closure_captures)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: for more information, see -help: add a dummy let to cause `f` to be fully captured - | -LL | let result = panic::catch_unwind(move || { let _ = &f; -LL | -LL | -LL | f.0() -LL | }); - | - -error: aborting due to previous error - diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/no_migrations.rs b/src/test/ui/closures/2229_closure_analysis/migrations/no_migrations.rs deleted file mode 100644 index 8b75e226ab59b..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/no_migrations.rs +++ /dev/null @@ -1,81 +0,0 @@ -// run-pass - -// Set of test cases that don't need migrations - -#![deny(rust_2021_incompatible_closure_captures)] - -// Copy types as copied by the closure instead of being moved into the closure -// Therefore their drop order isn't tied to the closure and won't be requiring any -// migrations. -fn test1_only_copy_types() { - let t = (0i32, 0i32); - - let c = || { - let _t = t.0; - }; - - c(); -} - -// Same as test1 but using a move closure -fn test2_only_copy_types_move_closure() { - let t = (0i32, 0i32); - - let c = move || { - println!("{}", t.0); - }; - - c(); -} - -// Don't need to migrate if captured by ref -fn test3_only_copy_types_move_closure() { - let t = (String::new(), String::new()); - - let c = || { - println!("{}", t.0); - }; - - c(); -} - -// Test migration analysis in case of Insignificant Drop + Non Drop aggregates. -// Note in this test the closure captures a non Drop type and therefore the variable -// is only captured by ref. -fn test4_insignificant_drop_non_drop_aggregate() { - let t = (String::new(), 0i32); - - let c = || { - let _t = t.1; - }; - - c(); -} - -struct Foo(i32); -impl Drop for Foo { - fn drop(&mut self) { - println!("{:?} dropped", self.0); - } -} - -// Test migration analysis in case of Significant Drop + Non Drop aggregates. -// Note in this test the closure captures a non Drop type and therefore the variable -// is only captured by ref. -fn test5_significant_drop_non_drop_aggregate() { - let t = (Foo(0), 0i32); - - let c = || { - let _t = t.1; - }; - - c(); -} - -fn main() { - test1_only_copy_types(); - test2_only_copy_types_move_closure(); - test3_only_copy_types_move_closure(); - test4_insignificant_drop_non_drop_aggregate(); - test5_significant_drop_non_drop_aggregate(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/old_name.rs b/src/test/ui/closures/2229_closure_analysis/migrations/old_name.rs deleted file mode 100644 index 16e3cca7b7714..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/old_name.rs +++ /dev/null @@ -1,9 +0,0 @@ -// check-pass - -// Ensure that the old name for `rust_2021_incompatible_closure_captures` is still -// accepted by the compiler - -#![allow(disjoint_capture_migration)] -//~^ WARN lint `disjoint_capture_migration` has been renamed - -fn main() {} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/old_name.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/old_name.stderr deleted file mode 100644 index 47cb689fa0193..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/old_name.stderr +++ /dev/null @@ -1,10 +0,0 @@ -warning: lint `disjoint_capture_migration` has been renamed to `rust_2021_incompatible_closure_captures` - --> $DIR/old_name.rs:6:10 - | -LL | #![allow(disjoint_capture_migration)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `rust_2021_incompatible_closure_captures` - | - = note: `#[warn(renamed_and_removed_lints)]` on by default - -warning: 1 warning emitted - diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/precise.fixed b/src/test/ui/closures/2229_closure_analysis/migrations/precise.fixed deleted file mode 100644 index ba5e5b573f1d6..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/precise.fixed +++ /dev/null @@ -1,55 +0,0 @@ -// run-rustfix - -#![deny(rust_2021_incompatible_closure_captures)] - -#[derive(Debug)] -struct Foo(i32); -impl Drop for Foo { - fn drop(&mut self) { - println!("{:?} dropped", self.0); - } -} - -struct ConstainsDropField(Foo, Foo); - -// Test that lint is triggered if a path that implements Drop is not captured by move -fn test_precise_analysis_drop_paths_not_captured_by_move() { - let t = ConstainsDropField(Foo(10), Foo(20)); - - let c = || { let _ = &t; - //~^ ERROR: drop order - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - let _t = &t.1; - }; - - c(); -} - -struct S; -impl Drop for S { - fn drop(&mut self) {} -} - -struct T(S, S); -struct U(T, T); - -// Test precise analysis for the lint works with paths longer than one. -fn test_precise_analysis_long_path_missing() { - let u = U(T(S, S), T(S, S)); - - let c = || { let _ = &u; - //~^ ERROR: drop order - //~| HELP: add a dummy let to cause `u` to be fully captured - let _x = u.0.0; - let _x = u.0.1; - let _x = u.1.0; - }; - - c(); -} - -fn main() { - test_precise_analysis_drop_paths_not_captured_by_move(); - test_precise_analysis_long_path_missing(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/precise.rs b/src/test/ui/closures/2229_closure_analysis/migrations/precise.rs deleted file mode 100644 index 92b6f25c80dad..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/precise.rs +++ /dev/null @@ -1,55 +0,0 @@ -// run-rustfix - -#![deny(rust_2021_incompatible_closure_captures)] - -#[derive(Debug)] -struct Foo(i32); -impl Drop for Foo { - fn drop(&mut self) { - println!("{:?} dropped", self.0); - } -} - -struct ConstainsDropField(Foo, Foo); - -// Test that lint is triggered if a path that implements Drop is not captured by move -fn test_precise_analysis_drop_paths_not_captured_by_move() { - let t = ConstainsDropField(Foo(10), Foo(20)); - - let c = || { - //~^ ERROR: drop order - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - let _t = &t.1; - }; - - c(); -} - -struct S; -impl Drop for S { - fn drop(&mut self) {} -} - -struct T(S, S); -struct U(T, T); - -// Test precise analysis for the lint works with paths longer than one. -fn test_precise_analysis_long_path_missing() { - let u = U(T(S, S), T(S, S)); - - let c = || { - //~^ ERROR: drop order - //~| HELP: add a dummy let to cause `u` to be fully captured - let _x = u.0.0; - let _x = u.0.1; - let _x = u.1.0; - }; - - c(); -} - -fn main() { - test_precise_analysis_drop_paths_not_captured_by_move(); - test_precise_analysis_long_path_missing(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/precise.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/precise.stderr deleted file mode 100644 index 2788207296f11..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/precise.stderr +++ /dev/null @@ -1,54 +0,0 @@ -error: drop order will change in Rust 2021 - --> $DIR/precise.rs:19:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | let _t = t.0; -LL | | let _t = &t.1; -LL | | }; - | |_____^ - | -note: the lint level is defined here - --> $DIR/precise.rs:3:9 - | -LL | #![deny(rust_2021_incompatible_closure_captures)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: for more information, see -help: add a dummy let to cause `t` to be fully captured - | -LL | let c = || { let _ = &t; -LL | -LL | -LL | let _t = t.0; -LL | let _t = &t.1; -LL | }; - | - -error: drop order will change in Rust 2021 - --> $DIR/precise.rs:41:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | let _x = u.0.0; -LL | | let _x = u.0.1; -LL | | let _x = u.1.0; -LL | | }; - | |_____^ - | - = note: for more information, see -help: add a dummy let to cause `u` to be fully captured - | -LL | let c = || { let _ = &u; -LL | -LL | -LL | let _x = u.0.0; -LL | let _x = u.0.1; -LL | let _x = u.1.0; - ... - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/precise_no_migrations.rs b/src/test/ui/closures/2229_closure_analysis/migrations/precise_no_migrations.rs deleted file mode 100644 index 587d71c40fc69..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/precise_no_migrations.rs +++ /dev/null @@ -1,104 +0,0 @@ -// run-pass - -#![deny(rust_2021_incompatible_closure_captures)] - -#[derive(Debug)] -struct Foo(i32); -impl Drop for Foo { - fn drop(&mut self) { - println!("{:?} dropped", self.0); - } -} - -struct ConstainsDropField(Foo, Foo); - -// Test that if all paths starting at root variable that implement Drop are captured -// then it doesn't trigger the lint. -fn test_precise_analysis_simple_1() { - let t = (Foo(10), Foo(20), Foo(30)); - - let c = || { - let _t = t.0; - let _t = t.1; - let _t = t.2; - }; - - c(); -} - -// Test that if all paths starting at root variable that implement Drop are captured -// then it doesn't trigger the lint. -fn test_precise_analysis_simple_2() { - let t = ConstainsDropField(Foo(10), Foo(20)); - - let c = || { - let _t = t.0; - let _t = t.1; - }; - - c(); -} - -#[derive(Debug)] -struct ContainsAndImplsDrop(Foo); -impl Drop for ContainsAndImplsDrop { - fn drop(&mut self) { - println!("{:?} dropped", self.0); - } -} - -// If a path isn't directly captured but requires Drop, then this tests that migrations aren't -// needed if the a parent to that path is captured. -fn test_precise_analysis_parent_captured_1() { - let t = ConstainsDropField(Foo(10), Foo(20)); - - let c = || { - let _t = t; - }; - - c(); -} - -// If a path isn't directly captured but requires Drop, then this tests that migrations aren't -// needed if the a parent to that path is captured. -fn test_precise_analysis_parent_captured_2() { - let t = ContainsAndImplsDrop(Foo(10)); - - let c = || { - let _t = t; - }; - - c(); -} - -struct S; -impl Drop for S { - fn drop(&mut self) {} -} - -struct T(S, S); -struct U(T, T); - -// Test that if the path is longer than just one element, precise analysis works correctly. -fn test_precise_analysis_long_path() { - let u = U(T(S, S), T(S, S)); - - let c = || { - let _x = u.0.0; - let _x = u.0.1; - let _x = u.1.0; - let _x = u.1.1; - }; - - c(); -} - -fn main() { - test_precise_analysis_simple_1(); - test_precise_analysis_simple_2(); - - test_precise_analysis_parent_captured_1(); - test_precise_analysis_parent_captured_2(); - - test_precise_analysis_long_path(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/significant_drop.fixed b/src/test/ui/closures/2229_closure_analysis/migrations/significant_drop.fixed deleted file mode 100644 index 58ed2de26b3a7..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/significant_drop.fixed +++ /dev/null @@ -1,143 +0,0 @@ -// run-rustfix -#![deny(rust_2021_incompatible_closure_captures)] -//~^ NOTE: the lint level is defined here - -// Test cases for types that implement a significant drop (user defined) - -#[derive(Debug)] -struct Foo(i32); -impl Drop for Foo { - fn drop(&mut self) { - println!("{:?} dropped", self.0); - } -} - -#[derive(Debug)] -struct ConstainsDropField(Foo, Foo); - -// `t` needs Drop because one of its elements needs drop, -// therefore precise capture might affect drop ordering -fn test1_all_need_migration() { - let t = (Foo(0), Foo(0)); - let t1 = (Foo(0), Foo(0)); - let t2 = (Foo(0), Foo(0)); - - let c = || { let _ = (&t, &t1, &t2); - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t`, `t1`, `t2` to be fully captured - let _t = t.0; - let _t1 = t1.0; - let _t2 = t2.0; - }; - - c(); -} - -// String implements drop and therefore should be migrated. -// But in this test cases, `t2` is completely captured and when it is dropped won't be affected -fn test2_only_precise_paths_need_migration() { - let t = (Foo(0), Foo(0)); - let t1 = (Foo(0), Foo(0)); - let t2 = (Foo(0), Foo(0)); - - let c = || { let _ = (&t, &t1); - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t`, `t1` to be fully captured - let _t = t.0; - let _t1 = t1.0; - let _t2 = t2; - }; - - c(); -} - -// If a variable would've not been captured by value then it would've not been -// dropped with the closure and therefore doesn't need migration. -fn test3_only_by_value_need_migration() { - let t = (Foo(0), Foo(0)); - let t1 = (Foo(0), Foo(0)); - let c = || { let _ = &t; - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - println!("{:?}", t1.1); - }; - - c(); -} - -// The root variable might not implement drop themselves but some path starting -// at the root variable might implement Drop. -// -// If this path isn't captured we need to migrate for the root variable. -fn test4_type_contains_drop_need_migration() { - let t = ConstainsDropField(Foo(0), Foo(0)); - - let c = || { let _ = &t; - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - }; - - c(); -} - -// Test migration analysis in case of Drop + Non Drop aggregates. -// Note we need migration here only because the non-copy (because Drop type) is captured, -// otherwise we won't need to, since we can get away with just by ref capture in that case. -fn test5_drop_non_drop_aggregate_need_migration() { - let t = (Foo(0), Foo(0), 0i32); - - let c = || { let _ = &t; - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - }; - - c(); -} - -// Test migration analysis in case of Significant and Insignificant Drop aggregates. -fn test6_significant_insignificant_drop_aggregate_need_migration() { - let t = (Foo(0), String::new()); - - let c = || { let _ = &t; - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.1; - }; - - c(); -} - -// Since we are using a move closure here, both `t` and `t1` get moved -// even though they are being used by ref inside the closure. -fn test7_move_closures_non_copy_types_might_need_migration() { - let t = (Foo(0), Foo(0)); - let t1 = (Foo(0), Foo(0), Foo(0)); - - let c = move || { let _ = (&t1, &t); - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t1`, `t` to be fully captured - println!("{:?} {:?}", t1.1, t.1); - }; - - c(); -} - -fn main() { - test1_all_need_migration(); - test2_only_precise_paths_need_migration(); - test3_only_by_value_need_migration(); - test4_type_contains_drop_need_migration(); - test5_drop_non_drop_aggregate_need_migration(); - test6_significant_insignificant_drop_aggregate_need_migration(); - test7_move_closures_non_copy_types_might_need_migration(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/significant_drop.rs b/src/test/ui/closures/2229_closure_analysis/migrations/significant_drop.rs deleted file mode 100644 index 0890fc1c21256..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/significant_drop.rs +++ /dev/null @@ -1,143 +0,0 @@ -// run-rustfix -#![deny(rust_2021_incompatible_closure_captures)] -//~^ NOTE: the lint level is defined here - -// Test cases for types that implement a significant drop (user defined) - -#[derive(Debug)] -struct Foo(i32); -impl Drop for Foo { - fn drop(&mut self) { - println!("{:?} dropped", self.0); - } -} - -#[derive(Debug)] -struct ConstainsDropField(Foo, Foo); - -// `t` needs Drop because one of its elements needs drop, -// therefore precise capture might affect drop ordering -fn test1_all_need_migration() { - let t = (Foo(0), Foo(0)); - let t1 = (Foo(0), Foo(0)); - let t2 = (Foo(0), Foo(0)); - - let c = || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t`, `t1`, `t2` to be fully captured - let _t = t.0; - let _t1 = t1.0; - let _t2 = t2.0; - }; - - c(); -} - -// String implements drop and therefore should be migrated. -// But in this test cases, `t2` is completely captured and when it is dropped won't be affected -fn test2_only_precise_paths_need_migration() { - let t = (Foo(0), Foo(0)); - let t1 = (Foo(0), Foo(0)); - let t2 = (Foo(0), Foo(0)); - - let c = || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t`, `t1` to be fully captured - let _t = t.0; - let _t1 = t1.0; - let _t2 = t2; - }; - - c(); -} - -// If a variable would've not been captured by value then it would've not been -// dropped with the closure and therefore doesn't need migration. -fn test3_only_by_value_need_migration() { - let t = (Foo(0), Foo(0)); - let t1 = (Foo(0), Foo(0)); - let c = || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - println!("{:?}", t1.1); - }; - - c(); -} - -// The root variable might not implement drop themselves but some path starting -// at the root variable might implement Drop. -// -// If this path isn't captured we need to migrate for the root variable. -fn test4_type_contains_drop_need_migration() { - let t = ConstainsDropField(Foo(0), Foo(0)); - - let c = || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - }; - - c(); -} - -// Test migration analysis in case of Drop + Non Drop aggregates. -// Note we need migration here only because the non-copy (because Drop type) is captured, -// otherwise we won't need to, since we can get away with just by ref capture in that case. -fn test5_drop_non_drop_aggregate_need_migration() { - let t = (Foo(0), Foo(0), 0i32); - - let c = || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.0; - }; - - c(); -} - -// Test migration analysis in case of Significant and Insignificant Drop aggregates. -fn test6_significant_insignificant_drop_aggregate_need_migration() { - let t = (Foo(0), String::new()); - - let c = || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t` to be fully captured - let _t = t.1; - }; - - c(); -} - -// Since we are using a move closure here, both `t` and `t1` get moved -// even though they are being used by ref inside the closure. -fn test7_move_closures_non_copy_types_might_need_migration() { - let t = (Foo(0), Foo(0)); - let t1 = (Foo(0), Foo(0), Foo(0)); - - let c = move || { - //~^ ERROR: drop order - //~| NOTE: for more information, see - //~| HELP: add a dummy let to cause `t1`, `t` to be fully captured - println!("{:?} {:?}", t1.1, t.1); - }; - - c(); -} - -fn main() { - test1_all_need_migration(); - test2_only_precise_paths_need_migration(); - test3_only_by_value_need_migration(); - test4_type_contains_drop_need_migration(); - test5_drop_non_drop_aggregate_need_migration(); - test6_significant_insignificant_drop_aggregate_need_migration(); - test7_move_closures_non_copy_types_might_need_migration(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/significant_drop.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/significant_drop.stderr deleted file mode 100644 index ebf9f169fd400..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/migrations/significant_drop.stderr +++ /dev/null @@ -1,171 +0,0 @@ -error: drop order will change in Rust 2021 - --> $DIR/significant_drop.rs:25:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | -... | -LL | | let _t2 = t2.0; -LL | | }; - | |_____^ - | -note: the lint level is defined here - --> $DIR/significant_drop.rs:2:9 - | -LL | #![deny(rust_2021_incompatible_closure_captures)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: for more information, see -help: add a dummy let to cause `t`, `t1`, `t2` to be fully captured - | -LL | let c = || { let _ = (&t, &t1, &t2); -LL | -LL | -LL | -LL | let _t = t.0; -LL | let _t1 = t1.0; - ... - -error: drop order will change in Rust 2021 - --> $DIR/significant_drop.rs:44:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | -... | -LL | | let _t2 = t2; -LL | | }; - | |_____^ - | - = note: for more information, see -help: add a dummy let to cause `t`, `t1` to be fully captured - | -LL | let c = || { let _ = (&t, &t1); -LL | -LL | -LL | -LL | let _t = t.0; -LL | let _t1 = t1.0; - ... - -error: drop order will change in Rust 2021 - --> $DIR/significant_drop.rs:61:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | -LL | | let _t = t.0; -LL | | println!("{:?}", t1.1); -LL | | }; - | |_____^ - | - = note: for more information, see -help: add a dummy let to cause `t` to be fully captured - | -LL | let c = || { let _ = &t; -LL | -LL | -LL | -LL | let _t = t.0; -LL | println!("{:?}", t1.1); - ... - -error: drop order will change in Rust 2021 - --> $DIR/significant_drop.rs:79:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | -LL | | let _t = t.0; -LL | | }; - | |_____^ - | - = note: for more information, see -help: add a dummy let to cause `t` to be fully captured - | -LL | let c = || { let _ = &t; -LL | -LL | -LL | -LL | let _t = t.0; -LL | }; - | - -error: drop order will change in Rust 2021 - --> $DIR/significant_drop.rs:95:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | -LL | | let _t = t.0; -LL | | }; - | |_____^ - | - = note: for more information, see -help: add a dummy let to cause `t` to be fully captured - | -LL | let c = || { let _ = &t; -LL | -LL | -LL | -LL | let _t = t.0; -LL | }; - | - -error: drop order will change in Rust 2021 - --> $DIR/significant_drop.rs:109:13 - | -LL | let c = || { - | _____________^ -LL | | -LL | | -LL | | -LL | | let _t = t.1; -LL | | }; - | |_____^ - | - = note: for more information, see -help: add a dummy let to cause `t` to be fully captured - | -LL | let c = || { let _ = &t; -LL | -LL | -LL | -LL | let _t = t.1; -LL | }; - | - -error: drop order will change in Rust 2021 - --> $DIR/significant_drop.rs:125:13 - | -LL | let c = move || { - | _____________^ -LL | | -LL | | -LL | | -LL | | println!("{:?} {:?}", t1.1, t.1); -LL | | }; - | |_____^ - | - = note: for more information, see -help: add a dummy let to cause `t1`, `t` to be fully captured - | -LL | let c = move || { let _ = (&t1, &t); -LL | -LL | -LL | -LL | println!("{:?} {:?}", t1.1, t.1); -LL | }; - | - -error: aborting due to 7 previous errors - diff --git a/src/test/ui/closures/2229_closure_analysis/move_closure.rs b/src/test/ui/closures/2229_closure_analysis/move_closure.rs deleted file mode 100644 index 06db19974eb04..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/move_closure.rs +++ /dev/null @@ -1,171 +0,0 @@ -// edition:2021 - -// Test that move closures drop derefs with `capture_disjoint_fields` enabled. - -#![feature(rustc_attrs)] - -fn simple_move_closure() { - struct S(String); - struct T(S); - - let t = T(S("s".into())); - let mut c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - move || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - t.0.0 = "new S".into(); - //~^ NOTE: Capturing t[(0, 0),(0, 0)] -> ByValue - //~| NOTE: Min Capture t[(0, 0),(0, 0)] -> ByValue - }; - c(); -} - -// Test move closure use reborrows when using references -fn simple_ref() { - let mut s = 10; - let ref_s = &mut s; - - let mut c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - move || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - *ref_s += 10; - //~^ NOTE: Capturing ref_s[Deref] -> UniqueImmBorrow - //~| NOTE: Min Capture ref_s[Deref] -> UniqueImmBorrow - }; - c(); -} - -// Test move closure use reborrows when using references -fn struct_contains_ref_to_another_struct_1() { - struct S(String); - struct T<'a>(&'a mut S); - - let mut s = S("s".into()); - let t = T(&mut s); - - let mut c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - move || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - t.0.0 = "new s".into(); - //~^ NOTE: Capturing t[(0, 0),Deref,(0, 0)] -> UniqueImmBorrow - //~| NOTE: Min Capture t[(0, 0),Deref,(0, 0)] -> UniqueImmBorrow - }; - - c(); -} - -// Test that we can use reborrows to read data of Copy types -// i.e. without truncating derefs -fn struct_contains_ref_to_another_struct_2() { - struct S(i32); - struct T<'a>(&'a S); - - let s = S(0); - let t = T(&s); - - let mut c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - move || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - let _t = t.0.0; - //~^ NOTE: Capturing t[(0, 0),Deref,(0, 0)] -> ImmBorrow - //~| NOTE: Min Capture t[(0, 0),Deref,(0, 0)] -> ImmBorrow - }; - - c(); -} - -// Test that we can use truncate to move out of !Copy types -fn struct_contains_ref_to_another_struct_3() { - struct S(String); - struct T<'a>(&'a S); - - let s = S("s".into()); - let t = T(&s); - - let mut c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - move || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - let _t = t.0.0; - //~^ NOTE: Capturing t[(0, 0),Deref,(0, 0)] -> ImmBorrow - //~| NOTE: Capturing t[(0, 0)] -> ByValue - //~| NOTE: Min Capture t[(0, 0)] -> ByValue - }; - - c(); -} - -// Test that derefs of box are truncated in move closures -fn truncate_box_derefs() { - struct S(i32); - - - // Content within the box is moved within the closure - let b = Box::new(S(10)); - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - move || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - let _t = b.0; - //~^ NOTE: Capturing b[Deref,(0, 0)] -> ByValue - //~| NOTE: Capturing b[] -> ByValue - //~| NOTE: Min Capture b[] -> ByValue - }; - - c(); - - // Content within the box is used by a shared ref and the box is the root variable - let b = Box::new(S(10)); - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - move || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - println!("{}", b.0); - //~^ NOTE: Capturing b[Deref,(0, 0)] -> ByValue - //~| NOTE: Min Capture b[] -> ByValue - }; - - c(); - - // Content within the box is used by a shared ref and the box is not the root variable - let b = Box::new(S(10)); - let t = (0, b); - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - move || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - println!("{}", t.1.0); - //~^ NOTE: Capturing t[(1, 0),Deref,(0, 0)] -> ByValue - //~| NOTE: Min Capture t[(1, 0)] -> ByValue - }; -} - -fn main() { - simple_move_closure(); - simple_ref(); - struct_contains_ref_to_another_struct_1(); - struct_contains_ref_to_another_struct_2(); - struct_contains_ref_to_another_struct_3(); - truncate_box_derefs(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/move_closure.stderr b/src/test/ui/closures/2229_closure_analysis/move_closure.stderr deleted file mode 100644 index 013cacfb9f2a5..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/move_closure.stderr +++ /dev/null @@ -1,373 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/move_closure.rs:12:17 - | -LL | let mut c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/move_closure.rs:30:17 - | -LL | let mut c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/move_closure.rs:51:17 - | -LL | let mut c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/move_closure.rs:74:17 - | -LL | let mut c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/move_closure.rs:96:17 - | -LL | let mut c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/move_closure.rs:118:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/move_closure.rs:135:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/move_closure.rs:152:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/move_closure.rs:15:5 - | -LL | / move || { -LL | | -LL | | -LL | | t.0.0 = "new S".into(); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Capturing t[(0, 0),(0, 0)] -> ByValue - --> $DIR/move_closure.rs:18:9 - | -LL | t.0.0 = "new S".into(); - | ^^^^^ - -error: Min Capture analysis includes: - --> $DIR/move_closure.rs:15:5 - | -LL | / move || { -LL | | -LL | | -LL | | t.0.0 = "new S".into(); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture t[(0, 0),(0, 0)] -> ByValue - --> $DIR/move_closure.rs:18:9 - | -LL | t.0.0 = "new S".into(); - | ^^^^^ - -error: First Pass analysis includes: - --> $DIR/move_closure.rs:33:5 - | -LL | / move || { -LL | | -LL | | -LL | | *ref_s += 10; -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Capturing ref_s[Deref] -> UniqueImmBorrow - --> $DIR/move_closure.rs:36:9 - | -LL | *ref_s += 10; - | ^^^^^^ - -error: Min Capture analysis includes: - --> $DIR/move_closure.rs:33:5 - | -LL | / move || { -LL | | -LL | | -LL | | *ref_s += 10; -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture ref_s[Deref] -> UniqueImmBorrow - --> $DIR/move_closure.rs:36:9 - | -LL | *ref_s += 10; - | ^^^^^^ - -error: First Pass analysis includes: - --> $DIR/move_closure.rs:54:5 - | -LL | / move || { -LL | | -LL | | -LL | | t.0.0 = "new s".into(); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Capturing t[(0, 0),Deref,(0, 0)] -> UniqueImmBorrow - --> $DIR/move_closure.rs:57:9 - | -LL | t.0.0 = "new s".into(); - | ^^^^^ - -error: Min Capture analysis includes: - --> $DIR/move_closure.rs:54:5 - | -LL | / move || { -LL | | -LL | | -LL | | t.0.0 = "new s".into(); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture t[(0, 0),Deref,(0, 0)] -> UniqueImmBorrow - --> $DIR/move_closure.rs:57:9 - | -LL | t.0.0 = "new s".into(); - | ^^^^^ - -error: First Pass analysis includes: - --> $DIR/move_closure.rs:77:5 - | -LL | / move || { -LL | | -LL | | -LL | | let _t = t.0.0; -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Capturing t[(0, 0),Deref,(0, 0)] -> ImmBorrow - --> $DIR/move_closure.rs:80:18 - | -LL | let _t = t.0.0; - | ^^^^^ - -error: Min Capture analysis includes: - --> $DIR/move_closure.rs:77:5 - | -LL | / move || { -LL | | -LL | | -LL | | let _t = t.0.0; -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture t[(0, 0),Deref,(0, 0)] -> ImmBorrow - --> $DIR/move_closure.rs:80:18 - | -LL | let _t = t.0.0; - | ^^^^^ - -error: First Pass analysis includes: - --> $DIR/move_closure.rs:99:5 - | -LL | / move || { -LL | | -LL | | -LL | | let _t = t.0.0; -... | -LL | | -LL | | }; - | |_____^ - | -note: Capturing t[(0, 0),Deref,(0, 0)] -> ImmBorrow - --> $DIR/move_closure.rs:102:18 - | -LL | let _t = t.0.0; - | ^^^^^ -note: Capturing t[(0, 0)] -> ByValue - --> $DIR/move_closure.rs:102:18 - | -LL | let _t = t.0.0; - | ^^^^^ - -error: Min Capture analysis includes: - --> $DIR/move_closure.rs:99:5 - | -LL | / move || { -LL | | -LL | | -LL | | let _t = t.0.0; -... | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture t[(0, 0)] -> ByValue - --> $DIR/move_closure.rs:102:18 - | -LL | let _t = t.0.0; - | ^^^^^ - -error: First Pass analysis includes: - --> $DIR/move_closure.rs:121:5 - | -LL | / move || { -LL | | -LL | | -LL | | let _t = b.0; -... | -LL | | -LL | | }; - | |_____^ - | -note: Capturing b[Deref,(0, 0)] -> ByValue - --> $DIR/move_closure.rs:124:18 - | -LL | let _t = b.0; - | ^^^ -note: Capturing b[] -> ByValue - --> $DIR/move_closure.rs:124:18 - | -LL | let _t = b.0; - | ^^^ - -error: Min Capture analysis includes: - --> $DIR/move_closure.rs:121:5 - | -LL | / move || { -LL | | -LL | | -LL | | let _t = b.0; -... | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture b[] -> ByValue - --> $DIR/move_closure.rs:124:18 - | -LL | let _t = b.0; - | ^^^ - -error: First Pass analysis includes: - --> $DIR/move_closure.rs:138:5 - | -LL | / move || { -LL | | -LL | | -LL | | println!("{}", b.0); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Capturing b[Deref,(0, 0)] -> ByValue - --> $DIR/move_closure.rs:141:24 - | -LL | println!("{}", b.0); - | ^^^ - -error: Min Capture analysis includes: - --> $DIR/move_closure.rs:138:5 - | -LL | / move || { -LL | | -LL | | -LL | | println!("{}", b.0); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture b[] -> ByValue - --> $DIR/move_closure.rs:141:24 - | -LL | println!("{}", b.0); - | ^^^ - -error: First Pass analysis includes: - --> $DIR/move_closure.rs:155:5 - | -LL | / move || { -LL | | -LL | | -LL | | println!("{}", t.1.0); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Capturing t[(1, 0),Deref,(0, 0)] -> ByValue - --> $DIR/move_closure.rs:158:24 - | -LL | println!("{}", t.1.0); - | ^^^^^ - -error: Min Capture analysis includes: - --> $DIR/move_closure.rs:155:5 - | -LL | / move || { -LL | | -LL | | -LL | | println!("{}", t.1.0); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture t[(1, 0)] -> ByValue - --> $DIR/move_closure.rs:158:24 - | -LL | println!("{}", t.1.0); - | ^^^^^ - -error: aborting due to 24 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/multilevel-path-1.rs b/src/test/ui/closures/2229_closure_analysis/multilevel-path-1.rs deleted file mode 100644 index a8a2acfa78d2c..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/multilevel-path-1.rs +++ /dev/null @@ -1,39 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] -#![allow(unused)] - -struct Point { - x: i32, - y: i32, -} -struct Wrapper { - p: Point, -} - -fn main() { - let mut w = Wrapper { p: Point { x: 10, y: 10 } }; - - // Only paths that appears within the closure that directly start off - // a variable defined outside the closure are captured. - // - // Therefore `w.p` is captured - // Note that `wp.x` doesn't start off a variable defined outside the closure. - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - let wp = &w.p; - //~^ NOTE: Capturing w[(0, 0)] -> ImmBorrow - //~| NOTE: Min Capture w[(0, 0)] -> ImmBorrow - println!("{}", wp.x); - }; - - // Since `c` captures `w.p` by an ImmBorrow, `w.p.y` can't be mutated. - let py = &mut w.p.y; - c(); - - *py = 20 -} diff --git a/src/test/ui/closures/2229_closure_analysis/multilevel-path-1.stderr b/src/test/ui/closures/2229_closure_analysis/multilevel-path-1.stderr deleted file mode 100644 index 29ad1c59198cf..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/multilevel-path-1.stderr +++ /dev/null @@ -1,48 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/multilevel-path-1.rs:22:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/multilevel-path-1.rs:25:5 - | -LL | / || { -LL | | -LL | | -LL | | let wp = &w.p; -... | -LL | | println!("{}", wp.x); -LL | | }; - | |_____^ - | -note: Capturing w[(0, 0)] -> ImmBorrow - --> $DIR/multilevel-path-1.rs:28:19 - | -LL | let wp = &w.p; - | ^^^ - -error: Min Capture analysis includes: - --> $DIR/multilevel-path-1.rs:25:5 - | -LL | / || { -LL | | -LL | | -LL | | let wp = &w.p; -... | -LL | | println!("{}", wp.x); -LL | | }; - | |_____^ - | -note: Min Capture w[(0, 0)] -> ImmBorrow - --> $DIR/multilevel-path-1.rs:28:19 - | -LL | let wp = &w.p; - | ^^^ - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/multilevel-path-2.rs b/src/test/ui/closures/2229_closure_analysis/multilevel-path-2.rs deleted file mode 100644 index e21fe318cd105..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/multilevel-path-2.rs +++ /dev/null @@ -1,33 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] -#![allow(unused)] - -struct Point { - x: i32, - y: i32, -} -struct Wrapper { - p: Point, -} - -fn main() { - let mut w = Wrapper { p: Point { x: 10, y: 10 } }; - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - println!("{}", w.p.x); - //~^ NOTE: Capturing w[(0, 0),(0, 0)] -> ImmBorrow - //~| NOTE: Min Capture w[(0, 0),(0, 0)] -> ImmBorrow - }; - - // `c` only captures `w.p.x`, therefore it's safe to mutate `w.p.y`. - let py = &mut w.p.y; - c(); - - *py = 20 -} diff --git a/src/test/ui/closures/2229_closure_analysis/multilevel-path-2.stderr b/src/test/ui/closures/2229_closure_analysis/multilevel-path-2.stderr deleted file mode 100644 index 929cba113146b..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/multilevel-path-2.stderr +++ /dev/null @@ -1,48 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/multilevel-path-2.rs:17:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/multilevel-path-2.rs:20:5 - | -LL | / || { -LL | | -LL | | -LL | | println!("{}", w.p.x); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Capturing w[(0, 0),(0, 0)] -> ImmBorrow - --> $DIR/multilevel-path-2.rs:23:24 - | -LL | println!("{}", w.p.x); - | ^^^^^ - -error: Min Capture analysis includes: - --> $DIR/multilevel-path-2.rs:20:5 - | -LL | / || { -LL | | -LL | | -LL | | println!("{}", w.p.x); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture w[(0, 0),(0, 0)] -> ImmBorrow - --> $DIR/multilevel-path-2.rs:23:24 - | -LL | println!("{}", w.p.x); - | ^^^^^ - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/nested-closure.rs b/src/test/ui/closures/2229_closure_analysis/nested-closure.rs deleted file mode 100644 index f6775b3a3a5ac..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/nested-closure.rs +++ /dev/null @@ -1,52 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] - -struct Point { - x: i32, - y: i32, -} - -// This testcase ensures that nested closures are handles properly -// - The nested closure is analyzed first. -// - The capture kind of the nested closure is accounted for by the enclosing closure -// - Any captured path by the nested closure that starts off a local variable in the enclosing -// closure is not listed as a capture of the enclosing closure. - -fn main() { - let mut p = Point { x: 5, y: 20 }; - - let mut c1 = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - println!("{}", p.x); - //~^ NOTE: Capturing p[(0, 0)] -> ImmBorrow - //~| NOTE: Min Capture p[(0, 0)] -> ImmBorrow - let incr = 10; - let mut c2 = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || p.y += incr; - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - //~| NOTE: Capturing p[(1, 0)] -> MutBorrow - //~| NOTE: Capturing incr[] -> ImmBorrow - //~| NOTE: Min Capture p[(1, 0)] -> MutBorrow - //~| NOTE: Min Capture incr[] -> ImmBorrow - //~| NOTE: Capturing p[(1, 0)] -> MutBorrow - //~| NOTE: Min Capture p[(1, 0)] -> MutBorrow - c2(); - println!("{}", p.y); - }; - - c1(); - - let px = &p.x; - - println!("{}", px); - - c1(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/nested-closure.stderr b/src/test/ui/closures/2229_closure_analysis/nested-closure.stderr deleted file mode 100644 index 013bc74e67e1e..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/nested-closure.stderr +++ /dev/null @@ -1,101 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/nested-closure.rs:19:18 - | -LL | let mut c1 = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/nested-closure.rs:29:22 - | -LL | let mut c2 = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/nested-closure.rs:32:9 - | -LL | || p.y += incr; - | ^^^^^^^^^^^^^^ - | -note: Capturing p[(1, 0)] -> MutBorrow - --> $DIR/nested-closure.rs:32:12 - | -LL | || p.y += incr; - | ^^^ -note: Capturing incr[] -> ImmBorrow - --> $DIR/nested-closure.rs:32:19 - | -LL | || p.y += incr; - | ^^^^ - -error: Min Capture analysis includes: - --> $DIR/nested-closure.rs:32:9 - | -LL | || p.y += incr; - | ^^^^^^^^^^^^^^ - | -note: Min Capture p[(1, 0)] -> MutBorrow - --> $DIR/nested-closure.rs:32:12 - | -LL | || p.y += incr; - | ^^^ -note: Min Capture incr[] -> ImmBorrow - --> $DIR/nested-closure.rs:32:19 - | -LL | || p.y += incr; - | ^^^^ - -error: First Pass analysis includes: - --> $DIR/nested-closure.rs:22:5 - | -LL | / || { -LL | | -LL | | -LL | | println!("{}", p.x); -... | -LL | | println!("{}", p.y); -LL | | }; - | |_____^ - | -note: Capturing p[(0, 0)] -> ImmBorrow - --> $DIR/nested-closure.rs:25:24 - | -LL | println!("{}", p.x); - | ^^^ -note: Capturing p[(1, 0)] -> MutBorrow - --> $DIR/nested-closure.rs:32:12 - | -LL | || p.y += incr; - | ^^^ - -error: Min Capture analysis includes: - --> $DIR/nested-closure.rs:22:5 - | -LL | / || { -LL | | -LL | | -LL | | println!("{}", p.x); -... | -LL | | println!("{}", p.y); -LL | | }; - | |_____^ - | -note: Min Capture p[(0, 0)] -> ImmBorrow - --> $DIR/nested-closure.rs:25:24 - | -LL | println!("{}", p.x); - | ^^^ -note: Min Capture p[(1, 0)] -> MutBorrow - --> $DIR/nested-closure.rs:32:12 - | -LL | || p.y += incr; - | ^^^ - -error: aborting due to 6 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/path-with-array-access.rs b/src/test/ui/closures/2229_closure_analysis/path-with-array-access.rs deleted file mode 100644 index 0c10319314a6f..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/path-with-array-access.rs +++ /dev/null @@ -1,33 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] - -struct Point { - x: f32, - y: f32, -} - -struct Pentagon { - points: [Point; 5], -} - -fn main() { - let p1 = Point { x: 10.0, y: 10.0 }; - let p2 = Point { x: 7.5, y: 12.5 }; - let p3 = Point { x: 15.0, y: 15.0 }; - let p4 = Point { x: 12.5, y: 12.5 }; - let p5 = Point { x: 20.0, y: 10.0 }; - - let pent = Pentagon { points: [p1, p2, p3, p4, p5] }; - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - println!("{}", pent.points[5].x); - //~^ NOTE: Capturing pent[(0, 0)] -> ImmBorrow - //~| NOTE: Min Capture pent[(0, 0)] -> ImmBorrow - }; -} diff --git a/src/test/ui/closures/2229_closure_analysis/path-with-array-access.stderr b/src/test/ui/closures/2229_closure_analysis/path-with-array-access.stderr deleted file mode 100644 index 124b7bf6fe270..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/path-with-array-access.stderr +++ /dev/null @@ -1,48 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/path-with-array-access.rs:23:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/path-with-array-access.rs:26:5 - | -LL | / || { -LL | | -LL | | -LL | | println!("{}", pent.points[5].x); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Capturing pent[(0, 0)] -> ImmBorrow - --> $DIR/path-with-array-access.rs:29:24 - | -LL | println!("{}", pent.points[5].x); - | ^^^^^^^^^^^ - -error: Min Capture analysis includes: - --> $DIR/path-with-array-access.rs:26:5 - | -LL | / || { -LL | | -LL | | -LL | | println!("{}", pent.points[5].x); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture pent[(0, 0)] -> ImmBorrow - --> $DIR/path-with-array-access.rs:29:24 - | -LL | println!("{}", pent.points[5].x); - | ^^^^^^^^^^^ - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/pattern-matching-should-fail.rs b/src/test/ui/closures/2229_closure_analysis/pattern-matching-should-fail.rs deleted file mode 100644 index 0f288ffa95a87..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/pattern-matching-should-fail.rs +++ /dev/null @@ -1,82 +0,0 @@ -// edition:2021 - -#![feature(never_type)] - -// Should fake read the discriminant and throw an error -fn test1() { - let x: !; - let c1 = || match x { }; - //~^ ERROR: use of possibly-uninitialized variable: `x` -} - -// Should fake read the discriminant and throw an error -fn test2() { - let x: !; - let c2 = || match x { _ => () }; - //~^ ERROR: borrow of possibly-uninitialized variable: `x` -} - -// Testing single variant patterns -enum SingleVariant { - Points(u32) -} - -// Should fake read the discriminant and throw an error -fn test3() { - let variant: !; - let c = || { - //~^ ERROR: borrow of possibly-uninitialized variable: `variant` - match variant { - SingleVariant::Points(_) => {} - } - }; - c(); -} - -// Should fake read the discriminant and throw an error -fn test4() { - let variant: !; - let c = || { - //~^ ERROR: borrow of possibly-uninitialized variable: `variant` - match variant { - SingleVariant::Points(a) => { - println!("{:?}", a); - } - } - }; - c(); -} - -fn test5() { - let t: !; - let g: !; - - let a = || { - match g { }; - //~^ ERROR: use of possibly-uninitialized variable: `g` - let c = || { - match t { }; - //~^ ERROR: use of possibly-uninitialized variable: `t` - }; - - c(); - }; - -} - -// Should fake read the discriminant and throw an error -fn test6() { - let x: u8; - let c1 = || match x { }; - //~^ ERROR: use of possibly-uninitialized variable: `x` - //~| ERROR: non-exhaustive patterns: type `u8` is non-empty -} - -fn main() { - test1(); - test2(); - test3(); - test4(); - test5(); - test6(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/pattern-matching-should-fail.stderr b/src/test/ui/closures/2229_closure_analysis/pattern-matching-should-fail.stderr deleted file mode 100644 index 45641ea3de3e0..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/pattern-matching-should-fail.stderr +++ /dev/null @@ -1,63 +0,0 @@ -error[E0004]: non-exhaustive patterns: type `u8` is non-empty - --> $DIR/pattern-matching-should-fail.rs:70:23 - | -LL | let c1 = || match x { }; - | ^ - | - = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms - = note: the matched value is of type `u8` - -error[E0381]: use of possibly-uninitialized variable: `x` - --> $DIR/pattern-matching-should-fail.rs:8:23 - | -LL | let c1 = || match x { }; - | ^ use of possibly-uninitialized `x` - -error[E0381]: borrow of possibly-uninitialized variable: `x` - --> $DIR/pattern-matching-should-fail.rs:15:14 - | -LL | let c2 = || match x { _ => () }; - | ^^ - borrow occurs due to use in closure - | | - | use of possibly-uninitialized `x` - -error[E0381]: borrow of possibly-uninitialized variable: `variant` - --> $DIR/pattern-matching-should-fail.rs:27:13 - | -LL | let c = || { - | ^^ use of possibly-uninitialized `variant` -LL | -LL | match variant { - | ------- borrow occurs due to use in closure - -error[E0381]: borrow of possibly-uninitialized variable: `variant` - --> $DIR/pattern-matching-should-fail.rs:39:13 - | -LL | let c = || { - | ^^ use of possibly-uninitialized `variant` -LL | -LL | match variant { - | ------- borrow occurs due to use in closure - -error[E0381]: use of possibly-uninitialized variable: `g` - --> $DIR/pattern-matching-should-fail.rs:55:15 - | -LL | match g { }; - | ^ use of possibly-uninitialized `g` - -error[E0381]: use of possibly-uninitialized variable: `t` - --> $DIR/pattern-matching-should-fail.rs:58:19 - | -LL | match t { }; - | ^ use of possibly-uninitialized `t` - -error[E0381]: use of possibly-uninitialized variable: `x` - --> $DIR/pattern-matching-should-fail.rs:70:23 - | -LL | let c1 = || match x { }; - | ^ use of possibly-uninitialized `x` - -error: aborting due to 8 previous errors - -Some errors have detailed explanations: E0004, E0381. -For more information about an error, try `rustc --explain E0004`. diff --git a/src/test/ui/closures/2229_closure_analysis/patterns-capture-analysis.rs b/src/test/ui/closures/2229_closure_analysis/patterns-capture-analysis.rs deleted file mode 100644 index 56f5ac44db068..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/patterns-capture-analysis.rs +++ /dev/null @@ -1,137 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] - -// Should capture the discriminant since a variant of a multivariant enum is -// mentioned in the match arm; the discriminant is captured by the closure regardless -// of if it creates a binding -fn test_1_should_capture() { - let variant = Some(2229); - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - - || { - //~^ First Pass analysis includes: - //~| Min Capture analysis includes: - match variant { - //~^ NOTE: Capturing variant[] -> ImmBorrow - //~| NOTE: Min Capture variant[] -> ImmBorrow - Some(_) => {} - _ => {} - } - }; - c(); -} - -// Should not capture the discriminant since only a wildcard is mentioned in the -// match arm -fn test_2_should_not_capture() { - let variant = Some(2229); - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ First Pass analysis includes: - match variant { - _ => {} - } - }; - c(); -} - -// Testing single variant patterns -enum SingleVariant { - Points(u32) -} - -// Should not capture the discriminant since the single variant mentioned -// in the match arm does not trigger a binding -fn test_3_should_not_capture_single_variant() { - let variant = SingleVariant::Points(1); - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ First Pass analysis includes: - match variant { - SingleVariant::Points(_) => {} - } - }; - c(); -} - -// Should not capture the discriminant since the single variant mentioned -// in the match arm does not trigger a binding -fn test_6_should_capture_single_variant() { - let variant = SingleVariant::Points(1); - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ First Pass analysis includes: - //~| Min Capture analysis includes: - match variant { - //~^ NOTE: Capturing variant[] -> ImmBorrow - //~| NOTE: Capturing variant[(0, 0)] -> ImmBorrow - //~| NOTE: Min Capture variant[] -> ImmBorrow - SingleVariant::Points(a) => { - println!("{:?}", a); - } - } - }; - c(); -} - -// Should not capture the discriminant since only wildcards are mentioned in the -// match arm -fn test_4_should_not_capture_array() { - let array: [i32; 3] = [0; 3]; - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ First Pass analysis includes: - match array { - [_,_,_] => {} - } - }; - c(); -} - -// Testing MultiVariant patterns -enum MVariant { - A, - B, - C, -} - -// Should capture the discriminant since a variant of the multi variant enum is -// mentioned in the match arm; the discriminant is captured by the closure -// regardless of if it creates a binding -fn test_5_should_capture_multi_variant() { - let variant = MVariant::A; - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ First Pass analysis includes: - //~| Min Capture analysis includes: - match variant { - //~^ NOTE: Capturing variant[] -> ImmBorrow - //~| NOTE: Min Capture variant[] -> ImmBorrow - MVariant::A => {} - _ => {} - } - }; - c(); -} - -fn main() { - test_1_should_capture(); - test_2_should_not_capture(); - test_3_should_not_capture_single_variant(); - test_6_should_capture_single_variant(); - test_4_should_not_capture_array(); - test_5_should_capture_multi_variant(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/patterns-capture-analysis.stderr b/src/test/ui/closures/2229_closure_analysis/patterns-capture-analysis.stderr deleted file mode 100644 index 460813333952b..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/patterns-capture-analysis.stderr +++ /dev/null @@ -1,203 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/patterns-capture-analysis.rs:10:14 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/patterns-capture-analysis.rs:31:14 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/patterns-capture-analysis.rs:52:14 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/patterns-capture-analysis.rs:68:14 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/patterns-capture-analysis.rs:90:14 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/patterns-capture-analysis.rs:114:14 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/patterns-capture-analysis.rs:14:5 - | -LL | / || { -LL | | -LL | | -LL | | match variant { -... | -LL | | } -LL | | }; - | |_____^ - | -note: Capturing variant[] -> ImmBorrow - --> $DIR/patterns-capture-analysis.rs:17:15 - | -LL | match variant { - | ^^^^^^^ - -error: Min Capture analysis includes: - --> $DIR/patterns-capture-analysis.rs:14:5 - | -LL | / || { -LL | | -LL | | -LL | | match variant { -... | -LL | | } -LL | | }; - | |_____^ - | -note: Min Capture variant[] -> ImmBorrow - --> $DIR/patterns-capture-analysis.rs:17:15 - | -LL | match variant { - | ^^^^^^^ - -error: First Pass analysis includes: - --> $DIR/patterns-capture-analysis.rs:34:5 - | -LL | / || { -LL | | -LL | | match variant { -LL | | _ => {} -LL | | } -LL | | }; - | |_____^ - -error: First Pass analysis includes: - --> $DIR/patterns-capture-analysis.rs:55:5 - | -LL | / || { -LL | | -LL | | match variant { -LL | | SingleVariant::Points(_) => {} -LL | | } -LL | | }; - | |_____^ - -error: First Pass analysis includes: - --> $DIR/patterns-capture-analysis.rs:71:5 - | -LL | / || { -LL | | -LL | | -LL | | match variant { -... | -LL | | } -LL | | }; - | |_____^ - | -note: Capturing variant[] -> ImmBorrow - --> $DIR/patterns-capture-analysis.rs:74:15 - | -LL | match variant { - | ^^^^^^^ -note: Capturing variant[(0, 0)] -> ImmBorrow - --> $DIR/patterns-capture-analysis.rs:74:15 - | -LL | match variant { - | ^^^^^^^ - -error: Min Capture analysis includes: - --> $DIR/patterns-capture-analysis.rs:71:5 - | -LL | / || { -LL | | -LL | | -LL | | match variant { -... | -LL | | } -LL | | }; - | |_____^ - | -note: Min Capture variant[] -> ImmBorrow - --> $DIR/patterns-capture-analysis.rs:74:15 - | -LL | match variant { - | ^^^^^^^ - -error: First Pass analysis includes: - --> $DIR/patterns-capture-analysis.rs:93:5 - | -LL | / || { -LL | | -LL | | match array { -LL | | [_,_,_] => {} -LL | | } -LL | | }; - | |_____^ - -error: First Pass analysis includes: - --> $DIR/patterns-capture-analysis.rs:117:5 - | -LL | / || { -LL | | -LL | | -LL | | match variant { -... | -LL | | } -LL | | }; - | |_____^ - | -note: Capturing variant[] -> ImmBorrow - --> $DIR/patterns-capture-analysis.rs:120:15 - | -LL | match variant { - | ^^^^^^^ - -error: Min Capture analysis includes: - --> $DIR/patterns-capture-analysis.rs:117:5 - | -LL | / || { -LL | | -LL | | -LL | | match variant { -... | -LL | | } -LL | | }; - | |_____^ - | -note: Min Capture variant[] -> ImmBorrow - --> $DIR/patterns-capture-analysis.rs:120:15 - | -LL | match variant { - | ^^^^^^^ - -error: aborting due to 15 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/repr_packed.rs b/src/test/ui/closures/2229_closure_analysis/repr_packed.rs deleted file mode 100644 index 7d472ad020f29..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/repr_packed.rs +++ /dev/null @@ -1,100 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] - -// `u8` aligned at a byte and are unaffected by repr(packed). -// Therefore we can precisely (and safely) capture references to both the fields. -fn test_alignment_not_affected() { - #[repr(packed)] - struct Foo { x: u8, y: u8 } - - let mut foo = Foo { x: 0, y: 0 }; - - let mut c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - let z1: &u8 = &foo.x; - //~^ NOTE: Capturing foo[(0, 0)] -> ImmBorrow - //~| NOTE: Min Capture foo[(0, 0)] -> ImmBorrow - let z2: &mut u8 = &mut foo.y; - //~^ NOTE: Capturing foo[(1, 0)] -> MutBorrow - //~| NOTE: Min Capture foo[(1, 0)] -> MutBorrow - - *z2 = 42; - - println!("({}, {})", z1, z2); - }; - - c(); -} - -// `String`, `u16` are not aligned at a one byte boundry and are thus affected by repr(packed). -// -// Here we test that the closure doesn't capture a reference point to `foo.x` but -// rather capture `foo` entirely. -fn test_alignment_affected() { - #[repr(packed)] - struct Foo { x: String, y: u16 } - - let mut foo = Foo { x: String::new(), y: 0 }; - - let mut c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - let z1: &String = &foo.x; - let z2: &mut u16 = &mut foo.y; - //~^ NOTE: Capturing foo[] -> MutBorrow - //~| NOTE: Min Capture foo[] -> MutBorrow - - - *z2 = 42; - - println!("({}, {})", z1, z2); - }; - - c(); -} - -// Given how the closure desugaring is implemented (at least at the time of writing this test), -// we don't need to truncate the captured path to a reference into a packed-struct if the field -// being referenced will be moved into the closure, since it's safe to move out a field from a -// packed-struct. -// -// However to avoid surprises for the user, or issues when the closure is -// inlined we will truncate the capture to access just the struct regardless of if the field -// might get moved into the closure. -fn test_truncation_when_ref_and_move() { - #[repr(packed)] - struct Foo { x: String } - - let mut foo = Foo { x: String::new() }; - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - println!("{}", foo.x); - //~^ NOTE: Capturing foo[] -> ImmBorrow - //~| NOTE: Min Capture foo[] -> ByValue - //~| NOTE: foo[] used here - let _z = foo.x; - //~^ NOTE: Capturing foo[(0, 0)] -> ByValue - //~| NOTE: foo[] captured as ByValue here - }; - - c(); -} - -fn main() { - test_truncation_when_ref_and_move(); - test_alignment_affected(); - test_alignment_not_affected(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/repr_packed.stderr b/src/test/ui/closures/2229_closure_analysis/repr_packed.stderr deleted file mode 100644 index 405f66210aa55..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/repr_packed.stderr +++ /dev/null @@ -1,156 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/repr_packed.rs:13:17 - | -LL | let mut c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/repr_packed.rs:44:17 - | -LL | let mut c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/repr_packed.rs:78:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/repr_packed.rs:16:5 - | -LL | / || { -LL | | -LL | | -LL | | let z1: &u8 = &foo.x; -... | -LL | | println!("({}, {})", z1, z2); -LL | | }; - | |_____^ - | -note: Capturing foo[(0, 0)] -> ImmBorrow - --> $DIR/repr_packed.rs:19:24 - | -LL | let z1: &u8 = &foo.x; - | ^^^^^ -note: Capturing foo[(1, 0)] -> MutBorrow - --> $DIR/repr_packed.rs:22:32 - | -LL | let z2: &mut u8 = &mut foo.y; - | ^^^^^ - -error: Min Capture analysis includes: - --> $DIR/repr_packed.rs:16:5 - | -LL | / || { -LL | | -LL | | -LL | | let z1: &u8 = &foo.x; -... | -LL | | println!("({}, {})", z1, z2); -LL | | }; - | |_____^ - | -note: Min Capture foo[(0, 0)] -> ImmBorrow - --> $DIR/repr_packed.rs:19:24 - | -LL | let z1: &u8 = &foo.x; - | ^^^^^ -note: Min Capture foo[(1, 0)] -> MutBorrow - --> $DIR/repr_packed.rs:22:32 - | -LL | let z2: &mut u8 = &mut foo.y; - | ^^^^^ - -error: First Pass analysis includes: - --> $DIR/repr_packed.rs:47:5 - | -LL | / || { -LL | | -LL | | -LL | | let z1: &String = &foo.x; -... | -LL | | println!("({}, {})", z1, z2); -LL | | }; - | |_____^ - | -note: Capturing foo[] -> MutBorrow - --> $DIR/repr_packed.rs:51:33 - | -LL | let z2: &mut u16 = &mut foo.y; - | ^^^^^ - -error: Min Capture analysis includes: - --> $DIR/repr_packed.rs:47:5 - | -LL | / || { -LL | | -LL | | -LL | | let z1: &String = &foo.x; -... | -LL | | println!("({}, {})", z1, z2); -LL | | }; - | |_____^ - | -note: Min Capture foo[] -> MutBorrow - --> $DIR/repr_packed.rs:51:33 - | -LL | let z2: &mut u16 = &mut foo.y; - | ^^^^^ - -error: First Pass analysis includes: - --> $DIR/repr_packed.rs:81:5 - | -LL | / || { -LL | | -LL | | -LL | | println!("{}", foo.x); -... | -LL | | -LL | | }; - | |_____^ - | -note: Capturing foo[] -> ImmBorrow - --> $DIR/repr_packed.rs:84:24 - | -LL | println!("{}", foo.x); - | ^^^^^ -note: Capturing foo[(0, 0)] -> ByValue - --> $DIR/repr_packed.rs:88:18 - | -LL | let _z = foo.x; - | ^^^^^ - -error: Min Capture analysis includes: - --> $DIR/repr_packed.rs:81:5 - | -LL | / || { -LL | | -LL | | -LL | | println!("{}", foo.x); -... | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture foo[] -> ByValue - --> $DIR/repr_packed.rs:84:24 - | -LL | println!("{}", foo.x); - | ^^^^^ foo[] used here -... -LL | let _z = foo.x; - | ^^^^^ foo[] captured as ByValue here - -error: aborting due to 9 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/box.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/box.rs deleted file mode 100644 index 73aca288faa88..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/box.rs +++ /dev/null @@ -1,92 +0,0 @@ -// edition:2021 -// run-pass - -// Test precise capture when using boxes - -struct MetaData { x: String, name: String } -struct Data { m: MetaData } -struct BoxedData(Box); -struct EvenMoreBoxedData(Box); - -// Mutate disjoint paths, one inside one outside the closure -fn box_1() { - let m = MetaData { x: format!("x"), name: format!("name") }; - let d = Data { m }; - let b = BoxedData(Box::new(d)); - let mut e = EvenMoreBoxedData(Box::new(b)); - - let mut c = || { - e.0.0.m.x = format!("not-x"); - }; - - e.0.0.m.name = format!("not-name"); - c(); -} - -// Mutate a path inside the closure and read a disjoint path outside the closure -fn box_2() { - let m = MetaData { x: format!("x"), name: format!("name") }; - let d = Data { m }; - let b = BoxedData(Box::new(d)); - let mut e = EvenMoreBoxedData(Box::new(b)); - - let mut c = || { - e.0.0.m.x = format!("not-x"); - }; - - println!("{}", e.0.0.m.name); - c(); -} - -// Read a path inside the closure and mutate a disjoint path outside the closure -fn box_3() { - let m = MetaData { x: format!("x"), name: format!("name") }; - let d = Data { m }; - let b = BoxedData(Box::new(d)); - let mut e = EvenMoreBoxedData(Box::new(b)); - - let c = || { - println!("{}", e.0.0.m.name); - }; - - e.0.0.m.x = format!("not-x"); - c(); -} - -// Read disjoint paths, one inside the closure and one outside the closure. -fn box_4() { - let m = MetaData { x: format!("x"), name: format!("name") }; - let d = Data { m }; - let b = BoxedData(Box::new(d)); - let e = EvenMoreBoxedData(Box::new(b)); - - let c = || { - println!("{}", e.0.0.m.name); - }; - - println!("{}", e.0.0.m.x); - c(); -} - -// Read the same path, once inside the closure and once outside the closure. -fn box_5() { - let m = MetaData { x: format!("x"), name: format!("name") }; - let d = Data { m }; - let b = BoxedData(Box::new(d)); - let e = EvenMoreBoxedData(Box::new(b)); - - let c = || { - println!("{}", e.0.0.m.name); - }; - - println!("{}", e.0.0.m.name); - c(); -} - -fn main() { - box_1(); - box_2(); - box_3(); - box_4(); - box_5(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/by_value.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/by_value.rs deleted file mode 100644 index 2c828aed528bf..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/by_value.rs +++ /dev/null @@ -1,26 +0,0 @@ -// edition:2021 -// run-pass - -// Test that ByValue captures compile sucessefully especially when the captures are -// derefenced within the closure. - -#[derive(Debug, Default)] -struct SomeLargeType; -struct MuchLargerType([SomeLargeType; 32]); - -fn big_box() { - let s = MuchLargerType(Default::default()); - let b = Box::new(s); - let t = (b, 10); - - let c = || { - let p = t.0.0; - println!("{} {:?}", t.1, p); - }; - - c(); -} - -fn main() { - big_box(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/capture-disjoint-field-struct.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/capture-disjoint-field-struct.rs deleted file mode 100644 index 3cb1eb32952d8..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/capture-disjoint-field-struct.rs +++ /dev/null @@ -1,24 +0,0 @@ -// edition:2021 -// run-pass - -// Test that we can immutably borrow field of an instance of a structure from within a closure, -// while having a mutable borrow to another field of the same instance outside the closure. - -struct Point { - x: i32, - y: i32, -} - -fn main() { - let mut p = Point { x: 10, y: 10 }; - - let c = || { - println!("{}", p.x); - }; - - // `c` should only capture `p.x`, therefore mutating `p.y` is allowed. - let py = &mut p.y; - - c(); - *py = 20; -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/capture-disjoint-field-tuple-mut.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/capture-disjoint-field-tuple-mut.rs deleted file mode 100644 index 0f79b7ae7b8c6..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/capture-disjoint-field-tuple-mut.rs +++ /dev/null @@ -1,20 +0,0 @@ -// edition:2021 -// run-pass - -// Test that we can mutate an element of a tuple from within a closure -// while immutably borrowing another element of the same tuple outside the closure. - -#![feature(rustc_attrs)] - -fn main() { - let mut t = (10, 10); - - let mut c = || { - let t1 = &mut t.1; - *t1 = 20; - }; - - // Test that `c` only captures t.1, therefore reading t.0 is allowed. - println!("{}", t.0); - c(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/capture-disjoint-field-tuple.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/capture-disjoint-field-tuple.rs deleted file mode 100644 index 81f0328b9ba5f..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/capture-disjoint-field-tuple.rs +++ /dev/null @@ -1,21 +0,0 @@ -// edition:2021 -// run-pass - -// Test that we can immutably borrow an element of a tuple from within a closure, -// while having a mutable borrow to another element of the same tuple outside the closure. - -#![feature(rustc_attrs)] - -fn main() { - let mut t = (10, 10); - - let c = || { - println!("{}", t.0); - }; - - // `c` only captures t.0, therefore mutating t.1 is allowed. - let t1 = &mut t.1; - - c(); - *t1 = 20; -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/capture_with_wildcard_match.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/capture_with_wildcard_match.rs deleted file mode 100644 index cea02fbe15d34..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/capture_with_wildcard_match.rs +++ /dev/null @@ -1,27 +0,0 @@ -// edition:2021 -//check-pass - -fn test1() { - let foo : [Vec; 3] = ["String".into(), "String".into(), "String".into()]; - let c = || { - match foo { _ => () }; - }; - drop(foo); - c(); -} - -fn test2() { - let foo : Option<[Vec; 3]> = Some(["String".into(), "String".into(), "String".into()]); - let c = || { - match foo { - Some(_) => 1, - _ => 2 - }; - }; - c(); -} - -fn main() { - test1(); - test2(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/destructure-pattern-closure-within-closure.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/destructure-pattern-closure-within-closure.rs deleted file mode 100644 index 5c278bff90bb0..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/destructure-pattern-closure-within-closure.rs +++ /dev/null @@ -1,21 +0,0 @@ -// edition:2021 -// check-pass -#![warn(unused)] - -fn main() { - let t = (String::from("Hello"), String::from("World")); - let g = (String::from("Mr"), String::from("Goose")); - - let a = || { - let (_, g2) = g; - //~^ WARN unused variable: `g2` - let c = || { - let (_, t2) = t; - //~^ WARN unused variable: `t2` - }; - - c(); - }; - - a(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/destructure-pattern-closure-within-closure.stderr b/src/test/ui/closures/2229_closure_analysis/run_pass/destructure-pattern-closure-within-closure.stderr deleted file mode 100644 index 40274c88318c3..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/destructure-pattern-closure-within-closure.stderr +++ /dev/null @@ -1,21 +0,0 @@ -warning: unused variable: `t2` - --> $DIR/destructure-pattern-closure-within-closure.rs:13:21 - | -LL | let (_, t2) = t; - | ^^ help: if this is intentional, prefix it with an underscore: `_t2` - | -note: the lint level is defined here - --> $DIR/destructure-pattern-closure-within-closure.rs:3:9 - | -LL | #![warn(unused)] - | ^^^^^^ - = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]` - -warning: unused variable: `g2` - --> $DIR/destructure-pattern-closure-within-closure.rs:10:17 - | -LL | let (_, g2) = g; - | ^^ help: if this is intentional, prefix it with an underscore: `_g2` - -warning: 2 warnings emitted - diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.rs deleted file mode 100644 index 07adbee03f968..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.rs +++ /dev/null @@ -1,122 +0,0 @@ -// edition:2021 -// check-pass -#![warn(unused)] - -struct Point { - x: u32, - y: u32, -} - -fn test1() { - let t = (String::from("Hello"), String::from("World")); - - let c = || { - let (t1, t2) = t; - //~^ WARN unused variable: `t1` - //~| WARN unused variable: `t2` - }; - - c(); -} - -fn test2() { - let t = (String::from("Hello"), String::from("World")); - - let c = || { - let (t1, _) = t; - //~^ WARN unused variable: `t1` - }; - - c(); -} - -fn test3() { - let t = (String::from("Hello"), String::from("World")); - - let c = || { - let (_, t2) = t; - //~^ WARN unused variable: `t2` - }; - - c(); -} - -fn test4() { - let t = (String::from("Hello"), String::from("World")); - //~^ WARN unused variable: `t` - - let c = || { - let (_, _) = t; - }; - - c(); -} - -fn test5() { - let t = (String::new(), String::new()); - let _c = || { - let _a = match t { - (t1, _) => t1, - }; - }; -} - -fn test6() { - let t = (String::new(), String::new()); - let _c = || { - let _a = match t { - (_, t2) => t2, - }; - }; -} - -fn test7() { - let t = (String::new(), String::new()); - let _c = || { - let _a = match t { - (t1, t2) => (t1, t2), - }; - }; -} - -fn test8() { - let x = 0; - //~^ WARN unused variable: `x` - let tup = (1, 2); - //~^ WARN unused variable: `tup` - let p = Point { x: 10, y: 20 }; - - let c = || { - let _ = x; - let Point { x, y } = p; - //~^ WARN unused variable: `x` - println!("{}", y); - let (_, _) = tup; - }; - - c(); -} - -fn test9() { - let _z = 9; - let t = (String::from("Hello"), String::from("World")); - - let c = || { - let (_, t) = t; - println!("{}", t); - }; - - c(); -} - -fn main() { - test1(); - test2(); - test3(); - test4(); - test5(); - test6(); - test7(); - test8(); - test9(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.stderr b/src/test/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.stderr deleted file mode 100644 index 6523f2b34d537..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.stderr +++ /dev/null @@ -1,57 +0,0 @@ -warning: unused variable: `t1` - --> $DIR/destructure_patterns.rs:14:14 - | -LL | let (t1, t2) = t; - | ^^ help: if this is intentional, prefix it with an underscore: `_t1` - | -note: the lint level is defined here - --> $DIR/destructure_patterns.rs:3:9 - | -LL | #![warn(unused)] - | ^^^^^^ - = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]` - -warning: unused variable: `t2` - --> $DIR/destructure_patterns.rs:14:18 - | -LL | let (t1, t2) = t; - | ^^ help: if this is intentional, prefix it with an underscore: `_t2` - -warning: unused variable: `t1` - --> $DIR/destructure_patterns.rs:26:14 - | -LL | let (t1, _) = t; - | ^^ help: if this is intentional, prefix it with an underscore: `_t1` - -warning: unused variable: `t2` - --> $DIR/destructure_patterns.rs:37:17 - | -LL | let (_, t2) = t; - | ^^ help: if this is intentional, prefix it with an underscore: `_t2` - -warning: unused variable: `t` - --> $DIR/destructure_patterns.rs:45:9 - | -LL | let t = (String::from("Hello"), String::from("World")); - | ^ help: if this is intentional, prefix it with an underscore: `_t` - -warning: unused variable: `x` - --> $DIR/destructure_patterns.rs:91:21 - | -LL | let Point { x, y } = p; - | ^ help: try ignoring the field: `x: _` - -warning: unused variable: `x` - --> $DIR/destructure_patterns.rs:83:9 - | -LL | let x = 0; - | ^ help: if this is intentional, prefix it with an underscore: `_x` - -warning: unused variable: `tup` - --> $DIR/destructure_patterns.rs:85:9 - | -LL | let tup = (1, 2); - | ^^^ help: if this is intentional, prefix it with an underscore: `_tup` - -warning: 8 warnings emitted - diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/disjoint-capture-in-same-closure.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/disjoint-capture-in-same-closure.rs deleted file mode 100644 index 88a9816a05263..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/disjoint-capture-in-same-closure.rs +++ /dev/null @@ -1,23 +0,0 @@ -// edition:2021 -// run-pass - -// Tests that if a closure uses indivual fields of the same object -// then that case is handled properly. - -#![allow(unused)] - -struct Struct { - x: i32, - y: i32, - s: String, -} - -fn main() { - let mut s = Struct { x: 10, y: 10, s: String::new() }; - - let mut c = { - s.x += 10; - s.y += 42; - s.s = String::from("new"); - }; -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/drop_then_use_fake_reads.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/drop_then_use_fake_reads.rs deleted file mode 100644 index 477fdd613f521..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/drop_then_use_fake_reads.rs +++ /dev/null @@ -1,11 +0,0 @@ -// edition:2021 -// check-pass -#![feature(rustc_attrs)] - -fn main() { - let mut x = 1; - let c = || { - drop(&mut x); - match x { _ => () } - }; -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/edition.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/edition.rs deleted file mode 100644 index 20bbe1d89e45d..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/edition.rs +++ /dev/null @@ -1,23 +0,0 @@ -// edition:2021 -// run-pass - -// Test that edition 2021 enables disjoint capture by default. - -struct Point { - x: i32, - y: i32, -} - -fn main() { - let mut p = Point { x: 10, y: 10 }; - - let c = || { - println!("{}", p.x); - }; - - // `c` should only capture `p.x`, therefore mutating `p.y` is allowed. - let py = &mut p.y; - - c(); - *py = 20; -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/filter-on-struct-member.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/filter-on-struct-member.rs deleted file mode 100644 index e19f5ff1bae4d..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/filter-on-struct-member.rs +++ /dev/null @@ -1,37 +0,0 @@ -// edition:2021 -// run-pass - -// Test disjoint capture within an impl block - -struct Filter { - div: i32, -} -impl Filter { - fn allowed(&self, x: i32) -> bool { - x % self.div == 1 - } -} - -struct Data { - filter: Filter, - list: Vec, -} -impl Data { - fn update(&mut self) { - // The closure passed to filter only captures self.filter, - // therefore mutating self.list is allowed. - self.list.retain( - |v| self.filter.allowed(*v), - ); - } -} - -fn main() { - let mut d = Data { filter: Filter { div: 3 }, list: Vec::new() }; - - for i in 1..10 { - d.list.push(i); - } - - d.update(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/fru_syntax.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/fru_syntax.rs deleted file mode 100644 index 1286613cb13ba..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/fru_syntax.rs +++ /dev/null @@ -1,42 +0,0 @@ -// edition:2021 -// run-pass - -// Test that functional record update/struct update syntax works inside -// a closure when the feature `capture_disjoint_fields` is enabled. - -#[derive(Clone)] -struct S { - a: String, - b: String, -} - -struct T { - a: String, - s: S, -} - -fn main() { - let a = String::new(); - let b = String::new(); - let c = String::new(); - let s = S {a, b}; - let t = T { - a: c, - s: s.clone() - }; - - let c = || { - let s2 = S { - a: format!("New s2"), - ..s - }; - let s3 = S { - a: format!("New s3"), - ..t.s - }; - println!("{} {}", s2.a, s2.b); - println!("{} {} {}", s3.a, s3.b, t.a); - }; - - c(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/lit-pattern-matching-with-methods.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/lit-pattern-matching-with-methods.rs deleted file mode 100644 index d2375aa69ec25..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/lit-pattern-matching-with-methods.rs +++ /dev/null @@ -1,30 +0,0 @@ -// edition:2021 -//check-pass -#![warn(unused)] -#![feature(rustc_attrs)] -#![feature(btree_drain_filter)] - -use std::collections::BTreeMap; -use std::panic::{catch_unwind, AssertUnwindSafe}; - -fn main() { - let mut map = BTreeMap::new(); - map.insert("a", ()); - map.insert("b", ()); - map.insert("c", ()); - - { - let mut it = map.drain_filter(|_, _| true); - catch_unwind(AssertUnwindSafe(|| while it.next().is_some() {})).unwrap_err(); - let result = catch_unwind(AssertUnwindSafe(|| it.next())); - assert!(matches!(result, Ok(None))); - } - - { - let mut it = map.drain_filter(|_, _| true); - catch_unwind(AssertUnwindSafe(|| while let Some(_) = it.next() {})).unwrap_err(); - let result = catch_unwind(AssertUnwindSafe(|| it.next())); - assert!(matches!(result, Ok(None))); - } - -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/move_closure.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/move_closure.rs deleted file mode 100644 index 65c8a5a7850fe..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/move_closure.rs +++ /dev/null @@ -1,103 +0,0 @@ -// edition:2021 -// run-pass - -// Test that move closures compile properly with `capture_disjoint_fields` enabled. - -fn simple_ref() { - let mut s = 10; - let ref_s = &mut s; - - let mut c = move || { - *ref_s += 10; - }; - c(); -} - -fn struct_contains_ref_to_another_struct() { - struct S(String); - struct T<'a>(&'a mut S); - - let mut s = S("s".into()); - let t = T(&mut s); - - let mut c = move || { - t.0.0 = "new s".into(); - }; - - c(); -} - -#[derive(Debug)] -struct S(String); - -#[derive(Debug)] -struct T(S); - -fn no_ref() { - let mut t = T(S("s".into())); - let mut c = move || { - t.0.0 = "new S".into(); - }; - c(); -} - -fn no_ref_nested() { - let mut t = T(S("s".into())); - let c = || { - println!("{:?}", t.0); - let mut c = move || { - t.0.0 = "new S".into(); - println!("{:?}", t.0.0); - }; - c(); - }; - c(); -} - -struct A<'a>(&'a mut String, &'a mut String); -// Test that reborrowing works as expected for move closures -// by attempting a disjoint capture through a reference. -fn disjoint_via_ref() { - let mut x = String::new(); - let mut y = String::new(); - - let mut a = A(&mut x, &mut y); - let a = &mut a; - - let mut c1 = move || { - a.0.truncate(0); - }; - - let mut c2 = move || { - a.1.truncate(0); - }; - - c1(); - c2(); -} - -// Test that even if a path is moved into the closure, the closure is not FnOnce -// if the path is not moved by the closure call. -fn data_moved_but_not_fn_once() { - let x = Box::new(10i32); - - let c = move || { - // *x has type i32 which is Copy. So even though the box `x` will be moved - // into the closure, `x` is never moved when the closure is called, i.e. the - // ownership stays with the closure and therefore we can call the function multiple times. - let _x = *x; - }; - - c(); - c(); -} - -fn main() { - simple_ref(); - struct_contains_ref_to_another_struct(); - no_ref(); - no_ref_nested(); - - disjoint_via_ref(); - data_moved_but_not_fn_once(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/multilevel-path-1.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/multilevel-path-1.rs deleted file mode 100644 index b8e464031813b..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/multilevel-path-1.rs +++ /dev/null @@ -1,33 +0,0 @@ -// edition:2021 -// run-pass - -// Test that closures can catpure paths that are more precise than just one level -// from the root variable. -// -// If the closures can handle such precison we should be able to mutate one path in the closure -// while being able to mutate another path outside the closure, where the two paths are disjoint -// after applying two projections on the root variable. - -#![allow(unused)] - -struct Point { - x: i32, - y: i32, -} -struct Wrapper { - p: Point, -} - -fn main() { - let mut w = Wrapper { p: Point { x: 10, y: 10 } }; - - let mut c = || { - w.p.x += 20; - }; - - // `c` only captures `w.p.x`, therefore it's safe to mutate `w.p.y`. - let py = &mut w.p.y; - c(); - - *py = 20 -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/multilevel-path-2.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/multilevel-path-2.rs deleted file mode 100644 index 11a324d8a34e3..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/multilevel-path-2.rs +++ /dev/null @@ -1,31 +0,0 @@ -// edition:2021 -// run-pass - -#![allow(unused)] - -// If the closures can handle such precison we should be able to read one path in the closure -// while being able mutate another path outside the closure, where the two paths are disjoint -// after applying two projections on the root variable. - - -struct Point { - x: i32, - y: i32, -} -struct Wrapper { - p: Point, -} - -fn main() { - let mut w = Wrapper { p: Point { x: 10, y: 10 } }; - - let c = || { - println!("{}", w.p.x); - }; - - // `c` only captures `w.p.x`, therefore it's safe to mutate `w.p.y`. - let py = &mut w.p.y; - c(); - - *py = 20 -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/multilevel-path-3.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/multilevel-path-3.rs deleted file mode 100644 index 8fc0efb60b755..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/multilevel-path-3.rs +++ /dev/null @@ -1,28 +0,0 @@ -// edition:2021 -// run-pass - -#![allow(unused)] - -// Test that when `capture_disjoint_fields` is enabled we can read a path -// both inside and outside the closure at the same time. - -struct Point { - x: i32, - y: i32, -} -struct Wrapper { - p: Point, -} - -fn main() { - let mut w = Wrapper { p: Point { x: 10, y: 10 } }; - - let c = || { - println!("{}", w.p.x); - }; - - let px = &w.p.x; - c(); - - println!("{}", px); -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/mut_ref.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/mut_ref.rs deleted file mode 100644 index 9f0c4d96aa5d9..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/mut_ref.rs +++ /dev/null @@ -1,54 +0,0 @@ -// edition:2021 -// run-pass - -// Test that we can mutate a place through a mut-borrow -// that is captured by the closure - -// Check that we can mutate when one deref is required -fn mut_ref_1() { - let mut x = String::new(); - let rx = &mut x; - - let mut c = || { - *rx = String::new(); - }; - - c(); -} - -// Similar example as mut_ref_1, we don't deref the imm-borrow here, -// and so we are allowed to mutate. -fn mut_ref_2() { - let x = String::new(); - let y = String::new(); - let mut ref_x = &x; - let m_ref_x = &mut ref_x; - - let mut c = || { - *m_ref_x = &y; - }; - - c(); -} - -// Check that we can mutate when multiple derefs of mut-borrows are required to reach -// the target place. -// It works because all derefs are mutable, if either of them was an immutable -// borrow, then we would not be able to deref. -fn mut_mut_ref() { - let mut x = String::new(); - let mut mref_x = &mut x; - let m_mref_x = &mut mref_x; - - let mut c = || { - **m_mref_x = String::new(); - }; - - c(); -} - -fn main() { - mut_ref_1(); - mut_ref_2(); - mut_mut_ref(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/mut_ref_struct_mem.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/mut_ref_struct_mem.rs deleted file mode 100644 index bb784774b8cd4..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/mut_ref_struct_mem.rs +++ /dev/null @@ -1,43 +0,0 @@ -// edition:2021 -// run-pass - -// Test that we can mutate a place through a mut-borrow -// that is captured by the closure - -// More specifically we test that the if the mutable reference isn't root variable of a capture -// but rather accessed while acessing the precise capture. - -fn mut_tuple() { - let mut t = (10, 10); - - let t1 = (&mut t, 10); - - let mut c = || { - // Mutable because (*t.0) is mutable - t1.0.0 += 10; - }; - - c(); -} - -fn mut_tuple_nested() { - let mut t = (10, 10); - - let t1 = (&mut t, 10); - - let mut c = || { - let mut c = || { - // Mutable because (*t.0) is mutable - t1.0.0 += 10; - }; - - c(); - }; - - c(); -} - -fn main() { - mut_tuple(); - mut_tuple_nested(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/nested-closure.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/nested-closure.rs deleted file mode 100644 index a80b40bb46957..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/nested-closure.rs +++ /dev/null @@ -1,36 +0,0 @@ -// edition:2021 -// run-pass - -// Test whether if we can do precise capture when using nested clsoure. - -struct Point { - x: i32, - y: i32, -} - -fn main() { - let mut p = Point { x: 5, y: 20 }; - - // c1 should capture `p.x` via immutable borrow and - // `p.y` via mutable borrow. - let mut c1 = || { - println!("{}", p.x); - - let incr = 10; - - let mut c2 = || p.y += incr; - c2(); - - println!("{}", p.y); - }; - - c1(); - - // This should not throw an error because `p.x` is borrowed via Immutable borrow, - // and multiple immutable borrow of the same place are allowed. - let px = &p.x; - - println!("{}", px); - - c1(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/struct-pattern-matching-with-methods.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/struct-pattern-matching-with-methods.rs deleted file mode 100644 index 045fe78040a92..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/struct-pattern-matching-with-methods.rs +++ /dev/null @@ -1,48 +0,0 @@ -// edition:2021 -//check-pass -#![warn(unused)] -#![feature(rustc_attrs)] - -#[derive(Debug, Clone, Copy)] -enum PointType { - TwoD { x: u32, y: u32 }, - - ThreeD{ x: u32, y: u32, z: u32 } -} - -// Testing struct patterns -struct Points { - points: Vec, -} - -impl Points { - pub fn test1(&mut self) -> Vec { - (0..self.points.len()) - .filter_map(|i| { - let idx = i as usize; - match self.test2(idx) { - PointType::TwoD { .. } => Some(i), - PointType::ThreeD { .. } => None, - } - }) - .collect() - } - - pub fn test2(&mut self, i: usize) -> PointType { - self.points[i] - } -} - -fn main() { - let mut points = Points { - points: Vec::::new() - }; - - points.points.push(PointType::ThreeD { x:0, y:0, z:0 }); - points.points.push(PointType::TwoD{ x:0, y:0 }); - points.points.push(PointType::ThreeD{ x:0, y:0, z:0 }); - points.points.push(PointType::TwoD{ x:0, y:0 }); - - println!("{:?}", points.test1()); - println!("{:?}", points.points); -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/tuple-struct-pattern-matching-with-methods.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/tuple-struct-pattern-matching-with-methods.rs deleted file mode 100644 index f3f44433ccf3d..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/tuple-struct-pattern-matching-with-methods.rs +++ /dev/null @@ -1,43 +0,0 @@ -// edition:2021 -//check-pass - -#[derive(Copy, Clone)] -enum PointType { - TwoD(u32, u32), - ThreeD(u32, u32, u32) -} - -// Testing tuple struct patterns -struct Points { - points: Vec, -} - -impl Points { - pub fn test1(&mut self) -> Vec { - (0..self.points.len()) - .filter_map(|i| { - match self.test2(i) { - PointType::TwoD (..) => Some(i), - PointType::ThreeD (..) => None, - } - }) - .collect() - } - - pub fn test2(&mut self, i: usize) -> PointType { - self.points[i] - } -} - -fn main() { - let mut points = Points { - points: Vec::::new() - }; - - points.points.push(PointType::ThreeD(0,0,0)); - points.points.push(PointType::TwoD(0,0)); - points.points.push(PointType::ThreeD(0,0,1)); - points.points.push(PointType::TwoD(0,1)); - - println!("{:?}", points.test1()); -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/unsafe_ptr.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/unsafe_ptr.rs deleted file mode 100644 index 8e4f91c27e224..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/unsafe_ptr.rs +++ /dev/null @@ -1,45 +0,0 @@ -// edition:2021 -// run-pass - -// Test that we can use raw ptrs when using `capture_disjoint_fields`. - -#[derive(Debug)] -struct S { - s: String, - t: String, -} - -struct T(*const S); - -fn unsafe_imm() { - let s = "".into(); - let t = "".into(); - let my_speed: Box = Box::new(S { s, t }); - - let p : *const S = Box::into_raw(my_speed); - let t = T(p); - - let c = || unsafe { - println!("{:?}", (*t.0).s); - }; - - c(); -} - -fn unsafe_mut() { - let s = "".into(); - let t = "".into(); - let mut my_speed: Box = Box::new(S { s, t }); - let p : *mut S = &mut *my_speed; - - let c = || { - let x = unsafe { &mut (*p).s }; - *x = "s".into(); - }; - c(); -} - -fn main() { - unsafe_mut(); - unsafe_imm(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/use_of_mutable_borrow_and_fake_reads.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/use_of_mutable_borrow_and_fake_reads.rs deleted file mode 100644 index 0206927cc59e9..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/use_of_mutable_borrow_and_fake_reads.rs +++ /dev/null @@ -1,11 +0,0 @@ -// edition:2021 -//check-pass -#![feature(rustc_attrs)] - -fn main() { - let mut x = 0; - let c = || { - &mut x; // mutable borrow of `x` - match x { _ => () } // fake read of `x` - }; -} diff --git a/src/test/ui/closures/2229_closure_analysis/simple-struct-min-capture.rs b/src/test/ui/closures/2229_closure_analysis/simple-struct-min-capture.rs deleted file mode 100644 index 563095d440d24..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/simple-struct-min-capture.rs +++ /dev/null @@ -1,39 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] - -// Test to ensure that min analysis meets capture kind for all paths captured. - -#[derive(Debug)] -struct Point { - x: i32, - y: i32, -} - -fn main() { - let mut p = Point { x: 10, y: 20 }; - - // - // Requirements: - // p.x -> MutBoorrow - // p -> ImmBorrow - // - // Requirements met when p is captured via MutBorrow - // - let mut c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - p.x += 10; - //~^ NOTE: Capturing p[(0, 0)] -> MutBorrow - //~| NOTE: p[] captured as MutBorrow here - println!("{:?}", p); - //~^ NOTE: Capturing p[] -> ImmBorrow - //~| NOTE: Min Capture p[] -> MutBorrow - //~| NOTE: p[] used here - }; - - c(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/simple-struct-min-capture.stderr b/src/test/ui/closures/2229_closure_analysis/simple-struct-min-capture.stderr deleted file mode 100644 index 05d79797ab3c0..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/simple-struct-min-capture.stderr +++ /dev/null @@ -1,56 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/simple-struct-min-capture.rs:23:17 - | -LL | let mut c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/simple-struct-min-capture.rs:26:5 - | -LL | / || { -LL | | -LL | | -LL | | p.x += 10; -... | -LL | | -LL | | }; - | |_____^ - | -note: Capturing p[(0, 0)] -> MutBorrow - --> $DIR/simple-struct-min-capture.rs:29:9 - | -LL | p.x += 10; - | ^^^ -note: Capturing p[] -> ImmBorrow - --> $DIR/simple-struct-min-capture.rs:32:26 - | -LL | println!("{:?}", p); - | ^ - -error: Min Capture analysis includes: - --> $DIR/simple-struct-min-capture.rs:26:5 - | -LL | / || { -LL | | -LL | | -LL | | p.x += 10; -... | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture p[] -> MutBorrow - --> $DIR/simple-struct-min-capture.rs:29:9 - | -LL | p.x += 10; - | ^^^ p[] captured as MutBorrow here -... -LL | println!("{:?}", p); - | ^ p[] used here - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/unsafe_ptr.rs b/src/test/ui/closures/2229_closure_analysis/unsafe_ptr.rs deleted file mode 100644 index eab9f9d08a9f6..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/unsafe_ptr.rs +++ /dev/null @@ -1,62 +0,0 @@ -// edition:2021 - -// Test that we restrict precision of a capture when we access a raw ptr, -// i.e. the capture doesn't deref the raw ptr. - - -#![feature(rustc_attrs)] - -#[derive(Debug)] -struct S { - s: String, - t: String, -} - -struct T(*const S); - -fn unsafe_imm() { - let s = "".into(); - let t = "".into(); - let my_speed: Box = Box::new(S { s, t }); - - let p : *const S = Box::into_raw(my_speed); - let t = T(p); - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || unsafe { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - println!("{:?}", (*t.0).s); - //~^ NOTE: Capturing t[(0, 0),Deref,(0, 0)] -> ImmBorrow - //~| NOTE: Min Capture t[(0, 0)] -> ImmBorrow - }; - - c(); -} - -fn unsafe_mut() { - let s = "".into(); - let t = "".into(); - let mut my_speed: Box = Box::new(S { s, t }); - let p : *mut S = &mut *my_speed; - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - let x = unsafe { &mut (*p).s }; - //~^ NOTE: Capturing p[Deref,(0, 0)] -> ImmBorrow - //~| NOTE: Min Capture p[] -> ImmBorrow - *x = "s".into(); - }; - c(); -} - -fn main() { - unsafe_mut(); - unsafe_imm(); -} diff --git a/src/test/ui/closures/2229_closure_analysis/unsafe_ptr.stderr b/src/test/ui/closures/2229_closure_analysis/unsafe_ptr.stderr deleted file mode 100644 index e740a4d2d6b80..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/unsafe_ptr.stderr +++ /dev/null @@ -1,93 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/unsafe_ptr.rs:25:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/unsafe_ptr.rs:45:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/unsafe_ptr.rs:28:6 - | -LL | / || unsafe { -LL | | -LL | | -LL | | println!("{:?}", (*t.0).s); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Capturing t[(0, 0),Deref,(0, 0)] -> ImmBorrow - --> $DIR/unsafe_ptr.rs:31:26 - | -LL | println!("{:?}", (*t.0).s); - | ^^^^^^^^ - -error: Min Capture analysis includes: - --> $DIR/unsafe_ptr.rs:28:6 - | -LL | / || unsafe { -LL | | -LL | | -LL | | println!("{:?}", (*t.0).s); -LL | | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture t[(0, 0)] -> ImmBorrow - --> $DIR/unsafe_ptr.rs:31:26 - | -LL | println!("{:?}", (*t.0).s); - | ^^^^^^^^ - -error: First Pass analysis includes: - --> $DIR/unsafe_ptr.rs:48:5 - | -LL | / || { -LL | | -LL | | -LL | | let x = unsafe { &mut (*p).s }; -... | -LL | | *x = "s".into(); -LL | | }; - | |_____^ - | -note: Capturing p[Deref,(0, 0)] -> ImmBorrow - --> $DIR/unsafe_ptr.rs:51:31 - | -LL | let x = unsafe { &mut (*p).s }; - | ^^^^^^ - -error: Min Capture analysis includes: - --> $DIR/unsafe_ptr.rs:48:5 - | -LL | / || { -LL | | -LL | | -LL | | let x = unsafe { &mut (*p).s }; -... | -LL | | *x = "s".into(); -LL | | }; - | |_____^ - | -note: Min Capture p[] -> ImmBorrow - --> $DIR/unsafe_ptr.rs:51:31 - | -LL | let x = unsafe { &mut (*p).s }; - | ^^^^^^ - -error: aborting due to 6 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/wild_patterns.rs b/src/test/ui/closures/2229_closure_analysis/wild_patterns.rs deleted file mode 100644 index 7843c251666c5..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/wild_patterns.rs +++ /dev/null @@ -1,73 +0,0 @@ -// edition:2021 - -#![feature(rustc_attrs)] - -// Test to ensure that we can handle cases where -// let statements create no bindings are intialized -// using a Place expression -// -// Note: Currently when feature `capture_disjoint_fields` is enabled -// we can't handle such cases. So the test current use `_x` instead of -// `_` until the issue is resolved. -// Check rust-lang/project-rfc-2229#24 for status. - -struct Point { - x: i32, - y: i32, -} - -fn wild_struct() { - let p = Point { x: 10, y: 20 }; - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - // FIXME(arora-aman): Change `_x` to `_` - let Point { x: _x, y: _ } = p; - //~^ NOTE: Capturing p[(0, 0)] -> ImmBorrow - //~| NOTE: Min Capture p[(0, 0)] -> ImmBorrow - }; - - c(); -} - -fn wild_tuple() { - let t = (String::new(), 10); - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - // FIXME(arora-aman): Change `_x` to `_` - let (_x, _) = t; - //~^ NOTE: Capturing t[(0, 0)] -> ByValue - //~| NOTE: Min Capture t[(0, 0)] -> ByValue - }; - - c(); -} - -fn wild_arr() { - let arr = [String::new(), String::new()]; - - let c = #[rustc_capture_analysis] - //~^ ERROR: attributes on expressions are experimental - //~| NOTE: see issue #15701 - || { - //~^ ERROR: First Pass analysis includes: - //~| ERROR: Min Capture analysis includes: - // FIXME(arora-aman): Change `_x` to `_` - let [_x, _] = arr; - //~^ NOTE: Capturing arr[Index] -> ByValue - //~| NOTE: Min Capture arr[] -> ByValue - }; - - c(); -} - -fn main() {} diff --git a/src/test/ui/closures/2229_closure_analysis/wild_patterns.stderr b/src/test/ui/closures/2229_closure_analysis/wild_patterns.stderr deleted file mode 100644 index c64378091e6e0..0000000000000 --- a/src/test/ui/closures/2229_closure_analysis/wild_patterns.stderr +++ /dev/null @@ -1,138 +0,0 @@ -error[E0658]: attributes on expressions are experimental - --> $DIR/wild_patterns.rs:22:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/wild_patterns.rs:40:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error[E0658]: attributes on expressions are experimental - --> $DIR/wild_patterns.rs:58:13 - | -LL | let c = #[rustc_capture_analysis] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #15701 for more information - = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - -error: First Pass analysis includes: - --> $DIR/wild_patterns.rs:25:5 - | -LL | / || { -LL | | -LL | | -LL | | // FIXME(arora-aman): Change `_x` to `_` -... | -LL | | -LL | | }; - | |_____^ - | -note: Capturing p[(0, 0)] -> ImmBorrow - --> $DIR/wild_patterns.rs:29:37 - | -LL | let Point { x: _x, y: _ } = p; - | ^ - -error: Min Capture analysis includes: - --> $DIR/wild_patterns.rs:25:5 - | -LL | / || { -LL | | -LL | | -LL | | // FIXME(arora-aman): Change `_x` to `_` -... | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture p[(0, 0)] -> ImmBorrow - --> $DIR/wild_patterns.rs:29:37 - | -LL | let Point { x: _x, y: _ } = p; - | ^ - -error: First Pass analysis includes: - --> $DIR/wild_patterns.rs:43:5 - | -LL | / || { -LL | | -LL | | -LL | | // FIXME(arora-aman): Change `_x` to `_` -... | -LL | | -LL | | }; - | |_____^ - | -note: Capturing t[(0, 0)] -> ByValue - --> $DIR/wild_patterns.rs:47:23 - | -LL | let (_x, _) = t; - | ^ - -error: Min Capture analysis includes: - --> $DIR/wild_patterns.rs:43:5 - | -LL | / || { -LL | | -LL | | -LL | | // FIXME(arora-aman): Change `_x` to `_` -... | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture t[(0, 0)] -> ByValue - --> $DIR/wild_patterns.rs:47:23 - | -LL | let (_x, _) = t; - | ^ - -error: First Pass analysis includes: - --> $DIR/wild_patterns.rs:61:5 - | -LL | / || { -LL | | -LL | | -LL | | // FIXME(arora-aman): Change `_x` to `_` -... | -LL | | -LL | | }; - | |_____^ - | -note: Capturing arr[Index] -> ByValue - --> $DIR/wild_patterns.rs:65:23 - | -LL | let [_x, _] = arr; - | ^^^ - -error: Min Capture analysis includes: - --> $DIR/wild_patterns.rs:61:5 - | -LL | / || { -LL | | -LL | | -LL | | // FIXME(arora-aman): Change `_x` to `_` -... | -LL | | -LL | | }; - | |_____^ - | -note: Min Capture arr[] -> ByValue - --> $DIR/wild_patterns.rs:65:23 - | -LL | let [_x, _] = arr; - | ^^^ - -error: aborting due to 9 previous errors - -For more information about this error, try `rustc --explain E0658`.