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 #![cfg_attr(core, no_std)]
24 // an easy mistake in the implementation of 'assert!'
25 // would cause this to say "explicit panic"
27 #[should_panic(expected = "assertion failed")]
32 // same as 'assert_1arg'
34 #[should_panic(expected = "assertion failed")]
35 fn debug_assert_1arg() {
36 debug_assert!(false,);
39 // make sure we don't accidentally forward to `write!("text")`
45 let mut s = String::new();
46 writeln!(&mut s,).unwrap();
50 // A number of format_args-like macros have special-case treatment
51 // for a single message string, which is not formatted.
53 // This test ensures that the addition of a trailing comma does not
54 // suddenly cause these strings to get formatted when they otherwise
55 // would not be. This is an easy mistake to make by having such a macro
56 // accept ", $($tok:tt)*" instead of ", $($tok:tt)+" after its minimal
59 // (Example: Issue #48042)
61 #[allow(non_fmt_panics)]
62 fn to_format_or_not_to_format() {
63 // ("{}" is the easiest string to test because if this gets
64 // sent to format_args!, it'll simply fail to compile.
65 // "{{}}" is an example of an input that could compile and
66 // produce an incorrect program, but testing the panics
67 // would be burdensome.)
68 let falsum = || false;
72 // assert_eq!(1, 1, "{}",); // see check-fail
73 // assert_ne!(1, 2, "{}",); // see check-fail
75 debug_assert!(true, "{}",);
77 // debug_assert_eq!(1, 1, "{}",); // see check-fail
78 // debug_assert_ne!(1, 2, "{}",); // see check-fail
79 // eprint!("{}",); // see check-fail
80 // eprintln!("{}",); // see check-fail
81 // format!("{}",); // see check-fail
82 // format_args!("{}",); // see check-fail
88 // print!("{}",); // see check-fail
89 // println!("{}",); // see check-fail
90 // unimplemented!("{}",); // see check-fail
96 // write!(&mut stdout, "{}",); // see check-fail
97 // writeln!(&mut stdout, "{}",); // see check-fail