about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-07-22 15:32:29 +0200
committerGitHub <noreply@github.com>2019-07-22 15:32:29 +0200
commit376382aff3e8dad93b273ce7e9231ec7946edbe0 (patch)
treed182bd52c502a10edf0c1f8dfd172f1081685ac2 /src
parente178a1e1b3ef21f12d08db2e287b51a6cbf6bacd (diff)
parent647bf96b796a56e01557c14731719ab93f39063f (diff)
downloadrust-376382aff3e8dad93b273ce7e9231ec7946edbe0.tar.gz
rust-376382aff3e8dad93b273ce7e9231ec7946edbe0.zip
Rollup merge of #62870 - matklad:issue-62863, r=petrochenkov
fix lexing of comments with many \r

closes #62863
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax/parse/lexer/mod.rs2
-rw-r--r--src/test/ui/parser/several-carriage-returns-in-doc-comment.rs10
-rw-r--r--src/test/ui/parser/several-carriage-returns-in-doc-comment.stderr20
3 files changed, 31 insertions, 1 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs
index 317c49c7d35..bfefd9adbfe 100644
--- a/src/libsyntax/parse/lexer/mod.rs
+++ b/src/libsyntax/parse/lexer/mod.rs
@@ -226,7 +226,7 @@ impl<'a> StringReader<'a> {
                     loop {
                         idx = match string[idx..].find('\r') {
                             None => break,
-                            Some(it) => it + 1
+                            Some(it) => idx + it + 1
                         };
                         if string[idx..].chars().next() != Some('\n') {
                             self.err_span_(start + BytePos(idx as u32 - 1),
diff --git a/src/test/ui/parser/several-carriage-returns-in-doc-comment.rs b/src/test/ui/parser/several-carriage-returns-in-doc-comment.rs
new file mode 100644
index 00000000000..ee14c55d292
--- /dev/null
+++ b/src/test/ui/parser/several-carriage-returns-in-doc-comment.rs
@@ -0,0 +1,10 @@
+// Issue #62863
+// ignore-tidy-cr
+
+// Note: if you see ^M in this file, that's how your editor renders literal `\r`
+
+/// This do
c comment contains 
three isolated `\r`
 symbols
+//~^ ERROR bare CR not allowed in doc-comment
+//~| ERROR bare CR not allowed in doc-comment
+//~| ERROR bare CR not allowed in doc-comment
+fn main() {}
diff --git a/src/test/ui/parser/several-carriage-returns-in-doc-comment.stderr b/src/test/ui/parser/several-carriage-returns-in-doc-comment.stderr
new file mode 100644
index 00000000000..07066fc22e6
--- /dev/null
+++ b/src/test/ui/parser/several-carriage-returns-in-doc-comment.stderr
@@ -0,0 +1,20 @@
+error: bare CR not allowed in doc-comment
+  --> $DIR/several-carriage-returns-in-doc-comment.rs:6:12
+   |
+LL | /// This do
c comment contains 
three isolated `\r`
 symbols
+   |            ^
+
+error: bare CR not allowed in doc-comment
+  --> $DIR/several-carriage-returns-in-doc-comment.rs:6:32
+   |
+LL | /// This do
c comment contains 
three isolated `\r`
 symbols
+   |                               ^
+
+error: bare CR not allowed in doc-comment
+  --> $DIR/several-carriage-returns-in-doc-comment.rs:6:52
+   |
+LL | /// This do
c comment contains 
three isolated `\r`
 symbols
+   |                                                  ^
+
+error: aborting due to 3 previous errors
+