Skip to content

Commit ffccdbf

Browse files
committed
Add wasm_c_abi future-incompat lint
1 parent 49b27f4 commit ffccdbf

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

compiler/rustc_lint_defs/src/builtin.rs

+19
Original file line numberDiff line numberDiff line change
@@ -4619,3 +4619,22 @@ declare_lint! {
46194619
reference: "issue #115010 <https://github.com/rust-lang/rust/issues/115010>",
46204620
};
46214621
}
4622+
4623+
declare_lint! {
4624+
/// The `wasm_c_abi` lint detects crate dependencies that are incompatible
4625+
/// with future versions of Rust that will emit spec-compliant C ABI.
4626+
///
4627+
/// ### Explanation
4628+
///
4629+
/// Rust has historically emitted non-spec-compliant C ABI. This has caused
4630+
/// incompatibilities between other compilers and Wasm targets. In a future
4631+
/// version of Rust this will be fixed and therefor dependencies relying on
4632+
/// the non-spec-compliant C ABI will stop functioning.
4633+
pub WASM_C_ABI,
4634+
Warn,
4635+
"detects dependencies that are incompatible with the Wasm C ABI",
4636+
@future_incompatible = FutureIncompatibleInfo {
4637+
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
4638+
reference: "issue #71871 <https://github.com/rust-lang/rust/issues/71871>",
4639+
};
4640+
}

compiler/rustc_metadata/src/creader.rs

+42-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ use proc_macro::bridge::client::ProcMacro;
3131
use std::error::Error;
3232
use std::ops::Fn;
3333
use std::path::Path;
34+
use std::str::FromStr;
3435
use std::time::Duration;
35-
use std::{cmp, iter};
36+
use std::{cmp, env, iter};
3637

3738
pub struct CStore {
3839
metadata_loader: Box<MetadataLoaderDyn>,
@@ -979,13 +980,53 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
979980
}
980981
}
981982

983+
fn report_future_incompatible_deps(&self, krate: &ast::Crate) {
984+
let name = self.tcx.crate_name(LOCAL_CRATE);
985+
986+
if name.as_str() == "wasm_bindgen" {
987+
if !env::var("CARGO_PKG_VERSION_MAJOR")
988+
.ok()
989+
.and_then(|major| u64::from_str(&major).ok())
990+
.is_some_and(|major| major == 0)
991+
{
992+
return;
993+
}
994+
if !env::var("CARGO_PKG_VERSION_MINOR")
995+
.ok()
996+
.and_then(|minor| u64::from_str(&minor).ok())
997+
.is_some_and(|minor| minor <= 2)
998+
{
999+
return;
1000+
}
1001+
if !env::var("CARGO_PKG_VERSION_PATCH")
1002+
.ok()
1003+
.and_then(|patch| u64::from_str(&patch).ok())
1004+
.is_some_and(|minor| minor <= 87)
1005+
{
1006+
return;
1007+
}
1008+
1009+
// Make a point span rather than covering the whole file
1010+
let span = krate.spans.inner_span.shrink_to_lo();
1011+
1012+
self.sess.parse_sess.buffer_lint(
1013+
lint::builtin::WASM_C_ABI,
1014+
span,
1015+
ast::CRATE_NODE_ID,
1016+
"older versions of the `wasm-bindgen` crate will be incompatible with future versions of Rust; \
1017+
please update to `wasm-bindgen` v0.2.88".to_string(),
1018+
);
1019+
}
1020+
}
1021+
9821022
pub fn postprocess(&mut self, krate: &ast::Crate) {
9831023
self.inject_forced_externs();
9841024
self.inject_profiler_runtime(krate);
9851025
self.inject_allocator_crate(krate);
9861026
self.inject_panic_runtime(krate);
9871027

9881028
self.report_unused_deps(krate);
1029+
self.report_future_incompatible_deps(krate);
9891030

9901031
info!("{:?}", CrateDump(&self.cstore));
9911032
}

0 commit comments

Comments
 (0)