Skip to content

Commit 8b56a83

Browse files
committed
librustc: Modify all code to use new lifetime binder syntax
1 parent 15688ea commit 8b56a83

File tree

138 files changed

+427
-509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+427
-509
lines changed

doc/rust.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ static bit2: uint = 1 << 1;
11161116
static bits: [uint, ..2] = [bit1, bit2];
11171117
static string: &'static str = "bitstring";
11181118
1119-
struct BitsNStrings {
1119+
struct BitsNStrings<'self> {
11201120
mybits: [uint, ..2],
11211121
mystring: &'self str
11221122
}

doc/tutorial-borrowed-ptr.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ For example, we could write a subroutine like this:
485485

486486
~~~
487487
struct Point {x: float, y: float}
488-
fn get_x(p: &'r Point) -> &'r float { &p.x }
488+
fn get_x<'r>(p: &'r Point) -> &'r float { &p.x }
489489
~~~
490490

491491
Here, the function `get_x()` returns a pointer into the structure it
@@ -571,8 +571,8 @@ function:
571571
# Rectangle(Point, Size) // upper-left, dimensions
572572
# }
573573
# fn compute_area(shape: &Shape) -> float { 0f }
574-
fn select<T>(shape: &'r Shape, threshold: float,
575-
a: &'r T, b: &'r T) -> &'r T {
574+
fn select<'r, T>(shape: &'r Shape, threshold: float,
575+
a: &'r T, b: &'r T) -> &'r T {
576576
if compute_area(shape) > threshold {a} else {b}
577577
}
578578
~~~
@@ -591,12 +591,12 @@ example:
591591
# Rectangle(Point, Size) // upper-left, dimensions
592592
# }
593593
# fn compute_area(shape: &Shape) -> float { 0f }
594-
# fn select<T>(shape: &Shape, threshold: float,
595-
# a: &'r T, b: &'r T) -> &'r T {
594+
# fn select<'r, T>(shape: &Shape, threshold: float,
595+
# a: &'r T, b: &'r T) -> &'r T {
596596
# if compute_area(shape) > threshold {a} else {b}
597597
# }
598598
// -+ r
599-
fn select_based_on_unit_circle<T>( // |-+ B
599+
fn select_based_on_unit_circle<'r, T>( // |-+ B
600600
threshold: float, a: &'r T, b: &'r T) -> &'r T { // | |
601601
// | |
602602
let shape = Circle(Point {x: 0., y: 0.}, 1.); // | |
@@ -628,8 +628,8 @@ returned. Here is how the new `select()` might look:
628628
# Rectangle(Point, Size) // upper-left, dimensions
629629
# }
630630
# fn compute_area(shape: &Shape) -> float { 0f }
631-
fn select<T>(shape: &'tmp Shape, threshold: float,
632-
a: &'r T, b: &'r T) -> &'r T {
631+
fn select<'r, 'tmp, T>(shape: &'tmp Shape, threshold: float,
632+
a: &'r T, b: &'r T) -> &'r T {
633633
if compute_area(shape) > threshold {a} else {b}
634634
}
635635
~~~
@@ -647,8 +647,8 @@ concise to just omit the named lifetime for `shape` altogether:
647647
# Rectangle(Point, Size) // upper-left, dimensions
648648
# }
649649
# fn compute_area(shape: &Shape) -> float { 0f }
650-
fn select<T>(shape: &Shape, threshold: float,
651-
a: &'r T, b: &'r T) -> &'r T {
650+
fn select<'r, T>(shape: &Shape, threshold: float,
651+
a: &'r T, b: &'r T) -> &'r T {
652652
if compute_area(shape) > threshold {a} else {b}
653653
}
654654
~~~

