mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-15 10:07:30 +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
@ -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) {
|
||||
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) {
|
||||
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 New Issue
Block a user