Skip to content

Commit 66416bc

Browse files
committed
Document that literals with any suffixes are valid as tokens
1 parent 73f7cba commit 66416bc

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/tokens.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ evaluated (primarily) at compile time.
3232
|----------------------------------------------|-----------------|-------------|-------------|---------------------|
3333
| [Character](#character-literals) | `'H'` | 0 | All Unicode | [Quote](#quote-escapes) & [ASCII](#ascii-escapes) & [Unicode](#unicode-escapes) |
3434
| [String](#string-literals) | `"hello"` | 0 | All Unicode | [Quote](#quote-escapes) & [ASCII](#ascii-escapes) & [Unicode](#unicode-escapes) |
35-
| [Raw](#raw-string-literals) | `r#"hello"#` | 0 or more\* | All Unicode | `N/A` |
35+
| [Raw string](#raw-string-literals) | `r#"hello"#` | 0 or more\* | All Unicode | `N/A` |
3636
| [Byte](#byte-literals) | `b'H'` | 0 | All ASCII | [Quote](#quote-escapes) & [Byte](#byte-escapes) |
3737
| [Byte string](#byte-string-literals) | `b"hello"` | 0 | All ASCII | [Quote](#quote-escapes) & [Byte](#byte-escapes) |
3838
| [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.
8888

8989
#### Suffixes
9090

91+
Any kind of literal (string, integer, etc) with any suffix is valid as a token,
92+
and can be passed to a macro without producing an error.
93+
The macro itself will decide how to interpret such a token and whether to produce an error or not.
94+
95+
```rust
96+
macro_rules! blackhole { ($tt:tt) => () }
97+
98+
blackhole!("string"suffix); // OK
99+
```
100+
101+
However, suffixes on literal tokens parsed as Rust code are restricted.
102+
Any suffixes are rejected on non-numeric literal tokens,
103+
and numeric literal tokens are accepted only with suffixes from the list below.
104+
91105
| Integer | Floating-point |
92106
|---------|----------------|
93107
| `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, `i64`, `u128`, `i128`, `usize`, `isize` | `f32`, `f64` |

0 commit comments

Comments
 (0)