@@ -5,10 +5,10 @@ use crate::util::{describe_rvalue, ty_callee, Callee, RvalueDesc};
5
5
use assert_matches:: assert_matches;
6
6
use rustc_hir:: def_id:: DefId ;
7
7
use rustc_middle:: mir:: {
8
- AggregateKind , BinOp , Body , ConstantKind , Location , Mutability , Operand , Place , PlaceRef ,
9
- ProjectionElem , Rvalue , Statement , StatementKind , Terminator , TerminatorKind ,
8
+ AggregateKind , BinOp , Body , Location , Mutability , Operand , Place , PlaceRef , ProjectionElem ,
9
+ Rvalue , Statement , StatementKind , Terminator , TerminatorKind ,
10
10
} ;
11
- use rustc_middle:: ty:: { self , SubstsRef , Ty , TyKind } ;
11
+ use rustc_middle:: ty:: { SubstsRef , Ty , TyKind } ;
12
12
13
13
/// Visitor that walks over the MIR, computing types of rvalues/operands/places and generating
14
14
/// constraints as a side effect.
@@ -454,21 +454,6 @@ impl<'tcx> TypeChecker<'tcx, '_> {
454
454
}
455
455
}
456
456
457
- fn const_perms ( constant : ConstantKind ) -> PermissionSet {
458
- let ref_ty = constant. ty ( ) ;
459
- let ty = match ref_ty. kind ( ) {
460
- ty:: Ref ( _, ty, _) => ty,
461
- _ => panic ! ( "expected only `Ref`s for constants: {ref_ty:?}" ) ,
462
- } ;
463
- if ty. is_array ( ) || ty. is_str ( ) {
464
- PermissionSet :: READ | PermissionSet :: OFFSET_ADD
465
- } else if ty. is_primitive_ty ( ) {
466
- PermissionSet :: READ
467
- } else {
468
- panic ! ( "expected an array, str, or primitive type: {ty:?}" ) ;
469
- }
470
- }
471
-
472
457
pub fn visit < ' tcx > (
473
458
acx : & AnalysisCtxt < ' _ , ' tcx > ,
474
459
mir : & Body < ' tcx > ,
@@ -482,7 +467,7 @@ pub fn visit<'tcx>(
482
467
483
468
for ( & constant, const_lty) in & acx. const_ref_tys {
484
469
tc. constraints
485
- . add_all_perms ( const_lty. label , const_perms ( constant) ) ;
470
+ . add_all_perms ( const_lty. label , PermissionSet :: for_const ( constant) ) ;
486
471
}
487
472
488
473
for ( bb, bb_data) in mir. basic_blocks ( ) . iter_enumerated ( ) {
@@ -506,7 +491,7 @@ pub fn visit<'tcx>(
506
491
507
492
for ( & constant, const_lty) in & acx. const_ref_tys {
508
493
let _ptr_id = const_lty. label ;
509
- let _expected_perms = const_perms ( constant) ;
494
+ let _expected_perms = PermissionSet :: for_const ( constant) ;
510
495
// TODO: check that perms match the expected ones
511
496
}
512
497
0 commit comments