Skip to content

Commit e621e32

Browse files
committed
Add error message specific to \<carriage return>.
This can crop-up with a misconfigured editor or an unexpected interaction between version control and certain operating systems. Closes #11669.
1 parent ceff2ca commit e621e32

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/libsyntax/parse/lexer/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,13 @@ impl<'a> StringReader<'a> {
806806
if ascii_only { "unknown byte escape" }
807807
else { "unknown character escape" },
808808
c);
809+
if e == '\r' {
810+
let sp = codemap::mk_sp(escaped_pos, last_pos);
811+
self.span_diagnostic.span_help(
812+
sp,
813+
"this is an isolated carriage return; consider checking \
814+
your editor and version control settings.")
815+
}
809816
false
810817
}
811818
}

src/test/compile-fail/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trailing-carriage-return-in-string.rs -text

src/test/compile-fail/trailing-carriage-return-in-string.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-tidy-cr
12+
// Issue #11669
13+
14+
fn main() {
15+
// \r\n
16+
let ok = "This is \
17+
a test";
18+
// \r only
19+
let bad = "This is \ a test";
20+
//~^ ERROR unknown character escape: \r
21+
//~^^ HELP this is an isolated carriage return
22+
23+
}

0 commit comments

Comments
 (0)