diff --git a/compiler/rustc_builtin_macros/src/deriving/debug.rs b/compiler/rustc_builtin_macros/src/deriving/debug.rs index ba43be6ae9a9e..cc6dac52d7663 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); diff --git a/src/test/run-make-fulldeps/coverage-spanview/expected_mir_dump.partial_eq/partial_eq.{impl#7}-fmt.-------.InstrumentCoverage.0.html b/src/test/run-make-fulldeps/coverage-spanview/expected_mir_dump.partial_eq/partial_eq.{impl#7}-fmt.-------.InstrumentCoverage.0.html index 5b9e070864b40..930492f24841f 100644 --- a/src/test/run-make-fulldeps/coverage-spanview/expected_mir_dump.partial_eq/partial_eq.{impl#7}-fmt.-------.InstrumentCoverage.0.html +++ b/src/test/run-make-fulldeps/coverage-spanview/expected_mir_dump.partial_eq/partial_eq.{impl#7}-fmt.-------.InstrumentCoverage.0.html @@ -73,41 +73,38 @@ 4:17-4:22: @0[2]: _3 = &((*_1).0: usize) 4:17-4:22: @0[4]: _4 = &((*_1).1: usize) 4:17-4:22: @0[6]: _5 = &((*_1).2: usize) -4:17-4:22: @0[9]: _7 = &mut (*_2) -4:17-4:22: @0[12]: _9 = const "Version" -4:17-4:22: @0[13]: _8 = &(*_9) -4:17-4:22: @0.Call: _6 = std::fmt::Formatter::debug_struct(move _7, move _8) -> [return: bb1, unwind: bb6] -4:17-4:22: @1[2]: FakeRead(ForLet, _6) -4:17-4:22: @1[7]: _12 = &mut _6 -4:17-4:22: @1[8]: _11 = &mut (*_12) -4:17-4:22: @1[11]: _14 = const "major" -4:17-4:22: @1[12]: _13 = &(*_14) -4:17-4:22: @1[17]: _18 = &(*_3) -4:17-4:22: @1[18]: _17 = &_18 -4:17-4:22: @1[19]: _16 = &(*_17) -4:17-4:22: @1[20]: _15 = move _16 as &dyn std::fmt::Debug (Pointer(Unsize)) -4:17-4:22: @1.Call: _10 = std::fmt::DebugStruct::field(move _11, move _13, move _15) -> [return: bb2, unwind: bb6] -4:17-4:22: @2[11]: _21 = &mut _6 -4:17-4:22: @2[12]: _20 = &mut (*_21) -4:17-4:22: @2[15]: _23 = const "minor" -4:17-4:22: @2[16]: _22 = &(*_23) -4:17-4:22: @2[21]: _27 = &(*_4) -4:17-4:22: @2[22]: _26 = &_27 -4:17-4:22: @2[23]: _25 = &(*_26) -4:17-4:22: @2[24]: _24 = move _25 as &dyn std::fmt::Debug (Pointer(Unsize)) -4:17-4:22: @2.Call: _19 = std::fmt::DebugStruct::field(move _20, move _22, move _24) -> [return: bb3, unwind: bb6] -4:17-4:22: @3[11]: _30 = &mut _6 -4:17-4:22: @3[12]: _29 = &mut (*_30) -4:17-4:22: @3[15]: _32 = const "patch" -4:17-4:22: @3[16]: _31 = &(*_32) -4:17-4:22: @3[21]: _36 = &(*_5) -4:17-4:22: @3[22]: _35 = &_36 -4:17-4:22: @3[23]: _34 = &(*_35) -4:17-4:22: @3[24]: _33 = move _34 as &dyn std::fmt::Debug (Pointer(Unsize)) -4:17-4:22: @3.Call: _28 = std::fmt::DebugStruct::field(move _29, move _31, move _33) -> [return: bb4, unwind: bb6] -4:17-4:22: @4[10]: _38 = &mut _6 -4:17-4:22: @4[11]: _37 = &mut (*_38) -4:17-4:22: @4.Call: _0 = std::fmt::DebugStruct::finish(move _37) -> [return: bb5, unwind: bb6] +4:17-4:22: @0[10]: _8 = &mut (*_2) +4:17-4:22: @0[13]: _10 = const "Version" +4:17-4:22: @0[14]: _9 = &(*_10) +4:17-4:22: @0.Call: _7 = std::fmt::Formatter::debug_struct(move _8, move _9) -> [return: bb1, unwind: bb6] +4:17-4:22: @1[2]: _6 = &mut _7 +4:17-4:22: @1[3]: FakeRead(ForLet, _6) +4:17-4:22: @1[7]: _12 = &mut (*_6) +4:17-4:22: @1[10]: _14 = const "major" +4:17-4:22: @1[11]: _13 = &(*_14) +4:17-4:22: @1[16]: _18 = &(*_3) +4:17-4:22: @1[17]: _17 = &_18 +4:17-4:22: @1[18]: _16 = &(*_17) +4:17-4:22: @1[19]: _15 = move _16 as &dyn std::fmt::Debug (Pointer(Unsize)) +4:17-4:22: @1.Call: _11 = std::fmt::DebugStruct::field(move _12, move _13, move _15) -> [return: bb2, unwind: bb6] +4:17-4:22: @2[9]: _20 = &mut (*_6) +4:17-4:22: @2[12]: _22 = const "minor" +4:17-4:22: @2[13]: _21 = &(*_22) +4:17-4:22: @2[18]: _26 = &(*_4) +4:17-4:22: @2[19]: _25 = &_26 +4:17-4:22: @2[20]: _24 = &(*_25) +4:17-4:22: @2[21]: _23 = move _24 as &dyn std::fmt::Debug (Pointer(Unsize)) +4:17-4:22: @2.Call: _19 = std::fmt::DebugStruct::field(move _20, move _21, move _23) -> [return: bb3, unwind: bb6] +4:17-4:22: @3[9]: _28 = &mut (*_6) +4:17-4:22: @3[12]: _30 = const "patch" +4:17-4:22: @3[13]: _29 = &(*_30) +4:17-4:22: @3[18]: _34 = &(*_5) +4:17-4:22: @3[19]: _33 = &_34 +4:17-4:22: @3[20]: _32 = &(*_33) +4:17-4:22: @3[21]: _31 = move _32 as &dyn std::fmt::Debug (Pointer(Unsize)) +4:17-4:22: @3.Call: _27 = std::fmt::DebugStruct::field(move _28, move _29, move _31) -> [return: bb4, unwind: bb6] +4:17-4:22: @4[8]: _35 = &mut (*_6) +4:17-4:22: @4.Call: _0 = std::fmt::DebugStruct::finish(move _35) -> [return: bb5, unwind: bb6] 4:22-4:22: @5.Return: return">@0,1,2,3,4,5⦊Debug⦉@0,1,2,3,4,5