2 #![allow(unused_imports)]
3 // Ideally, any macro call with a trailing comma should behave
4 // identically to a call without the comma.
6 // This checks the behavior of macros with trailing commas in key
7 // places where regressions in behavior seem highly possible (due
8 // to it being e.g., a place where the addition of an argument
9 // causes it to go down a code path with subtly different behavior).
11 // There is a companion test in compile-fail.
13 // compile-flags: --test -C debug_assertions=yes
14 // revisions: std core
16 // ignore-wasm32-bare compiled with panic=abort by default
18 #![cfg_attr(core, no_std)]
20 #[cfg(std)] use std::fmt;
21 #[cfg(core)] use core::fmt;
23 // an easy mistake in the implementation of 'assert!'
24 // would cause this to say "explicit panic"
26 #[should_panic(expected = "assertion failed")]
31 // same as 'assert_1arg'
33 #[should_panic(expected = "assertion failed")]
34 fn debug_assert_1arg() {
35 debug_assert!(false,);
38 // make sure we don't accidentally forward to `write!("text")`
44 let mut s = String::new();
45 writeln!(&mut s,).unwrap();
49 // A number of format_args-like macros have special-case treatment
50 // for a single message string, which is not formatted.
52 // This test ensures that the addition of a trailing comma does not
53 // suddenly cause these strings to get formatted when they otherwise
54 // would not be. This is an easy mistake to make by having such a macro
55 // accept ", $($tok:tt)*" instead of ", $($tok:tt)+" after its minimal
58 // (Example: Issue #48042)
61 fn to_format_or_not_to_format() {
62 // ("{}" is the easiest string to test because if this gets
63 // sent to format_args!, it'll simply fail to compile.
64 // "{{}}" is an example of an input that could compile and
65 // produce an incorrect program, but testing the panics
66 // would be burdensome.)
67 let falsum = || false;
71 // assert_eq!(1, 1, "{}",); // see compile-fail
72 // assert_ne!(1, 2, "{}",); // see compile-fail
74 debug_assert!(true, "{}",);
76 // debug_assert_eq!(1, 1, "{}",); // see compile-fail
77 // debug_assert_ne!(1, 2, "{}",); // see compile-fail
78 // eprint!("{}",); // see compile-fail
79 // eprintln!("{}",); // see compile-fail
80 // format!("{}",); // see compile-fail
81 // format_args!("{}",); // see compile-fail
83 if falsum() { panic!("{}",); }
85 // print!("{}",); // see compile-fail
86 // println!("{}",); // see compile-fail
87 // unimplemented!("{}",); // see compile-fail
89 if falsum() { unreachable!("{}",); }
91 // write!(&mut stdout, "{}",); // see compile-fail
92 // writeln!(&mut stdout, "{}",); // see compile-fail