summary refs log tree commit diff
path: root/src/libsyntax/parse/parser.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-01-27 22:52:32 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-01-30 08:52:44 -0800
commit0cdde6e5e015ee6f6d9381ab624a312af7c9b069 (patch)
treeaf04df6cb8bb0ce50036333bae380602d42fabe2 /src/libsyntax/parse/parser.rs
parent1a51eb9cca3ae5f815825096de4dfbdc9267f735 (diff)
downloadrust-0cdde6e5e015ee6f6d9381ab624a312af7c9b069.tar.gz
rust-0cdde6e5e015ee6f6d9381ab624a312af7c9b069.zip
std: Stabilize FromStr and parse
This commits adds an associated type to the `FromStr` trait representing an
error payload for parses which do not succeed. The previous return value,
`Option<Self>` did not allow for this form of payload. After the associated type
was added, the following attributes were applied:

* `FromStr` is now stable
* `FromStr::Err` is now stable
* `FromStr::from_str` is now stable
* `StrExt::parse` is now stable
* `FromStr for bool` is now stable
* `FromStr for $float` is now stable
* `FromStr for $integral` is now stable
* Errors returned from stable `FromStr` implementations are stable
* Errors implement `Display` and `Error` (both impl blocks being `#[stable]`)

Closes #15138
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
-rw-r--r--src/libsyntax/parse/parser.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index c4224db8e18..d99095eeba3 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -2459,7 +2459,7 @@ impl<'a> Parser<'a> {
                     hi = self.span.hi;
                     self.bump();
 
-                    let index = n.as_str().parse::<usize>();
+                    let index = n.as_str().parse::<usize>().ok();
                     match index {
                         Some(n) => {
                             let id = spanned(dot, hi, n);
@@ -2479,7 +2479,7 @@ impl<'a> Parser<'a> {
                     self.span_err(last_span,
                                   &format!("unexpected token: `{}`", n.as_str())[]);
                     if fstr.chars().all(|x| "0123456789.".contains_char(x)) {
-                        let float = match fstr.parse::<f64>() {
+                        let float = match fstr.parse::<f64>().ok() {
                             Some(f) => f,
                             None => continue,
                         };