@@ -2,6 +2,7 @@ use std::borrow::Cow;
2
2
use std:: ops:: Range ;
3
3
4
4
use crate :: utils:: { snippet_with_applicability, span_lint, span_lint_and_sugg, span_lint_and_then} ;
5
+ use if_chain:: if_chain;
5
6
use rustc_ast:: ast:: { Expr , ExprKind , Item , ItemKind , MacCall , StrLit , StrStyle } ;
6
7
use rustc_ast:: token;
7
8
use rustc_ast:: tokenstream:: TokenStream ;
@@ -11,7 +12,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass};
11
12
use rustc_parse:: parser;
12
13
use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
13
14
use rustc_span:: symbol:: Symbol ;
14
- use rustc_span:: { BytePos , Span } ;
15
+ use rustc_span:: { BytePos , FileName , Span } ;
15
16
16
17
declare_clippy_lint ! {
17
18
/// **What it does:** This lint warns when you use `println!("")` to
@@ -236,7 +237,15 @@ impl EarlyLintPass for Write {
236
237
237
238
fn check_mac ( & mut self , cx : & EarlyContext < ' _ > , mac : & MacCall ) {
238
239
if mac. path == sym ! ( println) {
239
- span_lint ( cx, PRINT_STDOUT , mac. span ( ) , "use of `println!`" ) ;
240
+ let filename = cx. sess . source_map ( ) . span_to_filename ( mac. span ( ) ) ;
241
+ if_chain ! {
242
+ if let FileName :: Real ( filename) = filename;
243
+ if let Some ( filename) = filename. local_path( ) . file_name( ) ;
244
+ if filename != "build.rs" ;
245
+ then {
246
+ span_lint( cx, PRINT_STDOUT , mac. span( ) , "use of `println!`" ) ;
247
+ }
248
+ }
240
249
if let ( Some ( fmt_str) , _) = self . check_tts ( cx, mac. args . inner_tokens ( ) , false ) {
241
250
if fmt_str. symbol == Symbol :: intern ( "" ) {
242
251
span_lint_and_sugg (
@@ -251,7 +260,15 @@ impl EarlyLintPass for Write {
251
260
}
252
261
}
253
262
} else if mac. path == sym ! ( print) {
254
- span_lint ( cx, PRINT_STDOUT , mac. span ( ) , "use of `print!`" ) ;
263
+ if_chain ! {
264
+ let filename = cx. sess. source_map( ) . span_to_filename( mac. span( ) ) ;
265
+ if let FileName :: Real ( filename) = filename;
266
+ if let Some ( filename) = filename. local_path( ) . file_name( ) ;
267
+ if filename != "build.rs" ;
268
+ then {
269
+ span_lint( cx, PRINT_STDOUT , mac. span( ) , "use of `print!`" ) ;
270
+ }
271
+ }
255
272
if let ( Some ( fmt_str) , _) = self . check_tts ( cx, mac. args . inner_tokens ( ) , false ) {
256
273
if check_newlines ( & fmt_str) {
257
274
span_lint_and_then (
0 commit comments