Skip to content

Commit 9089cf2

Browse files
committed
librustc: Forbid & pointers (other than &'static) inside @ boxes.
This makes custom borrowing implementations for custom smart pointers sound.
1 parent 93fa7a4 commit 9089cf2

24 files changed

+84
-81
lines changed

src/libextra/fun_treemap.rs

Lines changed: 14 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,8 +1259,9 @@ fn encode_info_for_items(ecx: &EncodeContext,
12591259

12601260
// Path and definition ID indexing
12611261

1262-
fn create_index<T:Clone + Hash + IterBytes>(index: ~[entry<T>])
1263-
-> ~[@~[entry<T>]] {
1262+
fn create_index<T:Clone + Hash + IterBytes + 'static>(
1263+
index: ~[entry<T>])
1264+
-> ~[@~[entry<T>]] {
12641265
let mut buckets: ~[@mut ~[entry<T>]] = ~[];
12651266
for uint::range(0u, 256u) |_i| { buckets.push(@mut ~[]); };
12661267
for index.iter().advance |elt| {
@@ -1275,9 +1276,10 @@ fn create_index<T:Clone + Hash + IterBytes>(index: ~[entry<T>])
12751276
return buckets_frozen;
12761277
}
12771278

1278-
fn encode_index<T>(ebml_w: &mut writer::Encoder,
1279-
buckets: ~[@~[entry<T>]],
1280-
write_fn: &fn(@io::Writer, &T)) {
1279+
fn encode_index<T:'static>(
1280+
ebml_w: &mut writer::Encoder,
1281+
buckets: ~[@~[entry<T>]],
1282+
write_fn: &fn(@io::Writer, &T)) {
12811283
let writer = ebml_w.writer;
12821284
ebml_w.start_tag(tag_index);
12831285
let mut bucket_locs: ~[uint] = ~[];

src/librustc/middle/kind.rs

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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
}

0 commit comments

Comments
 (0)