about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-29 20:45:00 +0000
committerbors <bors@rust-lang.org>2024-08-29 20:45:00 +0000
commit0d634185dfddefe09047881175f35c65d68dcff1 (patch)
treec85fc78596b0d89063efefc1e1f3437e51c7e15e /compiler/rustc_builtin_macros/src
parent784d444733d65c3d305ce5edcbb41e3d0d0aee2e (diff)
parent9c7ae1d4d88b5212eabff72441b7d316e52df164 (diff)
downloadrust-0d634185dfddefe09047881175f35c65d68dcff1.tar.gz
rust-0d634185dfddefe09047881175f35c65d68dcff1.zip
Auto merge of #129750 - GuillaumeGomez:rollup-gphsb7y, r=GuillaumeGomez
Rollup of 7 pull requests

Successful merges:

 - #123940 (debug-fmt-detail option)
 - #128166 (Improved `checked_isqrt` and `isqrt` methods)
 - #128970 (Add `-Zlint-llvm-ir`)
 - #129316 (riscv64imac: allow shadow call stack sanitizer)
 - #129690 (Add `needs-unwind` compiletest directive to `libtest-thread-limit` and replace some `Path` with `path` in `run-make`)
 - #129732 (Add `unreachable_pub`, round 3)
 - #129743 (Fix rustdoc clippy lints)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_builtin_macros/src')
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/debug.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/compiler/rustc_builtin_macros/src/deriving/debug.rs b/compiler/rustc_builtin_macros/src/deriving/debug.rs
index 755e6ee0d3e..57d9c076150 100644
--- a/compiler/rustc_builtin_macros/src/deriving/debug.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/debug.rs
@@ -1,5 +1,6 @@
 use rustc_ast::{self as ast, EnumDef, MetaItem};
 use rustc_expand::base::{Annotatable, ExtCtxt};
+use rustc_session::config::FmtDebug;
 use rustc_span::symbol::{sym, Ident, Symbol};
 use rustc_span::Span;
 use thin_vec::{thin_vec, ThinVec};
@@ -49,6 +50,11 @@ fn show_substructure(cx: &ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) ->
     // We want to make sure we have the ctxt set so that we can use unstable methods
     let span = cx.with_def_site_ctxt(span);
 
+    let fmt_detail = cx.sess.opts.unstable_opts.fmt_debug;
+    if fmt_detail == FmtDebug::None {
+        return BlockOrExpr::new_expr(cx.expr_ok(span, cx.expr_tuple(span, ThinVec::new())));
+    }
+
     let (ident, vdata, fields) = match substr.fields {
         Struct(vdata, fields) => (substr.type_ident, *vdata, fields),
         EnumMatching(_, v, fields) => (v.ident, &v.data, fields),
@@ -61,6 +67,13 @@ fn show_substructure(cx: &ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) ->
     let name = cx.expr_str(span, ident.name);
     let fmt = substr.nonselflike_args[0].clone();
 
+    // Fieldless enums have been special-cased earlier
+    if fmt_detail == FmtDebug::Shallow {
+        let fn_path_write_str = cx.std_path(&[sym::fmt, sym::Formatter, sym::write_str]);
+        let expr = cx.expr_call_global(span, fn_path_write_str, thin_vec![fmt, name]);
+        return BlockOrExpr::new_expr(expr);
+    }
+
     // Struct and tuples are similar enough that we use the same code for both,
     // with some extra pieces for structs due to the field names.
     let (is_struct, args_per_field) = match vdata {