src/libcore/at_vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pub mod traits {
174174
use kinds::Copy;
175175
use ops::Add;
176176

177-
impl<T:Copy> Add<&'self const [T],@[T]> for @[T] {
177+
impl<'self,T:Copy> Add<&'self const [T],@[T]> for @[T] {
178178
#[inline(always)]
179179
fn add(&self, rhs: & &'self const [T]) -> @[T] {
180180
append(*self, (*rhs))

src/libcore/cast.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,19 @@ pub unsafe fn transmute<L, G>(thing: L) -> G {
6161

6262
/// Coerce an immutable reference to be mutable.
6363
#[inline(always)]
64-
pub unsafe fn transmute_mut<T>(ptr: &'a T) -> &'a mut T { transmute(ptr) }
64+
pub unsafe fn transmute_mut<'a,T>(ptr: &'a T) -> &'a mut T { transmute(ptr) }
6565

6666
/// Coerce a mutable reference to be immutable.
6767
#[inline(always)]
68-
pub unsafe fn transmute_immut<T>(ptr: &'a mut T) -> &'a T {
68+
pub unsafe fn transmute_immut<'a,T>(ptr: &'a mut T) -> &'a T {
6969
transmute(ptr)
7070
}
7171

7272
/// Coerce a borrowed pointer to have an arbitrary associated region.
7373
#[inline(always)]
74-
pub unsafe fn transmute_region<T>(ptr: &'a T) -> &'b T { transmute(ptr) }
74+
pub unsafe fn transmute_region<'a,'b,T>(ptr: &'a T) -> &'b T {
75+
transmute(ptr)
76+
}
7577

7678
/// Coerce an immutable reference to be mutable.
7779
#[inline(always)]
@@ -87,19 +89,19 @@ pub unsafe fn transmute_immut_unsafe<T>(ptr: *const T) -> *T {
8789

8890
/// Coerce a borrowed mutable pointer to have an arbitrary associated region.
8991
#[inline(always)]
90-
pub unsafe fn transmute_mut_region<T>(ptr: &'a mut T) -> &'b mut T {
92+
pub unsafe fn transmute_mut_region<'a,'b,T>(ptr: &'a mut T) -> &'b mut T {
9193
transmute(ptr)
9294
}
9395

9496
/// Transforms lifetime of the second pointer to match the first.
9597
#[inline(always)]
96-
pub unsafe fn copy_lifetime<S,T>(_ptr: &'a S, ptr: &T) -> &'a T {
98+
pub unsafe fn copy_lifetime<'a,S,T>(_ptr: &'a S, ptr: &T) -> &'a T {
9799
transmute_region(ptr)
98100
}
99101

100102
/// Transforms lifetime of the second pointer to match the first.
101103
#[inline(always)]
102-
pub unsafe fn copy_lifetime_vec<S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
104+
pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
103105
transmute_region(ptr)
104106
}
105107

src/libcore/cleanup.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use cast::transmute;
2222
* NB: These must match the representation in the C++ runtime.
2323
*/
2424

25-
type DropGlue = &'self fn(**TypeDesc, *c_void);
26-
type FreeGlue = &'self fn(**TypeDesc, *c_void);
25+
type DropGlue<'self> = &'self fn(**TypeDesc, *c_void);
26+
type FreeGlue<'self> = &'self fn(**TypeDesc, *c_void);
2727

2828
type TaskID = uintptr_t;
2929

src/libcore/condition.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ pub struct Handler<T, U> {
2222
prev: Option<@Handler<T, U>>,
2323
}
2424

25-
pub struct Condition<T, U> {
25+
pub struct Condition<'self, T, U> {
2626
name: &'static str,
2727
key: task::local_data::LocalDataKey<'self, Handler<T, U>>
2828
}
2929

30-
pub impl<T, U> Condition<'self, T, U> {
30+
pub impl<'self, T, U> Condition<'self, T, U> {
3131
fn trap(&self, h: &'self fn(T) -> U) -> Trap<'self, T, U> {
3232
unsafe {
3333
let p : *RustClosure = ::cast::transmute(&h);
@@ -66,12 +66,12 @@ pub impl<T, U> Condition<'self, T, U> {
6666
}
6767
}
6868

69-
struct Trap<T, U> {
69+
struct Trap<'self, T, U> {
7070
cond: &'self Condition<'self, T, U>,
7171
handler: @Handler<T, U>
7272
}
7373

74-
pub impl<T, U> Trap<'self, T, U> {
74+
pub impl<'self, T, U> Trap<'self, T, U> {
7575
fn in<V>(&self, inner: &'self fn() -> V) -> V {
7676
unsafe {
7777
let _g = Guard { cond: self.cond };
@@ -82,12 +82,12 @@ pub impl<T, U> Trap<'self, T, U> {
8282
}
8383
}
8484

85-
struct Guard<T, U> {
85+
struct Guard<'self, T, U> {
8686
cond: &'self Condition<'self, T, U>
8787
}
8888

8989
#[unsafe_destructor]
90-
impl<T, U> Drop for Guard<'self, T, U> {
90+
impl<'self, T, U> Drop for Guard<'self, T, U> {
9191
fn finalize(&self) {
9292
unsafe {
9393
debug!("Guard: popping handler from TLS");

src/libcore/gc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ unsafe fn is_safe_point(pc: *Word) -> Option<SafePoint> {
124124
return None;
125125
}
126126

127-
type Visitor = &'self fn(root: **Word, tydesc: *Word) -> bool;
127+
type Visitor<'self> = &'self fn(root: **Word, tydesc: *Word) -> bool;
128128

129129
// Walks the list of roots for the given safe point, and calls visitor
130130
// on each root.

src/libcore/hashmap.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,8 @@ pub mod linear {
278278
}
279279
}
280280
281-
impl<K:Hash + IterBytes + Eq,V>
282-
BaseIter<(&'self K, &'self V)> for LinearMap<K, V>
283-
{
281+
impl<'self,K:Hash + IterBytes + Eq,V>
282+
BaseIter<(&'self K, &'self V)> for LinearMap<K, V> {
284283
/// Visit all key-value pairs
285284
fn each(&self, blk: &fn(&(&'self K, &'self V)) -> bool) {
286285
for uint::range(0, self.buckets.len()) |i| {
@@ -315,7 +314,7 @@ pub mod linear {
315314
}
316315
}
317316
318-
impl<K:Hash + IterBytes + Eq,V> Map<K, V> for LinearMap<K, V> {
317+
impl<'self,K:Hash + IterBytes + Eq,V> Map<K, V> for LinearMap<K, V> {
319318
/// Return true if the map contains a value for the specified key
320319
fn contains_key(&self, k: &K) -> bool {
321320
match self.bucket_for_key(k) {

src/libcore/io.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -616,12 +616,12 @@ pub fn file_reader(path: &Path) -> Result<@Reader, ~str> {
616616
617617
618618
// Byte readers
619-
pub struct BytesReader {
619+
pub struct BytesReader<'self> {
620620
bytes: &'self [u8],
621621
mut pos: uint
622622
}
623623
624-
impl Reader for BytesReader<'self> {
624+
impl<'self> Reader for BytesReader<'self> {
625625
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
626626
let count = uint::min(len, self.bytes.len() - self.pos);
627627

src/libcore/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use option::{None, Option, Some};
2020
use vec;
2121

2222
/// A function used to initialize the elements of a sequence
23-
pub type InitOp<T> = &'self fn(uint) -> T;
23+
pub type InitOp<'self,T> = &'self fn(uint) -> T;
2424

2525
pub trait BaseIter<A> {
2626
fn each(&self, blk: &fn(v: &A) -> bool);

src/libcore/pipes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
439439
let p = unsafe { &*p_ };
440440
441441
#[unsafe_destructor]
442-
struct DropState {
442+
struct DropState<'self> {
443443
p: &'self PacketHeader,
444444
445445
drop {

src/libcore/ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pub fn to_uint<T>(thing: &T) -> uint {
178178

179179
/// Determine if two borrowed pointers point to the same thing.
180180
#[inline(always)]
181-
pub fn ref_eq<T>(thing: &'a T, other: &'b T) -> bool {
181+
pub fn ref_eq<'a,'b,T>(thing: &'a T, other: &'b T) -> bool {
182182
to_uint(thing) == to_uint(other)
183183
}
184184

@@ -312,7 +312,7 @@ impl<T> Ord for *const T {
312312
313313
// Equality for region pointers
314314
#[cfg(notest)]
315-
impl<T:Eq> Eq for &'self const T {
315+
impl<'self,T:Eq> Eq for &'self const T {
316316
#[inline(always)]
317317
fn eq(&self, other: & &'self const T) -> bool {
318318
return *(*self) == *(*other);
@@ -325,7 +325,7 @@ impl<T:Eq> Eq for &'self const T {
325325
326326
// Comparison for region pointers
327327
#[cfg(notest)]
328-
impl<T:Ord> Ord for &'self const T {
328+
impl<'self,T:Ord> Ord for &'self const T {
329329
#[inline(always)]
330330
fn lt(&self, other: & &'self const T) -> bool {
331331
*(*self) < *(*other)

src/libcore/result.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn get<T:Copy,U>(res: &Result<T, U>) -> T {
5353
* If the result is an error
5454
*/
5555
#[inline(always)]
56-
pub fn get_ref<T, U>(res: &'a Result<T, U>) -> &'a T {
56+
pub fn get_ref<'a, T, U>(res: &'a Result<T, U>) -> &'a T {
5757
match *res {
5858
Ok(ref t) => t,
5959
Err(ref the_err) => unsafe {

src/libcore/rt/uv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ pub fn install_watcher_data<H, W: Watcher + NativeHandle<*H>>(watcher: &mut W) {
321321
}
322322
}
323323
324-
pub fn get_watcher_data<H, W: Watcher + NativeHandle<*H>>(
324+
pub fn get_watcher_data<'r, H, W: Watcher + NativeHandle<*H>>(
325325
watcher: &'r mut W) -> &'r mut WatcherData {
326326
327327
unsafe {

0 commit comments

Comments
 (0)