@@ -84,17 +84,27 @@ impl LateLintPass for Pass {
84
84
// Check print! with format string ending in "\n".
85
85
if_let_chain ! { [
86
86
name == "print" ,
87
+
87
88
// ensure we're calling Arguments::new_v1
88
89
args. len( ) == 1 ,
89
90
let ExprCall ( ref args_fun, ref args_args) = args[ 0 ] . node,
90
91
let ExprPath ( _, ref args_path) = args_fun. node,
91
92
match_path( args_path, & paths:: FMT_ARGUMENTS_NEWV1 ) ,
92
93
args_args. len( ) == 2 ,
94
+ let ExprAddrOf ( _, ref match_expr) = args_args[ 1 ] . node,
95
+ let ExprMatch ( ref args, _, _) = match_expr. node,
96
+ let ExprTup ( ref args) = args. node,
97
+
93
98
// collect the format string parts and check the last one
94
99
let Some ( fmtstrs) = get_argument_fmtstr_parts( cx, & args_args[ 0 ] ) ,
95
100
let Some ( last_str) = fmtstrs. last( ) ,
96
- let Some ( last_chr) = last_str. chars( ) . last( ) ,
97
- last_chr == '\n'
101
+ let Some ( '\n' ) = last_str. chars( ) . last( ) ,
102
+
103
+ // "foo{}bar" is made into two strings + one argument,
104
+ // if the format string starts with `{}` (eg. "{}foo"),
105
+ // the string array is prepended an empty string "".
106
+ // We only want to check the last string after any `{}`:
107
+ args. len( ) < fmtstrs. len( ) ,
98
108
] , {
99
109
span_lint( cx, PRINT_WITH_NEWLINE , span,
100
110
"using `print!()` with a format string that ends in a \
0 commit comments