Skip to content

Commit

Permalink
In ty::normalize_ty, don't replace self_regions with None
Browse files Browse the repository at this point in the history
Instead, replace with re_static. This was causing ty::subst to
fail when called from trans::type_of::type_of.

Already discussed with nmatsakis and it's a small change, so
no review.

Closes #3447
  • Loading branch information
catamorphism committed Oct 16, 2012
1 parent bbc46d5 commit b38092e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/rustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,10 @@ fn subst(cx: ctxt,
fold_regions_and_ty(
cx, typ,
|r| match r {
re_bound(br_self) => substs.self_r.get(),
re_bound(br_self) => substs.self_r.expect(
#fmt("ty::subst: \
Reference to self region when given substs with no \
self region, ty = %s", ty_to_str(cx, typ))),
_ => r
},
|t| do_subst(cx, substs, t),
Expand Down Expand Up @@ -3910,9 +3913,11 @@ fn normalize_ty(cx: ctxt, t: t) -> t {
ty_enum(did, r) =>
match r.self_r {
Some(_) =>
// This enum has a self region. Get rid of it
// Use re_static since trans doesn't care about regions
mk_enum(cx, did,
{self_r: None, self_ty: None, tps: r.tps}),
{self_r: Some(ty::re_static),
self_ty: None,
tps: r.tps}),
None =>
t
},
Expand All @@ -3921,7 +3926,8 @@ fn normalize_ty(cx: ctxt, t: t) -> t {
match r.self_r {
Some(_) =>
// Ditto.
mk_class(cx, did, {self_r: None, self_ty: None, tps: r.tps}),
mk_class(cx, did, {self_r: Some(ty::re_static), self_ty: None,
tps: r.tps}),
None =>
t
},
Expand Down
5 changes: 2 additions & 3 deletions src/test/run-pass/issue-3447.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// xfail-test
struct list<T> {
element: &self/T,
mut next: Option<@list<T>>
Expand All @@ -11,13 +10,13 @@ impl<T> list<T>{
next: option::None
};

self.next = Some(@newList);
self.next = Some(@(move newList));
}
}

fn main() {
let s = @"str";
let ls: list<@str> = list {
let ls = list {
element: &s,
next: option::None
};
Expand Down

0 comments on commit b38092e

Please sign in to comment.