@@ -1933,8 +1933,8 @@ fn lookup_field_ty(cx: ty::ctxt, items:[@ast::class_item],
1933
1933
1934
1934
/*
1935
1935
* 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.
1938
1938
*
1939
1939
* Note that borrowing is not detected here, because we would have to
1940
1940
* immediately structurally resolve too many types otherwise. Thus the
@@ -1958,10 +1958,20 @@ fn region_of(fcx: @fn_ctxt, expr: @ast::expr) -> ty::region {
1958
1958
}
1959
1959
}
1960
1960
}
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
+ }
1965
1975
}
1966
1976
_ {
1967
1977
let blk_id = fcx. ccx . tcx . region_map . rvalue_to_block . get ( expr. id ) ;
0 commit comments