Skip to content

Commit 56634ba

Browse files
committed
---
yaml --- r: 152903 b: refs/heads/try2 c: 04e64c0 h: refs/heads/master i: 152901: 08a3a95 152899: 1890590 152895: 38db87d v: v3
1 parent 33de1f3 commit 56634ba

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: abdf71cf73fd8b0b5bca78da830fe6f2a49ff8c2
8+
refs/heads/try2: 04e64c0c91f1d0de04940eab76ddcfe126d635b1
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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)