Skip to content

Commit ac56d7f

Browse files
committed
Regression test.
1 parent ee66bcd commit ac56d7f

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/test/compile-fail/issue-22932.rs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Issue 22932: `panic!("{}");` should not compile.
12+
13+
pub fn f1() { panic!("this does not work {}");
14+
//~^ ERROR panic! input cannot be format string literal
15+
}
16+
17+
pub fn workaround_1() {
18+
panic!(("This *does* works {}"));
19+
}
20+
21+
pub fn workaround_2() {
22+
const MSG: &'static str = "This *does* work {}";
23+
panic!(MSG);
24+
}
25+
26+
pub fn f2() { panic!("this does not work {");
27+
//~^ ERROR panic! input cannot be format string literal
28+
}
29+
30+
pub fn f3() { panic!("nor this }");
31+
//~^ ERROR panic! input cannot be format string literal
32+
}
33+
34+
pub fn f4() { panic!("nor this {{");
35+
//~^ ERROR panic! input cannot be format string literal
36+
}
37+
38+
pub fn f5() { panic!("nor this }}");
39+
//~^ ERROR panic! input cannot be format string literal
40+
}
41+
42+
pub fn f0_a() {
43+
ensure_not_fmt_string_literal!("`f0_a`", "this does not work {}");
44+
//~^ ERROR `f0_a` input cannot be format string literal
45+
}
46+
47+
pub fn f0_b() {
48+
println!(ensure_not_fmt_string_literal!("`f0_b`", "this does work"));
49+
}
50+
51+
pub fn main() {}

0 commit comments

Comments
 (0)