Allow explicit_write in tests (#15862)
Resolves rust-lang/rust-clippy#15780. I didn't get any feedback on that issue. So I hope it is okay that I charged ahead and addressed it. changelog: Allow `explicit_write` in tests
This commit is contained in:
commit
d230acd9cf
3 changed files with 15 additions and 1 deletions
|
|
@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
|
|||
use clippy_utils::macros::{FormatArgsStorage, format_args_inputs_span};
|
||||
use clippy_utils::res::MaybeResPath;
|
||||
use clippy_utils::source::snippet_with_applicability;
|
||||
use clippy_utils::{is_expn_of, sym};
|
||||
use clippy_utils::{is_expn_of, is_in_test, sym};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::{BindingMode, Block, BlockCheckMode, Expr, ExprKind, Node, PatKind, QPath, Stmt, StmtKind};
|
||||
|
|
@ -72,6 +72,11 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite {
|
|||
return;
|
||||
};
|
||||
|
||||
// Performing an explicit write in a test circumvent's libtest's capture of stdio and stdout.
|
||||
if is_in_test(cx.tcx, expr.hir_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
// ordering is important here, since `writeln!` uses `write!` internally
|
||||
let calling_macro = if is_expn_of(write_call.span, sym::writeln).is_some() {
|
||||
Some("writeln")
|
||||
|
|
|
|||
9
tests/ui/explicit_write_in_test.rs
Normal file
9
tests/ui/explicit_write_in_test.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
//@ check-pass
|
||||
#![warn(clippy::explicit_write)]
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
use std::io::Write;
|
||||
writeln!(std::io::stderr(), "I am an explicit write.").unwrap();
|
||||
eprintln!("I am not an explicit write.");
|
||||
}
|
||||
0
tests/ui/explicit_write_in_test.stderr
Normal file
0
tests/ui/explicit_write_in_test.stderr
Normal file
Loading…
Add table
Add a link
Reference in a new issue