Skip to content

Commit 61cc9ae

Browse files
committed
---
yaml --- r: 150829 b: refs/heads/try2 c: 349d66a h: refs/heads/master i: 150827: ded25ae v: v3
1 parent aa19000 commit 61cc9ae

File tree

9 files changed

+125
-18
lines changed

9 files changed

+125
-18
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: c18c9284b352f3605553343cd78c7a8eb75b5cd2
8+
refs/heads/try2: 349d66af9420eeeeedfc648eb6ec3fd28015d4b3
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/guide-unsafe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ use std::cast;
7070
let mut x: u8 = 1;
7171
7272
let ref_1: &mut u8 = &mut x;
73-
let ref_2: &mut u8 = unsafe { cast::transmute_mut_region(ref_1) };
73+
let ref_2: &mut u8 = unsafe { cast::transmute_mut_lifetime(ref_1) };
7474
7575
// oops, ref_1 and ref_2 point to the same piece of data (x) and are
7676
// both usable

branches/try2/src/libarena/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
extern crate collections;
2828

29-
use std::cast::{transmute, transmute_mut, transmute_mut_region};
29+
use std::cast::{transmute, transmute_mut, transmute_mut_lifetime};
3030
use std::cast;
3131
use std::cell::{Cell, RefCell};
3232
use std::mem;
@@ -186,7 +186,7 @@ impl Arena {
186186
#[inline]
187187
fn alloc_copy_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
188188
unsafe {
189-
let this = transmute_mut_region(self);
189+
let this = transmute_mut_lifetime(self);
190190
let start = round_up(this.copy_head.fill.get(), align);
191191
let end = start + n_bytes;
192192
if end > self.chunk_size() {
@@ -233,7 +233,7 @@ impl Arena {
233233
let after_tydesc;
234234

235235
{
236-
let head = transmute_mut_region(&mut self.head);
236+
let head = transmute_mut_lifetime(&mut self.head);
237237

238238
tydesc_start = head.fill.get();
239239
after_tydesc = head.fill.get() + mem::size_of::<*TyDesc>();
@@ -245,7 +245,7 @@ impl Arena {
245245
return self.alloc_noncopy_grow(n_bytes, align);
246246
}
247247

248-
let head = transmute_mut_region(&mut self.head);
248+
let head = transmute_mut_lifetime(&mut self.head);
249249
head.fill.set(round_up(end, mem::pref_align_of::<*TyDesc>()));
250250

251251
//debug!("idx = {}, size = {}, align = {}, fill = {}",

branches/try2/src/libgreen/sched.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ impl Scheduler {
630630
unsafe {
631631

632632
let sched: &mut Scheduler =
633-
cast::transmute_mut_region(*next_task.sched.get_mut_ref());
633+
cast::transmute_mut_lifetime(*next_task.sched.get_mut_ref());
634634

635635
let current_task: &mut GreenTask = match sched.cleanup_job {
636636
Some(CleanupJob { task: ref mut task, .. }) => &mut **task,
@@ -681,8 +681,8 @@ impl Scheduler {
681681
let next_task_context =
682682
&mut next_task.coroutine.get_mut_ref().saved_context;
683683
unsafe {
684-
(cast::transmute_mut_region(current_task_context),
685-
cast::transmute_mut_region(next_task_context))
684+
(cast::transmute_mut_lifetime(current_task_context),
685+
cast::transmute_mut_lifetime(next_task_context))
686686
}
687687
}
688688

branches/try2/src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ pub fn init_local<'a>(bcx: &'a Block<'a>, local: &ast::Local)
936936
// Handle let _ = e; just like e;
937937
match local.init {
938938
Some(init) => {
939-
return expr::trans_into(bcx, init, expr::Ignore);
939+
return controlflow::trans_stmt_semi(bcx, init)
940940
}
941941
None => { return bcx; }
942942
}

branches/try2/src/librustc/middle/trans/controlflow.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use middle::trans::debuginfo;
1919
use middle::trans::cleanup;
2020
use middle::trans::cleanup::CleanupMethods;
2121
use middle::trans::expr;
22+
use middle::ty;
2223
use util::ppaux::Repr;
2324

2425
use middle::trans::type_::Type;
@@ -49,7 +50,7 @@ pub fn trans_stmt<'a>(cx: &'a Block<'a>,
4950

5051
match s.node {
5152
ast::StmtExpr(e, _) | ast::StmtSemi(e, _) => {
52-
bcx = expr::trans_into(cx, e, expr::Ignore);
53+
bcx = trans_stmt_semi(bcx, e);
5354
}
5455
ast::StmtDecl(d, _) => {
5556
match d.node {
@@ -71,6 +72,16 @@ pub fn trans_stmt<'a>(cx: &'a Block<'a>,
7172
return bcx;
7273
}
7374

75+
pub fn trans_stmt_semi<'a>(cx: &'a Block<'a>, e: &ast::Expr) -> &'a Block<'a> {
76+
let _icx = push_ctxt("trans_stmt_semi");
77+
let ty = expr_ty(cx, e);
78+
if ty::type_needs_drop(cx.tcx(), ty) {
79+
expr::trans_to_lvalue(cx, e, "stmt").bcx
80+
} else {
81+
expr::trans_into(cx, e, expr::Ignore)
82+
}
83+
}
84+
7485
pub fn trans_block<'a>(bcx: &'a Block<'a>,
7586
b: &ast::Block,
7687
mut dest: expr::Dest)

branches/try2/src/libstd/cast.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ pub unsafe fn transmute<L, G>(thing: L) -> G {
6363
#[inline]
6464
pub unsafe fn transmute_mut<'a,T>(ptr: &'a T) -> &'a mut T { transmute(ptr) }
6565

66-
/// Coerce a reference to have an arbitrary associated region.
66+
/// Coerce a reference to have an arbitrary associated lifetime.
6767
#[inline]
68-
pub unsafe fn transmute_region<'a,'b,T>(ptr: &'a T) -> &'b T {
68+
pub unsafe fn transmute_lifetime<'a,'b,T>(ptr: &'a T) -> &'b T {
6969
transmute(ptr)
7070
}
7171

@@ -75,28 +75,28 @@ pub unsafe fn transmute_mut_unsafe<T>(ptr: *T) -> *mut T {
7575
transmute(ptr)
7676
}
7777

78-
/// Coerce a mutable reference to have an arbitrary associated region.
78+
/// Coerce a mutable reference to have an arbitrary associated lifetime.
7979
#[inline]
80-
pub unsafe fn transmute_mut_region<'a,'b,T>(ptr: &'a mut T) -> &'b mut T {
80+
pub unsafe fn transmute_mut_lifetime<'a,'b,T>(ptr: &'a mut T) -> &'b mut T {
8181
transmute(ptr)
8282
}
8383

8484
/// Transforms lifetime of the second pointer to match the first.
8585
#[inline]
8686
pub unsafe fn copy_lifetime<'a,S,T>(_ptr: &'a S, ptr: &T) -> &'a T {
87-
transmute_region(ptr)
87+
transmute_lifetime(ptr)
8888
}
8989

9090
/// Transforms lifetime of the second pointer to match the first.
9191
#[inline]
9292
pub unsafe fn copy_mut_lifetime<'a,S,T>(_ptr: &'a mut S, ptr: &mut T) -> &'a mut T {
93-
transmute_mut_region(ptr)
93+
transmute_mut_lifetime(ptr)
9494
}
9595

9696
/// Transforms lifetime of the second pointer to match the first.
9797
#[inline]
9898
pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
99-
transmute_region(ptr)
99+
transmute_lifetime(ptr)
100100
}
101101

102102

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2012-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+
// Ensures that destructors are run for expressions of the form "e;" where
12+
// `e` is a type which requires a destructor.
13+
14+
#![allow(path_statement)]
15+
16+
struct A { n: int }
17+
struct B;
18+
19+
static mut NUM_DROPS: uint = 0;
20+
21+
impl Drop for A {
22+
fn drop(&mut self) {
23+
unsafe { NUM_DROPS += 1; }
24+
}
25+
}
26+
27+
impl Drop for B {
28+
fn drop(&mut self) {
29+
unsafe { NUM_DROPS += 1; }
30+
}
31+
}
32+
33+
fn main() {
34+
assert_eq!(unsafe { NUM_DROPS }, 0);
35+
{ let _a = A { n: 1 }; }
36+
assert_eq!(unsafe { NUM_DROPS }, 1);
37+
{ A { n: 3 }; }
38+
assert_eq!(unsafe { NUM_DROPS }, 2);
39+
40+
{ let _b = B; }
41+
assert_eq!(unsafe { NUM_DROPS }, 3);
42+
{ B; }
43+
assert_eq!(unsafe { NUM_DROPS }, 4);
44+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2012-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+
// Ensures that destructors are run for expressions of the form "let _ = e;"
12+
// where `e` is a type which requires a destructor.
13+
14+
struct Foo;
15+
struct Bar { x: int }
16+
struct Baz(int);
17+
18+
static mut NUM_DROPS: uint = 0;
19+
20+
impl Drop for Foo {
21+
fn drop(&mut self) {
22+
unsafe { NUM_DROPS += 1; }
23+
}
24+
}
25+
impl Drop for Bar {
26+
fn drop(&mut self) {
27+
unsafe { NUM_DROPS += 1; }
28+
}
29+
}
30+
impl Drop for Baz {
31+
fn drop(&mut self) {
32+
unsafe { NUM_DROPS += 1; }
33+
}
34+
}
35+
36+
fn main() {
37+
assert_eq!(unsafe { NUM_DROPS }, 0);
38+
{ let _x = Foo; }
39+
assert_eq!(unsafe { NUM_DROPS }, 1);
40+
{ let _x = Bar { x: 21 }; }
41+
assert_eq!(unsafe { NUM_DROPS }, 2);
42+
{ let _x = Baz(21); }
43+
assert_eq!(unsafe { NUM_DROPS }, 3);
44+
45+
assert_eq!(unsafe { NUM_DROPS }, 3);
46+
{ let _ = Foo; }
47+
assert_eq!(unsafe { NUM_DROPS }, 4);
48+
{ let _ = Bar { x: 21 }; }
49+
assert_eq!(unsafe { NUM_DROPS }, 5);
50+
{ let _ = Baz(21); }
51+
assert_eq!(unsafe { NUM_DROPS }, 6);
52+
}

0 commit comments

Comments
 (0)