@@ -495,20 +495,22 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
495
495
this. super_place ( place, context, location) ;
496
496
match proj. elem {
497
497
ProjectionElem :: Deref => {
498
- if let Mode :: Fn = this. mode {
499
- this. add ( Qualif :: NOT_CONST ) ;
500
- } else {
501
- let base_ty = proj. base . ty ( this. mir , this. tcx ) . to_ty ( this. tcx ) ;
502
- if let ty:: RawPtr ( _) = base_ty. sty {
503
- if !this. tcx . sess . features_untracked ( ) . const_raw_ptr_deref {
504
- emit_feature_err (
505
- & this. tcx . sess . parse_sess , "const_raw_ptr_deref" ,
506
- this. span , GateIssue :: Language ,
507
- & format ! (
508
- "dereferencing raw pointers in {}s is unstable" ,
509
- this. mode,
510
- ) ,
511
- ) ;
498
+ this. add ( Qualif :: NOT_CONST ) ;
499
+ let base_ty = proj. base . ty ( this. mir , this. tcx ) . to_ty ( this. tcx ) ;
500
+ match this. mode {
501
+ Mode :: Fn => { } ,
502
+ _ => {
503
+ if let ty:: RawPtr ( _) = base_ty. sty {
504
+ if !this. tcx . sess . features_untracked ( ) . const_raw_ptr_deref {
505
+ emit_feature_err (
506
+ & this. tcx . sess . parse_sess , "const_raw_ptr_deref" ,
507
+ this. span , GateIssue :: Language ,
508
+ & format ! (
509
+ "dereferencing raw pointers in {}s is unstable" ,
510
+ this. mode,
511
+ ) ,
512
+ ) ;
513
+ }
512
514
}
513
515
}
514
516
}
@@ -732,8 +734,11 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
732
734
( CastTy :: Ptr ( _) , CastTy :: Int ( _) ) |
733
735
( CastTy :: FnPtr , CastTy :: Int ( _) ) => {
734
736
if let Mode :: Fn = self . mode {
737
+ // in normal functions, mark such casts as not promotable
735
738
self . add ( Qualif :: NOT_CONST ) ;
736
739
} else if !self . tcx . sess . features_untracked ( ) . const_raw_ptr_to_usize_cast {
740
+ // in const fn and constants require the feature gate
741
+ // FIXME: make it unsafe inside const fn and constants
737
742
emit_feature_err (
738
743
& self . tcx . sess . parse_sess , "const_raw_ptr_to_usize_cast" ,
739
744
self . span , GateIssue :: Language ,
@@ -756,8 +761,11 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
756
761
op == BinOp :: Offset ) ;
757
762
758
763
if let Mode :: Fn = self . mode {
764
+ // raw pointer operations are not allowed inside promoteds
759
765
self . add ( Qualif :: NOT_CONST ) ;
760
766
} else if !self . tcx . sess . features_untracked ( ) . const_compare_raw_pointers {
767
+ // require the feature gate inside constants and const fn
768
+ // FIXME: make it unsafe to use these operations
761
769
emit_feature_err (
762
770
& self . tcx . sess . parse_sess ,
763
771
"const_compare_raw_pointers" ,
0 commit comments