-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[rfc 2229] Drop fully captured upvars in the same order as the regular drop code #89208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
7a3e450
ab8aef4
3893656
dd91804
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// 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. | ||
|
||
#![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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My concern with this test is that we need to reply on checking the stderr, and I feel like if the fields order does get changed, we won't need to update the annoatations in this file and someone might ignore the stderr changes because the ouput needed is all there. I think we should go with testing with stdout here because changes to stdout are observable behaviour to the user and might be more cause of concern in case something breaks down the line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's useful to check both the internal results via |
||
//~^ ERROR: attributes on expressions are experimental | ||
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> | ||
|| { | ||
//~^ ERROR: First Pass analysis includes: | ||
//~| ERROR: Min Capture analysis includes: | ||
println!("{:?}", a.0); | ||
//~^ NOTE: Capturing a[(0, 0)] -> ImmBorrow | ||
//~| NOTE: Min Capture a[(0, 0)] -> ImmBorrow | ||
println!("{:?}", a.1); | ||
//~^ NOTE: Capturing a[(1, 0)] -> ImmBorrow | ||
//~| NOTE: Min Capture a[(1, 0)] -> ImmBorrow | ||
|
||
println!("{:?}", b.0); | ||
//~^ NOTE: Capturing b[(0, 0)] -> ImmBorrow | ||
//~| NOTE: Min Capture b[(0, 0)] -> ImmBorrow | ||
println!("{:?}", b.1); | ||
//~^ NOTE: Capturing b[(1, 0)] -> ImmBorrow | ||
//~| NOTE: Min Capture b[(1, 0)] -> ImmBorrow | ||
}; | ||
} | ||
|
||
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: First Pass analysis includes: | ||
//~| ERROR: Min Capture analysis includes: | ||
println!("{:?}", a.1); | ||
//~^ NOTE: Capturing a[(1, 0)] -> ImmBorrow | ||
//~| NOTE: Min Capture a[(1, 0)] -> ImmBorrow | ||
println!("{:?}", a.0); | ||
//~^ NOTE: Capturing a[(0, 0)] -> ImmBorrow | ||
//~| NOTE: Min Capture a[(0, 0)] -> ImmBorrow | ||
|
||
println!("{:?}", b.1); | ||
//~^ NOTE: Capturing b[(1, 0)] -> ImmBorrow | ||
//~| NOTE: Min Capture b[(1, 0)] -> ImmBorrow | ||
println!("{:?}", b.0); | ||
//~^ NOTE: Capturing b[(0, 0)] -> ImmBorrow | ||
//~| NOTE: Min Capture b[(0, 0)] -> ImmBorrow | ||
}; | ||
} | ||
|
||
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: First Pass analysis includes: | ||
//~| ERROR: Min Capture analysis includes: | ||
println!("{:?}", b.1); | ||
//~^ NOTE: Capturing b[(1, 0)] -> ImmBorrow | ||
//~| NOTE: Min Capture b[(1, 0)] -> ImmBorrow | ||
println!("{:?}", a.1); | ||
//~^ NOTE: Capturing a[(1, 0)] -> ImmBorrow | ||
//~| NOTE: Min Capture a[(1, 0)] -> ImmBorrow | ||
println!("{:?}", a.0); | ||
//~^ NOTE: Capturing a[(0, 0)] -> ImmBorrow | ||
//~| NOTE: Min Capture a[(0, 0)] -> ImmBorrow | ||
|
||
println!("{:?}", b.0); | ||
//~^ NOTE: Capturing b[(0, 0)] -> ImmBorrow | ||
//~| NOTE: Min Capture b[(0, 0)] -> ImmBorrow | ||
}; | ||
} | ||
|
||
fn main() { | ||
test_one(); | ||
test_two(); | ||
test_three(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
error[E0658]: attributes on expressions are experimental | ||
--> $DIR/preserve_field_drop_order.rs:20:13 | ||
| | ||
LL | let c = #[rustc_capture_analysis] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information | ||
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable | ||
|
||
error[E0658]: attributes on expressions are experimental | ||
--> $DIR/preserve_field_drop_order.rs:46:13 | ||
| | ||
LL | let c = #[rustc_capture_analysis] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information | ||
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable | ||
|
||
error[E0658]: attributes on expressions are experimental | ||
--> $DIR/preserve_field_drop_order.rs:72:13 | ||
| | ||
LL | let c = #[rustc_capture_analysis] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information | ||
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable | ||
|
||
error: First Pass analysis includes: | ||
--> $DIR/preserve_field_drop_order.rs:23:5 | ||
| | ||
LL | / || { | ||
LL | | | ||
LL | | | ||
LL | | println!("{:?}", a.0); | ||
... | | ||
LL | | | ||
LL | | }; | ||
| |_____^ | ||
| | ||
note: Capturing a[(0, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:26:26 | ||
| | ||
LL | println!("{:?}", a.0); | ||
| ^^^ | ||
note: Capturing a[(1, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:29:26 | ||
| | ||
LL | println!("{:?}", a.1); | ||
| ^^^ | ||
note: Capturing b[(0, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:33:26 | ||
| | ||
LL | println!("{:?}", b.0); | ||
| ^^^ | ||
note: Capturing b[(1, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:36:26 | ||
| | ||
LL | println!("{:?}", b.1); | ||
| ^^^ | ||
|
||
error: Min Capture analysis includes: | ||
--> $DIR/preserve_field_drop_order.rs:23:5 | ||
| | ||
LL | / || { | ||
LL | | | ||
LL | | | ||
LL | | println!("{:?}", a.0); | ||
... | | ||
LL | | | ||
LL | | }; | ||
| |_____^ | ||
| | ||
note: Min Capture a[(0, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:26:26 | ||
| | ||
LL | println!("{:?}", a.0); | ||
| ^^^ | ||
note: Min Capture a[(1, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:29:26 | ||
| | ||
LL | println!("{:?}", a.1); | ||
| ^^^ | ||
note: Min Capture b[(0, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:33:26 | ||
| | ||
LL | println!("{:?}", b.0); | ||
| ^^^ | ||
note: Min Capture b[(1, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:36:26 | ||
| | ||
LL | println!("{:?}", b.1); | ||
| ^^^ | ||
|
||
error: First Pass analysis includes: | ||
--> $DIR/preserve_field_drop_order.rs:49:5 | ||
| | ||
LL | / || { | ||
LL | | | ||
LL | | | ||
LL | | println!("{:?}", a.1); | ||
... | | ||
LL | | | ||
LL | | }; | ||
| |_____^ | ||
| | ||
note: Capturing a[(1, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:52:26 | ||
| | ||
LL | println!("{:?}", a.1); | ||
| ^^^ | ||
note: Capturing a[(0, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:55:26 | ||
| | ||
LL | println!("{:?}", a.0); | ||
| ^^^ | ||
note: Capturing b[(1, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:59:26 | ||
| | ||
LL | println!("{:?}", b.1); | ||
| ^^^ | ||
note: Capturing b[(0, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:62:26 | ||
| | ||
LL | println!("{:?}", b.0); | ||
| ^^^ | ||
|
||
error: Min Capture analysis includes: | ||
--> $DIR/preserve_field_drop_order.rs:49:5 | ||
| | ||
LL | / || { | ||
LL | | | ||
LL | | | ||
LL | | println!("{:?}", a.1); | ||
... | | ||
LL | | | ||
LL | | }; | ||
| |_____^ | ||
| | ||
note: Min Capture a[(0, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:55:26 | ||
| | ||
LL | println!("{:?}", a.0); | ||
| ^^^ | ||
note: Min Capture a[(1, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:52:26 | ||
| | ||
LL | println!("{:?}", a.1); | ||
| ^^^ | ||
note: Min Capture b[(0, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:62:26 | ||
| | ||
LL | println!("{:?}", b.0); | ||
| ^^^ | ||
note: Min Capture b[(1, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:59:26 | ||
| | ||
LL | println!("{:?}", b.1); | ||
| ^^^ | ||
|
||
error: First Pass analysis includes: | ||
--> $DIR/preserve_field_drop_order.rs:75:5 | ||
| | ||
LL | / || { | ||
LL | | | ||
LL | | | ||
LL | | println!("{:?}", b.1); | ||
... | | ||
LL | | | ||
LL | | }; | ||
| |_____^ | ||
| | ||
note: Capturing b[(1, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:78:26 | ||
| | ||
LL | println!("{:?}", b.1); | ||
| ^^^ | ||
note: Capturing a[(1, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:81:26 | ||
| | ||
LL | println!("{:?}", a.1); | ||
| ^^^ | ||
note: Capturing a[(0, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:84:26 | ||
| | ||
LL | println!("{:?}", a.0); | ||
| ^^^ | ||
note: Capturing b[(0, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:88:26 | ||
| | ||
LL | println!("{:?}", b.0); | ||
| ^^^ | ||
|
||
error: Min Capture analysis includes: | ||
--> $DIR/preserve_field_drop_order.rs:75:5 | ||
| | ||
LL | / || { | ||
LL | | | ||
LL | | | ||
LL | | println!("{:?}", b.1); | ||
... | | ||
LL | | | ||
LL | | }; | ||
| |_____^ | ||
| | ||
note: Min Capture b[(0, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:88:26 | ||
| | ||
LL | println!("{:?}", b.0); | ||
| ^^^ | ||
note: Min Capture b[(1, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:78:26 | ||
| | ||
LL | println!("{:?}", b.1); | ||
| ^^^ | ||
note: Min Capture a[(0, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:84:26 | ||
| | ||
LL | println!("{:?}", a.0); | ||
| ^^^ | ||
note: Min Capture a[(1, 0)] -> ImmBorrow | ||
--> $DIR/preserve_field_drop_order.rs:81:26 | ||
| | ||
LL | println!("{:?}", a.1); | ||
| ^^^ | ||
|
||
error: aborting due to 9 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
Uh oh!
There was an error while loading. Please reload this page.