11//! The `Visitor` responsible for actually checking a `mir::Body` for invalid operations.
22
33use rustc_errors:: struct_span_err;
4- use rustc_hir:: lang_items;
4+ use rustc_hir:: { self as hir , lang_items} ;
55use rustc_hir:: { def_id:: DefId , HirId } ;
66use rustc_infer:: infer:: TyCtxtInferExt ;
77use rustc_middle:: mir:: visit:: { MutatingUseContext , NonMutatingUseContext , PlaceContext , Visitor } ;
@@ -18,7 +18,7 @@ use std::ops::Deref;
1818use super :: ops:: { self , NonConstOp } ;
1919use super :: qualifs:: { self , CustomEq , HasMutInterior , NeedsDrop } ;
2020use super :: resolver:: FlowSensitiveAnalysis ;
21- use super :: { is_lang_panic_fn, ConstCx , ConstKind , Qualif } ;
21+ use super :: { is_lang_panic_fn, ConstCx , Qualif } ;
2222use crate :: const_eval:: { is_const_fn, is_unstable_const_fn} ;
2323use crate :: dataflow:: MaybeMutBorrowedLocals ;
2424use crate :: dataflow:: { self , Analysis } ;
@@ -145,17 +145,13 @@ impl Qualifs<'mir, 'tcx> {
145145 // We don't care whether a `const fn` returns a value that is not structurally
146146 // matchable. Functions calls are opaque and always use type-based qualification, so
147147 // this value should never be used.
148- ConstKind :: ConstFn => true ,
148+ hir :: ConstContext :: ConstFn => true ,
149149
150150 // If we know that all values of the return type are structurally matchable, there's no
151151 // need to run dataflow.
152- ConstKind :: Const | ConstKind :: Static | ConstKind :: StaticMut
153- if !CustomEq :: in_any_value_of_ty ( ccx, ccx. body . return_ty ( ) ) =>
154- {
155- false
156- }
152+ _ if !CustomEq :: in_any_value_of_ty ( ccx, ccx. body . return_ty ( ) ) => false ,
157153
158- ConstKind :: Const | ConstKind :: Static | ConstKind :: StaticMut => {
154+ hir :: ConstContext :: Const | hir :: ConstContext :: Static ( _ ) => {
159155 let mut cursor = FlowSensitiveAnalysis :: new ( CustomEq , ccx)
160156 . into_engine ( ccx. tcx , & ccx. body , ccx. def_id )
161157 . iterate_to_fixpoint ( )
@@ -198,7 +194,7 @@ impl Validator<'mir, 'tcx> {
198194 pub fn check_body ( & mut self ) {
199195 let ConstCx { tcx, body, def_id, const_kind, .. } = * self . ccx ;
200196
201- let use_min_const_fn_checks = ( const_kind == Some ( ConstKind :: ConstFn )
197+ let use_min_const_fn_checks = ( const_kind == Some ( hir :: ConstContext :: ConstFn )
202198 && crate :: const_eval:: is_min_const_fn ( tcx, def_id) )
203199 && !tcx. sess . opts . debugging_opts . unleash_the_miri_inside_of_you ;
204200
@@ -222,8 +218,9 @@ impl Validator<'mir, 'tcx> {
222218 self . visit_body ( & body) ;
223219
224220 // Ensure that the end result is `Sync` in a non-thread local `static`.
225- let should_check_for_sync =
226- const_kind == Some ( ConstKind :: Static ) && !tcx. is_thread_local_static ( def_id) ;
221+ let should_check_for_sync = const_kind
222+ == Some ( hir:: ConstContext :: Static ( hir:: Mutability :: Not ) )
223+ && !tcx. is_thread_local_static ( def_id) ;
227224
228225 if should_check_for_sync {
229226 let hir_id = tcx. hir ( ) . as_local_hir_id ( def_id. expect_local ( ) ) ;
@@ -351,7 +348,9 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
351348 let ty = place. ty ( self . body , self . tcx ) . ty ;
352349 let is_allowed = match ty. kind {
353350 // Inside a `static mut`, `&mut [...]` is allowed.
354- ty:: Array ( ..) | ty:: Slice ( _) if self . const_kind ( ) == ConstKind :: StaticMut => {
351+ ty:: Array ( ..) | ty:: Slice ( _)
352+ if self . const_kind ( ) == hir:: ConstContext :: Static ( hir:: Mutability :: Mut ) =>
353+ {
355354 true
356355 }
357356
0 commit comments