clippy: use --cap-lints=warn; apply clippy_flags when capture_output=True (#2451)
Instead of using `-Wclippy::all` to override deny-by-default clippy
lints into warnings, use `--cap-lints=warn`.
This allows users to provide whatever lint flags they like and the
compiler will still succeed.
Co-authored-by: Krasimir Georgiev <krasimir@google.com>
Co-authored-by: scentini <rosica@google.com>
diff --git a/rust/private/clippy.bzl b/rust/private/clippy.bzl
index 579bbcc..f11a818 100644
--- a/rust/private/clippy.bzl
+++ b/rust/private/clippy.bzl
@@ -141,12 +141,11 @@
args.process_wrapper_flags.add("--stderr-file", clippy_out)
if clippy_flags:
- fail("""Combining @rules_rust//:clippy_flags with @rules_rust//:capture_clippy_output=true is currently not supported.
-See https://github.com/bazelbuild/rules_rust/pull/1264#discussion_r853241339 for more detail.""")
+ args.rustc_flags.add_all(clippy_flags)
# If we are capturing the output, we want the build system to be able to keep going
- # and consume the output. Some clippy lints are denials, so we treat them as warnings.
- args.rustc_flags.add("-Wclippy::all")
+ # and consume the output. Some clippy lints are denials, so we cap everything at warn.
+ args.rustc_flags.add("--cap-lints=warn")
else:
# A marker file indicating clippy has executed successfully.
# This file is necessary because "ctx.actions.run" mandates an output.
diff --git a/test/clippy/clippy_failure_test.sh b/test/clippy/clippy_failure_test.sh
index 0accd98..a805d47 100755
--- a/test/clippy/clippy_failure_test.sh
+++ b/test/clippy/clippy_failure_test.sh
@@ -102,6 +102,7 @@
check_build_result $BUILD_OK bad_static_library_clippy $CAPTURE_OUTPUT
check_build_result $BUILD_OK bad_test_clippy $CAPTURE_OUTPUT
check_build_result $BUILD_OK bad_proc_macro_clippy $CAPTURE_OUTPUT
+ check_build_result $BUILD_OK ok_library_clippy $CAPTURE_OUTPUT --@rules_rust//:clippy_flags=-Dclippy::pedantic
# Test that we can make the ok_library_clippy fail when using an extra config file.
# Proves that the config file is used and overrides default settings.