diff options
| author | bors <bors@rust-lang.org> | 2023-08-11 01:41:30 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-08-11 01:41:30 +0000 |
| commit | e286f25ec058276c2c83b809f18eaa7e3db52d99 (patch) | |
| tree | 35e2bbf6d673427ffa9c054a3109e17ce7cb2491 /tests/ui/fmt | |
| parent | a9b2c6a0ce700ee6d1cdcab3f3c1f7997ae726d1 (diff) | |
| parent | d003fd985976ce65d446243df182c935e5395334 (diff) | |
| download | rust-e286f25ec058276c2c83b809f18eaa7e3db52d99.tar.gz rust-e286f25ec058276c2c83b809f18eaa7e3db52d99.zip | |
Auto merge of #114507 - sebastiantoh:issue-114235, r=jackh726
Add suggestion to quote inlined format argument as string literal Fixes #114235
Diffstat (limited to 'tests/ui/fmt')
| -rw-r--r-- | tests/ui/fmt/suggest-inline-args.rs | 28 | ||||
| -rw-r--r-- | tests/ui/fmt/suggest-inline-args.stderr | 57 |
2 files changed, 85 insertions, 0 deletions
diff --git a/tests/ui/fmt/suggest-inline-args.rs b/tests/ui/fmt/suggest-inline-args.rs new file mode 100644 index 00000000000..515335ed9f4 --- /dev/null +++ b/tests/ui/fmt/suggest-inline-args.rs @@ -0,0 +1,28 @@ +mod foo { + pub fn bar() -> i32 { + 1 + } +} + +fn bar() -> i32 { + 2 +} + +fn main() { + let stderr = 3; + eprintln!({stderr}); + //~^ ERROR format argument must be a string literal + //~| HELP quote your inlined format argument to use as string literal + eprintln!({1}); + //~^ ERROR format argument must be a string literal + //~| HELP you might be missing a string literal to format with + eprintln!({foo::bar()}); + //~^ ERROR format argument must be a string literal + //~| HELP you might be missing a string literal to format with + eprintln!({bar()}); + //~^ ERROR format argument must be a string literal + //~| HELP you might be missing a string literal to format with + eprintln!({1; 2}); + //~^ ERROR format argument must be a string literal + //~| HELP you might be missing a string literal to format with +} diff --git a/tests/ui/fmt/suggest-inline-args.stderr b/tests/ui/fmt/suggest-inline-args.stderr new file mode 100644 index 00000000000..cf70568cf3f --- /dev/null +++ b/tests/ui/fmt/suggest-inline-args.stderr @@ -0,0 +1,57 @@ +error: format argument must be a string literal + --> $DIR/suggest-inline-args.rs:13:15 + | +LL | eprintln!({stderr}); + | ^^^^^^^^ + | +help: quote your inlined format argument to use as string literal + | +LL | eprintln!("{stderr}"); + | + + + +error: format argument must be a string literal + --> $DIR/suggest-inline-args.rs:16:15 + | +LL | eprintln!({1}); + | ^^^ + | +help: you might be missing a string literal to format with + | +LL | eprintln!("{}", {1}); + | +++++ + +error: format argument must be a string literal + --> $DIR/suggest-inline-args.rs:19:15 + | +LL | eprintln!({foo::bar()}); + | ^^^^^^^^^^^^ + | +help: you might be missing a string literal to format with + | +LL | eprintln!("{}", {foo::bar()}); + | +++++ + +error: format argument must be a string literal + --> $DIR/suggest-inline-args.rs:22:15 + | +LL | eprintln!({bar()}); + | ^^^^^^^ + | +help: you might be missing a string literal to format with + | +LL | eprintln!("{}", {bar()}); + | +++++ + +error: format argument must be a string literal + --> $DIR/suggest-inline-args.rs:25:15 + | +LL | eprintln!({1; 2}); + | ^^^^^^ + | +help: you might be missing a string literal to format with + | +LL | eprintln!("{}", {1; 2}); + | +++++ + +error: aborting due to 5 previous errors + |
