diff options
| author | Tomoaki Kobayashi <tomoaki.kobayashi.t3@alumni.tohoku.ac.jp> | 2025-09-18 14:23:58 +0900 |
|---|---|---|
| committer | Tomoaki Kobayashi <tomoaki.kobayashi.t3@alumni.tohoku.ac.jp> | 2025-09-30 15:50:30 +0900 |
| commit | 0fd6f1113b7209d24d4954ef99165aba09ed27f7 (patch) | |
| tree | 7fcbd862abe3b6425a9e9a1e8498a7dd3f5ea158 /tests/ui | |
| parent | c5dc558e6cca43958616b268b66c49763f2e9e9a (diff) | |
| download | rust-0fd6f1113b7209d24d4954ef99165aba09ed27f7.tar.gz rust-0fd6f1113b7209d24d4954ef99165aba09ed27f7.zip | |
Add test for unuseful span in type error in some format_args!() invocations
Diffstat (limited to 'tests/ui')
| -rw-r--r-- | tests/ui/errors/span-format_args-issue-140578.rs | 31 | ||||
| -rw-r--r-- | tests/ui/errors/span-format_args-issue-140578.stderr | 49 |
2 files changed, 80 insertions, 0 deletions
diff --git a/tests/ui/errors/span-format_args-issue-140578.rs b/tests/ui/errors/span-format_args-issue-140578.rs new file mode 100644 index 00000000000..d086fde09f7 --- /dev/null +++ b/tests/ui/errors/span-format_args-issue-140578.rs @@ -0,0 +1,31 @@ +fn check_format_args() { + print!("{:?} {a} {a:?}", [], a = 1 + 1); + //~^ ERROR type annotations needed +} + +fn check_format_args_nl() { + println!("{:?} {a} {a:?}", [], a = 1 + 1); + //~^ ERROR type annotations needed +} + +fn check_multi1() { + println!("{:?} {:?} {a} {a:?}", [], [], a = 1 + 1); + //~^ ERROR type annotations needed +} + +fn check_multi2() { + println!("{:?} {:?} {a} {a:?} {b:?}", [], [], a = 1 + 1, b = []); + //~^ ERROR type annotations needed +} + +fn check_unformatted() { + println!(" //~ ERROR type annotations needed + {:?} {:?} +{a} +{a:?}", + [], + [], +a = 1 + 1); +} + +fn main() {} diff --git a/tests/ui/errors/span-format_args-issue-140578.stderr b/tests/ui/errors/span-format_args-issue-140578.stderr new file mode 100644 index 00000000000..4c19b491959 --- /dev/null +++ b/tests/ui/errors/span-format_args-issue-140578.stderr @@ -0,0 +1,49 @@ +error[E0282]: type annotations needed + --> $DIR/span-format_args-issue-140578.rs:2:3 + | +LL | print!("{:?} {a} {a:?}", [], a = 1 + 1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type + | + = note: this error originates in the macro `print` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0282]: type annotations needed + --> $DIR/span-format_args-issue-140578.rs:7:3 + | +LL | println!("{:?} {a} {a:?}", [], a = 1 + 1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type + | + = note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0282]: type annotations needed + --> $DIR/span-format_args-issue-140578.rs:12:3 + | +LL | println!("{:?} {:?} {a} {a:?}", [], [], a = 1 + 1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type + | + = note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0282]: type annotations needed + --> $DIR/span-format_args-issue-140578.rs:17:3 + | +LL | println!("{:?} {:?} {a} {a:?} {b:?}", [], [], a = 1 + 1, b = []); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type + | + = note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0282]: type annotations needed + --> $DIR/span-format_args-issue-140578.rs:22:3 + | +LL | / println!(" +LL | | {:?} {:?} +LL | | {a} +LL | | {a:?}", +LL | | [], +LL | | [], +LL | | a = 1 + 1); + | |__________^ cannot infer type + | + = note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0282`. |
