Skip to content

Async drop - type instead of async drop fn, fixes #140484 #141677

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
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
16 changes: 14 additions & 2 deletions compiler/rustc_mir_transform/src/elaborate_drop.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{fmt, iter, mem};

use rustc_abi::{FIRST_VARIANT, FieldIdx, VariantIdx};
use rustc_hir::def::DefKind;
use rustc_hir::lang_items::LangItem;
use rustc_index::Idx;
use rustc_middle::mir::*;
Expand Down Expand Up @@ -254,8 +255,19 @@ where
// 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()
let Some(drop_fn_def_id) = tcx
.associated_item_def_ids(drop_trait)
.first()
.and_then(|def_id| {
if tcx.def_kind(def_id) == DefKind::AssocFn
&& tcx.check_args_compatible(*def_id, trait_args)
{
Some(def_id)
} else {
None
}
})
.copied()
else {
tcx.dcx().span_delayed_bug(
self.elaborator.body().span,
Expand Down
14 changes: 0 additions & 14 deletions tests/crashes/140484.rs

This file was deleted.

14 changes: 0 additions & 14 deletions tests/crashes/140500.rs

This file was deleted.

16 changes: 16 additions & 0 deletions tests/ui/async-await/async-drop/type-parameter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ edition: 2024
// ex-ice: #140500
#![crate_type = "lib"]
#![feature(async_drop)]
#![expect(incomplete_features)]
use std::future::AsyncDrop;
struct A;
impl Drop for A {
fn drop(&mut self) {}
}
impl AsyncDrop for A {
fn drop(_wrong: impl Sized) {} //~ ERROR: method `drop` has a `self: Pin<&mut Self>` declaration in the trait, but not in the impl
}
async fn bar() {
A;
}
11 changes: 11 additions & 0 deletions tests/ui/async-await/async-drop/type-parameter.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0186]: method `drop` has a `self: Pin<&mut Self>` declaration in the trait, but not in the impl
--> $DIR/type-parameter.rs:12:5
|
LL | fn drop(_wrong: impl Sized) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `self: Pin<&mut Self>` in impl
|
= note: `drop` from trait: `fn(Pin<&mut Self>) -> impl Future<Output = ()>`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0186`.
18 changes: 18 additions & 0 deletions tests/ui/async-await/async-drop/unexpected-sort.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Ex-ice: #140484
//@ edition: 2024
#![crate_type = "lib"]
#![allow(incomplete_features)]
#![allow(non_camel_case_types)]
#![feature(async_drop)]
use std::future::AsyncDrop;
struct a;
impl Drop for a { //~ ERROR: not all trait items implemented, missing: `drop`
fn b() {} //~ ERROR: method `b` is not a member of trait `Drop`
}
impl AsyncDrop for a { //~ ERROR: not all trait items implemented, missing: `drop`
type c = ();
//~^ ERROR: type `c` is not a member of trait `AsyncDrop`
}
async fn bar() {
a;
}
32 changes: 32 additions & 0 deletions tests/ui/async-await/async-drop/unexpected-sort.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
error[E0407]: method `b` is not a member of trait `Drop`
--> $DIR/unexpected-sort.rs:10:5
|
LL | fn b() {}
| ^^^^^^^^^ not a member of trait `Drop`

error[E0437]: type `c` is not a member of trait `AsyncDrop`
--> $DIR/unexpected-sort.rs:13:5
|
LL | type c = ();
| ^^^^^^^^^^^^ not a member of trait `AsyncDrop`

error[E0046]: not all trait items implemented, missing: `drop`
--> $DIR/unexpected-sort.rs:9:1
|
LL | impl Drop for a {
| ^^^^^^^^^^^^^^^ missing `drop` in implementation
|
= help: implement the missing item: `fn drop(&mut self) { todo!() }`

error[E0046]: not all trait items implemented, missing: `drop`
--> $DIR/unexpected-sort.rs:12:1
|
LL | impl AsyncDrop for a {
| ^^^^^^^^^^^^^^^^^^^^ missing `drop` in implementation
|
= help: implement the missing item: `async fn drop(self: Pin<&mut Self>) { todo!() }`

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0046, E0407, E0437.
For more information about an error, try `rustc --explain E0046`.
Loading