@@ -200,7 +200,7 @@ impl EarlyLintPass for Write {
200
200
} else if mac. node . path == sym ! ( print) {
201
201
span_lint ( cx, PRINT_STDOUT , mac. span , "use of `print!`" ) ;
202
202
if let ( Some ( fmt_str) , _) = check_tts ( cx, & mac. node . tts , false ) {
203
- if check_newlines ( & fmt_str) {
203
+ if terminating_newline ( & fmt_str) {
204
204
span_lint_and_then (
205
205
cx,
206
206
PRINT_WITH_NEWLINE ,
@@ -221,7 +221,7 @@ impl EarlyLintPass for Write {
221
221
}
222
222
} else if mac. node . path == sym ! ( write) {
223
223
if let ( Some ( fmt_str) , _) = check_tts ( cx, & mac. node . tts , true ) {
224
- if check_newlines ( & fmt_str) {
224
+ if terminating_newline ( & fmt_str) {
225
225
span_lint_and_then (
226
226
cx,
227
227
WRITE_WITH_NEWLINE ,
@@ -439,10 +439,15 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (O
439
439
/// Checks if the format string constains a single newline that terminates it.
440
440
///
441
441
/// Literal and escaped newlines are both checked (only literal for raw strings).
442
- fn check_newlines ( fmt_str : & FmtStr ) -> bool {
442
+ fn terminating_newline ( fmt_str : & FmtStr ) -> bool {
443
443
let s = & fmt_str. contents ;
444
444
445
445
if s. ends_with ( '\n' ) {
446
+ let last_but_one = s. chars ( ) . rev ( ) . nth ( 1 ) ;
447
+ if last_but_one == Some ( '\r' ) {
448
+ return false
449
+ }
450
+
446
451
return true ;
447
452
} else if let StrStyle :: Raw ( _) = fmt_str. style {
448
453
return false ;
0 commit comments