Skip to content

When AsyncDrop impl is empty, sync drop generated in elaborator #141328

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion compiler/rustc_mir_transform/src/elaborate_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,29 @@ where
span_bug!(span, "invalid `AsyncDrop` impl_source: {:?}", impl_source);
}
};
let drop_fn_def_id = tcx.associated_item_def_ids(drop_trait)[0];
// impl_item_refs may be empty if drop fn is not implemented in 'impl AsyncDrop for ...'
// (#140974).
// Such code will report error, so just generate sync drop here and return
let Some(drop_fn_def_id) =
tcx.associated_item_def_ids(drop_trait).into_iter().nth(0).copied()
else {
tcx.dcx().span_delayed_bug(
self.elaborator.body().span,
"AsyncDrop type without correct `async fn drop(...)`.",
);
self.elaborator.patch().patch_terminator(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delay a bug first, to make sure we actually emit an error somewhere

pin_obj_bb,
TerminatorKind::Drop {
place,
target: succ,
unwind: unwind.into_action(),
replace: false,
drop: None,
async_fut: None,
},
);
return pin_obj_bb;
};
let drop_fn = Ty::new_fn_def(tcx, drop_fn_def_id, trait_args);
let sig = drop_fn.fn_sig(tcx);
let sig = tcx.instantiate_bound_regions_with_erased(sig);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//@ known-bug: #140974
//@edition:2021
//@ edition: 2024
// Ex-ICE: #140974
#![crate_type = "lib"]
#![allow(incomplete_features)]
#![feature(async_drop)]
use core::future::AsyncDrop;

Expand All @@ -10,5 +12,6 @@ impl Drop for HasIncompleteAsyncDrop {
fn drop(&mut self) {}
}
impl AsyncDrop for HasIncompleteAsyncDrop {
//~^ ERROR: not all trait items implemented, missing: `drop` [E0046]
// not implemented yet..
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0046]: not all trait items implemented, missing: `drop`
--> $DIR/elaborate-index-out-of-bounds.rs:14:1
|
LL | impl AsyncDrop for HasIncompleteAsyncDrop {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `drop` in implementation
|
= help: implement the missing item: `async fn drop(self: Pin<&mut Self>) { todo!() }`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0046`.
Loading