diff options
| author | Andrew Zhogin <andrew.zhogin@gmail.com> | 2025-05-19 21:14:28 +0700 |
|---|---|---|
| committer | Andrew Zhogin <andrew.zhogin@gmail.com> | 2025-05-19 21:38:07 +0700 |
| commit | 61059282eb9ea1f37804790b182e5821337924b4 (patch) | |
| tree | a13dd5743b40836b431c051fe824162d9c0891d4 /compiler/rustc_metadata | |
| parent | 7068c8bd81c73db264c544f75a43158555567848 (diff) | |
| download | rust-61059282eb9ea1f37804790b182e5821337924b4.tar.gz rust-61059282eb9ea1f37804790b182e5821337924b4.zip | |
Warning added when dependency crate has async drop types, and the feature is disabled
Diffstat (limited to 'compiler/rustc_metadata')
| -rw-r--r-- | compiler/rustc_metadata/messages.ftl | 4 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/creader.rs | 21 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/errors.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/decoder.rs | 4 |
4 files changed, 39 insertions, 0 deletions
diff --git a/compiler/rustc_metadata/messages.ftl b/compiler/rustc_metadata/messages.ftl index d997ba198ac..cac8f34b0fa 100644 --- a/compiler/rustc_metadata/messages.ftl +++ b/compiler/rustc_metadata/messages.ftl @@ -1,6 +1,10 @@ metadata_as_needed_compatibility = linking modifier `as-needed` is only compatible with `dylib` and `framework` linking kinds +metadata_async_drop_types_in_dependency = + found async drop types in dependecy `{$extern_crate}`, but async_drop feature is disabled for `{$local_crate}` + .help = if async drop type will be dropped in a crate without `feature(async_drop)`, sync Drop will be used + metadata_bad_panic_strategy = the linked panic runtime `{$runtime}` is not compiled with this crate's panic strategy `{$strategy}` diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 07fb2de8a3e..c7e9a2936f5 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -473,6 +473,27 @@ 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, diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index c45daeda85d..16f59793e63 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -811,3 +811,13 @@ pub struct UnknownTargetModifierUnsafeAllowed { pub span: Span, pub flag_name: String, } + +#[derive(Diagnostic)] +#[diag(metadata_async_drop_types_in_dependency)] +#[help] +pub struct AsyncDropTypesInDependency { + #[primary_span] + pub span: Span, + pub extern_crate: Symbol, + pub local_crate: Symbol, +} diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index bd813cadedc..2e4352ca532 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1984,6 +1984,10 @@ 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() } |
