about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_lint/src/panic_fmt.rs16
-rw-r--r--compiler/rustc_span/src/symbol.rs1
-rw-r--r--library/core/src/macros/mod.rs1
-rw-r--r--src/test/ui/panic-brace.rs1
-rw-r--r--src/test/ui/panic-brace.stderr14
5 files changed, 23 insertions, 10 deletions
diff --git a/compiler/rustc_lint/src/panic_fmt.rs b/compiler/rustc_lint/src/panic_fmt.rs
index 75ee0896510..05bc272d0e0 100644
--- a/compiler/rustc_lint/src/panic_fmt.rs
+++ b/compiler/rustc_lint/src/panic_fmt.rs
@@ -47,7 +47,7 @@ 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 expn = f.span.ctxt().outer_expn_data();
+            let mut 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)
@@ -59,19 +59,17 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
                     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!().
+                    // Unwrap another level of macro expansion if this panic!()
+                    // was expanded from assert!() or debug_assert!().
+                    for &assert in &[sym::assert_macro, sym::debug_assert_macro] {
                         let parent = expn.call_site.ctxt().outer_expn_data();
                         if parent
                             .macro_def_id
-                            .map_or(false, |id| cx.tcx.is_diagnostic_item(sym::assert_macro, id))
+                            .map_or(false, |id| cx.tcx.is_diagnostic_item(assert, id))
                         {
-                            parent
-                        } else {
-                            expn
+                            expn = parent;
                         }
-                    };
+                    }
                     if looks_like_placeholder {
                         cx.struct_span_lint(PANIC_FMT, arg.span.source_callsite(), |lint| {
                             let mut l = lint.build("Panic message contains an unused formatting placeholder");
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 733d2b1ef9a..338ff005995 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -418,6 +418,7 @@ symbols! {
         dead_code,
         dealloc,
         debug,
+        debug_assert_macro,
         debug_assertions,
         debug_struct,
         debug_trait,
diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs
index 54bbedcd914..0416a7614a3 100644
--- a/library/core/src/macros/mod.rs
+++ b/library/core/src/macros/mod.rs
@@ -163,6 +163,7 @@ macro_rules! assert_ne {
 /// ```
 #[macro_export]
 #[stable(feature = "rust1", since = "1.0.0")]
+#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "debug_assert_macro")]
 macro_rules! debug_assert {
     ($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert!($($arg)*); })
 }
diff --git a/src/test/ui/panic-brace.rs b/src/test/ui/panic-brace.rs
index 01ffb800768..d6bb3222ac7 100644
--- a/src/test/ui/panic-brace.rs
+++ b/src/test/ui/panic-brace.rs
@@ -6,4 +6,5 @@ fn main() {
     std::panic!("another one: }"); //~ WARN Panic message contains a brace
     core::panic!("Hello {}"); //~ WARN Panic message contains an unused formatting placeholder
     assert!(false, "{:03x} bla"); //~ WARN Panic message contains an unused formatting placeholder
+    debug_assert!(false, "{{}} bla"); //~ WARN Panic message contains a brace
 }
diff --git a/src/test/ui/panic-brace.stderr b/src/test/ui/panic-brace.stderr
index b91ce8f603a..578731896ba 100644
--- a/src/test/ui/panic-brace.stderr
+++ b/src/test/ui/panic-brace.stderr
@@ -55,5 +55,17 @@ help: or add a "{}" format string to use the message literally
 LL |     assert!(false, "{}", "{:03x} bla");
    |                    ^^^^^
 
-warning: 4 warnings emitted
+warning: Panic message contains a brace
+  --> $DIR/panic-brace.rs:9:5
+   |
+LL |     debug_assert!(false, "{{}} bla");
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: This message is not used as a format string, but will be in a future Rust version
+help: add a "{}" format string to use the message literally
+   |
+LL |     debug_assert!(false, "{}", "{{}} bla");
+   |                          ^^^^^
+
+warning: 5 warnings emitted