aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoffry Song <goffrie@gmail.com>2024-04-10 17:15:13 +0900
committerGitHub <noreply@github.com>2024-04-10 08:15:13 +0000
commit8802f4ddbd2393ff87c494cb52c2e29313201a61 (patch)
tree4ba670bf1a9b0e958b060e6b7b79ef1a165c0254
parent6489c3881f950a3bdb6f057d899c19b0b186e87f (diff)
downloadbazelbuild-rules_rust-8802f4ddbd2393ff87c494cb52c2e29313201a61.tar.gz
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>
-rw-r--r--rust/private/clippy.bzl7
-rwxr-xr-xtest/clippy/clippy_failure_test.sh1
2 files changed, 4 insertions, 4 deletions
diff --git a/rust/private/clippy.bzl b/rust/private/clippy.bzl
index 579bbcca..f11a818f 100644
--- a/rust/private/clippy.bzl
+++ b/rust/private/clippy.bzl
@@ -141,12 +141,11 @@ def _clippy_aspect_impl(target, ctx):
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 0accd986..a805d47d 100755
--- a/test/clippy/clippy_failure_test.sh
+++ b/test/clippy/clippy_failure_test.sh
@@ -102,6 +102,7 @@ EOF
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.