@@ -2,8 +2,7 @@ use crate::deriving::generic::ty::*;
22use crate :: deriving:: generic:: * ;
33use crate :: deriving:: path_std;
44
5- use rustc_ast:: ptr:: P ;
6- use rustc_ast:: { self as ast, Expr , MetaItem } ;
5+ use rustc_ast:: { self as ast, MetaItem } ;
76use rustc_expand:: base:: { Annotatable , ExtCtxt } ;
87use rustc_span:: symbol:: { sym, Ident , Symbol } ;
98use rustc_span:: Span ;
@@ -42,7 +41,7 @@ pub fn expand_deriving_debug(
4241 trait_def. expand ( cx, mitem, item, push)
4342}
4443
45- fn show_substructure ( cx : & mut ExtCtxt < ' _ > , span : Span , substr : & Substructure < ' _ > ) -> P < Expr > {
44+ fn show_substructure ( cx : & mut ExtCtxt < ' _ > , span : Span , substr : & Substructure < ' _ > ) -> BlockOrExpr {
4645 let ( ident, vdata, fields) = match substr. fields {
4746 Struct ( vdata, fields) => ( substr. type_ident , * vdata, fields) ,
4847 EnumMatching ( _, _, v, fields) => ( v. ident , & v. data , fields) ,
@@ -74,7 +73,8 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
7473 if fields. is_empty ( ) {
7574 // Special case for no fields.
7675 let fn_path_write_str = cx. std_path ( & [ sym:: fmt, sym:: Formatter , sym:: write_str] ) ;
77- cx. expr_call_global ( span, fn_path_write_str, vec ! [ fmt, name] )
76+ let expr = cx. expr_call_global ( span, fn_path_write_str, vec ! [ fmt, name] ) ;
77+ BlockOrExpr :: new_expr ( expr)
7878 } else if fields. len ( ) <= CUTOFF {
7979 // Few enough fields that we can use a specific-length method.
8080 let debug = if is_struct {
@@ -100,7 +100,8 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
100100 let field = cx. expr_addr_of ( field. span , field) ;
101101 args. push ( field) ;
102102 }
103- cx. expr_call_global ( span, fn_path_debug, args)
103+ let expr = cx. expr_call_global ( span, fn_path_debug, args) ;
104+ BlockOrExpr :: new_expr ( expr)
104105 } else {
105106 // Enough fields that we must use the any-length method.
106107 let mut name_exprs = Vec :: with_capacity ( fields. len ( ) ) ;
@@ -176,8 +177,6 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
176177 stmts. push ( names_let. unwrap ( ) ) ;
177178 }
178179 stmts. push ( values_let) ;
179- stmts. push ( cx. stmt_expr ( expr) ) ;
180-
181- cx. expr_block ( cx. block ( span, stmts) )
180+ BlockOrExpr :: new_mixed ( stmts, expr)
182181 }
183182}
0 commit comments