Skip to content

Commit 1ed768b

Browse files
committed
rustc: Determine the region of pointer dereference expressions
1 parent 1600be2 commit 1ed768b

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/rustc/middle/typeck.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,8 +1933,8 @@ fn lookup_field_ty(cx: ty::ctxt, items:[@ast::class_item],
19331933

19341934
/*
19351935
* Returns the region that the value named by the given expression lives in.
1936-
* If the expression is not an lvalue, reports an error and returns the block
1937-
* region.
1936+
* The expression must have been typechecked. If the expression is not an
1937+
* lvalue, returns the block region.
19381938
*
19391939
* Note that borrowing is not detected here, because we would have to
19401940
* immediately structurally resolve too many types otherwise. Thus the
@@ -1958,10 +1958,20 @@ fn region_of(fcx: @fn_ctxt, expr: @ast::expr) -> ty::region {
19581958
}
19591959
}
19601960
}
1961-
ast::expr_field(base, _, _) | ast::expr_index(base, _) |
1962-
ast::expr_unary(ast::deref, base) {
1963-
fcx.ccx.tcx.sess.span_unimpl(expr.span, "regions of field, " +
1964-
"index, or deref operations");
1961+
ast::expr_field(base, _, _) | ast::expr_index(base, _) {
1962+
fcx.ccx.tcx.sess.span_unimpl(expr.span, "regions of field or " +
1963+
"index operations");
1964+
}
1965+
ast::expr_unary(ast::deref, base) {
1966+
let expr_ty = ty::expr_ty(fcx.ccx.tcx, base);
1967+
let expr_ty = structurally_resolved_type(fcx, expr.span, expr_ty);
1968+
alt ty::get(expr_ty).struct {
1969+
ty::ty_rptr(region, _) { region }
1970+
ty::ty_box(_) | ty::ty_uniq(_) {
1971+
fcx.ccx.tcx.sess.span_unimpl(expr.span, "borrowing");
1972+
}
1973+
_ { ret region_of(fcx, base); }
1974+
}
19651975
}
19661976
_ {
19671977
let blk_id = fcx.ccx.tcx.region_map.rvalue_to_block.get(expr.id);

0 commit comments

Comments
 (0)