mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-17 05:25:37 +03:00
Rollup merge of #48235 - varkor:parse-float-lonely-exponent, r=alexcrichton
Make ".e0" not parse as 0.0 This forces floats to have either a digit before the separating point, or after. Thus `".e0"` is invalid like `"."`, when using `parse()`. Fixes #40654. As mentioned in the issue, this is technically a breaking change... but clearly incorrect behaviour at present.
This commit is contained in:
@@ -73,7 +73,8 @@ pub fn parse_decimal(s: &str) -> ParseResult {
|
||||
}
|
||||
Some(&b'.') => {
|
||||
let (fractional, s) = eat_digits(&s[1..]);
|
||||
if integral.is_empty() && fractional.is_empty() && s.is_empty() {
|
||||
if integral.is_empty() && fractional.is_empty() {
|
||||
// We require at least a single digit before or after the point.
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,6 +101,12 @@ fn lonely_dot() {
|
||||
assert!(".".parse::<f64>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exponentiated_dot() {
|
||||
assert!(".e0".parse::<f32>().is_err());
|
||||
assert!(".e0".parse::<f64>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lonely_sign() {
|
||||
assert!("+".parse::<f32>().is_err());
|
||||
|
||||
Reference in New Issue
Block a user