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
This commit is contained in:
parent
1a51eb9cca
commit
0cdde6e5e0
39 changed files with 389 additions and 260 deletions
|
@ -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,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue