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