8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
+ #![ feature( rustc_attrs) ]
12
+
11
13
// Issue 22932: `panic!("{}");` should not compile.
12
14
13
15
pub fn f1 ( ) { panic ! ( "this does not work {}" ) ;
14
- //~^ ERROR panic! input cannot be format string literal
16
+ //~^ WARN unary panic! literal argument contains `{`
17
+ //~| NOTE Is it meant to be a `format!` string?
18
+ //~| HELP You can wrap the argument in parentheses to sidestep this warning
15
19
}
16
20
17
21
pub fn workaround_1 ( ) {
@@ -24,28 +28,49 @@ pub fn workaround_2() {
24
28
}
25
29
26
30
pub fn f2 ( ) { panic ! ( "this does not work {" ) ;
27
- //~^ ERROR panic! input cannot be format string literal
31
+ //~^ WARN unary panic! literal argument contains `{`
32
+ //~| NOTE Is it meant to be a `format!` string?
33
+ //~| HELP You can wrap the argument in parentheses to sidestep this warning
28
34
}
29
35
30
36
pub fn f3 ( ) { panic ! ( "nor this }" ) ;
31
- //~^ ERROR panic! input cannot be format string literal
37
+ //~^ WARN unary panic! literal argument contains `}`
38
+ //~| NOTE Is it meant to be a `format!` string?
39
+ //~| HELP You can wrap the argument in parentheses to sidestep this warning
32
40
}
33
41
34
42
pub fn f4 ( ) { panic ! ( "nor this {{" ) ;
35
- //~^ ERROR panic! input cannot be format string literal
43
+ //~^ WARN unary panic! literal argument contains `{`
44
+ //~| NOTE Is it meant to be a `format!` string?
45
+ //~| HELP You can wrap the argument in parentheses to sidestep this warning
36
46
}
37
47
38
48
pub fn f5 ( ) { panic ! ( "nor this }}" ) ;
39
- //~^ ERROR panic! input cannot be format string literal
49
+ //~^ WARN unary panic! literal argument contains `}`
50
+ //~| NOTE Is it meant to be a `format!` string?
51
+ //~| HELP You can wrap the argument in parentheses to sidestep this warning
40
52
}
41
53
42
54
pub fn f0_a ( ) {
43
55
ensure_not_fmt_string_literal ! ( "`f0_a`" , "this does not work {}" ) ;
44
- //~^ ERROR `f0_a` input cannot be format string literal
56
+ //~^ WARN `f0_a` literal argument contains `{`
57
+ //~| NOTE Is it meant to be a `format!` string?
58
+ //~| HELP You can wrap the argument in parentheses to sidestep this warning
45
59
}
46
60
47
61
pub fn f0_b ( ) {
48
62
println ! ( ensure_not_fmt_string_literal!( "`f0_b`" , "this does work" ) ) ;
49
63
}
50
64
51
- pub fn main ( ) { }
65
+ pub fn f0_c ( ) {
66
+ println ! ( "{}" ,
67
+ ensure_not_fmt_string_literal!( "`f0_c`" , ( "so does this {}" ) ) ) ;
68
+ }
69
+
70
+ // This test is just checking that we get all the right warnings; none
71
+ // of them are outright errors, so use the special `rustc_error`
72
+ // attribute to force a compile error.
73
+ #[ rustc_error]
74
+ pub fn main ( ) {
75
+ //~^ ERROR compilation successful
76
+ }
0 commit comments