mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-28 15:41:10 +00:00
Auto merge of #6079 - giraffate:print_stdout_in_build_rs, r=ebroto
Fix FP in `print_stdout` Fix #6041 This lint shouldn't be emitted in `build.rs` as `println!` and `print!` are used for the build script. changelog: none
This commit is contained in:
commit
b64d21d980
3 changed files with 34 additions and 2 deletions
|
@ -235,8 +235,19 @@ impl EarlyLintPass for Write {
|
|||
}
|
||||
|
||||
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &MacCall) {
|
||||
fn is_build_script(cx: &EarlyContext<'_>) -> bool {
|
||||
// Cargo sets the crate name for build scripts to `build_script_build`
|
||||
cx.sess
|
||||
.opts
|
||||
.crate_name
|
||||
.as_ref()
|
||||
.map_or(false, |crate_name| crate_name == "build_script_build")
|
||||
}
|
||||
|
||||
if mac.path == sym!(println) {
|
||||
span_lint(cx, PRINT_STDOUT, mac.span(), "use of `println!`");
|
||||
if !is_build_script(cx) {
|
||||
span_lint(cx, PRINT_STDOUT, mac.span(), "use of `println!`");
|
||||
}
|
||||
if let (Some(fmt_str), _) = self.check_tts(cx, mac.args.inner_tokens(), false) {
|
||||
if fmt_str.symbol == Symbol::intern("") {
|
||||
span_lint_and_sugg(
|
||||
|
@ -251,7 +262,9 @@ impl EarlyLintPass for Write {
|
|||
}
|
||||
}
|
||||
} else if mac.path == sym!(print) {
|
||||
span_lint(cx, PRINT_STDOUT, mac.span(), "use of `print!`");
|
||||
if !is_build_script(cx) {
|
||||
span_lint(cx, PRINT_STDOUT, mac.span(), "use of `print!`");
|
||||
}
|
||||
if let (Some(fmt_str), _) = self.check_tts(cx, mac.args.inner_tokens(), false) {
|
||||
if check_newlines(&fmt_str) {
|
||||
span_lint_and_then(
|
||||
|
|
7
clippy_workspace_tests/build.rs
Normal file
7
clippy_workspace_tests/build.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
#![deny(clippy::print_stdout)]
|
||||
|
||||
fn main() {
|
||||
// Test for #6041
|
||||
println!("Hello");
|
||||
print!("Hello");
|
||||
}
|
12
tests/ui/print_stdout_build_script.rs
Normal file
12
tests/ui/print_stdout_build_script.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
// compile-flags: --crate-name=build_script_build
|
||||
|
||||
#![warn(clippy::print_stdout)]
|
||||
|
||||
fn main() {
|
||||
// Fix #6041
|
||||
//
|
||||
// The `print_stdout` lint shouldn't emit in `build.rs`
|
||||
// as these methods are used for the build script.
|
||||
println!("Hello");
|
||||
print!("Hello");
|
||||
}
|
Loading…
Reference in a new issue