@@ -536,11 +536,32 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
536
536
"allocations are not allowed in {}s" , v. msg( ) ) ;
537
537
}
538
538
}
539
- ast:: ExprUnary ( ast :: UnDeref , ref ptr ) => {
540
- match ty:: node_id_to_type ( v. tcx , ptr . id ) . sty {
539
+ ast:: ExprUnary ( op , ref inner ) => {
540
+ match ty:: node_id_to_type ( v. tcx , inner . id ) . sty {
541
541
ty:: ty_ptr( _) => {
542
- // This shouldn't be allowed in constants at all.
542
+ assert ! ( op == ast:: UnDeref ) ;
543
+
544
+ v. add_qualif ( ConstQualif :: NOT_CONST ) ;
545
+ if v. mode != Mode :: Var {
546
+ span_err ! ( v. tcx. sess, e. span, E0381 ,
547
+ "raw pointers cannot be dereferenced in {}s" , v. msg( ) ) ;
548
+ }
549
+ }
550
+ _ => { }
551
+ }
552
+ }
553
+ ast:: ExprBinary ( op, ref lhs, _) => {
554
+ match ty:: node_id_to_type ( v. tcx , lhs. id ) . sty {
555
+ ty:: ty_ptr( _) => {
556
+ assert ! ( op. node == ast:: BiEq || op. node == ast:: BiNe ||
557
+ op. node == ast:: BiLe || op. node == ast:: BiLt ||
558
+ op. node == ast:: BiGe || op. node == ast:: BiGt ) ;
559
+
543
560
v. add_qualif ( ConstQualif :: NOT_CONST ) ;
561
+ if v. mode != Mode :: Var {
562
+ span_err ! ( v. tcx. sess, e. span, E0380 ,
563
+ "raw pointers cannot be compared in {}s" , v. msg( ) ) ;
564
+ }
544
565
}
545
566
_ => { }
546
567
}
@@ -553,7 +574,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
553
574
v. add_qualif ( ConstQualif :: NOT_CONST ) ;
554
575
if v. mode != Mode :: Var {
555
576
span_err ! ( v. tcx. sess, e. span, E0018 ,
556
- "can't cast a pointer to an integer in {}s" , v. msg( ) ) ;
577
+ "raw pointers cannot be cast to integers in {}s" , v. msg( ) ) ;
557
578
}
558
579
}
559
580
_ => { }
@@ -695,8 +716,6 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
695
716
}
696
717
697
718
ast:: ExprBlock ( _) |
698
- ast:: ExprUnary ( ..) |
699
- ast:: ExprBinary ( ..) |
700
719
ast:: ExprIndex ( ..) |
701
720
ast:: ExprField ( ..) |
702
721
ast:: ExprTupField ( ..) |
0 commit comments