about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2020-10-19 00:05:19 +0200
committerMara Bos <m-ou.se@m-ou.se>2020-10-19 00:05:19 +0200
commit9615d27ab7327abdb2ba4aef5f797c693d02ef17 (patch)
treee6a7c638e77a0e4b6866f855b5fb18f48a3c1a2c
parentdd262e385646fa94b85b5340f260efb01284261b (diff)
downloadrust-9615d27ab7327abdb2ba4aef5f797c693d02ef17.tar.gz
rust-9615d27ab7327abdb2ba4aef5f797c693d02ef17.zip
Don't see `{{}}` as placeholder in panic_fmt lint.
-rw-r--r--compiler/rustc_lint/src/panic_fmt.rs15
1 files changed, 7 insertions, 8 deletions
diff --git a/compiler/rustc_lint/src/panic_fmt.rs b/compiler/rustc_lint/src/panic_fmt.rs
index a615d57dfa7..75ee0896510 100644
--- a/compiler/rustc_lint/src/panic_fmt.rs
+++ b/compiler/rustc_lint/src/panic_fmt.rs
@@ -47,19 +47,18 @@ impl<'tcx> LateLintPass<'tcx> for PanicFmt {
 fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tcx hir::Expr<'tcx>) {
     if let hir::ExprKind::Lit(lit) = &arg.kind {
         if let ast::LitKind::Str(sym, _) = lit.node {
-            let s = sym.as_str();
-            let open = s.find('{');
-            let close = s[open.unwrap_or(0)..].find('}');
-            let looks_like_placeholder = match (open, close) {
-                (Some(_), Some(_)) => true,
-                (Some(_), None) | (None, Some(_)) => false,
-                (None, None) => return, // OK, no braces.
-            };
             let expn = f.span.ctxt().outer_expn_data();
             if let Some(id) = expn.macro_def_id {
                 if cx.tcx.is_diagnostic_item(sym::std_panic_macro, id)
                     || cx.tcx.is_diagnostic_item(sym::core_panic_macro, id)
                 {
+                    let s = sym.as_str();
+                    if !s.contains(&['{', '}'][..]) {
+                        return;
+                    }
+                    let s = s.replace("{{", "").replace("}}", "");
+                    let looks_like_placeholder =
+                        s.find('{').map_or(false, |i| s[i + 1..].contains('}'));
                     let expn = {
                         // Unwrap another level of macro expansion if this
                         // panic!() was expanded from assert!().