From 66416bc317488b44e372b24ed24d7cf3470043ee Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 31 May 2019 16:14:33 +0400 Subject: [PATCH 1/3] Document that literals with any suffixes are valid as tokens --- src/tokens.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/tokens.md b/src/tokens.md index 1962f3f97..079db3337 100644 --- a/src/tokens.md +++ b/src/tokens.md @@ -32,7 +32,7 @@ evaluated (primarily) at compile time. |----------------------------------------------|-----------------|-------------|-------------|---------------------| | [Character](#character-literals) | `'H'` | 0 | All Unicode | [Quote](#quote-escapes) & [ASCII](#ascii-escapes) & [Unicode](#unicode-escapes) | | [String](#string-literals) | `"hello"` | 0 | All Unicode | [Quote](#quote-escapes) & [ASCII](#ascii-escapes) & [Unicode](#unicode-escapes) | -| [Raw](#raw-string-literals) | `r#"hello"#` | 0 or more\* | All Unicode | `N/A` | +| [Raw string](#raw-string-literals) | `r#"hello"#` | 0 or more\* | All Unicode | `N/A` | | [Byte](#byte-literals) | `b'H'` | 0 | All ASCII | [Quote](#quote-escapes) & [Byte](#byte-escapes) | | [Byte string](#byte-string-literals) | `b"hello"` | 0 | All ASCII | [Quote](#quote-escapes) & [Byte](#byte-escapes) | | [Raw byte string](#raw-byte-string-literals) | `br#"hello"#` | 0 or more\* | All ASCII | `N/A` | @@ -88,6 +88,20 @@ evaluated (primarily) at compile time. #### Suffixes +Any kind of literal (string, integer, etc) with any suffix is valid as a token, +and can be passed to a macro without producing an error. +The macro itself will decide how to interpret such a token and whether to produce an error or not. + +```rust +macro_rules! blackhole { ($tt:tt) => () } + +blackhole!("string"suffix); // OK +``` + +However, suffixes on literal tokens parsed as Rust code are restricted. +Any suffixes are rejected on non-numeric literal tokens, +and numeric literal tokens are accepted only with suffixes from the list below. + | Integer | Floating-point | |---------|----------------| | `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, `i64`, `u128`, `i128`, `usize`, `isize` | `f32`, `f64` | From fbff649d31cc47e7be12ba8d4abbb8ed13a24bf1 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 31 May 2019 16:45:33 +0400 Subject: [PATCH 2/3] Tell what a literal suffix is --- src/tokens.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/tokens.md b/src/tokens.md index 079db3337..f661e505b 100644 --- a/src/tokens.md +++ b/src/tokens.md @@ -88,6 +88,9 @@ evaluated (primarily) at compile time. #### Suffixes +Suffix is a non-raw identifier immediately (without whitespace) +following the primary part of a literal. + Any kind of literal (string, integer, etc) with any suffix is valid as a token, and can be passed to a macro without producing an error. The macro itself will decide how to interpret such a token and whether to produce an error or not. From 8c75c7a2106896b461f531ced01dbfe5e837d1cf Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 31 May 2019 16:49:09 +0400 Subject: [PATCH 3/3] Update src/tokens.md Co-Authored-By: Mazdak Farrokhzad --- src/tokens.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tokens.md b/src/tokens.md index f661e505b..d75ae765c 100644 --- a/src/tokens.md +++ b/src/tokens.md @@ -88,7 +88,7 @@ evaluated (primarily) at compile time. #### Suffixes -Suffix is a non-raw identifier immediately (without whitespace) +A suffix is a non-raw identifier immediately (without whitespace) following the primary part of a literal. Any kind of literal (string, integer, etc) with any suffix is valid as a token,