Skip to content

Commit d0104d0

Browse files
committed
auto merge of #16659 : brson/rust/slowparse, r=alexcrichton
Note that this contains a 9.5MB test file, but it should compress thoroughly.
2 parents 58bb603 + f59cfd9 commit d0104d0

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

src/libsyntax/parse/mod.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,21 @@ pub fn str_lit(lit: &str) -> String {
412412
loop {
413413
match chars.next() {
414414
Some((i, c)) => {
415-
let em = error(i);
416415
match c {
417416
'\\' => {
418-
if chars.peek().expect(em.as_slice()).val1() == '\n' {
417+
let ch = chars.peek().unwrap_or_else(|| {
418+
fail!("{}", error(i).as_slice())
419+
}).val1();
420+
421+
if ch == '\n' {
419422
eat(&mut chars);
420-
} else if chars.peek().expect(em.as_slice()).val1() == '\r' {
423+
} else if ch == '\r' {
421424
chars.next();
422-
if chars.peek().expect(em.as_slice()).val1() != '\n' {
425+
let ch = chars.peek().unwrap_or_else(|| {
426+
fail!("{}", error(i).as_slice())
427+
}).val1();
428+
429+
if ch != '\n' {
423430
fail!("lexer accepted bare CR");
424431
}
425432
eat(&mut chars);
@@ -433,7 +440,11 @@ pub fn str_lit(lit: &str) -> String {
433440
}
434441
},
435442
'\r' => {
436-
if chars.peek().expect(em.as_slice()).val1() != '\n' {
443+
let ch = chars.peek().unwrap_or_else(|| {
444+
fail!("{}", error(i).as_slice())
445+
}).val1();
446+
447+
if ch != '\n' {
437448
fail!("lexer accepted bare CR");
438449
}
439450
chars.next();

src/test/run-pass/slowparse-bstring.rs

Lines changed: 15 additions & 0 deletions
Large diffs are not rendered by default.

src/test/run-pass/slowparse-string.rs

Lines changed: 15 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)