Skip to content

Lifetime syntax #5394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libcore/at_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ pub mod traits {
use kinds::Copy;
use ops::Add;

impl<T:Copy> Add<&self/[const T],@[T]> for @[T] {
impl<T:Copy> Add<&'self [const T],@[T]> for @[T] {
#[inline(always)]
pure fn add(&self, rhs: & &self/[const T]) -> @[T] {
pure fn add(&self, rhs: & &'self [const T]) -> @[T] {
append(*self, (*rhs))
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ pub unsafe fn transmute<L, G>(thing: L) -> G {

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

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

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

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

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/libcore/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use cast::transmute;
* NB: These must match the representation in the C++ runtime.
*/

type DropGlue = &self/fn(**TypeDesc, *c_void);
type FreeGlue = &self/fn(**TypeDesc, *c_void);
type DropGlue = &'self fn(**TypeDesc, *c_void);
type FreeGlue = &'self fn(**TypeDesc, *c_void);

type TaskID = uintptr_t;

Expand Down
10 changes: 5 additions & 5 deletions src/libcore/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ pub struct Handler<T, U> {
}

pub struct Condition<T, U> {
name: &static/str,
name: &'static str,
key: task::local_data::LocalDataKey/&self<Handler<T, U>>
}

pub impl<T, U> Condition/&self<T, U> {
fn trap(&self, h: &self/fn(T) -> U) -> Trap/&self<T, U> {
fn trap(&self, h: &'self fn(T) -> U) -> Trap/&self<T, U> {
unsafe {
let p : *RustClosure = ::cast::transmute(&h);
let prev = task::local_data::local_data_get(self.key);
Expand Down Expand Up @@ -65,12 +65,12 @@ pub impl<T, U> Condition/&self<T, U> {
}

struct Trap<T, U> {
cond: &self/Condition/&self<T, U>,
cond: &'self Condition/&self<T, U>,
handler: @Handler<T, U>
}

pub impl<T, U> Trap/&self<T, U> {
fn in<V>(&self, inner: &self/fn() -> V) -> V {
fn in<V>(&self, inner: &'self fn() -> V) -> V {
unsafe {
let _g = Guard { cond: self.cond };
debug!("Trap: pushing handler to TLS");
Expand All @@ -81,7 +81,7 @@ pub impl<T, U> Trap/&self<T, U> {
}

struct Guard<T, U> {
cond: &self/Condition/&self<T, U>
cond: &'self Condition/&self<T, U>
}

impl<T, U> Drop for Guard/&self<T, U> {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub trait Map<K, V>: Mutable {
fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool);

/// Return the value corresponding to the key in the map
pure fn find(&self, key: &K) -> Option<&self/V>;
pure fn find(&self, key: &K) -> Option<&'self V>;

/// Insert a key-value pair into the map. An existing value for a
/// key is replaced by the new value. Return true if the key did
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ unsafe fn is_safe_point(pc: *Word) -> Option<SafePoint> {
return None;
}

type Visitor = &self/fn(root: **Word, tydesc: *Word) -> bool;
type Visitor = &'self fn(root: **Word, tydesc: *Word) -> bool;

// Walks the list of roots for the given safe point, and calls visitor
// on each root.
Expand Down
16 changes: 8 additions & 8 deletions src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub mod linear {
}

#[inline(always)]
pure fn value_for_bucket(&self, idx: uint) -> &self/V {
pure fn value_for_bucket(&self, idx: uint) -> &'self V {
match self.buckets[idx] {
Some(ref bkt) => &bkt.value,
None => fail!(~"LinearMap::find: internal logic error"),
Expand Down Expand Up @@ -270,10 +270,10 @@ pub mod linear {
}

impl<K:Hash + IterBytes + Eq,V>
BaseIter<(&self/K, &self/V)> for LinearMap<K, V>
BaseIter<(&'self K, &'self V)> for LinearMap<K, V>
{
/// Visit all key-value pairs
pure fn each(&self, blk: &fn(&(&self/K, &self/V)) -> bool) {
pure fn each(&self, blk: &fn(&(&'self K, &'self V)) -> bool) {
for uint::range(0, self.buckets.len()) |i| {
let mut broke = false;
do self.buckets[i].map |bucket| {
Expand Down Expand Up @@ -339,7 +339,7 @@ pub mod linear {
}

/// Return the value corresponding to the key in the map
pure fn find(&self, k: &K) -> Option<&self/V> {
pure fn find(&self, k: &K) -> Option<&'self V> {
match self.bucket_for_key(k) {
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
TableFull | FoundHole(_) => None,
Expand Down Expand Up @@ -412,7 +412,7 @@ pub mod linear {

/// Return the value corresponding to the key in the map, or insert
/// and return the value if it doesn't exist.
fn find_or_insert(&mut self, k: K, v: V) -> &self/V {
fn find_or_insert(&mut self, k: K, v: V) -> &'self V {
if self.size >= self.resize_at {
// n.b.: We could also do this after searching, so
// that we do not resize if this call to insert is
Expand Down Expand Up @@ -442,7 +442,7 @@ pub mod linear {

/// Return the value corresponding to the key in the map, or create,
/// insert, and return a new value if it doesn't exist.
fn find_or_insert_with(&mut self, k: K, f: &fn(&K) -> V) -> &self/V {
fn find_or_insert_with(&mut self, k: K, f: &fn(&K) -> V) -> &'self V {
if self.size >= self.resize_at {
// n.b.: We could also do this after searching, so
// that we do not resize if this call to insert is
Expand Down Expand Up @@ -487,7 +487,7 @@ pub mod linear {
}
}

pure fn get(&self, k: &K) -> &self/V {
pure fn get(&self, k: &K) -> &'self V {
match self.find(k) {
Some(v) => v,
None => fail!(fmt!("No entry found for key: %?", k)),
Expand All @@ -509,7 +509,7 @@ pub mod linear {
/// Return the value corresponding to the key in the map, using
/// equivalence
pure fn find_equiv<Q:Hash + IterBytes + Equiv<K>>(&self, k: &Q)
-> Option<&self/V> {
-> Option<&'self V> {
match self.bucket_for_key_equiv(k) {
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
TableFull | FoundHole(_) => None,
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,11 @@ pub fn file_reader(path: &Path) -> Result<@Reader, ~str> {

// Byte readers
pub struct BytesReader {
bytes: &self/[u8],
bytes: &'self [u8],
mut pos: uint
}

impl Reader for BytesReader/&self {
impl Reader for BytesReader<'self> {
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
let count = uint::min(len, self.bytes.len() - self.pos);

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use option::{None, Option, Some};
use vec;

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

pub trait BaseIter<A> {
pure fn each(&self, blk: &fn(v: &A) -> bool);
Expand Down
20 changes: 10 additions & 10 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub pure fn get<T:Copy>(opt: Option<T>) -> T {
}

#[inline(always)]
pub pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T {
pub pure fn get_ref<T>(opt: &'r Option<T>) -> &'r T {
/*!
Gets an immutable reference to the value inside an option.

Expand All @@ -143,7 +143,7 @@ pub pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T {
}
}

pub pure fn get_mut_ref<T>(opt: &r/mut Option<T>) -> &r/mut T {
pub pure fn get_mut_ref<T>(opt: &'r mut Option<T>) -> &'r mut T {
/*!
Gets a mutable reference to the value inside an option.

Expand All @@ -165,7 +165,7 @@ pub pure fn get_mut_ref<T>(opt: &r/mut Option<T>) -> &r/mut T {
}

#[inline(always)]
pub pure fn map<T, U>(opt: &r/Option<T>, f: &fn(x: &r/T) -> U) -> Option<U> {
pub pure fn map<T, U>(opt: &'r Option<T>, f: &fn(x: &'r T) -> U) -> Option<U> {
//! Maps a `some` value by reference from one type to another

match *opt { Some(ref x) => Some(f(x)), None => None }
Expand Down Expand Up @@ -256,8 +256,8 @@ pub pure fn get_or_default<T:Copy>(opt: Option<T>, def: T) -> T {
}

#[inline(always)]
pub pure fn map_default<T, U>(opt: &r/Option<T>, def: U,
f: &fn(&r/T) -> U) -> U {
pub pure fn map_default<T, U>(opt: &'r Option<T>, def: U,
f: &fn(&'r T) -> U) -> U {
//! Applies a function to the contained value or returns a default

match *opt { None => def, Some(ref t) => f(t) }
Expand Down Expand Up @@ -313,7 +313,7 @@ pub pure fn expect<T>(opt: Option<T>, reason: &str) -> T {
impl<T> BaseIter<T> for Option<T> {
/// Performs an operation on the contained value by reference
#[inline(always)]
pure fn each(&self, f: &fn(x: &self/T) -> bool) {
pure fn each(&self, f: &fn(x: &'self T) -> bool) {
match *self { None => (), Some(ref t) => { f(t); } }
}

Expand Down Expand Up @@ -343,7 +343,7 @@ pub impl<T> Option<T> {

/// Maps a `some` value from one type to another by reference
#[inline(always)]
pure fn map<U>(&self, f: &fn(&self/T) -> U) -> Option<U> { map(self, f) }
pure fn map<U>(&self, f: &fn(&'self T) -> U) -> Option<U> { map(self, f) }

/// As `map`, but consumes the option and gives `f` ownership to avoid
/// copying.
Expand All @@ -354,7 +354,7 @@ pub impl<T> Option<T> {

/// Applies a function to the contained value or returns a default
#[inline(always)]
pure fn map_default<U>(&self, def: U, f: &fn(&self/T) -> U) -> U {
pure fn map_default<U>(&self, def: U, f: &fn(&'self T) -> U) -> U {
map_default(self, def, f)
}

Expand Down Expand Up @@ -396,7 +396,7 @@ pub impl<T> Option<T> {
case explicitly.
*/
#[inline(always)]
pure fn get_ref(&self) -> &self/T { get_ref(self) }
pure fn get_ref(&self) -> &'self T { get_ref(self) }

/**
Gets a mutable reference to the value inside an option.
Expand All @@ -413,7 +413,7 @@ pub impl<T> Option<T> {
case explicitly.
*/
#[inline(always)]
pure fn get_mut_ref(&mut self) -> &self/mut T { get_mut_ref(self) }
pure fn get_mut_ref(&mut self) -> &'self mut T { get_mut_ref(self) }

/**
* Gets the value out of an option without copying.
Expand Down
44 changes: 22 additions & 22 deletions src/libcore/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,11 +1170,11 @@ pub mod consts {
pub use os::consts::windows::*;

pub mod unix {
pub const FAMILY: &static/str = "unix";
pub const FAMILY: &'static str = "unix";
}

pub mod windows {
pub const FAMILY: &static/str = "windows";
pub const FAMILY: &'static str = "windows";
}

#[cfg(target_os = "macos")]
Expand All @@ -1193,38 +1193,38 @@ pub mod consts {
pub use os::consts::win32::*;

pub mod macos {
pub const SYSNAME: &static/str = "macos";
pub const DLL_PREFIX: &static/str = "lib";
pub const DLL_SUFFIX: &static/str = ".dylib";
pub const EXE_SUFFIX: &static/str = "";
pub const SYSNAME: &'static str = "macos";
pub const DLL_PREFIX: &'static str = "lib";
pub const DLL_SUFFIX: &'static str = ".dylib";
pub const EXE_SUFFIX: &'static str = "";
}

pub mod freebsd {
pub const SYSNAME: &static/str = "freebsd";
pub const DLL_PREFIX: &static/str = "lib";
pub const DLL_SUFFIX: &static/str = ".so";
pub const EXE_SUFFIX: &static/str = "";
pub const SYSNAME: &'static str = "freebsd";
pub const DLL_PREFIX: &'static str = "lib";
pub const DLL_SUFFIX: &'static str = ".so";
pub const EXE_SUFFIX: &'static str = "";
}

pub mod linux {
pub const SYSNAME: &static/str = "linux";
pub const DLL_PREFIX: &static/str = "lib";
pub const DLL_SUFFIX: &static/str = ".so";
pub const EXE_SUFFIX: &static/str = "";
pub const SYSNAME: &'static str = "linux";
pub const DLL_PREFIX: &'static str = "lib";
pub const DLL_SUFFIX: &'static str = ".so";
pub const EXE_SUFFIX: &'static str = "";
}

pub mod android {
pub const SYSNAME: &static/str = "android";
pub const DLL_PREFIX: &static/str = "lib";
pub const DLL_SUFFIX: &static/str = ".so";
pub const EXE_SUFFIX: &static/str = "";
pub const SYSNAME: &'static str = "android";
pub const DLL_PREFIX: &'static str = "lib";
pub const DLL_SUFFIX: &'static str = ".so";
pub const EXE_SUFFIX: &'static str = "";
}

pub mod win32 {
pub const SYSNAME: &static/str = "win32";
pub const DLL_PREFIX: &static/str = "";
pub const DLL_SUFFIX: &static/str = ".dll";
pub const EXE_SUFFIX: &static/str = ".exe";
pub const SYSNAME: &'static str = "win32";
pub const DLL_PREFIX: &'static str = "";
pub const DLL_SUFFIX: &'static str = ".dll";
pub const EXE_SUFFIX: &'static str = ".exe";
}


Expand Down
2 changes: 1 addition & 1 deletion src/libcore/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
let p = unsafe { &*p_ };

struct DropState {
p: &self/PacketHeader,
p: &'self PacketHeader,

drop {
if task::failing() {
Expand Down
Loading