From da607e7614ec8fe981d0b84804b1f908b0616128 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Fri, 8 Jan 2021 11:03:02 +0000 Subject: [PATCH 1/2] The rust compiler is permissive of f32 and f64 suffix on integer literals. --- src/tokens.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tokens.md b/src/tokens.md index f329ce912..332e1a938 100644 --- a/src/tokens.md +++ b/src/tokens.md @@ -349,6 +349,7 @@ literal_. The grammar for recognizing the two kinds of literals is mixed. > INTEGER_SUFFIX :\ >       `u8` | `u16` | `u32` | `u64` | `u128` | `usize`\ >    | `i8` | `i16` | `i32` | `i64` | `i128` | `isize` +>    | `f32` | `f64` An _integer literal_ has one of four forms: @@ -368,7 +369,10 @@ Like any literal, an integer literal may be followed (immediately, without any spaces) by an _integer suffix_, which forcibly sets the type of the literal. The integer suffix must be the name of one of the integral types: `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, `i64`, -`u128`, `i128`, `usize`, or `isize`. +`u128`, `i128`, `f32`,`f64`, `usize`, or `isize`. + +Note the suffix of `f32` and `f64` enforce that an integer literal can coerced +into a float of repestive suffix type, which the lexer can be permissive of. The type of an _unsuffixed_ integer literal is determined by type inference: From 3075d291b9097bd6e916c52b8a1a5cae06cff225 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Fri, 8 Jan 2021 11:37:54 +0000 Subject: [PATCH 2/2] Update src/tokens.md Co-authored-by: bjorn3 --- src/tokens.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tokens.md b/src/tokens.md index 332e1a938..0c8f6d359 100644 --- a/src/tokens.md +++ b/src/tokens.md @@ -371,8 +371,8 @@ type of the literal. The integer suffix must be the name of one of the integral types: `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, `i64`, `u128`, `i128`, `f32`,`f64`, `usize`, or `isize`. -Note the suffix of `f32` and `f64` enforce that an integer literal can coerced -into a float of repestive suffix type, which the lexer can be permissive of. +Note the suffix of `f32` and `f64` ensures that the literal has a floating point type. +Even when it would otherwise be lexed as an integer. The type of an _unsuffixed_ integer literal is determined by type inference: