@@ -200,7 +200,7 @@ impl EarlyLintPass for Write {
200200 } else if mac. node . path == sym ! ( print) {
201201 span_lint ( cx, PRINT_STDOUT , mac. span , "use of `print!`" ) ;
202202 if let ( Some ( fmt_str) , _) = check_tts ( cx, & mac. node . tts , false ) {
203- if check_newlines ( & fmt_str) {
203+ if terminating_newline ( & fmt_str) {
204204 span_lint_and_then (
205205 cx,
206206 PRINT_WITH_NEWLINE ,
@@ -221,7 +221,7 @@ impl EarlyLintPass for Write {
221221 }
222222 } else if mac. node . path == sym ! ( write) {
223223 if let ( Some ( fmt_str) , _) = check_tts ( cx, & mac. node . tts , true ) {
224- if check_newlines ( & fmt_str) {
224+ if terminating_newline ( & fmt_str) {
225225 span_lint_and_then (
226226 cx,
227227 WRITE_WITH_NEWLINE ,
@@ -439,10 +439,15 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (O
439439/// Checks if the format string constains a single newline that terminates it.
440440///
441441/// 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 {
443443 let s = & fmt_str. contents ;
444444
445445 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+
446451 return true ;
447452 } else if let StrStyle :: Raw ( _) = fmt_str. style {
448453 return false ;
0 commit comments