Skip to content

Commit 5c999d4

Browse files
committed
auto merge of #7894 : pcwalton/rust/and-pointers-in-at-boxes, r=brson
r? @brson
2 parents 8aae6ed + 9089cf2 commit 5c999d4

24 files changed

+84
-81
lines changed

src/libextra/fun_treemap.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,17 @@ enum TreeNode<K, V> {
3131
}
3232

3333
/// Create a treemap
34-
pub fn init<K, V>() -> Treemap<K, V> { @Empty }
34+
pub fn init<K: 'static, V: 'static>() -> Treemap<K, V> {
35+
@Empty
36+
}
3537

3638
/// Insert a value into the map
37-
pub fn insert<K:Eq + Ord,V>(m: Treemap<K, V>, k: K, v: V) -> Treemap<K, V> {
39+
pub fn insert<K:Eq + Ord + 'static,
40+
V:'static>(
41+
m: Treemap<K, V>,
42+
k: K,
43+
v: V)
44+
-> Treemap<K, V> {
3845
@match m {
3946
@Empty => Node(@k, @v, @Empty, @Empty),
4047
@Node(kk, vv, left, right) => cond!(
@@ -46,7 +53,11 @@ pub fn insert<K:Eq + Ord,V>(m: Treemap<K, V>, k: K, v: V) -> Treemap<K, V> {
4653
}
4754

4855
/// Find a value based on the key
49-
pub fn find<K:Eq + Ord,V:Clone>(m: Treemap<K, V>, k: K) -> Option<V> {
56+
pub fn find<K:Eq + Ord + 'static,
57+
V:Clone + 'static>(
58+
m: Treemap<K, V>,
59+
k: K)
60+
-> Option<V> {
5061
match *m {
5162
Empty => None,
5263
Node(kk, v, left, right) => cond!(

src/libextra/list.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub enum MutList<T> {
2525
}
2626

2727
/// Create a list from a vector
28-
pub fn from_vec<T:Clone>(v: &[T]) -> @List<T> {
28+
pub fn from_vec<T:Clone + 'static>(v: &[T]) -> @List<T> {
2929
v.rev_iter().fold(@Nil::<T>, |t, h| @Cons((*h).clone(), t))
3030
}
3131

@@ -109,7 +109,7 @@ pub fn head<T:Clone>(ls: @List<T>) -> T {
109109
}
110110

111111
/// Appends one list to another
112-
pub fn append<T:Clone>(l: @List<T>, m: @List<T>) -> @List<T> {
112+
pub fn append<T:Clone + 'static>(l: @List<T>, m: @List<T>) -> @List<T> {
113113
match *l {
114114
Nil => return m,
115115
Cons(ref x, xs) => {

src/libextra/serialize.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ impl<S:Encoder,T:Encodable<S>> Encodable<S> for @T {
423423
}
424424
}
425425

426-
impl<D:Decoder,T:Decodable<D>> Decodable<D> for @T {
426+
impl<D:Decoder,T:Decodable<D> + 'static> Decodable<D> for @T {
427427
fn decode(d: &mut D) -> @T {
428428
@Decodable::decode(d)
429429
}
@@ -435,7 +435,7 @@ impl<S:Encoder,T:Encodable<S>> Encodable<S> for @mut T {
435435
}
436436
}
437437

438-
impl<D:Decoder,T:Decodable<D>> Decodable<D> for @mut T {
438+
impl<D:Decoder,T:Decodable<D> + 'static> Decodable<D> for @mut T {
439439
fn decode(d: &mut D) -> @mut T {
440440
@mut Decodable::decode(d)
441441
}

src/librustc/metadata/encoder.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1238,8 +1238,9 @@ fn encode_info_for_items(ecx: &EncodeContext,
12381238

12391239
// Path and definition ID indexing
12401240

1241-
fn create_index<T:Clone + Hash + IterBytes>(index: ~[entry<T>])
1242-
-> ~[@~[entry<T>]] {
1241+
fn create_index<T:Clone + Hash + IterBytes + 'static>(
1242+
index: ~[entry<T>])
1243+
-> ~[@~[entry<T>]] {
12431244
let mut buckets: ~[@mut ~[entry<T>]] = ~[];
12441245
for uint::range(0u, 256u) |_i| { buckets.push(@mut ~[]); };
12451246
for index.iter().advance |elt| {
@@ -1254,9 +1255,10 @@ fn create_index<T:Clone + Hash + IterBytes>(index: ~[entry<T>])
12541255
return buckets_frozen;
12551256
}
12561257

1257-
fn encode_index<T>(ebml_w: &mut writer::Encoder,
1258-
buckets: ~[@~[entry<T>]],
1259-
write_fn: &fn(@io::Writer, &T)) {
1258+
fn encode_index<T:'static>(
1259+
ebml_w: &mut writer::Encoder,
1260+
buckets: ~[@~[entry<T>]],
1261+
write_fn: &fn(@io::Writer, &T)) {
12601262
let writer = ebml_w.writer;
12611263
ebml_w.start_tag(tag_index);
12621264
let mut bucket_locs: ~[uint] = ~[];

src/librustc/middle/kind.rs

+4
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ pub fn check_expr(e: @expr, (cx, v): (Context, visit::vt<Context>)) {
285285
}
286286

287287
match e.node {
288+
expr_unary(_, box(_), interior) => {
289+
let interior_type = ty::expr_ty(cx.tcx, interior);
290+
let _ = check_durable(cx.tcx, interior_type, interior.span);
291+
}
288292
expr_cast(source, _) => {
289293
check_cast_for_escaping_regions(cx, source, e);
290294
match ty::get(ty::expr_ty(cx.tcx, e)).sty {

src/librustc/middle/subst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<T:Subst> Subst for ~[T] {
7979
}
8080
}
8181

82-
impl<T:Subst> Subst for @T {
82+
impl<T:Subst + 'static> Subst for @T {
8383
fn subst(&self, tcx: ty::ctxt, substs: &ty::substs) -> @T {
8484
match self {
8585
&@ref t => @t.subst(tcx, substs)

src/librustc/middle/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ fn mk_rcache() -> creader_cache {
858858
return @mut HashMap::new();
859859
}
860860

861-
pub fn new_ty_hash<V>() -> @mut HashMap<t, V> {
861+
pub fn new_ty_hash<V:'static>() -> @mut HashMap<t, V> {
862862
@mut HashMap::new()
863863
}
864864

src/libstd/clone.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ impl<T: DeepClone> DeepClone for ~T {
112112
}
113113

114114
// FIXME: #6525: should also be implemented for `T: Send + DeepClone`
115-
impl<T: Freeze + DeepClone> DeepClone for @T {
115+
impl<T: Freeze + DeepClone + 'static> DeepClone for @T {
116116
/// Return a deep copy of the managed box. The `Freeze` trait is required to prevent performing
117117
/// a deep clone of a potentially cyclical type.
118118
#[inline]
119119
fn deep_clone(&self) -> @T { @(**self).deep_clone() }
120120
}
121121

122122
// FIXME: #6525: should also be implemented for `T: Send + DeepClone`
123-
impl<T: Freeze + DeepClone> DeepClone for @mut T {
123+
impl<T: Freeze + DeepClone + 'static> DeepClone for @mut T {
124124
/// Return a deep copy of the managed box. The `Freeze` trait is required to prevent performing
125125
/// a deep clone of a potentially cyclical type.
126126
#[inline]

src/libstd/num/num.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,12 @@ pub fn pow_with_uint<T:NumCast+One+Zero+Div<T,T>+Mul<T,T>>(radix: uint, pow: uin
446446
total
447447
}
448448

449-
impl<T: Zero> Zero for @mut T {
449+
impl<T: Zero + 'static> Zero for @mut T {
450450
fn zero() -> @mut T { @mut Zero::zero() }
451451
fn is_zero(&self) -> bool { (**self).is_zero() }
452452
}
453453

454-
impl<T: Zero> Zero for @T {
454+
impl<T: Zero + 'static> Zero for @T {
455455
fn zero() -> @T { @Zero::zero() }
456456
fn is_zero(&self) -> bool { (**self).is_zero() }
457457
}

src/libstd/rand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl<T: Rand> Rand for ~T {
242242
fn rand<R: Rng>(rng: &mut R) -> ~T { ~rng.gen() }
243243
}
244244

245-
impl<T: Rand> Rand for @T {
245+
impl<T: Rand + 'static> Rand for @T {
246246
#[inline]
247247
fn rand<R: Rng>(rng: &mut R) -> @T { @rng.gen() }
248248
}

src/libsyntax/ext/base.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,7 @@ pub enum MapChain<K,V> {
414414

415415

416416
// get the map from an env frame
417-
impl <K: Eq + Hash + IterBytes, V> MapChain<K,V>{
418-
417+
impl <K: Eq + Hash + IterBytes + 'static, V: 'static> MapChain<K,V>{
419418
// Constructor. I don't think we need a zero-arg one.
420419
fn new(init: ~HashMap<K,@V>) -> @mut MapChain<K,V> {
421420
@mut BaseMapChain(init)

src/libsyntax/util/interner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct Interner<T> {
2121
}
2222

2323
// when traits can extend traits, we should extend index<uint,T> to get []
24-
impl<T:Eq + IterBytes + Hash + Freeze + Clone> Interner<T> {
24+
impl<T:Eq + IterBytes + Hash + Freeze + Clone + 'static> Interner<T> {
2525
pub fn new() -> Interner<T> {
2626
Interner {
2727
map: @mut HashMap::new(),

src/test/auxiliary/cci_nested_lib.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ pub struct alist<A,B> {
1818
data: @mut ~[Entry<A,B>]
1919
}
2020

21-
pub fn alist_add<A,B>(lst: &alist<A,B>, k: A, v: B) {
21+
pub fn alist_add<A:'static,B:'static>(lst: &alist<A,B>, k: A, v: B) {
2222
lst.data.push(Entry{key:k, value:v});
2323
}
2424

25-
pub fn alist_get<A:Clone,B:Clone>(lst: &alist<A,B>, k: A) -> B {
25+
pub fn alist_get<A:Clone + 'static,
26+
B:Clone + 'static>(
27+
lst: &alist<A,B>,
28+
k: A)
29+
-> B {
2630
let eq_fn = lst.eq_fn;
2731
for lst.data.iter().advance |entry| {
2832
if eq_fn(entry.key.clone(), k.clone()) {
@@ -33,13 +37,13 @@ pub fn alist_get<A:Clone,B:Clone>(lst: &alist<A,B>, k: A) -> B {
3337
}
3438

3539
#[inline]
36-
pub fn new_int_alist<B>() -> alist<int, B> {
40+
pub fn new_int_alist<B:'static>() -> alist<int, B> {
3741
fn eq_int(a: int, b: int) -> bool { a == b }
3842
return alist {eq_fn: eq_int, data: @mut ~[]};
3943
}
4044

4145
#[inline]
42-
pub fn new_int_alist_2<B>() -> alist<int, B> {
46+
pub fn new_int_alist_2<B:'static>() -> alist<int, B> {
4347
#[inline]
4448
fn eq_int(a: int, b: int) -> bool { a == b }
4549
return alist {eq_fn: eq_int, data: @mut ~[]};
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn f<T>(x: T) -> @T {
2+
@x //~ ERROR value may contain borrowed pointers
3+
}
4+
5+
fn g<T:'static>(x: T) -> @T {
6+
@x // ok
7+
}
8+
9+
fn main() {}
10+

src/test/compile-fail/kindck-owned-trait.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ fn to_foo<T:Clone + foo>(t: T) -> @foo {
1414
@t as @foo
1515
//~^ ERROR value may contain borrowed pointers; add `'static` bound
1616
//~^^ ERROR cannot pack type
17+
//~^^^ ERROR value may contain borrowed pointers
1718
}
1819

1920
fn to_foo2<T:Clone + foo + 'static>(t: T) -> @foo {

src/test/compile-fail/kindck-owned.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ fn main() {
2323
copy2(&x); //~ ERROR does not fulfill `'static`
2424

2525
copy2(@3);
26-
copy2(@&x); //~ ERROR does not fulfill `'static`
26+
copy2(@&x); //~ ERROR value may contain borrowed pointers
27+
//~^ ERROR does not fulfill `'static`
2728
}

src/test/run-pass/alignment-gep-tup-like-2.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ struct Rec<A> {
1818
rec: Option<@mut RecEnum<A>>
1919
}
2020

21-
fn make_cycle<A>(a: A) {
21+
fn make_cycle<A:'static>(a: A) {
2222
let g: @mut RecEnum<A> = @mut RecEnum(Rec {val: a, rec: None});
2323
g.rec = Some(g);
2424
}
2525

26-
fn f<A:Send + Clone,B:Send + Clone>(a: A, b: B) -> @fn() -> (A, B) {
26+
fn f<A:Send + Clone + 'static,
27+
B:Send + Clone + 'static>(
28+
a: A,
29+
b: B)
30+
-> @fn() -> (A, B) {
2731
let result: @fn() -> (A, B) = || (a.clone(), b.clone());
2832
result
2933
}

src/test/run-pass/generic-box.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212

13-
fn box<T>(x: Box<T>) -> @Box<T> { return @x; }
13+
fn box<T:'static>(x: Box<T>) -> @Box<T> { return @x; }
1414

1515
struct Box<T> {x: T, y: T, z: T}
1616

src/test/run-pass/generic-exterior-box.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
struct Recbox<T> {x: @T}
1414

15-
fn reclift<T>(t: T) -> Recbox<T> { return Recbox {x: @t}; }
15+
fn reclift<T:'static>(t: T) -> Recbox<T> { return Recbox {x: @t}; }
1616

1717
pub fn main() {
1818
let foo: int = 17;

src/test/run-pass/infer-with-expected.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
// happen.)
1515

1616
fn eat_tup(_r: ~@(int, @fn(Pair) -> int)) {}
17-
fn eat_rec(_r: @~Rec) {}
17+
fn eat_rec(_r: ~Rec) {}
1818

1919
struct Rec<'self> { a: int, b: &'self fn(Pair) -> int }
2020
struct Pair { x: int, y: int }
2121

2222
pub fn main() {
2323
eat_tup(~@(10, |a| a.x ));
24-
eat_rec(@~Rec{a: 10, b: |a| a.x });
24+
eat_rec(~Rec{a: 10, b: |a| a.x });
2525
}

src/test/run-pass/issue-3447.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
struct list<'self, T> {
12-
element: &'self T,
13-
next: Option<@mut list<'self, T>>
11+
static S: &'static str = "str";
12+
13+
struct list<T> {
14+
element: T,
15+
next: Option<@mut list<T>>
1416
}
1517

16-
impl<'self, T> list<'self, T>{
17-
pub fn addEnd(&mut self, element: &'self T) {
18+
impl<T:'static> list<T> {
19+
pub fn addEnd(&mut self, element: T) {
1820
let newList = list {
1921
element: element,
2022
next: None
@@ -25,10 +27,9 @@ impl<'self, T> list<'self, T>{
2527
}
2628

2729
pub fn main() {
28-
let s = @"str";
2930
let ls = list {
30-
element: &s,
31+
element: S,
3132
next: None
3233
};
33-
println(*ls.element);
34+
println(ls.element);
3435
}

src/test/run-pass/kindck-owned-trait-contains-1.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010

1111
trait repeat<A> { fn get(&self) -> A; }
1212

13-
impl<A:Clone> repeat<A> for @A {
13+
impl<A:Clone + 'static> repeat<A> for @A {
1414
fn get(&self) -> A {
1515
(**self).clone()
1616
}
1717
}
1818

19-
fn repeater<A:Clone>(v: @A) -> @repeat:<A> {
19+
fn repeater<A:Clone + 'static>(v: @A) -> @repeat:<A> {
2020
// Note: owned kind is not necessary as A appears in the trait type
2121
@v as @repeat:<A> // No
2222
}
2323

2424
pub fn main() {
25-
let x = &3;
25+
let x = 3;
2626
let y = repeater(@x);
27-
assert_eq!(*x, *(y.get()));
27+
assert_eq!(x, y.get());
2828
}

src/test/run-pass/log-linearized.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ struct Smallintmap<T> {v: ~[option<T>]}
1919

2020
struct V<T> { v: ~[option<T>] }
2121

22-
fn mk<T>() -> @mut Smallintmap<T> {
22+
fn mk<T:'static>() -> @mut Smallintmap<T> {
2323
let mut v: ~[option<T>] = ~[];
2424
return @mut Smallintmap {v: v};
2525
}
2626

27-
fn f<T,U>() {
27+
fn f<T,U:'static>() {
2828
let mut sim = mk::<U>();
2929
error!(sim);
3030
}

0 commit comments

Comments
 (0)