@@ -5,7 +5,7 @@ use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput};
5
5
use rustc_middle:: thir:: visit;
6
6
use rustc_middle:: thir:: visit:: Visitor ;
7
7
use rustc_middle:: ty:: abstract_const:: CastKind ;
8
- use rustc_middle:: ty:: { self , ConstKind , Expr , TyCtxt , TypeVisitable } ;
8
+ use rustc_middle:: ty:: { self , Expr , TyCtxt , TypeVisitable } ;
9
9
use rustc_middle:: { mir, thir} ;
10
10
use rustc_span:: Span ;
11
11
use rustc_target:: abi:: VariantIdx ;
@@ -32,10 +32,8 @@ pub(crate) fn destructure_const<'tcx>(
32
32
let ( fields, variant) = match const_. ty ( ) . kind ( ) {
33
33
ty:: Array ( inner_ty, _) | ty:: Slice ( inner_ty) => {
34
34
// construct the consts for the elements of the array/slice
35
- let field_consts = branches
36
- . iter ( )
37
- . map ( |b| tcx. mk_const ( ty:: ConstKind :: Value ( * b) , * inner_ty) )
38
- . collect :: < Vec < _ > > ( ) ;
35
+ let field_consts =
36
+ branches. iter ( ) . map ( |b| tcx. mk_const ( * b, * inner_ty) ) . collect :: < Vec < _ > > ( ) ;
39
37
debug ! ( ?field_consts) ;
40
38
41
39
( field_consts, None )
@@ -53,7 +51,7 @@ pub(crate) fn destructure_const<'tcx>(
53
51
54
52
for ( field, field_valtree) in iter:: zip ( fields, branches) {
55
53
let field_ty = field. ty ( tcx, substs) ;
56
- let field_const = tcx. mk_const ( ty :: ConstKind :: Value ( * field_valtree) , field_ty) ;
54
+ let field_const = tcx. mk_const ( * field_valtree, field_ty) ;
57
55
field_consts. push ( field_const) ;
58
56
}
59
57
debug ! ( ?field_consts) ;
@@ -62,9 +60,7 @@ pub(crate) fn destructure_const<'tcx>(
62
60
}
63
61
ty:: Tuple ( elem_tys) => {
64
62
let fields = iter:: zip ( * elem_tys, branches)
65
- . map ( |( elem_ty, elem_valtree) | {
66
- tcx. mk_const ( ty:: ConstKind :: Value ( * elem_valtree) , elem_ty)
67
- } )
63
+ . map ( |( elem_ty, elem_valtree) | tcx. mk_const ( * elem_valtree, elem_ty) )
68
64
. collect :: < Vec < _ > > ( ) ;
69
65
70
66
( fields, None )
@@ -137,9 +133,9 @@ fn recurse_build<'tcx>(
137
133
}
138
134
& ExprKind :: NamedConst { def_id, substs, user_ty : _ } => {
139
135
let uneval = ty:: UnevaluatedConst :: new ( ty:: WithOptConstParam :: unknown ( def_id) , substs) ;
140
- tcx. mk_const ( ty :: ConstKind :: Unevaluated ( uneval) , node. ty )
136
+ tcx. mk_const ( uneval, node. ty )
141
137
}
142
- ExprKind :: ConstParam { param, .. } => tcx. mk_const ( ty :: ConstKind :: Param ( * param) , node. ty ) ,
138
+ ExprKind :: ConstParam { param, .. } => tcx. mk_const ( * param, node. ty ) ,
143
139
144
140
ExprKind :: Call { fun, args, .. } => {
145
141
let fun = recurse_build ( tcx, body, * fun, root_span) ?;
@@ -149,16 +145,16 @@ fn recurse_build<'tcx>(
149
145
new_args. push ( recurse_build ( tcx, body, id, root_span) ?) ;
150
146
}
151
147
let new_args = tcx. mk_const_list ( new_args. iter ( ) ) ;
152
- tcx. mk_const ( ConstKind :: Expr ( Expr :: FunctionCall ( fun, new_args) ) , node. ty )
148
+ tcx. mk_const ( Expr :: FunctionCall ( fun, new_args) , node. ty )
153
149
}
154
150
& ExprKind :: Binary { op, lhs, rhs } if check_binop ( op) => {
155
151
let lhs = recurse_build ( tcx, body, lhs, root_span) ?;
156
152
let rhs = recurse_build ( tcx, body, rhs, root_span) ?;
157
- tcx. mk_const ( ConstKind :: Expr ( Expr :: Binop ( op, lhs, rhs) ) , node. ty )
153
+ tcx. mk_const ( Expr :: Binop ( op, lhs, rhs) , node. ty )
158
154
}
159
155
& ExprKind :: Unary { op, arg } if check_unop ( op) => {
160
156
let arg = recurse_build ( tcx, body, arg, root_span) ?;
161
- tcx. mk_const ( ConstKind :: Expr ( Expr :: UnOp ( op, arg) ) , node. ty )
157
+ tcx. mk_const ( Expr :: UnOp ( op, arg) , node. ty )
162
158
}
163
159
// This is necessary so that the following compiles:
164
160
//
@@ -179,11 +175,11 @@ fn recurse_build<'tcx>(
179
175
// This is important so that `N as usize as usize` doesnt unify with `N as usize`. (untested)
180
176
& ExprKind :: Use { source } => {
181
177
let arg = recurse_build ( tcx, body, source, root_span) ?;
182
- tcx. mk_const ( ConstKind :: Expr ( Expr :: Cast ( CastKind :: Use , arg, node. ty ) ) , node. ty )
178
+ tcx. mk_const ( Expr :: Cast ( CastKind :: Use , arg, node. ty ) , node. ty )
183
179
}
184
180
& ExprKind :: Cast { source } => {
185
181
let arg = recurse_build ( tcx, body, source, root_span) ?;
186
- tcx. mk_const ( ConstKind :: Expr ( Expr :: Cast ( CastKind :: As , arg, node. ty ) ) , node. ty )
182
+ tcx. mk_const ( Expr :: Cast ( CastKind :: As , arg, node. ty ) , node. ty )
187
183
}
188
184
ExprKind :: Borrow { arg, .. } => {
189
185
let arg_node = & body. exprs [ * arg] ;
0 commit comments