@@ -536,11 +536,32 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
536536 "allocations are not allowed in {}s" , v. msg( ) ) ;
537537 }
538538 }
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 {
541541 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, E0396 ,
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+
543560 v. add_qualif ( ConstQualif :: NOT_CONST ) ;
561+ if v. mode != Mode :: Var {
562+ span_err ! ( v. tcx. sess, e. span, E0395 ,
563+ "raw pointers cannot be compared in {}s" , v. msg( ) ) ;
564+ }
544565 }
545566 _ => { }
546567 }
@@ -553,7 +574,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
553574 v. add_qualif ( ConstQualif :: NOT_CONST ) ;
554575 if v. mode != Mode :: Var {
555576 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( ) ) ;
557578 }
558579 }
559580 _ => { }
@@ -695,8 +716,6 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
695716 }
696717
697718 ast:: ExprBlock ( _) |
698- ast:: ExprUnary ( ..) |
699- ast:: ExprBinary ( ..) |
700719 ast:: ExprIndex ( ..) |
701720 ast:: ExprField ( ..) |
702721 ast:: ExprTupField ( ..) |
0 commit comments