From b8db4a34ef5b47b1f53ba4995509dda27e6e4bdf Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 28 Oct 2022 13:45:39 +1100 Subject: [PATCH] Add a test for different stages of lexer error reporting. --- src/test/ui/lexer/error-stage.rs | 31 ++++++++++++ src/test/ui/lexer/error-stage.stderr | 70 ++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 src/test/ui/lexer/error-stage.rs create mode 100644 src/test/ui/lexer/error-stage.stderr diff --git a/src/test/ui/lexer/error-stage.rs b/src/test/ui/lexer/error-stage.rs new file mode 100644 index 00000000000..05ae0e82bfb --- /dev/null +++ b/src/test/ui/lexer/error-stage.rs @@ -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 index 00000000000..024b7d94037 --- /dev/null +++ b/src/test/ui/lexer/error-stage.stderr @@ -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 +