about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-02-11 16:46:08 +0000
committerbors <bors@rust-lang.org>2021-02-11 16:46:08 +0000
commite9920ef7749d11fc71cc32ca4ba055bcfeaab945 (patch)
treebec30409fb491e4c3bf37f4a092dc3c43d40ec06 /compiler
parent26e5bcd22025a0d949b76766af76e92ed4434199 (diff)
parent1cf95059ebb6e01d4a914fbf84c9d56425265637 (diff)
downloadrust-e9920ef7749d11fc71cc32ca4ba055bcfeaab945.tar.gz
rust-e9920ef7749d11fc71cc32ca4ba055bcfeaab945.zip
Auto merge of #81760 - tmiasko:debug-borrow, r=pnkfelix
Borrow builder only once in debug derive
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/debug.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/compiler/rustc_builtin_macros/src/deriving/debug.rs b/compiler/rustc_builtin_macros/src/deriving/debug.rs
index ba43be6ae9a..cc6dac52d76 100644
--- a/compiler/rustc_builtin_macros/src/deriving/debug.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/debug.rs
@@ -77,7 +77,8 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
             // tuple struct/"normal" variant
             let fn_path_debug_tuple = cx.std_path(&[sym::fmt, sym::Formatter, sym::debug_tuple]);
             let expr = cx.expr_call_global(span, fn_path_debug_tuple, vec![fmt, name]);
-            stmts.push(cx.stmt_let(span, true, builder, expr));
+            let expr = make_mut_borrow(cx, span, expr);
+            stmts.push(cx.stmt_let(span, false, builder, expr));
 
             for field in fields {
                 // Use double indirection to make sure this works for unsized types
@@ -85,8 +86,8 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
                 let field = cx.expr_addr_of(field.span, field);
 
                 let fn_path_field = cx.std_path(&[sym::fmt, sym::DebugTuple, sym::field]);
-                let builder_recv = make_mut_borrow(cx, span, builder_expr.clone());
-                let expr = cx.expr_call_global(span, fn_path_field, vec![builder_recv, field]);
+                let expr =
+                    cx.expr_call_global(span, fn_path_field, vec![builder_expr.clone(), field]);
 
                 // Use `let _ = expr;` to avoid triggering the
                 // unused_results lint.
@@ -99,7 +100,8 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
             // normal struct/struct variant
             let fn_path_debug_struct = cx.std_path(&[sym::fmt, sym::Formatter, sym::debug_struct]);
             let expr = cx.expr_call_global(span, fn_path_debug_struct, vec![fmt, name]);
-            stmts.push(cx.stmt_let(DUMMY_SP, true, builder, expr));
+            let expr = make_mut_borrow(cx, span, expr);
+            stmts.push(cx.stmt_let(DUMMY_SP, false, builder, expr));
 
             for field in fields {
                 let name = cx.expr_lit(
@@ -111,17 +113,18 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
                 let fn_path_field = cx.std_path(&[sym::fmt, sym::DebugStruct, sym::field]);
                 let field = cx.expr_addr_of(field.span, field.self_.clone());
                 let field = cx.expr_addr_of(field.span, field);
-                let builder_recv = make_mut_borrow(cx, span, builder_expr.clone());
-                let expr =
-                    cx.expr_call_global(span, fn_path_field, vec![builder_recv, name, field]);
+                let expr = cx.expr_call_global(
+                    span,
+                    fn_path_field,
+                    vec![builder_expr.clone(), name, field],
+                );
                 stmts.push(stmt_let_underscore(cx, span, expr));
             }
             fn_path_finish = cx.std_path(&[sym::fmt, sym::DebugStruct, sym::finish]);
         }
     }
 
-    let builder_recv = make_mut_borrow(cx, span, builder_expr);
-    let expr = cx.expr_call_global(span, fn_path_finish, vec![builder_recv]);
+    let expr = cx.expr_call_global(span, fn_path_finish, vec![builder_expr]);
 
     stmts.push(cx.stmt_expr(expr));
     let block = cx.block(span, stmts);