@@ -47,19 +47,18 @@ impl<'tcx> LateLintPass<'tcx> for PanicFmt {
47
47
fn check_panic < ' tcx > ( cx : & LateContext < ' tcx > , f : & ' tcx hir:: Expr < ' tcx > , arg : & ' tcx hir:: Expr < ' tcx > ) {
48
48
if let hir:: ExprKind :: Lit ( lit) = & arg. kind {
49
49
if let ast:: LitKind :: Str ( sym, _) = lit. node {
50
- let s = sym. as_str ( ) ;
51
- let open = s. find ( '{' ) ;
52
- let close = s[ open. unwrap_or ( 0 ) ..] . find ( '}' ) ;
53
- let looks_like_placeholder = match ( open, close) {
54
- ( Some ( _) , Some ( _) ) => true ,
55
- ( Some ( _) , None ) | ( None , Some ( _) ) => false ,
56
- ( None , None ) => return , // OK, no braces.
57
- } ;
58
50
let expn = f. span . ctxt ( ) . outer_expn_data ( ) ;
59
51
if let Some ( id) = expn. macro_def_id {
60
52
if cx. tcx . is_diagnostic_item ( sym:: std_panic_macro, id)
61
53
|| cx. tcx . is_diagnostic_item ( sym:: core_panic_macro, id)
62
54
{
55
+ let s = sym. as_str ( ) ;
56
+ if !s. contains ( & [ '{' , '}' ] [ ..] ) {
57
+ return ;
58
+ }
59
+ let s = s. replace ( "{{" , "" ) . replace ( "}}" , "" ) ;
60
+ let looks_like_placeholder =
61
+ s. find ( '{' ) . map_or ( false , |i| s[ i + 1 ..] . contains ( '}' ) ) ;
63
62
let expn = {
64
63
// Unwrap another level of macro expansion if this
65
64
// panic!() was expanded from assert!().
0 commit comments