-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The lexer already ignores CRLF in between tokens, but it doesn't properly handle carriage returns inside strings and doc comments. Teach it to treat CRLF as LF inside these tokens, and to disallow carriage returns that are not followed by linefeeds. This includes handling an escaped CRLF inside a regular string token the same way it handles an escaped LF. This is technically a breaking change, as bare carriage returns are no longer allowed, and CRLF sequences are now treated as LF inside strings and doc comments, but it's very unlikely to actually affect any real-world code. This change is necessary to have Rust code compile on Windows the same way it does on Unix. The mozilla/rust repository explicitly sets eol=lf for Rust source files, but other Rust repositories don't. Notably, rust-http cannot be compiled on Windows without converting the CRLF line endings back to LF. [breaking-change]
- Loading branch information
Showing
5 changed files
with
215 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/test/compile-fail/lex-bare-cr-string-literal-doc-comment.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lexer-crlf-line-endings-string-literal-doc-comment.rs -text |
44 changes: 44 additions & 0 deletions
44
src/test/run-pass/lexer-crlf-line-endings-string-literal-doc-comment.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// ignore-tidy-cr ignore-license | ||
// ignore-tidy-cr (repeated again because of tidy bug) | ||
// license is ignored because tidy can't handle the CRLF here properly. | ||
|
||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// NB: this file needs CRLF line endings. The .gitattributes file in | ||
// this directory should enforce it. | ||
|
||
// ignore-pretty | ||
|
||
/// Doc comment that ends in CRLF | ||
pub fn foo() {} | ||
|
||
/** Block doc comment that | ||
* contains CRLF characters | ||
*/ | ||
pub fn bar() {} | ||
|
||
fn main() { | ||
let s = "string | ||
literal"; | ||
assert_eq!(s, "string\nliteral"); | ||
|
||
let s = "literal with \ | ||
escaped newline"; | ||
assert_eq!(s, "literal with escaped newline"); | ||
|
||
let s = r"string | ||
literal"; | ||
assert_eq!(s, "string\nliteral"); | ||
|
||
// validate that our source file has CRLF endings | ||
let source = include_str!("lexer-crlf-line-endings-string-literal-doc-comment.rs"); | ||
assert!(source.contains("string\r\nliteral")); | ||
} |
8a8e497
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from cmr
at lilyball@8a8e497
8a8e497
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging kballard/rust/lexer_crlf_handling = 8a8e497 into auto
8a8e497
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kballard/rust/lexer_crlf_handling = 8a8e497 merged ok, testing candidate = f8c9aec
8a8e497
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/6289
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/6288
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/5384
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/5393
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/6386
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/5475
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/5482
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/6389
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/5474
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/5479
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android/builds/5540
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/3275
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/6379
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/5490
8a8e497
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = f8c9aec