diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2019-01-20 14:25:53 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2019-01-20 14:25:53 -0800 |
| commit | 15bad8bbfd3125b1e94d04f274910e24d0bb63eb (patch) | |
| tree | 4533e892a8820a9ee4886d61f000e3f5e1faa6ef /src/libsyntax/parse/parser.rs | |
| parent | e387597a8f789ab6e37e6ce1bf67c8c45d4827c3 (diff) | |
| download | rust-15bad8bbfd3125b1e94d04f274910e24d0bb63eb.tar.gz rust-15bad8bbfd3125b1e94d04f274910e24d0bb63eb.zip | |
Extend incorrect float literal recovery to account for suffixes
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index fe6fa5e97d7..038d949d24a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1990,15 +1990,23 @@ impl<'a> Parser<'a> { result.unwrap() } token::Dot if self.look_ahead(1, |t| match t { - token::Literal(parse::token::Lit::Integer(_) , None) => true, + token::Literal(parse::token::Lit::Integer(_) , _) => true, _ => false, }) => { // recover from `let x = .4;` let lo = self.span; self.bump(); if let token::Literal( parse::token::Lit::Integer(val), - None + suffix, ) = self.token { + let suffix = suffix.and_then(|s| { + let s = s.as_str().get(); + if ["f32", "f64"].contains(&s) { + Some(s) + } else { + None + } + }).unwrap_or(""); self.bump(); let sp = lo.to(self.prev_span); let mut err = self.diagnostic() @@ -2006,11 +2014,15 @@ impl<'a> Parser<'a> { err.span_suggestion_with_applicability( sp, "must have an integer part", - format!("0.{}", val), + format!("0.{}{}", val, suffix), Applicability::MachineApplicable, ); err.emit(); - return Ok(ast::LitKind::Float(val, ast::FloatTy::F32)); + return Ok(match suffix { + "f32" => ast::LitKind::Float(val, ast::FloatTy::F32), + "f64" => ast::LitKind::Float(val, ast::FloatTy::F64), + _ => ast::LitKind::FloatUnsuffixed(val), + }); } else { unreachable!(); }; |
