Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b8db4a3

Browse files
committed
Add a test for different stages of lexer error reporting.
1 parent a00f8ba commit b8db4a3

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

src/test/ui/lexer/error-stage.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
macro_rules! sink {
2+
($($x:tt;)*) => {()}
3+
}
4+
5+
// The invalid literals are ignored because the macro consumes them.
6+
const _: () = sink! {
7+
"string"any_suffix; // OK
8+
10u123; // OK
9+
10.0f123; // OK
10+
0b10f32; // OK
11+
999340282366920938463463374607431768211455999; // OK
12+
};
13+
14+
// The invalid literals cause errors.
15+
#[cfg(FALSE)]
16+
fn configured_out() {
17+
"string"any_suffix; //~ ERROR suffixes on string literals are invalid
18+
10u123; //~ ERROR invalid width `123` for integer literal
19+
10.0f123; //~ ERROR invalid width `123` for float literal
20+
0b10f32; //~ ERROR binary float literal is not supported
21+
999340282366920938463463374607431768211455999; //~ ERROR integer literal is too large
22+
}
23+
24+
// The invalid literals cause errors.
25+
fn main() {
26+
"string"any_suffix; //~ ERROR suffixes on string literals are invalid
27+
10u123; //~ ERROR invalid width `123` for integer literal
28+
10.0f123; //~ ERROR invalid width `123` for float literal
29+
0b10f32; //~ ERROR binary float literal is not supported
30+
999340282366920938463463374607431768211455999; //~ ERROR integer literal is too large
31+
}

src/test/ui/lexer/error-stage.stderr

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
error: suffixes on string literals are invalid
2+
--> $DIR/error-stage.rs:17:5
3+
|
4+
LL | "string"any_suffix;
5+
| ^^^^^^^^^^^^^^^^^^ invalid suffix `any_suffix`
6+
7+
error: invalid width `123` for integer literal
8+
--> $DIR/error-stage.rs:18:5
9+
|
10+
LL | 10u123;
11+
| ^^^^^^
12+
|
13+
= help: valid widths are 8, 16, 32, 64 and 128
14+
15+
error: invalid width `123` for float literal
16+
--> $DIR/error-stage.rs:19:5
17+
|
18+
LL | 10.0f123;
19+
| ^^^^^^^^
20+
|
21+
= help: valid widths are 32 and 64
22+
23+
error: binary float literal is not supported
24+
--> $DIR/error-stage.rs:20:5
25+
|
26+
LL | 0b10f32;
27+
| ^^^^^^^ not supported
28+
29+
error: integer literal is too large
30+
--> $DIR/error-stage.rs:21:5
31+
|
32+
LL | 999340282366920938463463374607431768211455999;
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34+
35+
error: suffixes on string literals are invalid
36+
--> $DIR/error-stage.rs:26:5
37+
|
38+
LL | "string"any_suffix;
39+
| ^^^^^^^^^^^^^^^^^^ invalid suffix `any_suffix`
40+
41+
error: invalid width `123` for integer literal
42+
--> $DIR/error-stage.rs:27:5
43+
|
44+
LL | 10u123;
45+
| ^^^^^^
46+
|
47+
= help: valid widths are 8, 16, 32, 64 and 128
48+
49+
error: invalid width `123` for float literal
50+
--> $DIR/error-stage.rs:28:5
51+
|
52+
LL | 10.0f123;
53+
| ^^^^^^^^
54+
|
55+
= help: valid widths are 32 and 64
56+
57+
error: binary float literal is not supported
58+
--> $DIR/error-stage.rs:29:5
59+
|
60+
LL | 0b10f32;
61+
| ^^^^^^^ not supported
62+
63+
error: integer literal is too large
64+
--> $DIR/error-stage.rs:30:5
65+
|
66+
LL | 999340282366920938463463374607431768211455999;
67+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
68+
69+
error: aborting due to 10 previous errors
70+

0 commit comments

Comments
 (0)