1
1
use crate :: build;
2
2
use crate :: build:: scope:: DropKind ;
3
- use crate :: thir:: cx:: Cx ;
4
- use crate :: thir:: { BindingMode , Expr , LintLevel , Pat , PatKind } ;
3
+ use crate :: thir:: cx:: build_thir ;
4
+ use crate :: thir:: { Arena , BindingMode , Expr , LintLevel , Pat , PatKind } ;
5
5
use rustc_attr:: { self as attr, UnwindAttr } ;
6
6
use rustc_errors:: ErrorReported ;
7
7
use rustc_hir as hir;
@@ -43,6 +43,7 @@ crate fn mir_built<'tcx>(
43
43
fn mir_build ( tcx : TyCtxt < ' _ > , def : ty:: WithOptConstParam < LocalDefId > ) -> Body < ' _ > {
44
44
let id = tcx. hir ( ) . local_def_id_to_hir_id ( def. did ) ;
45
45
let body_owner_kind = tcx. hir ( ) . body_owner_kind ( id) ;
46
+ let typeck_results = tcx. typeck_opt_const_arg ( def) ;
46
47
47
48
// Figure out what primary body this item has.
48
49
let ( body_id, return_ty_span, span_with_body) = match tcx. hir ( ) . get ( id) {
@@ -87,15 +88,15 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
87
88
// If we don't have a specialized span for the body, just use the
88
89
// normal def span.
89
90
let span_with_body = span_with_body. unwrap_or_else ( || tcx. hir ( ) . span ( id) ) ;
91
+ let arena = Arena :: default ( ) ;
90
92
91
93
tcx. infer_ctxt ( ) . enter ( |infcx| {
92
- let mut cx = Cx :: new ( tcx, def) ;
93
- let body = if let Some ( ErrorReported ) = cx. typeck_results . tainted_by_errors {
94
+ let body = if let Some ( ErrorReported ) = typeck_results. tainted_by_errors {
94
95
build:: construct_error ( & infcx, def, id, body_id, body_owner_kind)
95
96
} else if body_owner_kind. is_fn_or_closure ( ) {
96
97
// fetch the fully liberated fn signature (that is, all bound
97
98
// types/lifetimes replaced)
98
- let fn_sig = cx . typeck_results . liberated_fn_sigs ( ) [ id] ;
99
+ let fn_sig = typeck_results. liberated_fn_sigs ( ) [ id] ;
99
100
let fn_def_id = tcx. hir ( ) . local_def_id ( id) ;
100
101
101
102
let safety = match fn_sig. unsafety {
@@ -104,7 +105,7 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
104
105
} ;
105
106
106
107
let body = tcx. hir ( ) . body ( body_id) ;
107
- let expr = cx . mirror_expr ( & body. value ) ;
108
+ let thir = build_thir ( tcx , def , & arena , & body. value ) ;
108
109
let ty = tcx. type_of ( fn_def_id) ;
109
110
let mut abi = fn_sig. abi ;
110
111
let implicit_argument = match ty. kind ( ) {
@@ -189,7 +190,7 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
189
190
return_ty,
190
191
return_ty_span,
191
192
body,
192
- expr ,
193
+ thir ,
193
194
span_with_body,
194
195
) ;
195
196
if yield_ty. is_some ( ) {
@@ -209,12 +210,12 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
209
210
// place to be the type of the constant because NLL typeck will
210
211
// equate them.
211
212
212
- let return_ty = cx . typeck_results . node_type ( id) ;
213
+ let return_ty = typeck_results. node_type ( id) ;
213
214
214
215
let ast_expr = & tcx. hir ( ) . body ( body_id) . value ;
215
- let expr = cx . mirror_expr ( ast_expr) ;
216
+ let thir = build_thir ( tcx , def , & arena , ast_expr) ;
216
217
217
- build:: construct_const ( & infcx, expr , def, id, return_ty, return_ty_span)
218
+ build:: construct_const ( & infcx, thir , def, id, return_ty, return_ty_span)
218
219
} ;
219
220
220
221
lints:: check ( tcx, & body) ;
@@ -601,7 +602,7 @@ fn construct_fn<'tcx, A>(
601
602
return_ty : Ty < ' tcx > ,
602
603
return_ty_span : Span ,
603
604
body : & ' tcx hir:: Body < ' tcx > ,
604
- expr : Expr < ' tcx > ,
605
+ expr : & Expr < ' _ , ' tcx > ,
605
606
span_with_body : Span ,
606
607
) -> Body < ' tcx >
607
608
where
@@ -668,7 +669,7 @@ where
668
669
669
670
fn construct_const < ' a , ' tcx > (
670
671
infcx : & ' a InferCtxt < ' a , ' tcx > ,
671
- expr : Expr < ' tcx > ,
672
+ expr : & Expr < ' _ , ' tcx > ,
672
673
def : ty:: WithOptConstParam < LocalDefId > ,
673
674
hir_id : hir:: HirId ,
674
675
const_ty : Ty < ' tcx > ,
@@ -825,7 +826,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
825
826
fn_def_id : DefId ,
826
827
arguments : & [ ArgInfo < ' tcx > ] ,
827
828
argument_scope : region:: Scope ,
828
- expr : & Expr < ' tcx > ,
829
+ expr : & Expr < ' _ , ' tcx > ,
829
830
) -> BlockAnd < ( ) > {
830
831
// Allocate locals for the function arguments
831
832
for & ArgInfo ( ty, _, arg_opt, _) in arguments. iter ( ) {
0 commit comments