1- use std:: iter;
2-
3- use rustc_abi:: { FIRST_VARIANT , VariantIdx } ;
41use rustc_errors:: ErrorGuaranteed ;
52use rustc_hir:: def:: DefKind ;
63use rustc_hir:: def_id:: LocalDefId ;
@@ -10,63 +7,12 @@ use rustc_middle::thir::visit;
107use rustc_middle:: thir:: visit:: Visitor ;
118use rustc_middle:: ty:: abstract_const:: CastKind ;
129use rustc_middle:: ty:: { self , Expr , TyCtxt , TypeVisitableExt } ;
13- use rustc_middle:: { bug , mir, thir} ;
10+ use rustc_middle:: { mir, thir} ;
1411use rustc_span:: Span ;
15- use tracing:: { debug , instrument} ;
12+ use tracing:: instrument;
1613
1714use crate :: errors:: { GenericConstantTooComplex , GenericConstantTooComplexSub } ;
1815
19- /// Destructures array, ADT or tuple constants into the constants
20- /// of their fields.
21- fn destructure_const < ' tcx > (
22- tcx : TyCtxt < ' tcx > ,
23- const_ : ty:: Const < ' tcx > ,
24- ) -> ty:: DestructuredConst < ' tcx > {
25- let ty:: ConstKind :: Value ( cv) = const_. kind ( ) else {
26- bug ! ( "cannot destructure constant {:?}" , const_)
27- } ;
28- let branches = cv. to_branch ( ) ;
29-
30- let ( fields, variant) = match cv. ty . kind ( ) {
31- ty:: Array ( inner_ty, _) | ty:: Slice ( inner_ty) => {
32- // construct the consts for the elements of the array/slice
33- let field_consts = branches
34- . iter ( )
35- . map ( |b| ty:: Const :: new_value ( tcx, b. to_value ( ) . valtree , * inner_ty) )
36- . collect :: < Vec < _ > > ( ) ;
37- debug ! ( ?field_consts) ;
38-
39- ( field_consts, None )
40- }
41- ty:: Adt ( def, _) if def. variants ( ) . is_empty ( ) => bug ! ( "unreachable" ) ,
42- ty:: Adt ( def, _) => {
43- let ( variant_idx, field_consts) = if def. is_enum ( ) {
44- let ( head, rest) = branches. split_first ( ) . unwrap ( ) ;
45- ( VariantIdx :: from_u32 ( head. to_leaf ( ) . to_u32 ( ) ) , rest)
46- } else {
47- ( FIRST_VARIANT , branches)
48- } ;
49- debug ! ( ?field_consts) ;
50-
51- ( field_consts. to_vec ( ) , Some ( variant_idx) )
52- }
53- ty:: Tuple ( elem_tys) => {
54- let fields = iter:: zip ( * elem_tys, branches)
55- . map ( |( elem_ty, elem_valtree) | {
56- ty:: Const :: new_value ( tcx, elem_valtree. to_value ( ) . valtree , elem_ty)
57- } )
58- . collect :: < Vec < _ > > ( ) ;
59-
60- ( fields, None )
61- }
62- _ => bug ! ( "cannot destructure constant {:?}" , const_) ,
63- } ;
64-
65- let fields = tcx. arena . alloc_from_iter ( fields) ;
66-
67- ty:: DestructuredConst { variant, fields }
68- }
69-
7016/// We do not allow all binary operations in abstract consts, so filter disallowed ones.
7117fn check_binop ( op : mir:: BinOp ) -> bool {
7218 use mir:: BinOp :: * ;
@@ -432,5 +378,5 @@ fn thir_abstract_const<'tcx>(
432378}
433379
434380pub ( crate ) fn provide ( providers : & mut Providers ) {
435- * providers = Providers { destructure_const , thir_abstract_const, ..* providers } ;
381+ * providers = Providers { thir_abstract_const, ..* providers } ;
436382}
0 commit comments