@@ -47,19 +47,18 @@ impl<'tcx> LateLintPass<'tcx> for PanicFmt {
4747fn check_panic < ' tcx > ( cx : & LateContext < ' tcx > , f : & ' tcx hir:: Expr < ' tcx > , arg : & ' tcx hir:: Expr < ' tcx > ) {
4848 if let hir:: ExprKind :: Lit ( lit) = & arg. kind {
4949 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- } ;
5850 let expn = f. span . ctxt ( ) . outer_expn_data ( ) ;
5951 if let Some ( id) = expn. macro_def_id {
6052 if cx. tcx . is_diagnostic_item ( sym:: std_panic_macro, id)
6153 || cx. tcx . is_diagnostic_item ( sym:: core_panic_macro, id)
6254 {
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 ( '}' ) ) ;
6362 let expn = {
6463 // Unwrap another level of macro expansion if this
6564 // panic!() was expanded from assert!().
0 commit comments