-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Emit either mono item of Drop::drop or Drop::pin_drop depending on which was implemented
#156495
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -1062,6 +1062,15 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> | |
| tcx.dcx().delayed_bug("attempt to codegen `#[rustc_force_inline]` item"); | ||
| } | ||
|
|
||
| // It is not possible to manually call `Drop::drop` and `Drop::pin_drop`, so we can | ||
| // skip codegen for mentioned associated items of the `Drop` trait, and only codegen | ||
| // `drop` or `pin_drop` depending on which was implemented. | ||
| if let Some(trait_id) = tcx.trait_of_assoc(def_id) | ||
| && tcx.is_lang_item(trait_id, LangItem::Drop) | ||
| { | ||
| return false; | ||
|
Contributor
Author
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. Like the I've also tried to add
Member
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. Either
Contributor
Author
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. Yes, that's true, but the root item |
||
| } | ||
|
|
||
| if def_id.is_local() { | ||
| // Local items cannot be referred to locally without monomorphizing them locally. | ||
| return true; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #![feature(pin_ergonomics)] | ||
| // Ensure that we emit either `Drop::drop` or `Drop::pin_drop` for types that implement `Drop`. | ||
|
|
||
| //@ compile-flags:-Clink-dead-code | ||
| //@ compile-flags:--crate-type=lib | ||
| //@ rustc-env:MONO_TEST=1 | ||
|
|
||
| //~ MONO_ITEM fn std::ptr::drop_glue::<StructWithDrop> - shim(Some(StructWithDrop)) | ||
| struct StructWithDrop { | ||
| x: i32, | ||
| } | ||
|
|
||
| impl Drop for StructWithDrop { | ||
| //~ MONO_ITEM fn <StructWithDrop as std::ops::Drop>::drop | ||
| fn drop(&mut self) {} | ||
| } | ||
|
|
||
| struct StructNoDrop { | ||
| x: i32, | ||
| } | ||
|
|
||
| //~ MONO_ITEM fn std::ptr::drop_glue::<StructWithPinDrop> - shim(Some(StructWithPinDrop)) | ||
| struct StructWithPinDrop { | ||
| x: i32, | ||
| } | ||
|
|
||
| impl Drop for StructWithPinDrop { | ||
| //~ MONO_ITEM fn <StructWithPinDrop as std::ops::Drop>::pin_drop | ||
| fn pin_drop(&pin mut self) {} | ||
| } | ||
|
|
||
| //~ MONO_ITEM fn std::ptr::drop_glue::<StructPinV2WithPinDrop> - shim(Some(StructPinV2WithPinDrop)) | ||
| #[pin_v2] | ||
| struct StructPinV2WithPinDrop { | ||
| x: i32, | ||
| } | ||
|
|
||
| impl Drop for StructPinV2WithPinDrop { | ||
| //~ MONO_ITEM fn <StructPinV2WithPinDrop as std::ops::Drop>::pin_drop | ||
| fn pin_drop(&pin mut self) {} | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change in this file looks correct to me.
View changes since the review