Skip to content

Commit e95315d

Browse files
authored
Rollup merge of #141253 - azhogin:azhogin/async-drop-feature-inconsistency-warning, r=oli-obk
Warning added when dependency crate has async drop types, and the feature is disabled In continue of #141031. When dependency crate has non-empty `adt_async_destructor` table in metadata, and `async_drop` feature is disabled for local crate, warning will be emitted. Test `dependency-dropped` has two revisions - with and without feature enabled. With feature enabled, async drop for dropee is executed ("Async drop" printed). Without the feature enabled, sync drop is executed ("Sync drop" printed) and warning is emitted. Warning example: ``` warning: found async drop types in dependecy `async_drop_dep`, but async_drop feature is disabled for `dependency_dropped` --> $DIR/dependency-dropped.rs:7:1 | LL | #![cfg_attr(with_feature, feature(async_drop))] | ^ | = help: if async drop type will be dropped in a crate without `feature(async_drop)`, sync Drop will be used ```
2 parents 421230f + 6105928 commit e95315d

File tree

9 files changed

+55
-1
lines changed

9 files changed

+55
-1
lines changed

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ fn configure_and_expand(
282282
resolver.resolve_crate(&krate);
283283

284284
CStore::from_tcx(tcx).report_incompatible_target_modifiers(tcx, &krate);
285+
CStore::from_tcx(tcx).report_incompatible_async_drop_feature(tcx, &krate);
285286
krate
286287
}
287288

compiler/rustc_metadata/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
metadata_as_needed_compatibility =
22
linking modifier `as-needed` is only compatible with `dylib` and `framework` linking kinds
33
4+
metadata_async_drop_types_in_dependency =
5+
found async drop types in dependecy `{$extern_crate}`, but async_drop feature is disabled for `{$local_crate}`
6+
.help = if async drop type will be dropped in a crate without `feature(async_drop)`, sync Drop will be used
7+
48
metadata_bad_panic_strategy =
59
the linked panic runtime `{$runtime}` is not compiled with this crate's panic strategy `{$strategy}`
610

compiler/rustc_metadata/src/creader.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,27 @@ impl CStore {
473473
}
474474
}
475475

476+
// Report about async drop types in dependency if async drop feature is disabled
477+
pub fn report_incompatible_async_drop_feature(&self, tcx: TyCtxt<'_>, krate: &Crate) {
478+
if tcx.features().async_drop() {
479+
return;
480+
}
481+
for (_cnum, data) in self.iter_crate_data() {
482+
if data.is_proc_macro_crate() {
483+
continue;
484+
}
485+
if data.has_async_drops() {
486+
let extern_crate = data.name();
487+
let local_crate = tcx.crate_name(LOCAL_CRATE);
488+
tcx.dcx().emit_warn(errors::AsyncDropTypesInDependency {
489+
span: krate.spans.inner_span.shrink_to_lo(),
490+
extern_crate,
491+
local_crate,
492+
});
493+
}
494+
}
495+
}
496+
476497
pub fn new(metadata_loader: Box<MetadataLoaderDyn>) -> CStore {
477498
CStore {
478499
metadata_loader,

compiler/rustc_metadata/src/errors.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,3 +811,13 @@ pub struct UnknownTargetModifierUnsafeAllowed {
811811
pub span: Span,
812812
pub flag_name: String,
813813
}
814+
815+
#[derive(Diagnostic)]
816+
#[diag(metadata_async_drop_types_in_dependency)]
817+
#[help]
818+
pub struct AsyncDropTypesInDependency {
819+
#[primary_span]
820+
pub span: Span,
821+
pub extern_crate: Symbol,
822+
pub local_crate: Symbol,
823+
}

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,10 @@ impl CrateMetadata {
19841984
self.root.header.hash
19851985
}
19861986

1987+
pub(crate) fn has_async_drops(&self) -> bool {
1988+
self.root.tables.adt_async_destructor.len > 0
1989+
}
1990+
19871991
fn num_def_ids(&self) -> usize {
19881992
self.root.tables.def_keys.size()
19891993
}

tests/ui/async-await/async-drop/dependency-dropped.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
//@ run-pass
22
//@ check-run-results
3+
//@ revisions: with_feature without_feature
34
//@ aux-build:async-drop-dep.rs
45
//@ edition:2021
56

6-
#![feature(async_drop)]
7+
#![cfg_attr(with_feature, feature(async_drop))]
8+
//[without_feature]~^ WARN found async drop types in dependecy `async_drop_dep`, but async_drop feature is disabled for `dependency_dropped`
9+
710
#![allow(incomplete_features)]
811

912
extern crate async_drop_dep;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sync drop
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: found async drop types in dependecy `async_drop_dep`, but async_drop feature is disabled for `dependency_dropped`
2+
--> $DIR/dependency-dropped.rs:7:1
3+
|
4+
LL | #![cfg_attr(with_feature, feature(async_drop))]
5+
| ^
6+
|
7+
= help: if async drop type will be dropped in a crate without `feature(async_drop)`, sync Drop will be used
8+
9+
warning: 1 warning emitted
10+

0 commit comments

Comments
 (0)