Skip to content

Commit 138f646

Browse files
committed
---
yaml --- r: 95268 b: refs/heads/dist-snap c: 6db8899 h: refs/heads/master v: v3
1 parent b379b93 commit 138f646

File tree

5 files changed

+74
-13
lines changed

5 files changed

+74
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 0cca359da690d357ae3447c0e18cf5fab4ee8732
9+
refs/heads/dist-snap: 6db889996be763ca9e429982894eb0e8d9d002cc
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libstd/num/num.rs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,7 @@ pub trait ToPrimitive {
404404

405405
/// Converts the value of `self` to an `u64`.
406406
#[inline]
407-
fn to_u64(&self) -> Option<u64> {
408-
self.to_u64().and_then(|x| x.to_u64())
409-
}
407+
fn to_u64(&self) -> Option<u64>;
410408

411409
/// Converts the value of `self` to an `f32`.
412410
#[inline]
@@ -1481,4 +1479,51 @@ mod tests {
14811479
assert_eq!(third.checked_mul(&3), Some(third * 3));
14821480
assert_eq!(third.checked_mul(&4), None);
14831481
}
1482+
1483+
1484+
#[deriving(Eq)]
1485+
struct Value { x: int }
1486+
1487+
impl ToPrimitive for Value {
1488+
fn to_i64(&self) -> Option<i64> { self.x.to_i64() }
1489+
fn to_u64(&self) -> Option<u64> { self.x.to_u64() }
1490+
}
1491+
1492+
impl FromPrimitive for Value {
1493+
fn from_i64(n: i64) -> Option<Value> { Some(Value { x: n as int }) }
1494+
fn from_u64(n: u64) -> Option<Value> { Some(Value { x: n as int }) }
1495+
}
1496+
1497+
#[test]
1498+
fn test_to_primitive() {
1499+
let value = Value { x: 5 };
1500+
assert_eq!(value.to_int(), Some(5));
1501+
assert_eq!(value.to_i8(), Some(5));
1502+
assert_eq!(value.to_i16(), Some(5));
1503+
assert_eq!(value.to_i32(), Some(5));
1504+
assert_eq!(value.to_i64(), Some(5));
1505+
assert_eq!(value.to_uint(), Some(5));
1506+
assert_eq!(value.to_u8(), Some(5));
1507+
assert_eq!(value.to_u16(), Some(5));
1508+
assert_eq!(value.to_u32(), Some(5));
1509+
assert_eq!(value.to_u64(), Some(5));
1510+
assert_eq!(value.to_f32(), Some(5f32));
1511+
assert_eq!(value.to_f64(), Some(5f64));
1512+
}
1513+
1514+
#[test]
1515+
fn test_from_primitive() {
1516+
assert_eq!(from_int(5), Some(Value { x: 5 }));
1517+
assert_eq!(from_i8(5), Some(Value { x: 5 }));
1518+
assert_eq!(from_i16(5), Some(Value { x: 5 }));
1519+
assert_eq!(from_i32(5), Some(Value { x: 5 }));
1520+
assert_eq!(from_i64(5), Some(Value { x: 5 }));
1521+
assert_eq!(from_uint(5), Some(Value { x: 5 }));
1522+
assert_eq!(from_u8(5), Some(Value { x: 5 }));
1523+
assert_eq!(from_u16(5), Some(Value { x: 5 }));
1524+
assert_eq!(from_u32(5), Some(Value { x: 5 }));
1525+
assert_eq!(from_u64(5), Some(Value { x: 5 }));
1526+
assert_eq!(from_f32(5f32), Some(Value { x: 5 }));
1527+
assert_eq!(from_f64(5f64), Some(Value { x: 5 }));
1528+
}
14841529
}

branches/dist-snap/src/libsyntax/parse/parser.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ pub fn Parser(sess: @mut ParseSess,
309309
quote_depth: @mut 0,
310310
obsolete_set: @mut HashSet::new(),
311311
mod_path_stack: @mut ~[],
312+
open_braces: @mut ~[]
312313
}
313314
}
314315

@@ -337,6 +338,8 @@ pub struct Parser {
337338
obsolete_set: @mut HashSet<ObsoleteSyntax>,
338339
/// Used to determine the path to externally loaded source files
339340
mod_path_stack: @mut ~[@str],
341+
/// Stack of spans of open delimiters. Used for error message.
342+
open_braces: @mut ~[Span]
340343
}
341344

342345
#[unsafe_destructor]
@@ -2024,12 +2027,18 @@ impl Parser {
20242027

20252028
match *self.token {
20262029
token::EOF => {
2027-
self.fatal("file ended with unbalanced delimiters");
2030+
for sp in self.open_braces.iter() {
2031+
self.span_note(*sp, "Did you mean to close this delimiter?");
2032+
}
2033+
// There shouldn't really be a span, but it's easier for the test runner
2034+
// if we give it one
2035+
self.fatal("This file contains an un-closed delimiter ");
20282036
}
20292037
token::LPAREN | token::LBRACE | token::LBRACKET => {
20302038
let close_delim = token::flip_delimiter(&*self.token);
20312039

20322040
// Parse the open delimiter.
2041+
(*self.open_braces).push(*self.span);
20332042
let mut result = ~[parse_any_tt_tok(self)];
20342043

20352044
let trees =
@@ -2040,6 +2049,7 @@ impl Parser {
20402049

20412050
// Parse the close delimiter.
20422051
result.push(parse_any_tt_tok(self));
2052+
self.open_braces.pop();
20432053

20442054
tt_delim(@mut result)
20452055
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2013 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+
static foo: int = 2; } //~ ERROR incorrect close delimiter:
12+

branches/dist-snap/src/test/compile-fail/issue-2354.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test
12-
/*
13-
Ideally, the error about the missing close brace in foo would be reported
14-
near the corresponding open brace. But currently it's reported at the end.
15-
xfailed for now (see Issue #2354)
16-
*/
17-
fn foo() { //~ ERROR this open brace is not closed
11+
fn foo() { //~ NOTE Did you mean to close this delimiter?
1812
match Some(x) {
1913
Some(y) { fail!(); }
2014
None { fail!(); }
@@ -25,4 +19,4 @@ fn bar() {
2519
while (i < 1000) {}
2620
}
2721

28-
fn main() {}
22+
fn main() {} //~ ERROR This file contains an un-closed delimiter

0 commit comments

Comments
 (0)