From ba2de1ccb86707ea682a9655a71d52023eed731d Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Mon, 22 Jan 2024 16:00:50 +0800 Subject: [PATCH] deny rw warnings Signed-off-by: Bugen Zhao --- ci/scripts/check-dylint.sh | 6 +++++- lints/src/lib.rs | 20 +++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ci/scripts/check-dylint.sh b/ci/scripts/check-dylint.sh index 1c9d9067fdd61..22f3e11b53da7 100755 --- a/ci/scripts/check-dylint.sh +++ b/ci/scripts/check-dylint.sh @@ -7,4 +7,8 @@ source ci/scripts/common.sh unset RUSTC_WRAPPER echo "--- Run dylint check (dev, all features)" -cargo dylint --all -- --all-targets --all-features --locked +# Instead of `-D warnings`, we only deny warnings from our own lints. This is because... +# - Warnings from `check` or `clippy` are already checked in `check.sh`. +# - The toolchain used for linting could be slightly different from the one used to +# compile RisingWave. Warnings from `rustc` itself may produce false positives. +DYLINT_RUSTFLAGS="-D rw_warnings" cargo dylint --all -- --all-targets --all-features --locked diff --git a/lints/src/lib.rs b/lints/src/lib.rs index 813c84780a81d..d2c78515272f4 100644 --- a/lints/src/lib.rs +++ b/lints/src/lib.rs @@ -45,12 +45,26 @@ pub fn register_lints(_sess: &rustc_session::Session, lint_store: &mut rustc_lin // -- End lint registration -- - // Register all lints in the `rw::all` group. - let all_lints = lint_store + // Register lints into groups. + // Note: use `rw_` instead of `rw::` to avoid "error[E0602]: unknown lint tool: `rw`". + register_group(lint_store, "rw_all", |_| true); + register_group(lint_store, "rw_warnings", |l| { + l.default_level >= rustc_lint::Level::Warn + }); +} + +fn register_group( + lint_store: &mut rustc_lint::LintStore, + name: &'static str, + filter_predicate: impl Fn(&rustc_lint::Lint) -> bool, +) { + let lints = lint_store .get_lints() .iter() .filter(|l| l.name.starts_with("rw::")) + .filter(|l| filter_predicate(l)) .map(|l| rustc_lint::LintId::of(l)) .collect(); - lint_store.register_group(true, "rw::all", None, all_lints); + + lint_store.register_group(true, name, None, lints); }