Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,10 @@ declare_features! (
(unstable, associated_const_equality, "1.58.0", Some(92827)),
/// Allows associated type defaults.
(unstable, associated_type_defaults, "1.2.0", Some(29661)),
/// Allows implementing `AsyncDrop`.
/// Enables async drop code generation
(incomplete, async_drop, "1.88.0", Some(126482)),
/// Allows implementing `AsyncDrop`. For usage in standard library.
(incomplete, async_drop_lib, "1.88.0", Some(126482)),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this feature is not checked anywhere in the compiler in the first commit. Move this change to the second commit

/// Allows async functions to be called from `dyn Trait`.
(incomplete, async_fn_in_dyn_trait, "1.85.0", Some(133119)),
/// Allows `#[track_caller]` on async functions.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ fn configure_and_expand(
resolver.resolve_crate(&krate);

CStore::from_tcx(tcx).report_incompatible_target_modifiers(tcx, &krate);
CStore::from_tcx(tcx).report_incompatible_async_drop_feature(tcx, &krate);
krate
}

Expand Down
21 changes: 0 additions & 21 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,27 +461,6 @@ impl CStore {
}
}

// Report about async drop types in dependency if async drop feature is disabled
pub fn report_incompatible_async_drop_feature(&self, tcx: TyCtxt<'_>, krate: &Crate) {
if tcx.features().async_drop() {
return;
}
for (_cnum, data) in self.iter_crate_data() {
if data.is_proc_macro_crate() {
continue;
}
if data.has_async_drops() {
let extern_crate = data.name();
let local_crate = tcx.crate_name(LOCAL_CRATE);
tcx.dcx().emit_warn(errors::AsyncDropTypesInDependency {
span: krate.spans.inner_span.shrink_to_lo(),
extern_crate,
local_crate,
});
}
}
}

