Skip to content

Commit 5ab33a2

Browse files
committed
correct incorrect handling of overloaded operators, exposing various other bits of rot
1 parent f236b85 commit 5ab33a2

File tree

9 files changed

+117
-129
lines changed

9 files changed

+117
-129
lines changed

src/libcore/ptr.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,34 +296,34 @@ impl<T> Ord for *const T {
296296
297297
// Equality for region pointers
298298
#[cfg(notest)]
299-
impl<'self,T:Eq> Eq for &'self const T {
299+
impl<'self,T:Eq> Eq for &'self T {
300300
#[inline(always)]
301-
fn eq(&self, other: & &'self const T) -> bool {
301+
fn eq(&self, other: & &'self T) -> bool {
302302
return *(*self) == *(*other);
303303
}
304304
#[inline(always)]
305-
fn ne(&self, other: & &'self const T) -> bool {
305+
fn ne(&self, other: & &'self T) -> bool {
306306
return *(*self) != *(*other);
307307
}
308308
}
309309
310310
// Comparison for region pointers
311311
#[cfg(notest)]
312-
impl<'self,T:Ord> Ord for &'self const T {
312+
impl<'self,T:Ord> Ord for &'self T {
313313
#[inline(always)]
314-
fn lt(&self, other: & &'self const T) -> bool {
314+
fn lt(&self, other: & &'self T) -> bool {
315315
*(*self) < *(*other)
316316
}
317317
#[inline(always)]
318-
fn le(&self, other: & &'self const T) -> bool {
318+
fn le(&self, other: & &'self T) -> bool {
319319
*(*self) <= *(*other)
320320
}
321321
#[inline(always)]
322-
fn ge(&self, other: & &'self const T) -> bool {
322+
fn ge(&self, other: & &'self T) -> bool {
323323
*(*self) >= *(*other)
324324
}
325325
#[inline(always)]
326-
fn gt(&self, other: & &'self const T) -> bool {
326+
fn gt(&self, other: & &'self T) -> bool {
327327
*(*self) > *(*other)
328328
}
329329
}

src/librustc/middle/borrowck/gather_loans/mod.rs

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ struct GatherLoanCtxt {
6868
id_range: id_range,
6969
all_loans: @mut ~[Loan],
7070
item_ub: ast::node_id,
71-
repeating_ids: ~[ast::node_id],
72-
ignore_adjustments: HashSet<ast::node_id>
71+
repeating_ids: ~[ast::node_id]
7372
}
7473

7574
pub fn gather_loans(bccx: @BorrowckCtxt,
@@ -79,8 +78,7 @@ pub fn gather_loans(bccx: @BorrowckCtxt,
7978
id_range: id_range::max(),
8079
all_loans: @mut ~[],
8180
item_ub: body.node.id,
82-
repeating_ids: ~[body.node.id],
83-
ignore_adjustments: HashSet::new()
81+
repeating_ids: ~[body.node.id]
8482
};
8583
let v = visit::mk_vt(@visit::Visitor {visit_expr: gather_loans_in_expr,
8684
visit_block: gather_loans_in_block,
@@ -147,13 +145,8 @@ fn gather_loans_in_expr(ex: @ast::expr,
147145
self.id_range.add(ex.callee_id);
148146

149147
// If this expression is borrowed, have to ensure it remains valid:
150-
{
151-
let this = &mut *self; // FIXME(#5074)
152-
if !this.ignore_adjustments.contains(&ex.id) {
153-
for tcx.adjustments.find(&ex.id).each |&adjustments| {
154-
this.guarantee_adjustments(ex, *adjustments);
155-
}
156-
}
148+
for tcx.adjustments.find(&ex.id).each |&adjustments| {
149+
self.guarantee_adjustments(ex, *adjustments);
157150
}
158151

159152
// Special checks for various kinds of expressions:
@@ -178,46 +171,20 @@ fn gather_loans_in_expr(ex: @ast::expr,
178171
visit::visit_expr(ex, self, vt);
179172
}
180173

181-
ast::expr_index(rcvr, _) |
182-
ast::expr_binary(_, rcvr, _) |
183-
ast::expr_unary(_, rcvr) |
184-
ast::expr_assign_op(_, rcvr, _)
174+
ast::expr_index(_, arg) |
175+
ast::expr_binary(_, _, arg)
185176
if self.bccx.method_map.contains_key(&ex.id) => {
186-
// Receivers in method calls are always passed by ref.
187-
//
188-
// Here, in an overloaded operator, the call is this expression,
189-
// and hence the scope of the borrow is this call.
190-
//
191-
// FIX? / NOT REALLY---technically we should check the other
192-
// argument and consider the argument mode. But how annoying.
193-
// And this problem when goes away when argument modes are
194-
// phased out. So I elect to leave this undone.
195-
let scope_r = ty::re_scope(ex.id);
196-
let rcvr_cmt = self.bccx.cat_expr(rcvr);
197-
self.guarantee_valid(rcvr.id, rcvr.span, rcvr_cmt, m_imm, scope_r);
198-
199-
// FIXME (#3387): Total hack: Ignore adjustments for the left-hand
200-
// side. Their regions will be inferred to be too large.
201-
self.ignore_adjustments.insert(rcvr.id);
202-
203-
visit::visit_expr(ex, self, vt);
177+
// Arguments in method calls are always passed by ref.
178+
//
179+
// Currently these do not use adjustments, so we have to
180+
// hardcode this check here (note that the receiver DOES use
181+
// adjustments).
182+
let scope_r = ty::re_scope(ex.id);
183+
let arg_cmt = self.bccx.cat_expr(arg);
184+
self.guarantee_valid(arg.id, arg.span, arg_cmt, m_imm, scope_r);
185+
visit::visit_expr(ex, self, vt);
204186
}
205187

206-
// FIXME--#3387
207-
// ast::expr_binary(_, lhs, rhs) => {
208-
// // Universal comparison operators like ==, >=, etc
209-
// // take their arguments by reference.
210-
// let lhs_ty = ty::expr_ty(self.tcx(), lhs);
211-
// if !ty::type_is_scalar(lhs_ty) {
212-
// let scope_r = ty::re_scope(ex.id);
213-
// let lhs_cmt = self.bccx.cat_expr(lhs);
214-
// self.guarantee_valid(lhs_cmt, m_imm, scope_r);
215-
// let rhs_cmt = self.bccx.cat_expr(rhs);
216-
// self.guarantee_valid(rhs_cmt, m_imm, scope_r);
217-
// }
218-
// visit::visit_expr(ex, self, vt);
219-
// }
220-
221188
// see explanation attached to the `root_ub` field:
222189
ast::expr_while(cond, ref body) => {
223190
// during the condition, can only root for the condition

src/librustc/middle/typeck/check/regionck.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,16 @@ fn visit_expr(expr: @ast::expr, rcx: @mut Rcx, v: rvt) {
236236
// overloaded. See #3511.
237237
let tcx = rcx.fcx.tcx();
238238
match expr.node {
239+
// You'd think that x += y where `+=` is overloaded would be a
240+
// cleanup scope. You'd be... kind of right. In fact the
241+
// handling of `+=` and friends in trans for overloaded
242+
// operators is a hopeless mess and I can't figure out how to
243+
// represent it. - ndm
244+
//
245+
// ast::expr_assign_op(*) |
246+
239247
ast::expr_index(*) |
240248
ast::expr_binary(*) |
241-
ast::expr_assign_op(*) |
242249
ast::expr_unary(*) if has_method_map => {
243250
tcx.region_maps.record_cleanup_scope(expr.id);
244251
}

src/libstd/arc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,8 @@ mod tests {
598598
let arc = ~RWARC(1);
599599
let arc2 = (*arc).clone();
600600
do task::try || {
601-
do arc2.write_downgrade |write_mode| {
602-
do (&write_mode).write |one| {
601+
do arc2.write_downgrade |mut write_mode| {
602+
do write_mode.write |one| {
603603
assert!(*one == 2);
604604
}
605605
}
@@ -733,8 +733,8 @@ mod tests {
733733
}
734734

735735
// Downgrader (us)
736-
do arc.write_downgrade |write_mode| {
737-
do (&write_mode).write_cond |state, cond| {
736+
do arc.write_downgrade |mut write_mode| {
737+
do write_mode.write_cond |state, cond| {
738738
wc1.send(()); // send to another writer who will wake us up
739739
while *state == 0 {
740740
cond.wait();

src/libstd/rope.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,22 +1256,24 @@ mod tests {
12561256
match (r) {
12571257
node::Empty => return ~"",
12581258
node::Content(x) => {
1259-
let str = @mut ~"";
1260-
fn aux(str: @mut ~str, node: @node::Node) {
1259+
let mut str = ~"";
1260+
fn aux(str: &mut ~str, node: @node::Node) {
12611261
match (*node) {
1262-
node::Leaf(x) => {
1263-
*str += str::slice(
1264-
*x.content, x.byte_offset,
1265-
x.byte_offset + x.byte_len).to_owned();
1266-
}
1267-
node::Concat(ref x) => {
1268-
aux(str, x.left);
1269-
aux(str, x.right);
1270-
}
1262+
node::Leaf(x) => {
1263+
str::push_str(
1264+
str,
1265+
str::slice(
1266+
*x.content, x.byte_offset,
1267+
x.byte_offset + x.byte_len));
1268+
}
1269+
node::Concat(ref x) => {
1270+
aux(str, x.left);
1271+
aux(str, x.right);
1272+
}
12711273
}
12721274
}
1273-
aux(str, x);
1274-
return *str
1275+
aux(&mut str, x);
1276+
return str
12751277
}
12761278
}
12771279
}

0 commit comments

Comments
 (0)