]> git.lizzy.rs Git - rust.git/commitdiff
Add a test for different stages of lexer error reporting.
authorNicholas Nethercote <n.nethercote@gmail.com>
Fri, 28 Oct 2022 02:45:39 +0000 (13:45 +1100)
committerNicholas Nethercote <n.nethercote@gmail.com>
Tue, 15 Nov 2022 22:02:19 +0000 (09:02 +1100)
src/test/ui/lexer/error-stage.rs [new file with mode: 0644]
src/test/ui/lexer/error-stage.stderr [new file with mode: 0644]

diff --git a/src/test/ui/lexer/error-stage.rs b/src/test/ui/lexer/error-stage.rs
new file mode 100644 (file)
index 0000000..05ae0e8
--- /dev/null
@@ -0,0 +1,31 @@
+macro_rules! sink {
+    ($($x:tt;)*) => {()}
+}
+
+// The invalid literals are ignored because the macro consumes them.
+const _: () = sink! {
+    "string"any_suffix; // OK
+    10u123; // OK
+    10.0f123; // OK
+    0b10f32; // OK
+    999340282366920938463463374607431768211455999; // OK
+};
+
+// The invalid literals cause errors.
+#[cfg(FALSE)]
+fn configured_out() {
+    "string"any_suffix; //~ ERROR suffixes on string literals are invalid
+    10u123; //~ ERROR invalid width `123` for integer literal
+    10.0f123; //~ ERROR invalid width `123` for float literal
+    0b10f32; //~ ERROR binary float literal is not supported
+    999340282366920938463463374607431768211455999; //~ ERROR integer literal is too large
+}
+
+// The invalid literals cause errors.
+fn main() {
+    "string"any_suffix; //~ ERROR suffixes on string literals are invalid
+    10u123; //~ ERROR invalid width `123` for integer literal
+    10.0f123; //~ ERROR invalid width `123` for float literal
+    0b10f32; //~ ERROR binary float literal is not supported
+    999340282366920938463463374607431768211455999; //~ ERROR integer literal is too large
+}
diff --git a/src/test/ui/lexer/error-stage.stderr b/src/test/ui/lexer/error-stage.stderr
new file mode 100644 (file)
index 0000000..024b7d9
--- /dev/null
@@ -0,0 +1,70 @@
+error: suffixes on string literals are invalid
+  --> $DIR/error-stage.rs:17:5
+   |
+LL |     "string"any_suffix;
+   |     ^^^^^^^^^^^^^^^^^^ invalid suffix `any_suffix`
+
+error: invalid width `123` for integer literal
+  --> $DIR/error-stage.rs:18:5
+   |
+LL |     10u123;
+   |     ^^^^^^
+   |
+   = help: valid widths are 8, 16, 32, 64 and 128
+
+error: invalid width `123` for float literal
+  --> $DIR/error-stage.rs:19:5
+   |
+LL |     10.0f123;
+   |     ^^^^^^^^
+   |
+   = help: valid widths are 32 and 64
+
+error: binary float literal is not supported
+  --> $DIR/error-stage.rs:20:5
+   |
+LL |     0b10f32;
+   |     ^^^^^^^ not supported
+
+error: integer literal is too large
+  --> $DIR/error-stage.rs:21:5
+   |
+LL |     999340282366920938463463374607431768211455999;
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: suffixes on string literals are invalid
+  --> $DIR/error-stage.rs:26:5
+   |
+LL |     "string"any_suffix;
+   |     ^^^^^^^^^^^^^^^^^^ invalid suffix `any_suffix`
+
+error: invalid width `123` for integer literal
+  --> $DIR/error-stage.rs:27:5
+   |
+LL |     10u123;
+   |     ^^^^^^
+   |
+   = help: valid widths are 8, 16, 32, 64 and 128
+
+error: invalid width `123` for float literal
+  --> $DIR/error-stage.rs:28:5
+   |
+LL |     10.0f123;
+   |     ^^^^^^^^
+   |
+   = help: valid widths are 32 and 64
+
+error: binary float literal is not supported
+  --> $DIR/error-stage.rs:29:5
+   |
+LL |     0b10f32;
+   |     ^^^^^^^ not supported
+
+error: integer literal is too large
+  --> $DIR/error-stage.rs:30:5
+   |
+LL |     999340282366920938463463374607431768211455999;
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 10 previous errors
+