-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Insignificant destructors rfc 2229 #84152
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
67 changes: 67 additions & 0 deletions
67
...est/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.fixed
This file contains hidden or 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,67 @@ | ||
// run-rustfix | ||
|
||
#![deny(disjoint_capture_migration)] | ||
//~^ 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, T); | ||
|
||
struct Wrapper<T>(GenericStruct<T>, i32); | ||
|
||
impl<T> Drop for GenericStruct<T> { | ||
#[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 affected for closure because of `capture_disjoint_fields` | ||
//~| 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 affected for closure because of `capture_disjoint_fields` | ||
//~| 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(); | ||
} |
67 changes: 67 additions & 0 deletions
67
src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.rs
This file contains hidden or 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,67 @@ | ||
// run-rustfix | ||
|
||
#![deny(disjoint_capture_migration)] | ||
//~^ 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, T); | ||
|
||
struct Wrapper<T>(GenericStruct<T>, i32); | ||
|
||
impl<T> Drop for GenericStruct<T> { | ||
#[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 affected for closure because of `capture_disjoint_fields` | ||
//~| 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 || { | ||
null-sleep marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//~^ ERROR: drop order affected for closure because of `capture_disjoint_fields` | ||
//~| 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(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.