Skip to content

Commit a66b372

Browse files
committed
auto merge of #10306 : alexcrichton/rust/issue-9970-better, r=huonw
There were a few ambiguous error messages which look like they could have cropped up from either the rust compiler for the format string parser. To differentiate, the prefix 'invalid format string' is now added in front of all format string errors. cc #9970
2 parents efaf730 + 2fc337a commit a66b372

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/libstd/fmt/parse.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl<'self> Iterator<Piece<'self>> for Parser<'self> {
180180
}
181181
Some((_, '}')) if self.depth == 0 => {
182182
self.cur.next();
183-
self.err(~"unmatched `}` found");
183+
self.err("unmatched `}` found");
184184
None
185185
}
186186
Some((_, '}')) | None => { None }
@@ -204,8 +204,8 @@ impl<'self> Parser<'self> {
204204
/// Notifies of an error. The message doesn't actually need to be of type
205205
/// ~str, but I think it does when this eventually uses conditions so it
206206
/// might as well start using it now.
207-
fn err(&self, msg: ~str) {
208-
parse_error::cond.raise(msg);
207+
fn err(&self, msg: &str) {
208+
parse_error::cond.raise("invalid format string: " + msg);
209209
}
210210

211211
/// Optionally consumes the specified character. If the character is not at
@@ -230,11 +230,11 @@ impl<'self> Parser<'self> {
230230
self.cur.next();
231231
}
232232
Some((_, other)) => {
233-
parse_error::cond.raise(
233+
self.err(
234234
format!("expected `{}` but found `{}`", c, other));
235235
}
236236
None => {
237-
parse_error::cond.raise(
237+
self.err(
238238
format!("expected `{}` but string was terminated", c));
239239
}
240240
}
@@ -267,7 +267,7 @@ impl<'self> Parser<'self> {
267267
c
268268
}
269269
None => {
270-
self.err(~"expected an escape sequence, but format string was \
270+
self.err("expected an escape sequence, but format string was \
271271
terminated");
272272
' '
273273
}
@@ -411,7 +411,7 @@ impl<'self> Parser<'self> {
411411
Some(self.plural())
412412
}
413413
"" => {
414-
self.err(~"expected method after comma");
414+
self.err("expected method after comma");
415415
return None;
416416
}
417417
method => {
@@ -430,7 +430,7 @@ impl<'self> Parser<'self> {
430430
self.ws();
431431
let selector = self.word();
432432
if selector == "" {
433-
self.err(~"cannot have an empty selector");
433+
self.err("cannot have an empty selector");
434434
break
435435
}
436436
self.must_consume('{');
@@ -440,7 +440,7 @@ impl<'self> Parser<'self> {
440440
self.must_consume('}');
441441
if selector == "other" {
442442
if !other.is_none() {
443-
self.err(~"multiple `other` statements in `select");
443+
self.err("multiple `other` statements in `select");
444444
}
445445
other = Some(pieces);
446446
} else {
@@ -456,7 +456,7 @@ impl<'self> Parser<'self> {
456456
let other = match other {
457457
Some(arm) => { arm }
458458
None => {
459-
self.err(~"`select` statement must provide an `other` case");
459+
self.err("`select` statement must provide an `other` case");
460460
~[]
461461
}
462462
};
@@ -488,7 +488,7 @@ impl<'self> Parser<'self> {
488488
match self.integer() {
489489
Some(i) => { offset = Some(i); }
490490
None => {
491-
self.err(~"offset must be an integer");
491+
self.err("offset must be an integer");
492492
}
493493
}
494494
}
@@ -506,8 +506,8 @@ impl<'self> Parser<'self> {
506506
match self.integer() {
507507
Some(i) => Right(i),
508508
None => {
509-
self.err(~"plural `=` selectors must be followed by an \
510-
integer");
509+
self.err("plural `=` selectors must be followed by an \
510+
integer");
511511
Right(0)
512512
}
513513
}
@@ -538,7 +538,7 @@ impl<'self> Parser<'self> {
538538
self.must_consume('}');
539539
if isother {
540540
if !other.is_none() {
541-
self.err(~"multiple `other` statements in `select");
541+
self.err("multiple `other` statements in `select");
542542
}
543543
other = Some(pieces);
544544
} else {
@@ -554,7 +554,7 @@ impl<'self> Parser<'self> {
554554
let other = match other {
555555
Some(arm) => { arm }
556556
None => {
557-
self.err(~"`plural` statement must provide an `other` case");
557+
self.err("`plural` statement must provide an `other` case");
558558
~[]
559559
}
560560
};

0 commit comments

Comments
 (0)