Skip to content

Commit e4e9525

Browse files
committed
---
yaml --- r: 121845 b: refs/heads/master c: 04e64c0 h: refs/heads/master i: 121843: a4d031d v: v3
1 parent 7da89a4 commit e4e9525

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: abdf71cf73fd8b0b5bca78da830fe6f2a49ff8c2
2+
refs/heads/master: 04e64c0c91f1d0de04940eab76ddcfe126d635b1
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: afdfe40aa0b7dfc7800dddbc1f55da979abfe486
55
refs/heads/try: 18dc3bc9e3314a250c0718ab329938e676410cdf

trunk/src/librustc/middle/trans/expr.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,19 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>,
277277
auto_ref(bcx, datum, expr)
278278
}
279279

280-
fn auto_borrow_obj<'a>(bcx: &'a Block<'a>,
280+
fn auto_borrow_obj<'a>(mut bcx: &'a Block<'a>,
281281
expr: &ast::Expr,
282282
source_datum: Datum<Expr>)
283283
-> DatumBlock<'a, Expr> {
284284
let tcx = bcx.tcx();
285285
let target_obj_ty = expr_ty_adjusted(bcx, expr);
286286
debug!("auto_borrow_obj(target={})", target_obj_ty.repr(tcx));
287287

288-
let mut datum = source_datum.to_expr_datum();
288+
// Arrange cleanup, if not already done. This is needed in
289+
// case we are auto-borrowing a Box<Trait> to &Trait
290+
let datum = unpack_datum!(
291+
bcx, source_datum.to_lvalue_datum(bcx, "autoborrowobj", expr.id));
292+
let mut datum = datum.to_expr_datum();
289293
datum.ty = target_obj_ty;
290294
DatumBlock::new(bcx, datum)
291295
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
// This would previously leak the Box<Trait> because we wouldn't
13+
// schedule cleanups when auto borrowing trait objects.
14+
// This program should be valgrind clean.
15+
16+
17+
static mut DROP_RAN: bool = false;
18+
19+
struct Foo;
20+
impl Drop for Foo {
21+
fn drop(&mut self) {
22+
unsafe { DROP_RAN = true; }
23+
}
24+
}
25+
26+
27+
trait Trait {}
28+
impl Trait for Foo {}
29+
30+
pub fn main() {
31+
{
32+
let _x: &Trait = box Foo as Box<Trait>;
33+
}
34+
unsafe {
35+
assert!(DROP_RAN);
36+
}
37+
}
38+

0 commit comments

Comments
 (0)