1 // This test is about the treatment of invalid literals. In particular, some
2 // literals are only considered invalid if they survive to HIR lowering.
4 // Literals with bad suffixes
5 // --------------------------
6 // Literals consist of a primary part and an optional suffix.
7 // https://doc.rust-lang.org/reference/tokens.html#suffixes says:
9 // Any kind of literal (string, integer, etc) with any suffix is valid as a
10 // token, and can be passed to a macro without producing an error. The macro
11 // itself will decide how to interpret such a token and whether to produce an
15 // macro_rules! blackhole { ($tt:tt) => () }
16 // blackhole!("string"suffix); // OK
19 // However, suffixes on literal tokens parsed as Rust code are restricted.
20 // Any suffixes are rejected on non-numeric literal tokens, and numeric
21 // literal tokens are accepted only with suffixes from the list below.
23 // Integer: u8, i8, u16, i16, u32, i32, u64, i64, u128, i128, usize, isize
24 // Floating-point: f32, f64
26 // This means that something like `"string"any_suffix` is a token accepted by
27 // the lexer, but rejected later for being an invalid combination of primary
30 // `0b10f32` is a similar case. `0b10` is a valid primary part that is a valid
31 // *integer* literal when no suffix is present. It only causes an error later
32 // when combined with the `f32` float suffix.
34 // However, `0b10.0f32` is different. It is rejected by the lexer because
35 // `0b10.0` is not a valid token even on its own.
37 // This difference is unfortunate, but it's baked into the language now.
39 // Too-large integer literals
40 // --------------------------
41 // https://doc.rust-lang.org/reference/tokens.html#integer-literals says that
42 // literals like `128_i8` and `256_u8` "are too big for their type, but are
43 // still valid tokens".
49 // The invalid literals are ignored because the macro consumes them. Except for
50 // `0b10.0f32` because it's a lexer error.
52 "string"any_suffix; // OK
56 0b10.0f32; //~ ERROR binary float literal is not supported
57 999340282366920938463463374607431768211455999; // OK
60 // The invalid literals used to cause errors, but this was changed by #102944.
61 // Except for `0b010.0f32`, because it's a lexer error.
64 "string"any_suffix; // OK
68 0b10.0f32; //~ ERROR binary float literal is not supported
69 999340282366920938463463374607431768211455999; // OK
72 // All the invalid literals cause errors.
74 "string"any_suffix; //~ ERROR suffixes on string literals are invalid
75 10u123; //~ ERROR invalid width `123` for integer literal
76 10.0f123; //~ ERROR invalid width `123` for float literal
77 0b10f32; //~ ERROR binary float literal is not supported
78 0b10.0f32; //~ ERROR binary float literal is not supported
79 999340282366920938463463374607431768211455999; //~ ERROR integer literal is too large