summaryrefslogtreecommitdiffstats
path: root/tests/ui/fmt
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:24 +0000
commit023939b627b7dc93b01471f7d41fb8553ddb4ffa (patch)
tree60fc59477c605c72b0a1051409062ddecc43f877 /tests/ui/fmt
parentAdding debian version 1.72.1+dfsg1-1. (diff)
downloadrustc-023939b627b7dc93b01471f7d41fb8553ddb4ffa.tar.xz
rustc-023939b627b7dc93b01471f7d41fb8553ddb4ffa.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/fmt')
-rw-r--r--tests/ui/fmt/closing-brace-as-fill.rs8
-rw-r--r--tests/ui/fmt/closing-brace-as-fill.stderr12
-rw-r--r--tests/ui/fmt/format-string-error-2.stderr26
-rw-r--r--tests/ui/fmt/format-string-error.stderr2
-rw-r--r--tests/ui/fmt/format-string-wrong-order.stderr4
-rw-r--r--tests/ui/fmt/ifmt-bad-arg.stderr2
-rw-r--r--tests/ui/fmt/suggest-inline-args.rs28
-rw-r--r--tests/ui/fmt/suggest-inline-args.stderr57
8 files changed, 122 insertions, 17 deletions
diff --git a/tests/ui/fmt/closing-brace-as-fill.rs b/tests/ui/fmt/closing-brace-as-fill.rs
new file mode 100644
index 000000000..6ad257f94
--- /dev/null
+++ b/tests/ui/fmt/closing-brace-as-fill.rs
@@ -0,0 +1,8 @@
+// issue: 112732
+
+// `}` is typoed since it is interpreted as a fill character rather than a closing bracket
+
+fn main() {
+ println!("Hello, world! {0:}<3", 2);
+ //~^ ERROR invalid format string: expected `'}'` but string was terminated
+}
diff --git a/tests/ui/fmt/closing-brace-as-fill.stderr b/tests/ui/fmt/closing-brace-as-fill.stderr
new file mode 100644
index 000000000..aa1e5aff6
--- /dev/null
+++ b/tests/ui/fmt/closing-brace-as-fill.stderr
@@ -0,0 +1,12 @@
+error: invalid format string: expected `'}'` but string was terminated
+ --> $DIR/closing-brace-as-fill.rs:6:35
+ |
+LL | println!("Hello, world! {0:}<3", 2);
+ | - ^ expected `'}'` in format string
+ | |
+ | this is not interpreted as a formatting closing brace
+ |
+ = note: the character `'}'` is interpreted as a fill character because of the `:` that precedes it
+
+error: aborting due to previous error
+
diff --git a/tests/ui/fmt/format-string-error-2.stderr b/tests/ui/fmt/format-string-error-2.stderr
index 76cdfbb93..dfd24bf60 100644
--- a/tests/ui/fmt/format-string-error-2.stderr
+++ b/tests/ui/fmt/format-string-error-2.stderr
@@ -10,7 +10,7 @@ error: invalid format string: expected `'}'`, found `'a'`
LL | format!("{
| - because of this opening brace
LL | a");
- | ^ expected `}` in format string
+ | ^ expected `'}'` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`
@@ -21,7 +21,7 @@ LL | format!("{ \
| - because of this opening brace
LL | \
LL | b");
- | ^ expected `}` in format string
+ | ^ expected `'}'` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`
@@ -29,7 +29,7 @@ error: invalid format string: expected `'}'`, found `'\'`
--> $DIR/format-string-error-2.rs:11:18
|
LL | format!(r#"{ \
- | - ^ expected `}` in format string
+ | - ^ expected `'}'` in format string
| |
| because of this opening brace
|
@@ -39,7 +39,7 @@ error: invalid format string: expected `'}'`, found `'\'`
--> $DIR/format-string-error-2.rs:15:18
|
LL | format!(r#"{ \n
- | - ^ expected `}` in format string
+ | - ^ expected `'}'` in format string
| |
| because of this opening brace
|
@@ -52,7 +52,7 @@ LL | format!("{ \n
| - because of this opening brace
LL | \n
LL | e");
- | ^ expected `}` in format string
+ | ^ expected `'}'` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`
@@ -62,7 +62,7 @@ error: invalid format string: expected `'}'`, found `'a'`
LL | {
| - because of this opening brace
LL | a");
- | ^ expected `}` in format string
+ | ^ expected `'}'` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`
@@ -72,7 +72,7 @@ error: invalid format string: expected `'}'`, found `'a'`
LL | {
| - because of this opening brace
LL | a
- | ^ expected `}` in format string
+ | ^ expected `'}'` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`
@@ -83,7 +83,7 @@ LL | { \
| - because of this opening brace
LL | \
LL | b");
- | ^ expected `}` in format string
+ | ^ expected `'}'` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`
@@ -94,7 +94,7 @@ LL | { \
| - because of this opening brace
LL | \
LL | b \
- | ^ expected `}` in format string
+ | ^ expected `'}'` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`
@@ -102,7 +102,7 @@ error: invalid format string: expected `'}'`, found `'\'`
--> $DIR/format-string-error-2.rs:45:8
|
LL | raw { \
- | - ^ expected `}` in format string
+ | - ^ expected `'}'` in format string
| |
| because of this opening brace
|
@@ -112,7 +112,7 @@ error: invalid format string: expected `'}'`, found `'\'`
--> $DIR/format-string-error-2.rs:50:8
|
LL | raw { \n
- | - ^ expected `}` in format string
+ | - ^ expected `'}'` in format string
| |
| because of this opening brace
|
@@ -125,7 +125,7 @@ LL | { \n
| - because of this opening brace
LL | \n
LL | e");
- | ^ expected `}` in format string
+ | ^ expected `'}'` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`
@@ -135,7 +135,7 @@ error: invalid format string: expected `'}'`, found `'a'`
LL | {
| - because of this opening brace
LL | asdf}
- | ^ expected `}` in format string
+ | ^ expected `'}'` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`
diff --git a/tests/ui/fmt/format-string-error.stderr b/tests/ui/fmt/format-string-error.stderr
index 8a32c2254..37a181e6f 100644
--- a/tests/ui/fmt/format-string-error.stderr
+++ b/tests/ui/fmt/format-string-error.stderr
@@ -62,7 +62,7 @@ error: invalid format string: expected `'}'`, found `'\'`
--> $DIR/format-string-error.rs:19:23
|
LL | let _ = format!("{\}");
- | -^ expected `}` in format string
+ | -^ expected `'}'` in format string
| |
| because of this opening brace
|
diff --git a/tests/ui/fmt/format-string-wrong-order.stderr b/tests/ui/fmt/format-string-wrong-order.stderr
index 461af354a..0a2e04026 100644
--- a/tests/ui/fmt/format-string-wrong-order.stderr
+++ b/tests/ui/fmt/format-string-wrong-order.stderr
@@ -26,7 +26,7 @@ error: invalid format string: expected `'}'`, found `'?'`
--> $DIR/format-string-wrong-order.rs:9:15
|
LL | format!("{??}", bar);
- | -^ expected `}` in format string
+ | -^ expected `'}'` in format string
| |
| because of this opening brace
|
@@ -36,7 +36,7 @@ error: invalid format string: expected `'}'`, found `'?'`
--> $DIR/format-string-wrong-order.rs:11:15
|
LL | format!("{?;bar}");
- | -^ expected `}` in format string
+ | -^ expected `'}'` in format string
| |
| because of this opening brace
|
diff --git a/tests/ui/fmt/ifmt-bad-arg.stderr b/tests/ui/fmt/ifmt-bad-arg.stderr
index ed008c454..09ce3dca4 100644
--- a/tests/ui/fmt/ifmt-bad-arg.stderr
+++ b/tests/ui/fmt/ifmt-bad-arg.stderr
@@ -178,7 +178,7 @@ error: invalid format string: expected `'}'`, found `'t'`
LL | ninth number: {
| - because of this opening brace
LL | tenth number: {}",
- | ^ expected `}` in format string
+ | ^ expected `'}'` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`
diff --git a/tests/ui/fmt/suggest-inline-args.rs b/tests/ui/fmt/suggest-inline-args.rs
new file mode 100644
index 000000000..515335ed9
--- /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 000000000..cf70568cf
--- /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
+