@@ -33,6 +33,7 @@ extern crate rustc_middle;
33
33
pub mod const_eval;
34
34
mod errors;
35
35
pub mod interpret;
36
+ pub mod might_permit_raw_init;
36
37
pub mod transform;
37
38
pub mod util;
38
39
@@ -60,49 +61,3 @@ pub fn provide(providers: &mut Providers) {
60
61
const_eval:: deref_mir_constant ( tcx, param_env, value)
61
62
} ;
62
63
}
63
-
64
- use crate :: const_eval:: CompileTimeInterpreter ;
65
- use crate :: interpret:: { InterpCx , MemoryKind , OpTy } ;
66
- use rustc_middle:: ty:: layout:: LayoutCx ;
67
- use rustc_middle:: ty:: { layout:: TyAndLayout , ParamEnv , TyCtxt } ;
68
- use rustc_session:: Limit ;
69
- use rustc_span:: Span ;
70
- use rustc_target:: abi:: InitKind ;
71
-
72
- pub fn might_permit_raw_init < ' tcx > (
73
- tcx : TyCtxt < ' tcx > ,
74
- root_span : Span ,
75
- ty : TyAndLayout < ' tcx > ,
76
- strict : bool ,
77
- kind : InitKind ,
78
- ) -> bool {
79
- if strict {
80
- let machine = CompileTimeInterpreter :: new ( Limit :: new ( 0 ) , false ) ;
81
-
82
- let mut cx = InterpCx :: new ( tcx, root_span, ParamEnv :: reveal_all ( ) , machine) ;
83
-
84
- // We could panic here... Or we could just return "yeah it's valid whatever". Or let
85
- // codegen_panic_intrinsic return an error that halts compilation.
86
- // I'm not exactly sure *when* this can fail. OOM?
87
- let allocated = cx
88
- . allocate ( ty, MemoryKind :: Machine ( const_eval:: MemoryKind :: Heap ) )
89
- . expect ( "failed to allocate for uninit check" ) ;
90
-
91
- if kind == InitKind :: Zero {
92
- // Again, unclear what to do here if it fails.
93
- cx. write_bytes_ptr (
94
- allocated. ptr ,
95
- std:: iter:: repeat ( 0_u8 ) . take ( ty. layout . size ( ) . bytes_usize ( ) ) ,
96
- )
97
- . expect ( "failed to write bytes for zero valid check" ) ;
98
- }
99
-
100
- let ot: OpTy < ' _ , _ > = allocated. into ( ) ;
101
-
102
- // Assume that if it failed, it's a validation failure.
103
- cx. validate_operand ( & ot) . is_ok ( )
104
- } else {
105
- let layout_cx = LayoutCx { tcx, param_env : ParamEnv :: reveal_all ( ) } ;
106
- !ty. might_permit_raw_init ( & layout_cx, kind)
107
- }
108
- }
0 commit comments