pub fn new(metadata_loader: Box<MetadataLoaderDyn>) -> CStore {
CStore {
metadata_loader,
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2022,10 +2022,6 @@ impl CrateMetadata {
self.root.header.hash
}

pub(crate) fn has_async_drops(&self) -> bool {
self.root.tables.adt_async_destructor.len > 0
}

fn num_def_ids(&self) -> usize {
self.root.tables.def_keys.size()
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
&& let hir::ItemKind::Impl(impl_) = item.kind
&& let Some(trait_) = impl_.of_trait
&& let Some(def_id) = trait_.trait_def_id()
&& self.tcx.is_lang_item(def_id, hir::LangItem::Drop)
&& (self.tcx.is_lang_item(def_id, hir::LangItem::Drop)
|| self.tcx.is_lang_item(def_id, hir::LangItem::AsyncDrop))
{
return;
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ symbols! {
async_closure,
async_drop,
async_drop_in_place,
async_drop_lib,
async_fn,
async_fn_in_dyn_trait,
async_fn_in_trait,
Expand Down
19 changes: 18 additions & 1 deletion library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ use core::clone::CloneToUninit;
use core::cmp::Ordering;
use core::error::{self, Error};
use core::fmt;
use core::future::Future;
use core::future::{AsyncDrop, Future};
use core::hash::{Hash, Hasher};
use core::marker::{Tuple, Unsize};
use core::mem::{self, SizedTypeProperties};
Expand Down Expand Up @@ -1669,6 +1669,23 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
}
}

#[unstable(feature = "async_drop_lib", issue = "126482")]
unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> AsyncDrop for Box<T, A> {
#[inline]
async fn drop(self: Pin<&mut Self>) {
// the T in the Box is dropped by the compiler before the destructor is run

let ptr = self.0;

unsafe {
let layout = Layout::for_value_raw(ptr.as_ptr());
if layout.size() != 0 {
self.1.deallocate(From::from(ptr.cast()), layout);
}
}
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Default> Default for Box<T> {
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
// tidy-alphabetical-start
#![feature(allocator_internals)]
#![feature(allow_internal_unstable)]
#![feature(async_drop_lib)]
#![feature(cfg_sanitize)]
#![feature(const_precise_live_drops)]
#![feature(coroutine_trait)]
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/future/async_drop.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![unstable(feature = "async_drop", issue = "126482")]
#![unstable(feature = "async_drop_lib", issue = "126482")]

#[allow(unused_imports)]
use core::future::Future;
Expand All @@ -24,7 +24,7 @@ use crate::task::{Context, Poll};
/// are `Copy` get implicitly duplicated by the compiler, making it very
/// hard to predict when, and how often destructors will be executed. As such,
/// these types cannot have destructors.
#[unstable(feature = "async_drop", issue = "126482")]
#[unstable(feature = "async_drop_lib", issue = "126482")]
#[lang = "async_drop"]
pub trait AsyncDrop {
/// Executes the async destructor for this type.
Expand All @@ -41,7 +41,7 @@ pub trait AsyncDrop {
}

/// Async drop.
#[unstable(feature = "async_drop", issue = "126482")]
#[unstable(feature = "async_drop_lib", issue = "126482")]
#[lang = "async_drop_in_place"]
pub async unsafe fn async_drop_in_place<T: ?Sized>(_to_drop: *mut T) {
// Code here does not matter - this is replaced by the
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod pending;
mod poll_fn;
mod ready;

#[unstable(feature = "async_drop", issue = "126482")]
#[unstable(feature = "async_drop_lib", issue = "126482")]
pub use async_drop::{AsyncDrop, async_drop_in_place};
#[stable(feature = "into_future", since = "1.64.0")]
pub use into_future::IntoFuture;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/tests/pass/async-drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// please consider modifying rustc's async drop test at
// `tests/ui/async-await/async-drop/async-drop-initial.rs`.

#![feature(async_drop, impl_trait_in_assoc_type)]
#![feature(async_drop, async_drop_lib, impl_trait_in_assoc_type)]
#![allow(incomplete_features, dead_code)]

// FIXME(zetanumbers): consider AsyncDestruct::async_drop cleanup tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Future `bar` with internal async drop `Foo` will have async drop itself.
// And we trying to drop this future in sync context (`block_on` func)

#![feature(async_drop)]
#![feature(async_drop, async_drop_lib)]
#![allow(incomplete_features)]

use std::mem::ManuallyDrop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Future `bar` with internal async drop `Foo` will have async drop itself.
// And we trying to drop this future in sync context (`block_on` func)

#![feature(async_drop)]
#![feature(async_drop, async_drop_lib)]
#![allow(incomplete_features)]

//@ edition: 2021
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-drop/async-drop-glue-array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// struct `Foo` has both sync and async drop.
// Struct `Complex` contains three `Foo` fields and has complex async drop glue.

#![feature(async_drop)]
#![feature(async_drop, async_drop_lib)]
#![allow(incomplete_features)]

use std::mem::ManuallyDrop;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-drop/async-drop-glue-generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//@ check-run-results
// struct `Foo` has both sync and async drop.

#![feature(async_drop)]
#![feature(async_drop, async_drop_lib)]
#![allow(incomplete_features)]

use std::mem::ManuallyDrop;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-drop/async-drop-glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// struct `Foo` has both sync and async drop.
// Struct `Complex` contains three `Foo` fields and has complex async drop glue.

#![feature(async_drop)]
#![feature(async_drop, async_drop_lib)]
#![allow(incomplete_features)]

use std::mem::ManuallyDrop;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-drop/async-drop-initial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// please consider modifying miri's async drop test at
// `src/tools/miri/tests/pass/async-drop.rs`.

#![feature(async_drop, impl_trait_in_assoc_type)]
#![feature(async_drop, async_drop_lib, impl_trait_in_assoc_type)]
#![allow(incomplete_features, dead_code)]

//@ edition: 2021
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-drop/async-drop-middle-drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Test async drop of coroutine `bar` (with internal async drop),
// stopped at the middle of execution, with AsyncDrop object Foo active.

#![feature(async_drop)]
#![feature(async_drop, async_drop_lib)]
#![allow(incomplete_features)]

//@ edition: 2021
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-drop/async-drop-open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// struct `Foo` has both sync and async drop.
// Struct `Complex` contains three `Foo` fields and one of them is moved out.

#![feature(async_drop)]
#![feature(async_drop, async_drop_lib)]
#![allow(incomplete_features)]

use std::mem::ManuallyDrop;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-drop/async-drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// struct `Foo` has both sync and async drop.
// Sync version is called in sync context, async version is called in async function.

#![feature(async_drop)]
#![feature(async_drop, async_drop_lib)]
#![allow(incomplete_features)]

use std::mem::ManuallyDrop;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ edition:2021

#![feature(async_drop)]
#![feature(async_drop, async_drop_lib)]
#![allow(incomplete_features)]

pub struct HasDrop;
Expand Down
37 changes: 0 additions & 37 deletions tests/ui/async-await/async-drop/dependency-dropped.rs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ui/async-await/async-drop/deref-later-projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//@ build-pass
//@ edition:2021
#![crate_type = "lib"]
#![feature(async_drop)]
#![feature(async_drop, async_drop_lib)]
#![allow(incomplete_features)]

use std::{future::AsyncDrop, pin::Pin};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Ex-ICE: #140974
#![crate_type = "lib"]
#![allow(incomplete_features)]
#![feature(async_drop)]
#![feature(async_drop, async_drop_lib)]
use core::future::AsyncDrop;

async fn fun(_: HasIncompleteAsyncDrop) {}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-drop/ex-ice-132103.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Fixed when re-work async drop to shim drop glue coroutine scheme.
//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes
//@ edition: 2018
#![feature(async_drop)]
#![feature(async_drop, async_drop_lib)]
#![allow(incomplete_features)]

use core::future::{async_drop_in_place, Future};
Expand Down
Loading