forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#89208 - wesleywiser:rfc_2229_droporder, r=n…
…ikomatsakis [rfc 2229] Drop fully captured upvars in the same order as the regular drop code Currently, with the new 2021 edition, if a closure captures all of the fields of an upvar, we'll drop those fields in the order they are used within the closure instead of the normal drop order (the definition order of the fields in the type). This changes that so we sort the captured fields by the definition order which causes them to drop in that same order as well. Fixes rust-lang/project-rfc-2229#42 r? `@nikomatsakis`
- Loading branch information
1 parent
4779e62
commit d0a8033
Showing
6 changed files
with
485 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// edition:2021 | ||
|
||
// Tests that in cases where we individually capture all the fields of a type, | ||
// we still drop them in the order they would have been dropped in the 2018 edition. | ||
|
||
// NOTE: It is *critical* that the order of the min capture NOTES in the stderr output | ||
// does *not* change! | ||
|
||
#![feature(rustc_attrs)] | ||
|
||
#[derive(Debug)] | ||
struct HasDrop; | ||
impl Drop for HasDrop { | ||
fn drop(&mut self) { | ||
println!("dropped"); | ||
} | ||
} | ||
|
||
fn test_one() { | ||
let a = (HasDrop, HasDrop); | ||
let b = (HasDrop, HasDrop); | ||
|
||
let c = #[rustc_capture_analysis] | ||
//~^ ERROR: attributes on expressions are experimental | ||
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> | ||
|| { | ||
//~^ ERROR: Min Capture analysis includes: | ||
//~| ERROR | ||
println!("{:?}", a.0); | ||
//~^ NOTE: Min Capture a[(0, 0)] -> ImmBorrow | ||
//~| NOTE | ||
println!("{:?}", a.1); | ||
//~^ NOTE: Min Capture a[(1, 0)] -> ImmBorrow | ||
//~| NOTE | ||
|
||
println!("{:?}", b.0); | ||
//~^ NOTE: Min Capture b[(0, 0)] -> ImmBorrow | ||
//~| NOTE | ||
println!("{:?}", b.1); | ||
//~^ NOTE: Min Capture b[(1, 0)] -> ImmBorrow | ||
//~| NOTE | ||
}; | ||
} | ||
|
||
fn test_two() { | ||
let a = (HasDrop, HasDrop); | ||
let b = (HasDrop, HasDrop); | ||
|
||
let c = #[rustc_capture_analysis] | ||
//~^ ERROR: attributes on expressions are experimental | ||
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> | ||
|| { | ||
//~^ ERROR: Min Capture analysis includes: | ||
//~| ERROR | ||
println!("{:?}", a.1); | ||
//~^ NOTE: Min Capture a[(1, 0)] -> ImmBorrow | ||
//~| NOTE | ||
println!("{:?}", a.0); | ||
//~^ NOTE: Min Capture a[(0, 0)] -> ImmBorrow | ||
//~| NOTE | ||
|
||
println!("{:?}", b.1); | ||
//~^ NOTE: Min Capture b[(1, 0)] -> ImmBorrow | ||
//~| NOTE | ||
println!("{:?}", b.0); | ||
//~^ NOTE: Min Capture b[(0, 0)] -> ImmBorrow | ||
//~| NOTE | ||
}; | ||
} | ||
|
||
fn test_three() { | ||
let a = (HasDrop, HasDrop); | ||
let b = (HasDrop, HasDrop); | ||
|
||
let c = #[rustc_capture_analysis] | ||
//~^ ERROR: attributes on expressions are experimental | ||
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> | ||
|| { | ||
//~^ ERROR: Min Capture analysis includes: | ||
//~| ERROR | ||
println!("{:?}", b.1); | ||
//~^ NOTE: Min Capture b[(1, 0)] -> ImmBorrow | ||
//~| NOTE | ||
println!("{:?}", a.1); | ||
//~^ NOTE: Min Capture a[(1, 0)] -> ImmBorrow | ||
//~| NOTE | ||
println!("{:?}", a.0); | ||
//~^ NOTE: Min Capture a[(0, 0)] -> ImmBorrow | ||
//~| NOTE | ||
|
||
println!("{:?}", b.0); | ||
//~^ NOTE: Min Capture b[(0, 0)] -> ImmBorrow | ||
//~| NOTE | ||
}; | ||
} | ||
|
||
fn main() { | ||
test_one(); | ||
test_two(); | ||
test_three(); | ||
} |
Oops, something went wrong.