@@ -2,8 +2,7 @@ use crate::deriving::generic::ty::*;
2
2
use crate :: deriving:: generic:: * ;
3
3
use crate :: deriving:: path_std;
4
4
5
- use rustc_ast:: ptr:: P ;
6
- use rustc_ast:: { self as ast, Expr , MetaItem } ;
5
+ use rustc_ast:: { self as ast, MetaItem } ;
7
6
use rustc_expand:: base:: { Annotatable , ExtCtxt } ;
8
7
use rustc_span:: symbol:: { sym, Ident , Symbol } ;
9
8
use rustc_span:: Span ;
@@ -42,7 +41,7 @@ pub fn expand_deriving_debug(
42
41
trait_def. expand ( cx, mitem, item, push)
43
42
}
44
43
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 {
46
45
let ( ident, vdata, fields) = match substr. fields {
47
46
Struct ( vdata, fields) => ( substr. type_ident , * vdata, fields) ,
48
47
EnumMatching ( _, _, v, fields) => ( v. ident , & v. data , fields) ,
@@ -74,7 +73,8 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
74
73
if fields. is_empty ( ) {
75
74
// Special case for no fields.
76
75
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)
78
78
} else if fields. len ( ) <= CUTOFF {
79
79
// Few enough fields that we can use a specific-length method.
80
80
let debug = if is_struct {
@@ -100,7 +100,8 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
100
100
let field = cx. expr_addr_of ( field. span , field) ;
101
101
args. push ( field) ;
102
102
}
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)
104
105
} else {
105
106
// Enough fields that we must use the any-length method.
106
107
let mut name_exprs = Vec :: with_capacity ( fields. len ( ) ) ;
@@ -176,8 +177,6 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
176
177
stmts. push ( names_let. unwrap ( ) ) ;
177
178
}
178
179
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)
182
181
}
183
182
}
0 commit comments