@@ -193,7 +193,7 @@ fn structurally_resolved_type(fcx: @fn_ctxt, sp: span, tp: ty::t) -> ty::t {
193
193
}
194
194
195
195
196
- // Returns the one-level-deep structure of the given type.
196
+ // Returns the one-level-deep structure of the given type.f
197
197
fn structure_of ( fcx : @fn_ctxt , sp : span , typ : ty:: t ) -> ty:: sty {
198
198
ret ty:: struct ( fcx. ccx . tcx , structurally_resolved_type ( fcx, sp, typ) ) ;
199
199
}
@@ -1530,7 +1530,7 @@ fn require_unsafe(sess: session::session, f_purity: ast::purity, sp: span) {
1530
1530
_ {
1531
1531
sess. span_fatal (
1532
1532
sp,
1533
- "Found unsafe expression in safe function decl " ) ;
1533
+ "unsafe operation requires unsafe function or block " ) ;
1534
1534
}
1535
1535
}
1536
1536
}
@@ -1591,6 +1591,23 @@ fn check_expr_with(fcx: @fn_ctxt, expr: @ast::expr, expected: ty::t) -> bool {
1591
1591
ret check_expr_with_unifier ( fcx, expr, demand:: simple, expected) ;
1592
1592
}
1593
1593
1594
+ fn check_for_unsafe_assignments ( fcx : @fn_ctxt , lhs : @ast:: expr ) {
1595
+ alt lhs. node {
1596
+ ast:: expr_unary ( ast:: deref. , ptr ) {
1597
+ let ty = expr_ty ( fcx. ccx . tcx , ptr) ;
1598
+ let sty = structure_of ( fcx, ptr. span , ty) ;
1599
+ alt sty {
1600
+ ty : : ty_ptr ( _) {
1601
+ require_unsafe ( fcx. ccx . tcx . sess , fcx. purity , lhs. span ) ;
1602
+ }
1603
+ _ { }
1604
+ }
1605
+ }
1606
+ _ {
1607
+ }
1608
+ }
1609
+ }
1610
+
1594
1611
fn check_expr_with_unifier ( fcx : @fn_ctxt , expr : @ast:: expr , unify : unifier ,
1595
1612
expected : ty:: t ) -> bool {
1596
1613
//log_err "typechecking expr " + syntax::print::pprust::expr_to_str(expr);
@@ -1702,6 +1719,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
1702
1719
rhs: @ast:: expr, id: ast:: node_id) -> bool {
1703
1720
let t = next_ty_var( fcx) ;
1704
1721
let bot = check_expr_with( fcx, lhs, t) | check_expr_with( fcx, rhs, t) ;
1722
+ check_for_unsafe_assignments( fcx, lhs) ;
1705
1723
write:: ty_only_fixup( fcx, id, ty:: mk_nil( fcx. ccx. tcx) ) ;
1706
1724
ret bot;
1707
1725
}
0 commit comments