1
1
//! The `Visitor` responsible for actually checking a `mir::Body` for invalid operations.
2
2
3
3
use rustc_errors:: struct_span_err;
4
- use rustc_hir:: lang_items;
4
+ use rustc_hir:: { self as hir , lang_items} ;
5
5
use rustc_hir:: { def_id:: DefId , HirId } ;
6
6
use rustc_infer:: infer:: TyCtxtInferExt ;
7
7
use rustc_middle:: mir:: visit:: { MutatingUseContext , NonMutatingUseContext , PlaceContext , Visitor } ;
@@ -18,7 +18,7 @@ use std::ops::Deref;
18
18
use super :: ops:: { self , NonConstOp } ;
19
19
use super :: qualifs:: { self , CustomEq , HasMutInterior , NeedsDrop } ;
20
20
use super :: resolver:: FlowSensitiveAnalysis ;
21
- use super :: { is_lang_panic_fn, ConstCx , ConstKind , Qualif } ;
21
+ use super :: { is_lang_panic_fn, ConstCx , Qualif } ;
22
22
use crate :: const_eval:: { is_const_fn, is_unstable_const_fn} ;
23
23
use crate :: dataflow:: impls:: MaybeMutBorrowedLocals ;
24
24
use crate :: dataflow:: { self , Analysis } ;
@@ -145,17 +145,13 @@ impl Qualifs<'mir, 'tcx> {
145
145
// We don't care whether a `const fn` returns a value that is not structurally
146
146
// matchable. Functions calls are opaque and always use type-based qualification, so
147
147
// this value should never be used.
148
- ConstKind :: ConstFn => true ,
148
+ hir :: ConstContext :: ConstFn => true ,
149
149
150
150
// If we know that all values of the return type are structurally matchable, there's no
151
151
// 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 ,
157
153
158
- ConstKind :: Const | ConstKind :: Static | ConstKind :: StaticMut => {
154
+ hir :: ConstContext :: Const | hir :: ConstContext :: Static ( _ ) => {
159
155
let mut cursor = FlowSensitiveAnalysis :: new ( CustomEq , ccx)
160
156
. into_engine ( ccx. tcx , & ccx. body , ccx. def_id )
161
157
. iterate_to_fixpoint ( )
@@ -198,7 +194,7 @@ impl Validator<'mir, 'tcx> {
198
194
pub fn check_body ( & mut self ) {
199
195
let ConstCx { tcx, body, def_id, const_kind, .. } = * self . ccx ;
200
196
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 )
202
198
&& crate :: const_eval:: is_min_const_fn ( tcx, def_id) )
203
199
&& !tcx. sess . opts . debugging_opts . unleash_the_miri_inside_of_you ;
204
200
@@ -222,8 +218,9 @@ impl Validator<'mir, 'tcx> {
222
218
self . visit_body ( & body) ;
223
219
224
220
// 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) ;
227
224
228
225
if should_check_for_sync {
229
226
let hir_id = tcx. hir ( ) . as_local_hir_id ( def_id. expect_local ( ) ) ;
@@ -351,7 +348,9 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
351
348
let ty = place. ty ( self . body , self . tcx ) . ty ;
352
349
let is_allowed = match ty. kind {
353
350
// 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
+ {
355
354
true
356
355
}
357
356
0 commit comments