Skip to content

Commit 1077202

Browse files
committed
---
yaml --- r: 15227 b: refs/heads/try c: ad26b00 h: refs/heads/master i: 15225: 26bc98a 15223: d8d2709 v: v3
1 parent d6411b0 commit 1077202

File tree

10 files changed

+144
-6
lines changed

10 files changed

+144
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 15de9b3c957eae9bfcfb8d34fc75377266512acd
5+
refs/heads/try: ad26b00696afb1b74a636fa02e2600485a914d47
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rustc/middle/ty.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -915,35 +915,64 @@ fn type_needs_unwind_cleanup(cx: ctxt, ty: t) -> bool {
915915
none { }
916916
}
917917

918+
let tycache = new_ty_hash();
919+
let needs_unwind_cleanup =
920+
type_needs_unwind_cleanup_(cx, ty, tycache, false);
921+
cx.needs_unwind_cleanup_cache.insert(ty, needs_unwind_cleanup);
922+
ret needs_unwind_cleanup;
923+
}
924+
925+
fn type_needs_unwind_cleanup_(cx: ctxt, ty: t,
926+
tycache: map::hashmap<t, ()>,
927+
encountered_box: bool) -> bool {
928+
918929
// Prevent infinite recursion
919-
cx.needs_unwind_cleanup_cache.insert(ty, false);
930+
alt tycache.find(ty) {
931+
some(_) { ret false; }
932+
none { tycache.insert(ty, ()); }
933+
}
920934

935+
let mut encountered_box = encountered_box;
921936
let mut needs_unwind_cleanup = false;
922937
maybe_walk_ty(ty) {|ty|
923938
alt get(ty).struct {
939+
ty_box(_) | ty_opaque_box {
940+
encountered_box = true;
941+
true
942+
}
924943
ty_nil | ty_bot | ty_bool |
925944
ty_int(_) | ty_uint(_) | ty_float(_) |
926-
ty_box(_) | ty_rec(_) | ty_tup(_) {
945+
ty_rec(_) | ty_tup(_) | ty_ptr(_) {
927946
true
928947
}
929948
ty_enum(did, tps) {
930949
for v in *enum_variants(cx, did) {
931950
for aty in v.args {
932951
let t = substitute_type_params(cx, tps, aty);
933-
needs_unwind_cleanup |= type_needs_unwind_cleanup(cx, t);
952+
needs_unwind_cleanup |=
953+
type_needs_unwind_cleanup_(cx, t, tycache,
954+
encountered_box);
934955
}
935956
}
936957
!needs_unwind_cleanup
937958
}
959+
ty_uniq(_) | ty_str | ty_vec(_) | ty_res(_, _, _) {
960+
// Once we're inside a box, the annihilator will find
961+
// it and destroy it.
962+
if !encountered_box {
963+
needs_unwind_cleanup = true;
964+
false
965+
} else {
966+
true
967+
}
968+
}
938969
_ {
939970
needs_unwind_cleanup = true;
940971
false
941972
}
942973
}
943974
}
944975

945-
cx.needs_unwind_cleanup_cache.insert(ty, needs_unwind_cleanup);
946-
947976
ret needs_unwind_cleanup;
948977
}
949978

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// error-pattern:fail
2+
3+
fn failfn() {
4+
fail;
5+
}
6+
7+
fn main() {
8+
let y = ~0;
9+
let x = @fn~() {
10+
log(error, y);
11+
};
12+
failfn();
13+
log(error, x);
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// error-pattern:fail
2+
3+
fn failfn() {
4+
fail;
5+
}
6+
7+
fn main() {
8+
let y = ~0;
9+
let x = @fn@() {
10+
log(error, y);
11+
};
12+
failfn();
13+
log(error, x);
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// error-pattern:fail
2+
3+
fn failfn() {
4+
fail;
5+
}
6+
7+
iface i {
8+
fn foo();
9+
}
10+
11+
impl of i for ~int {
12+
fn foo() { }
13+
}
14+
15+
fn main() {
16+
let x = ~0 as i;
17+
failfn();
18+
log(error, x);
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// error-pattern:fail
2+
3+
fn failfn() {
4+
fail;
5+
}
6+
7+
resource r(v: *int) unsafe {
8+
let v2: ~int = unsafe::reinterpret_cast(v);
9+
}
10+
11+
fn main() unsafe {
12+
let i1 = ~0;
13+
let i1p = unsafe::reinterpret_cast(i1);
14+
unsafe::forget(i1);
15+
let x = @r(i1p);
16+
failfn();
17+
log(error, x);
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// error-pattern:fail
2+
3+
fn failfn() {
4+
fail;
5+
}
6+
7+
fn main() {
8+
let x = @"hi";
9+
failfn();
10+
log(error, x);
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// error-pattern:fail
2+
3+
fn failfn() {
4+
fail;
5+
}
6+
7+
fn main() {
8+
let x = @~~0;
9+
failfn();
10+
log(error, x);
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// error-pattern:fail
2+
3+
fn failfn() {
4+
fail;
5+
}
6+
7+
fn main() {
8+
let x = @~0;
9+
failfn();
10+
log(error, x);
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// error-pattern:fail
2+
3+
fn failfn() {
4+
fail;
5+
}
6+
7+
fn main() {
8+
let x = @[0, 1, 2, 3, 4, 5];
9+
failfn();
10+
log(error, x);
11+
}

0 commit comments

Comments
 (0)