Skip to content

Commit 077ccfe

Browse files
committed
---
yaml --- r: 81712 b: refs/heads/master c: 807725b h: refs/heads/master v: v3
1 parent f97406f commit 077ccfe

15 files changed

+27
-267
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 7f826cb25ac3c1295a90bc8eb16e1cdf518fc6e1
2+
refs/heads/master: 807725b995a14c0aac5926c77636d3998b82dc9d
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6c08cc2db4f98e9f07ae7d50338396c4123c2f0a
55
refs/heads/try: 70152ff55722878cde684ee6462c14c65f2c4729

trunk/src/libstd/util.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,6 @@ pub fn id<T>(x: T) -> T { x }
2323
#[inline]
2424
pub fn ignore<T>(_x: T) { }
2525

26-
/// Sets `*ptr` to `new_value`, invokes `op()`, and then restores the
27-
/// original value of `*ptr`.
28-
///
29-
/// NB: This function accepts `@mut T` and not `&mut T` to avoid
30-
/// an obvious borrowck hazard. Typically passing in `&mut T` will
31-
/// cause borrow check errors because it freezes whatever location
32-
/// that `&mut T` is stored in (either statically or dynamically).
33-
#[inline]
34-
pub fn with<T,R>(
35-
ptr: @mut T,
36-
value: T,
37-
op: &fn() -> R) -> R
38-
{
39-
let prev = replace(ptr, value);
40-
let result = op();
41-
*ptr = prev;
42-
return result;
43-
}
44-
4526
/**
4627
* Swap the values at two mutable locations of the same type, without
4728
* deinitialising or copying either one.

trunk/src/libsyntax/parse/lexer.rs

Lines changed: 26 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -149,46 +149,6 @@ impl reader for TtReader {
149149
fn dup(@mut self) -> @mut reader { dup_tt_reader(self) as @mut reader }
150150
}
151151

152-
// report a lexical error spanning [`from_pos`, `to_pos`)
153-
fn fatal_span(rdr: @mut StringReader,
154-
from_pos: BytePos,
155-
to_pos: BytePos,
156-
m: ~str)
157-
-> ! {
158-
rdr.peek_span = codemap::mk_sp(from_pos, to_pos);
159-
rdr.fatal(m);
160-
}
161-
162-
// report a lexical error spanning [`from_pos`, `to_pos`), appending an
163-
// escaped character to the error message
164-
fn fatal_span_char(rdr: @mut StringReader,
165-
from_pos: BytePos,
166-
to_pos: BytePos,
167-
m: ~str,
168-
c: char)
169-
-> ! {
170-
let mut m = m;
171-
m.push_str(": ");
172-
char::escape_default(c, |c| m.push_char(c));
173-
fatal_span(rdr, from_pos, to_pos, m);
174-
}
175-
176-
// report a lexical error spanning [`from_pos`, `to_pos`), appending the
177-
// offending string to the error message
178-
fn fatal_span_verbose(rdr: @mut StringReader,
179-
from_pos: BytePos,
180-
to_pos: BytePos,
181-
m: ~str)
182-
-> ! {
183-
let mut m = m;
184-
m.push_str(": ");
185-
let s = rdr.src.slice(
186-
byte_offset(rdr, from_pos).to_uint(),
187-
byte_offset(rdr, to_pos).to_uint());
188-
m.push_str(s);
189-
fatal_span(rdr, from_pos, to_pos, m);
190-
}
191-
192152
// EFFECT: advance peek_tok and peek_span to refer to the next token.
193153
// EFFECT: update the interner, maybe.
194154
fn string_advance_token(r: @mut StringReader) {
@@ -367,8 +327,7 @@ fn consume_block_comment(rdr: @mut StringReader)
367327
bump(rdr);
368328
}
369329
if is_eof(rdr) {
370-
fatal_span(rdr, start_bpos, rdr.last_pos,
371-
~"unterminated block doc-comment");
330+
rdr.fatal(~"unterminated block doc-comment");
372331
} else {
373332
bump(rdr);
374333
bump(rdr);
@@ -385,12 +344,8 @@ fn consume_block_comment(rdr: @mut StringReader)
385344
}
386345
}
387346
} else {
388-
let start_bpos = rdr.last_pos - BytePos(2u);
389347
loop {
390-
if is_eof(rdr) {
391-
fatal_span(rdr, start_bpos, rdr.last_pos,
392-
~"unterminated block comment");
393-
}
348+
if is_eof(rdr) { rdr.fatal(~"unterminated block comment"); }
394349
if rdr.curr == '*' && nextch(rdr) == '/' {
395350
bump(rdr);
396351
bump(rdr);
@@ -406,7 +361,7 @@ fn consume_block_comment(rdr: @mut StringReader)
406361
if res.is_some() { res } else { consume_whitespace_and_comments(rdr) }
407362
}
408363

409-
fn scan_exponent(rdr: @mut StringReader, start_bpos: BytePos) -> Option<~str> {
364+
fn scan_exponent(rdr: @mut StringReader) -> Option<~str> {
410365
let mut c = rdr.curr;
411366
let mut rslt = ~"";
412367
if c == 'e' || c == 'E' {
@@ -420,10 +375,7 @@ fn scan_exponent(rdr: @mut StringReader, start_bpos: BytePos) -> Option<~str> {
420375
let exponent = scan_digits(rdr, 10u);
421376
if exponent.len() > 0u {
422377
return Some(rslt + exponent);
423-
} else {
424-
fatal_span(rdr, start_bpos, rdr.last_pos,
425-
~"scan_exponent: bad fp literal");
426-
}
378+
} else { rdr.fatal(~"scan_exponent: bad fp literal"); }
427379
} else { return None::<~str>; }
428380
}
429381

@@ -447,7 +399,6 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
447399
let mut base = 10u;
448400
let mut c = c;
449401
let mut n = nextch(rdr);
450-
let start_bpos = rdr.last_pos;
451402
if c == '0' && n == 'x' {
452403
bump(rdr);
453404
bump(rdr);
@@ -491,13 +442,11 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
491442
else { either::Right(ast::ty_u64) };
492443
}
493444
if num_str.len() == 0u {
494-
fatal_span(rdr, start_bpos, rdr.last_pos,
495-
~"no valid digits found for number");
445+
rdr.fatal(~"no valid digits found for number");
496446
}
497447
let parsed = match from_str_radix::<u64>(num_str, base as uint) {
498448
Some(p) => p,
499-
None => fatal_span(rdr, start_bpos, rdr.last_pos,
500-
~"int literal is too large")
449+
None => rdr.fatal(~"int literal is too large")
501450
};
502451

503452
match tp {
@@ -515,14 +464,12 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
515464
}
516465
if is_float {
517466
match base {
518-
16u => fatal_span(rdr, start_bpos, rdr.last_pos,
519-
~"hexadecimal float literal is not supported"),
520-
2u => fatal_span(rdr, start_bpos, rdr.last_pos,
521-
~"binary float literal is not supported"),
467+
16u => rdr.fatal(~"hexadecimal float literal is not supported"),
468+
2u => rdr.fatal(~"binary float literal is not supported"),
522469
_ => ()
523470
}
524471
}
525-
match scan_exponent(rdr, start_bpos) {
472+
match scan_exponent(rdr) {
526473
Some(ref s) => {
527474
is_float = true;
528475
num_str.push_str(*s);
@@ -560,13 +507,11 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
560507
return token::LIT_FLOAT_UNSUFFIXED(str_to_ident(num_str));
561508
} else {
562509
if num_str.len() == 0u {
563-
fatal_span(rdr, start_bpos, rdr.last_pos,
564-
~"no valid digits found for number");
510+
rdr.fatal(~"no valid digits found for number");
565511
}
566512
let parsed = match from_str_radix::<u64>(num_str, base as uint) {
567513
Some(p) => p,
568-
None => fatal_span(rdr, start_bpos, rdr.last_pos,
569-
~"int literal is too large")
514+
None => rdr.fatal(~"int literal is too large")
570515
};
571516

572517
debug!("lexing %s as an unsuffixed integer literal",
@@ -578,23 +523,19 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
578523
fn scan_numeric_escape(rdr: @mut StringReader, n_hex_digits: uint) -> char {
579524
let mut accum_int = 0;
580525
let mut i = n_hex_digits;
581-
let start_bpos = rdr.last_pos;
582526
while i != 0u {
583527
let n = rdr.curr;
528+
bump(rdr);
584529
if !is_hex_digit(n) {
585-
fatal_span_char(rdr, rdr.last_pos, rdr.pos,
586-
~"illegal character in numeric character escape",
587-
n);
530+
rdr.fatal(fmt!("illegal numeric character escape: %d", n as int));
588531
}
589-
bump(rdr);
590532
accum_int *= 16;
591533
accum_int += hex_digit_val(n);
592534
i -= 1u;
593535
}
594536
match char::from_u32(accum_int as u32) {
595537
Some(x) => x,
596-
None => fatal_span(rdr, start_bpos, rdr.last_pos,
597-
~"illegal numeric character escape")
538+
None => rdr.fatal(fmt!("illegal numeric character escape"))
598539
}
599540
}
600541

@@ -750,7 +691,6 @@ fn next_token_inner(rdr: @mut StringReader) -> token::Token {
750691
if c2 == '\\' {
751692
// '\X' for some X must be a character constant:
752693
let escaped = rdr.curr;
753-
let escaped_pos = rdr.last_pos;
754694
bump(rdr);
755695
match escaped {
756696
'n' => { c2 = '\n'; }
@@ -764,39 +704,32 @@ fn next_token_inner(rdr: @mut StringReader) -> token::Token {
764704
'u' => { c2 = scan_numeric_escape(rdr, 4u); }
765705
'U' => { c2 = scan_numeric_escape(rdr, 8u); }
766706
c2 => {
767-
fatal_span_char(rdr, escaped_pos, rdr.last_pos,
768-
~"unknown character escape", c2);
707+
rdr.fatal(fmt!("unknown character escape: %d", c2 as int));
769708
}
770709
}
771710
}
772711
if rdr.curr != '\'' {
773-
fatal_span_verbose(rdr,
774-
// Byte offsetting here is okay because the
775-
// character before position `start` is an
776-
// ascii single quote.
777-
start - BytePos(1u),
778-
rdr.last_pos,
779-
~"unterminated character constant");
712+
rdr.fatal(~"unterminated character constant");
780713
}
781714
bump(rdr); // advance curr past token
782715
return token::LIT_CHAR(c2 as u32);
783716
}
784717
'"' => {
785718
let mut accum_str = ~"";
786-
let start_bpos = rdr.last_pos;
719+
let n = rdr.last_pos;
787720
bump(rdr);
788721
while rdr.curr != '"' {
789722
if is_eof(rdr) {
790-
fatal_span(rdr, start_bpos, rdr.last_pos,
791-
~"unterminated double quote string");
723+
do with_str_from(rdr, n) |s| {
724+
rdr.fatal(fmt!("unterminated double quote string: %s", s));
725+
}
792726
}
793727

794728
let ch = rdr.curr;
795729
bump(rdr);
796730
match ch {
797731
'\\' => {
798732
let escaped = rdr.curr;
799-
let escaped_pos = rdr.last_pos;
800733
bump(rdr);
801734
match escaped {
802735
'n' => accum_str.push_char('\n'),
@@ -817,8 +750,7 @@ fn next_token_inner(rdr: @mut StringReader) -> token::Token {
817750
accum_str.push_char(scan_numeric_escape(rdr, 8u));
818751
}
819752
c2 => {
820-
fatal_span_char(rdr, escaped_pos, rdr.last_pos,
821-
~"unknown string escape", c2);
753+
rdr.fatal(fmt!("unknown string escape: %d", c2 as int));
822754
}
823755
}
824756
}
@@ -854,8 +786,11 @@ fn next_token_inner(rdr: @mut StringReader) -> token::Token {
854786
'^' => { return binop(rdr, token::CARET); }
855787
'%' => { return binop(rdr, token::PERCENT); }
856788
c => {
857-
fatal_span_char(rdr, rdr.last_pos, rdr.pos,
858-
~"unknown start of token", c);
789+
// So the error span points to the unrecognized character
790+
rdr.peek_span = codemap::mk_sp(rdr.last_pos, rdr.pos);
791+
let mut cs = ~"";
792+
char::escape_default(c, |c| cs.push_char(c));
793+
rdr.fatal(fmt!("unknown start of token: %s", cs));
859794
}
860795
}
861796
}

trunk/src/test/compile-fail/lex-bad-fp-lit.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

trunk/src/test/compile-fail/lex-hex-float-lit.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

trunk/src/test/compile-fail/lex-illegal-num-char-escape-2.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

trunk/src/test/compile-fail/lex-illegal-num-char-escape.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

trunk/src/test/compile-fail/lex-int-lit-too-large-2.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

trunk/src/test/compile-fail/lex-int-lit-too-large.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

trunk/src/test/compile-fail/lex-no-valid-digits-2.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

trunk/src/test/compile-fail/lex-no-valid-digits.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)