static bits: [uint, ..2] = [bit1, bit2];
static string: &'static str = "bitstring";
-struct BitsNStrings {
+struct BitsNStrings<'self> {
mybits: [uint, ..2],
mystring: &'self str
}
~~~
struct Point {x: float, y: float}
-fn get_x(p: &'r Point) -> &'r float { &p.x }
+fn get_x<'r>(p: &'r Point) -> &'r float { &p.x }
~~~
Here, the function `get_x()` returns a pointer into the structure it
# Rectangle(Point, Size) // upper-left, dimensions
# }
# fn compute_area(shape: &Shape) -> float { 0f }
-fn select<T>(shape: &'r Shape, threshold: float,
- a: &'r T, b: &'r T) -> &'r T {
+fn select<'r, T>(shape: &'r Shape, threshold: float,
+ a: &'r T, b: &'r T) -> &'r T {
if compute_area(shape) > threshold {a} else {b}
}
~~~
# Rectangle(Point, Size) // upper-left, dimensions
# }
# fn compute_area(shape: &Shape) -> float { 0f }
-# fn select<T>(shape: &Shape, threshold: float,
-# a: &'r T, b: &'r T) -> &'r T {
+# fn select<'r, T>(shape: &Shape, threshold: float,
+# a: &'r T, b: &'r T) -> &'r T {
# if compute_area(shape) > threshold {a} else {b}
# }
// -+ r
-fn select_based_on_unit_circle<T>( // |-+ B
+fn select_based_on_unit_circle<'r, T>( // |-+ B
threshold: float, a: &'r T, b: &'r T) -> &'r T { // | |
// | |
let shape = Circle(Point {x: 0., y: 0.}, 1.); // | |
# Rectangle(Point, Size) // upper-left, dimensions
# }
# fn compute_area(shape: &Shape) -> float { 0f }
-fn select<T>(shape: &'tmp Shape, threshold: float,
- a: &'r T, b: &'r T) -> &'r T {
+fn select<'r, 'tmp, T>(shape: &'tmp Shape, threshold: float,
+ a: &'r T, b: &'r T) -> &'r T {
if compute_area(shape) > threshold {a} else {b}
}
~~~
# Rectangle(Point, Size) // upper-left, dimensions
# }
# fn compute_area(shape: &Shape) -> float { 0f }
-fn select<T>(shape: &Shape, threshold: float,
- a: &'r T, b: &'r T) -> &'r T {
+fn select<'r, T>(shape: &Shape, threshold: float,
+ a: &'r T, b: &'r T) -> &'r T {
if compute_area(shape) > threshold {a} else {b}
}
~~~
use kinds::Copy;
use ops::Add;
- impl<T:Copy> Add<&'self const [T],@[T]> for @[T] {
+ impl<'self,T:Copy> Add<&'self const [T],@[T]> for @[T] {
#[inline(always)]
fn add(&self, rhs: & &'self const [T]) -> @[T] {
append(*self, (*rhs))
/// 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<'a,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<'a,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<'a,'b,T>(ptr: &'a T) -> &'b T {
+ transmute(ptr)
+}
/// Coerce an immutable reference to be mutable.
#[inline(always)]
/// 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<'a,'b,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<'a,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<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
transmute_region(ptr)
}
* 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> = &'self fn(**TypeDesc, *c_void);
+type FreeGlue<'self> = &'self fn(**TypeDesc, *c_void);
type TaskID = uintptr_t;
prev: Option<@Handler<T, U>>,
}
-pub struct Condition<T, U> {
+pub struct Condition<'self, T, U> {
name: &'static str,
key: task::local_data::LocalDataKey<'self, Handler<T, U>>
}
-pub impl<T, U> Condition<'self, T, U> {
+pub impl<'self, T, U> Condition<'self, T, U> {
fn trap(&self, h: &'self fn(T) -> U) -> Trap<'self, T, U> {
unsafe {
let p : *RustClosure = ::cast::transmute(&h);
}
}
-struct Trap<T, U> {
+struct Trap<'self, T, U> {
cond: &'self Condition<'self, T, U>,
handler: @Handler<T, U>
}
-pub impl<T, U> Trap<'self, T, U> {
+pub impl<'self, T, U> Trap<'self, T, U> {
fn in<V>(&self, inner: &'self fn() -> V) -> V {
unsafe {
let _g = Guard { cond: self.cond };
}
}
-struct Guard<T, U> {
+struct Guard<'self, T, U> {
cond: &'self Condition<'self, T, U>
}
#[unsafe_destructor]
-impl<T, U> Drop for Guard<'self, T, U> {
+impl<'self, T, U> Drop for Guard<'self, T, U> {
fn finalize(&self) {
unsafe {
debug!("Guard: popping handler from TLS");
return None;
}
-type Visitor = &'self fn(root: **Word, tydesc: *Word) -> bool;
+type Visitor<'self> = &'self fn(root: **Word, tydesc: *Word) -> bool;
// Walks the list of roots for the given safe point, and calls visitor
// on each root.
}
}
- impl<K:Hash + IterBytes + Eq,V>
- BaseIter<(&'self K, &'self V)> for LinearMap<K, V>
- {
+ impl<'self,K:Hash + IterBytes + Eq,V>
+ BaseIter<(&'self K, &'self V)> for LinearMap<K, V> {
/// Visit all key-value pairs
fn each(&self, blk: &fn(&(&'self K, &'self V)) -> bool) {
for uint::range(0, self.buckets.len()) |i| {
}
}
- impl<K:Hash + IterBytes + Eq,V> Map<K, V> for LinearMap<K, V> {
+ impl<'self,K:Hash + IterBytes + Eq,V> Map<K, V> for LinearMap<K, V> {
/// Return true if the map contains a value for the specified key
fn contains_key(&self, k: &K) -> bool {
match self.bucket_for_key(k) {
// Byte readers
-pub struct BytesReader {
+pub struct BytesReader<'self> {
bytes: &'self [u8],
mut pos: uint
}
-impl Reader for BytesReader<'self> {
+impl<'self> Reader for BytesReader<'self> {
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
let count = uint::min(len, self.bytes.len() - self.pos);
use vec;
/// A function used to initialize the elements of a sequence
-pub type InitOp<T> = &'self fn(uint) -> T;
+pub type InitOp<'self,T> = &'self fn(uint) -> T;
pub trait BaseIter<A> {
fn each(&self, blk: &fn(v: &A) -> bool);
let p = unsafe { &*p_ };
#[unsafe_destructor]
- struct DropState {
+ struct DropState<'self> {
p: &'self PacketHeader,
drop {
/// Determine if two borrowed pointers point to the same thing.
#[inline(always)]
-pub fn ref_eq<T>(thing: &'a T, other: &'b T) -> bool {
+pub fn ref_eq<'a,'b,T>(thing: &'a T, other: &'b T) -> bool {
to_uint(thing) == to_uint(other)
}
// Equality for region pointers
#[cfg(notest)]
-impl<T:Eq> Eq for &'self const T {
+impl<'self,T:Eq> Eq for &'self const T {
#[inline(always)]
fn eq(&self, other: & &'self const T) -> bool {
return *(*self) == *(*other);
// Comparison for region pointers
#[cfg(notest)]
-impl<T:Ord> Ord for &'self const T {
+impl<'self,T:Ord> Ord for &'self const T {
#[inline(always)]
fn lt(&self, other: & &'self const T) -> bool {
*(*self) < *(*other)
* If the result is an error
*/
#[inline(always)]
-pub fn get_ref<T, U>(res: &'a Result<T, U>) -> &'a T {
+pub fn get_ref<'a, T, U>(res: &'a Result<T, U>) -> &'a T {
match *res {
Ok(ref t) => t,
Err(ref the_err) => unsafe {
}
}
-pub fn get_watcher_data<H, W: Watcher + NativeHandle<*H>>(
+pub fn get_watcher_data<'r, H, W: Watcher + NativeHandle<*H>>(
watcher: &'r mut W) -> &'r mut WatcherData {
unsafe {
#[inline(always)]
fn to_str(&self) -> ~str { from_slice(*self) }
}
-impl ToStr for &'self str {
+impl<'self> ToStr for &'self str {
#[inline(always)]
fn to_str(&self) -> ~str { from_slice(*self) }
}
* If the string does not contain any characters
*/
#[inline]
-pub fn slice_shift_char(s: &'a str) -> (char, &'a str) {
+pub fn slice_shift_char<'a>(s: &'a str) -> (char, &'a str) {
let CharRange {ch, next} = char_range_at(s, 0u);
let next_s = unsafe { raw::slice_bytes(s, next, len(s)) };
return (ch, next_s);
* * chars_to_trim - A vector of chars
*
*/
-pub fn trim_left_chars(s: &'a str, chars_to_trim: &[char]) -> &'a str {
+pub fn trim_left_chars<'a>(s: &'a str, chars_to_trim: &[char]) -> &'a str {
if chars_to_trim.is_empty() { return s; }
match find(s, |c| !chars_to_trim.contains(&c)) {
* * chars_to_trim - A vector of chars
*
*/
-pub fn trim_right_chars(s: &'a str, chars_to_trim: &[char]) -> &'a str {
+pub fn trim_right_chars<'a>(s: &'a str, chars_to_trim: &[char]) -> &'a str {
if chars_to_trim.is_empty() { return s; }
match rfind(s, |c| !chars_to_trim.contains(&c)) {
* * chars_to_trim - A vector of chars
*
*/
-pub fn trim_chars(s: &'a str, chars_to_trim: &[char]) -> &'a str {
+pub fn trim_chars<'a>(s: &'a str, chars_to_trim: &[char]) -> &'a str {
trim_left_chars(trim_right_chars(s, chars_to_trim), chars_to_trim)
}
/// Returns a string with leading whitespace removed
-pub fn trim_left(s: &'a str) -> &'a str {
+pub fn trim_left<'a>(s: &'a str) -> &'a str {
match find(s, |c| !char::is_whitespace(c)) {
None => "",
Some(first) => unsafe { raw::slice_bytes(s, first, len(s)) }
}
/// Returns a string with trailing whitespace removed
-pub fn trim_right(s: &'a str) -> &'a str {
+pub fn trim_right<'a>(s: &'a str) -> &'a str {
match rfind(s, |c| !char::is_whitespace(c)) {
None => "",
Some(last) => {
}
/// Returns a string with leading and trailing whitespace removed
-pub fn trim(s: &'a str) -> &'a str { trim_left(trim_right(s)) }
+pub fn trim<'a>(s: &'a str) -> &'a str { trim_left(trim_right(s)) }
/*
Section: Transforming strings
* Returns a slice pointing at `n` characters starting from byte offset
* `begin`.
*/
-pub fn substr(s: &'a str, begin: uint, n: uint) -> &'a str {
+pub fn substr<'a>(s: &'a str, begin: uint, n: uint) -> &'a str {
slice(s, begin, begin + count_bytes(s, begin, n))
}
* Fails when `begin` and `end` do not point to valid characters or beyond
* the last character of the string
*/
-pub fn slice(s: &'a str, begin: uint, end: uint) -> &'a str {
+pub fn slice<'a>(s: &'a str, begin: uint, end: uint) -> &'a str {
fail_unless!(is_char_boundary(s, begin));
fail_unless!(is_char_boundary(s, end));
unsafe { raw::slice_bytes(s, begin, end) }
}
// See Issue #1932 for why this is a naive search
-fn iter_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint) -> bool) {
+fn iter_matches<'a,'b>(s: &'a str, sep: &'b str, f: &fn(uint, uint) -> bool) {
let sep_len = len(sep), l = len(s);
fail_unless!(sep_len > 0u);
let mut i = 0u, match_start = 0u, match_i = 0u;
}
}
-fn iter_between_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint) -> bool) {
+fn iter_between_matches<'a,'b>(s: &'a str,
+ sep: &'b str,
+ f: &fn(uint, uint) -> bool) {
let mut last_end = 0u;
for iter_matches(s, sep) |from, to| {
if !f(last_end, from) { return; }
* fail_unless!(v == ["", "XXX", "YYY", ""]);
* ~~~
*/
-pub fn each_split_str(s: &'a str, sep: &'b str, it: &fn(&'a str) -> bool) {
+pub fn each_split_str<'a,'b>(s: &'a str,
+ sep: &'b str,
+ it: &fn(&'a str) -> bool) {
for iter_between_matches(s, sep) |from, to| {
if !it( unsafe { raw::slice_bytes(s, from, to) } ) { return; }
}
}
-pub fn each_split_str_nonempty(s: &'a str, sep: &'b str, it: &fn(&'a str) -> bool) {
+pub fn each_split_str_nonempty<'a,'b>(s: &'a str,
+ sep: &'b str,
+ it: &fn(&'a str) -> bool) {
for iter_between_matches(s, sep) |from, to| {
if to > from {
if !it( unsafe { raw::slice_bytes(s, from, to) } ) { return; }
}
#[cfg(notest)]
-impl TotalOrd for &'self str {
+impl<'self> TotalOrd for &'self str {
fn cmp(&self, other: & &'self str) -> Ordering { cmp(*self, *other) }
}
}
#[cfg(notest)]
-impl Eq for &'self str {
+impl<'self> Eq for &'self str {
#[inline(always)]
fn eq(&self, other: & &'self str) -> bool {
eq_slice((*self), (*other))
}
#[cfg(notest)]
-impl Ord for &'self str {
+impl<'self> Ord for &'self str {
#[inline(always)]
fn lt(&self, other: & &'self str) -> bool { lt((*self), (*other)) }
#[inline(always)]
}
#[cfg(notest)]
-impl Equiv<~str> for &'self str {
+impl<'self> Equiv<~str> for &'self str {
#[inline(always)]
fn equiv(&self, other: &~str) -> bool { eq_slice(*self, *other) }
}
}
// Utility used by various searching functions
-fn match_at(haystack: &'a str, needle: &'b str, at: uint) -> bool {
+fn match_at<'a,'b>(haystack: &'a str, needle: &'b str, at: uint) -> bool {
let mut i = at;
for each(needle) |c| { if haystack[i] != c { return false; } i += 1u; }
return true;
* An `option` containing the byte index of the first matching substring
* or `none` if there is no match
*/
-pub fn find_str(haystack: &'a str, needle: &'b str) -> Option<uint> {
+pub fn find_str<'a,'b>(haystack: &'a str, needle: &'b str) -> Option<uint> {
find_str_between(haystack, needle, 0u, len(haystack))
}
*
* `start` must be less than or equal to `len(s)`
*/
-pub fn find_str_from(haystack: &'a str, needle: &'b str, start: uint) -> Option<uint> {
+pub fn find_str_from<'a,'b>(haystack: &'a str,
+ needle: &'b str,
+ start: uint)
+ -> Option<uint> {
find_str_between(haystack, needle, start, len(haystack))
}
* `start` must be less than or equal to `end` and `end` must be less than
* or equal to `len(s)`.
*/
-pub fn find_str_between(haystack: &'a str, needle: &'b str, start: uint, end:uint)
- -> Option<uint> {
+pub fn find_str_between<'a,'b>(haystack: &'a str,
+ needle: &'b str,
+ start: uint,
+ end:uint)
+ -> Option<uint> {
// See Issue #1932 for why this is a naive search
fail_unless!(end <= len(haystack));
let needle_len = len(needle);
* * haystack - The string to look in
* * needle - The string to look for
*/
-pub fn contains(haystack: &'a str, needle: &'b str) -> bool {
+pub fn contains<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
find_str(haystack, needle).is_some()
}
* * haystack - The string to look in
* * needle - The string to look for
*/
-pub fn starts_with(haystack: &'a str, needle: &'b str) -> bool {
+pub fn starts_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
let haystack_len = len(haystack), needle_len = len(needle);
if needle_len == 0u { true }
else if needle_len > haystack_len { false }
* * haystack - The string to look in
* * needle - The string to look for
*/
-pub fn ends_with(haystack: &'a str, needle: &'b str) -> bool {
+pub fn ends_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
let haystack_len = len(haystack), needle_len = len(needle);
if needle_len == 0u { true }
else if needle_len > haystack_len { false }
}
/// Counts the number of bytes taken by the `n` in `s` starting from `start`.
-pub fn count_bytes(s: &'b str, start: uint, n: uint) -> uint {
+pub fn count_bytes<'b>(s: &'b str, start: uint, n: uint) -> uint {
fail_unless!(is_char_boundary(s, start));
let mut end = start, cnt = n;
let l = len(s);
*
* The byte slice does not include the null terminator.
*/
-pub fn as_bytes_slice(s: &'a str) -> &'a [u8] {
+pub fn as_bytes_slice<'a>(s: &'a str) -> &'a [u8] {
unsafe {
let (ptr, len): (*u8, uint) = ::cast::reinterpret_cast(&s);
let outgoing_tuple: (*u8, uint) = (ptr, len - 1);
use ops::Add;
use str::append;
- impl Add<&'self str,~str> for ~str {
+ impl<'self> Add<&'self str,~str> for ~str {
#[inline(always)]
fn add(&self, rhs: & &'self str) -> ~str {
append(copy *self, (*rhs))
pub trait StrSlice<'self> {
fn all(&self, it: &fn(char) -> bool) -> bool;
fn any(&self, it: &fn(char) -> bool) -> bool;
- fn contains(&self, needle: &'a str) -> bool;
+ fn contains<'a>(&self, needle: &'a str) -> bool;
fn contains_char(&self, needle: char) -> bool;
fn each(&self, it: &fn(u8) -> bool);
fn eachi(&self, it: &fn(uint, u8) -> bool);
fn slice(&self, begin: uint, end: uint) -> &'self str;
fn each_split(&self, sepfn: &fn(char) -> bool, it: &fn(&'self str) -> bool);
fn each_split_char(&self, sep: char, it: &fn(&'self str) -> bool);
- fn each_split_str(&self, sep: &'a str, it: &fn(&'self str) -> bool);
- fn starts_with(&self, needle: &'a str) -> bool;
+ fn each_split_str<'a>(&self, sep: &'a str, it: &fn(&'self str) -> bool);
+ fn starts_with<'a>(&self, needle: &'a str) -> bool;
fn substr(&self, begin: uint, n: uint) -> &'self str;
fn to_lower(&self) -> ~str;
fn to_upper(&self) -> ~str;
}
/// Extension methods for strings
-impl StrSlice<'self> for &'self str {
+impl<'self> StrSlice<'self> for &'self str {
/**
* Return true if a predicate matches all characters or if the string
* contains no characters
fn any(&self, it: &fn(char) -> bool) -> bool { any(*self, it) }
/// Returns true if one string contains another
#[inline]
- fn contains(&self, needle: &'a str) -> bool {
+ fn contains<'a>(&self, needle: &'a str) -> bool {
contains(*self, needle)
}
/// Returns true if a string contains a char
* string
*/
#[inline]
- fn each_split_str(&self, sep: &'a str, it: &fn(&'self str) -> bool) {
+ fn each_split_str<'a>(&self, sep: &'a str, it: &fn(&'self str) -> bool) {
each_split_str(*self, sep, it)
}
/// Returns true if one string starts with another
#[inline]
- fn starts_with(&self, needle: &'a str) -> bool {
+ fn starts_with<'a>(&self, needle: &'a str) -> bool {
starts_with(*self, needle)
}
/**
#[test]
fn test_split_str() {
- fn t(s: &str, sep: &'a str, u: &[~str]) {
+ fn t<'a>(s: &str, sep: &'a str, u: &[~str]) {
let mut v = ~[];
for each_split_str(s, sep) |s| { v.push(s.to_owned()) }
fail_unless!(vec::all2(v, u, |a,b| a == b));
use repr;
use str;
-pub type FreeGlue = &'self fn(*TypeDesc, *c_void);
+pub type FreeGlue<'self> = &'self fn(*TypeDesc, *c_void);
// Corresponds to runtime type_desc type
pub struct TypeDesc {
*
* These two cases aside, the interface is safe.
*/
-pub type LocalDataKey<T> = &'self fn(v: @T);
+pub type LocalDataKey<'self,T> = &'self fn(v: @T);
/**
* Remove a task-local data value from the table, returning the
}
type TaskGroupArc = unstable::Exclusive<Option<TaskGroupData>>;
-type TaskGroupInner = &'self mut Option<TaskGroupData>;
+type TaskGroupInner<'self> = &'self mut Option<TaskGroupData>;
// A taskgroup is 'dead' when nothing can cause it to fail; only members can.
fn taskgroup_is_dead(tg: &TaskGroupData) -> bool {
use option::{None, Option, Some};
use str;
-pub type Cb = &'self fn(buf: &const [u8]) -> bool;
+pub type Cb<'self> = &'self fn(buf: &const [u8]) -> bool;
/**
* A trait to implement in order to make a type hashable;
}
}
-impl<A:IterBytes> IterBytes for &'self [A] {
+impl<'self,A:IterBytes> IterBytes for &'self [A] {
#[inline(always)]
fn iter_bytes(&self, lsb0: bool, f: Cb) {
for (*self).each |elt| {
}
// Move this to vec, probably.
-fn borrow<A>(a: &'x [A]) -> &'x [A] {
+fn borrow<'x,A>(a: &'x [A]) -> &'x [A] {
a
}
g.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
}
-impl IterBytes for &'self str {
+impl<'self> IterBytes for &'self str {
#[inline(always)]
fn iter_bytes(&self, _lsb0: bool, f: Cb) {
do str::byte_slice(*self) |bytes| {
}
}
-impl<A:IterBytes> IterBytes for &'self A {
+impl<'self,A:IterBytes> IterBytes for &'self A {
#[inline(always)]
fn iter_bytes(&self, lsb0: bool, f: Cb) {
(**self).iter_bytes(lsb0, f);
}
}
-impl<A:ToStr> ToStr for &'self [A] {
+impl<'self,A:ToStr> ToStr for &'self [A] {
#[inline(always)]
fn to_str(&self) -> ~str {
unsafe {
priv length: uint
}
-impl<T> BaseIter<(uint, &'self T)> for TrieMap<T> {
+impl<'self,T> BaseIter<(uint, &'self T)> for TrieMap<T> {
/// Visit all key-value pairs in order
#[inline(always)]
fn each(&self, f: &fn(&(uint, &'self T)) -> bool) {
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
-impl<T> ReverseIter<(uint, &'self T)> for TrieMap<T> {
+impl<'self,T> ReverseIter<(uint, &'self T)> for TrieMap<T> {
/// Visit all key-value pairs in reverse order
#[inline(always)]
fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) {
(n >> sh) & MASK
}
-fn find_mut<T>(child: &'r mut Child<T>, key: uint, idx: uint) -> Option<&'r mut T> {
+fn find_mut<'r, T>(child: &'r mut Child<T>, key: uint, idx: uint)
+ -> Option<&'r mut T> {
unsafe { // FIXME(#4903)---requires flow-sensitive borrow checker
(match *child {
External(_, ref value) => Some(cast::transmute_mut(value)),
fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C];
}
-impl<A:Copy,B:Copy> ExtendedTupleOps<A,B> for (&'self [A], &'self [B]) {
+impl<'self,A:Copy,B:Copy> ExtendedTupleOps<A,B> for (&'self [A], &'self [B]) {
#[inline(always)]
fn zip(&self) -> ~[(A, B)] {
match *self {
}
}
#[inline(always)]
-pub unsafe fn get_shared_immutable_state<T:Owned>(
+pub unsafe fn get_shared_immutable_state<'a,T:Owned>(
rc: &'a SharedMutableState<T>) -> &'a T {
unsafe {
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
fn finally(&self, dtor: &fn()) -> T;
}
-impl<T> Finally<T> for &'self fn() -> T {
+impl<'self,T> Finally<T> for &'self fn() -> T {
fn finally(&self, dtor: &fn()) -> T {
let _d = Finallyalizer {
dtor: dtor
#[cfg(test)] use task::spawn;
#[cfg(test)] use uint;
-pub type GlobalDataKey<T> = &'self fn(v: T);
+pub type GlobalDataKey<'self,T> = &'self fn(v: T);
pub unsafe fn global_data_clone_create<T:Owned + Clone>(
key: GlobalDataKey<T>, create: &fn() -> ~T) -> T {
// Accessors
/// Returns the first element of a vector
-pub fn head<T>(v: &'r [T]) -> &'r T {
+pub fn head<'r,T>(v: &'r [T]) -> &'r T {
if v.len() == 0 { fail!(~"head: empty vector") }
&v[0]
}
/// Returns `Some(x)` where `x` is the first element of the slice `v`,
/// or `None` if the vector is empty.
-pub fn head_opt<T>(v: &'r [T]) -> Option<&'r T> {
+pub fn head_opt<'r,T>(v: &'r [T]) -> Option<&'r T> {
if v.len() == 0 { None } else { Some(&v[0]) }
}
/// Returns a vector containing all but the first element of a slice
-pub fn tail<T>(v: &'r [T]) -> &'r [T] { slice(v, 1, v.len()) }
+pub fn tail<'r,T>(v: &'r [T]) -> &'r [T] { slice(v, 1, v.len()) }
/// Returns a vector containing all but the first `n` elements of a slice
-pub fn tailn<T>(v: &'r [T], n: uint) -> &'r [T] { slice(v, n, v.len()) }
+pub fn tailn<'r,T>(v: &'r [T], n: uint) -> &'r [T] { slice(v, n, v.len()) }
/// Returns a vector containing all but the last element of a slice
-pub fn init<T>(v: &'r [T]) -> &'r [T] { slice(v, 0, v.len() - 1) }
+pub fn init<'r,T>(v: &'r [T]) -> &'r [T] { slice(v, 0, v.len() - 1) }
/// Returns a vector containing all but the last `n' elements of a slice
-pub fn initn<T>(v: &'r [T], n: uint) -> &'r [T] {
+pub fn initn<'r,T>(v: &'r [T], n: uint) -> &'r [T] {
slice(v, 0, v.len() - n)
}
/// Returns the last element of the slice `v`, failing if the slice is empty.
-pub fn last<T>(v: &'r [T]) -> &'r T {
+pub fn last<'r,T>(v: &'r [T]) -> &'r T {
if v.len() == 0 { fail!(~"last: empty vector") }
&v[v.len() - 1]
}
/// Returns `Some(x)` where `x` is the last element of the slice `v`, or
/// `None` if the vector is empty.
-pub fn last_opt<T>(v: &'r [T]) -> Option<&'r T> {
+pub fn last_opt<'r,T>(v: &'r [T]) -> Option<&'r T> {
if v.len() == 0 { None } else { Some(&v[v.len() - 1]) }
}
/// Return a slice that points into another slice.
#[inline(always)]
-pub fn slice<T>(v: &'r [T], start: uint, end: uint) -> &'r [T] {
+pub fn slice<'r,T>(v: &'r [T], start: uint, end: uint) -> &'r [T] {
fail_unless!(start <= end);
fail_unless!(end <= len(v));
do as_imm_buf(v) |p, _len| {
/// Return a slice that points into another slice.
#[inline(always)]
-pub fn mut_slice<T>(v: &'r mut [T], start: uint, end: uint) -> &'r mut [T] {
+pub fn mut_slice<'r,T>(v: &'r mut [T], start: uint, end: uint)
+ -> &'r mut [T] {
fail_unless!(start <= end);
fail_unless!(end <= v.len());
do as_mut_buf(v) |p, _len| {
/// Return a slice that points into another slice.
#[inline(always)]
-pub fn const_slice<T>(v: &'r const [T], start: uint, end: uint)
- -> &'r const [T] {
+pub fn const_slice<'r,T>(v: &'r const [T], start: uint, end: uint)
+ -> &'r const [T] {
fail_unless!(start <= end);
fail_unless!(end <= len(v));
do as_const_buf(v) |p, _len| {
* ~~~
*/
#[inline(always)]
-pub fn each<T>(v: &'r [T], f: &fn(&'r T) -> bool) {
+pub fn each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) {
// ^^^^
// NB---this CANNOT be &const [T]! The reason
// is that you are passing it to `f()` using
/// a vector with mutable contents and you would like
/// to mutate the contents as you iterate.
#[inline(always)]
-pub fn each_mut<T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) {
+pub fn each_mut<'r,T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) {
let mut i = 0;
let n = v.len();
while i < n {
* Return true to continue, false to break.
*/
#[inline(always)]
-pub fn eachi<T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) {
+pub fn eachi<'r,T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) {
let mut i = 0;
for each(v) |p| {
if !f(i, p) { return; }
* Return true to continue, false to break.
*/
#[inline(always)]
-pub fn each_reverse<T>(v: &'r [T], blk: &fn(v: &'r T) -> bool) {
+pub fn each_reverse<'r,T>(v: &'r [T], blk: &fn(v: &'r T) -> bool) {
eachi_reverse(v, |_i, v| blk(v))
}
* Return true to continue, false to break.
*/
#[inline(always)]
-pub fn eachi_reverse<T>(v: &'r [T], blk: &fn(i: uint, v: &'r T) -> bool) {
+pub fn eachi_reverse<'r,T>(v: &'r [T], blk: &fn(i: uint, v: &'r T) -> bool) {
let mut i = v.len();
while i > 0 {
i -= 1;
}
#[cfg(notest)]
-impl<T:Eq> Eq for &'self [T] {
+impl<'self,T:Eq> Eq for &'self [T] {
#[inline(always)]
fn eq(&self, other: & &'self [T]) -> bool { eq((*self), (*other)) }
#[inline(always)]
}
#[cfg(notest)]
-impl<T:Eq> Equiv<~[T]> for &'self [T] {
+impl<'self,T:Eq> Equiv<~[T]> for &'self [T] {
#[inline(always)]
fn equiv(&self, other: &~[T]) -> bool { eq(*self, *other) }
}
}
#[cfg(notest)]
-impl<T: TotalOrd> TotalOrd for &'self [T] {
+impl<'self,T:TotalOrd> TotalOrd for &'self [T] {
#[inline(always)]
fn cmp(&self, other: & &'self [T]) -> Ordering { cmp(*self, *other) }
}
fn gt<T:Ord>(a: &[T], b: &[T]) -> bool { lt(b, a) }
#[cfg(notest)]
-impl<T:Ord> Ord for &'self [T] {
+impl<'self,T:Ord> Ord for &'self [T] {
#[inline(always)]
fn lt(&self, other: & &'self [T]) -> bool { lt((*self), (*other)) }
#[inline(always)]
use ops::Add;
use vec::append;
- impl<T:Copy> Add<&'self const [T],~[T]> for ~[T] {
+ impl<'self,T:Copy> Add<&'self const [T],~[T]> for ~[T] {
#[inline(always)]
fn add(&self, rhs: & &'self const [T]) -> ~[T] {
append(copy *self, (*rhs))
}
}
-impl<T> Container for &'self const [T] {
+impl<'self,T> Container for &'self const [T] {
/// Returns true if a vector contains no elements
#[inline]
fn is_empty(&const self) -> bool { is_empty(*self) }
}
/// Extension methods for vectors
-impl<T: Copy> CopyableVector<T> for &'self const [T] {
+impl<'self,T:Copy> CopyableVector<T> for &'self const [T] {
/// Returns a copy of `v`.
#[inline]
fn to_owned(&self) -> ~[T] {
}
/// Extension methods for vectors
-impl<T> ImmutableVector<T> for &'self [T] {
+impl<'self,T> ImmutableVector<T> for &'self [T] {
/// Return a slice that points into another slice.
#[inline]
fn slice(&self, start: uint, end: uint) -> &'self [T] {
fn rposition_elem(&self, t: &T) -> Option<uint>;
}
-impl<T:Eq> ImmutableEqVector<T> for &'self [T] {
+impl<'self,T:Eq> ImmutableEqVector<T> for &'self [T] {
/**
* Find the first index matching some predicate
*
}
/// Extension methods for vectors
-impl<T:Copy> ImmutableCopyableVector<T> for &'self [T] {
+impl<'self,T:Copy> ImmutableCopyableVector<T> for &'self [T] {
/**
* Construct a new vector from the elements of a vector for which some
* predicate holds.
// ___________________________________________________________________________
// ITERATION TRAIT METHODS
-impl<A> iter::BaseIter<A> for &'self [A] {
+impl<'self,A> iter::BaseIter<A> for &'self [A] {
#[inline(always)]
fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) }
#[inline(always)]
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
-impl<A> iter::MutableIter<A> for &'self mut [A] {
+impl<'self,A> iter::MutableIter<A> for &'self mut [A] {
#[inline(always)]
fn each_mut(&mut self, blk: &fn(v: &'self mut A) -> bool) {
each_mut(*self, blk)
}
}
-impl<A> iter::ExtendedIter<A> for &'self [A] {
+impl<'self,A> iter::ExtendedIter<A> for &'self [A] {
pub fn eachi(&self, blk: &fn(uint, v: &A) -> bool) {
iter::eachi(self, blk)
}
}
}
-impl<A:Eq> iter::EqIter<A> for &'self [A] {
+impl<'self,A:Eq> iter::EqIter<A> for &'self [A] {
pub fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
pub fn count(&self, x: &A) -> uint { iter::count(self, x) }
}
pub fn count(&self, x: &A) -> uint { iter::count(self, x) }
}
-impl<A:Copy> iter::CopyableIter<A> for &'self [A] {
+impl<'self,A:Copy> iter::CopyableIter<A> for &'self [A] {
fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] {
iter::filter_to_vec(self, pred)
}
}
}
-impl<A:Copy + Ord> iter::CopyableOrderedIter<A> for &'self [A] {
+impl<'self,A:Copy + Ord> iter::CopyableOrderedIter<A> for &'self [A] {
fn min(&self) -> A { iter::min(self) }
fn max(&self) -> A { iter::max(self) }
}
fn max(&self) -> A { iter::max(self) }
}
-impl<A:Copy> iter::CopyableNonstrictIter<A> for &'self [A] {
+impl<'self,A:Copy> iter::CopyableNonstrictIter<A> for &'self [A] {
fn each_val(&const self, f: &fn(A) -> bool) {
let mut i = 0;
while i < self.len() {
}
}
-enum Action {
+enum Action<'self> {
Exec(&'self str),
Call(&'self fn(args: &[~str]) -> ValidUsage)
}
-enum UsageSource {
+enum UsageSource<'self> {
UsgExec(&'self str),
UsgStr(&'self str)
}
None
}
-pub type GetCrateDataCb = &'self fn(ast::crate_num) -> cmd;
+pub type GetCrateDataCb<'self> = &'self fn(ast::crate_num) -> cmd;
pub fn maybe_find_item(item_id: int, items: ebml::Doc) -> Option<ebml::Doc> {
fn eq_item(bytes: &[u8], item_id: int) -> bool {
item_path(intr, lookup_item(id, cdata.data))
}
-pub type decode_inlined_item = &'self fn(
+pub type decode_inlined_item<'self> = &'self fn(
cdata: @cstore::crate_metadata,
tcx: ty::ctxt,
path: ast_map::path,
use core::result;
use core::str;
-pub type pick<T> = &'self fn(path: &Path) -> Option<T>;
+pub type pick<'self, T> = &'self fn(path: &Path) -> Option<T>;
pub fn pick_file(file: Path, path: &Path) -> Option<Path> {
if path.file_path() == file { option::Some(copy *path) }
// Identifies a type parameter (`fn foo<X>() { ... }`).
TypeParameter
}
-type conv_did = &'self fn(source: DefIdSource, ast::def_id) -> ast::def_id;
+type conv_did<'self> =
+ &'self fn(source: DefIdSource, ast::def_id) -> ast::def_id;
pub struct PState {
data: @~[u8],
}
}
-struct PreserveCtxt {
+struct PreserveCtxt<'self> {
bccx: &'self BorrowckCtxt,
// the region scope for which we must preserve the memory
}
}
-struct LanguageItemCollector {
+struct LanguageItemCollector<'self> {
items: &'self mut LanguageItems,
crate: @crate,
!ident.contains_char('_')
}
- fn ident_without_trailing_underscores(ident: &'r str) -> &'r str {
+ fn ident_without_trailing_underscores<'r>(ident: &'r str) -> &'r str {
match str::rfind(ident, |c| c != '_') {
Some(idx) => str::slice(ident, 0, idx + 1),
None => ident, // all underscores
}
}
- fn ident_without_leading_underscores(ident: &'r str) -> &'r str {
+ fn ident_without_leading_underscores<'r>(ident: &'r str) -> &'r str {
match str::find(ident, |c| c != '_') {
Some(idx) => str::slice(ident, idx, ident.len()),
None => ident // all underscores
pub type BindingsMap = LinearMap<ident, BindingInfo>;
-pub struct ArmData {
+pub struct ArmData<'self> {
bodycx: block,
arm: &'self ast::arm,
bindings_map: BindingsMap
}
}
-pub type enter_pat = &'self fn(@ast::pat) -> Option<~[@ast::pat]>;
+pub type enter_pat<'self> = &'self fn(@ast::pat) -> Option<~[@ast::pat]>;
pub fn assert_is_binding_or_wild(bcx: block, p: @ast::pat) {
if !pat_is_binding_or_wild(bcx.tcx().def_map, p) {
}
}
-pub fn enter_rec_or_struct(bcx: block,
- dm: DefMap,
- m: &[@Match<'r>],
- col: uint,
- fields: &[ast::ident],
- val: ValueRef)
- -> ~[@Match<'r>] {
+pub fn enter_rec_or_struct<'r>(bcx: block,
+ dm: DefMap,
+ m: &[@Match<'r>],
+ col: uint,
+ fields: &[ast::ident],
+ val: ValueRef)
+ -> ~[@Match<'r>] {
debug!("enter_rec_or_struct(bcx=%s, m=%s, col=%u, val=%?)",
bcx.to_str(),
matches_to_str(bcx, m),
}
-pub enum CallArgs {
+pub enum CallArgs<'self> {
ArgExprs(&'self [@ast::expr]),
ArgVals(&'self [ValueRef])
}
pub type val_and_ty_fn = @fn(block, ValueRef, ty::t) -> Result;
-pub type iter_vec_block = &'self fn(block, ValueRef, ty::t) -> block;
+pub type iter_vec_block<'self> = &'self fn(block, ValueRef, ty::t) -> block;
pub fn iter_vec_raw(bcx: block, data_ptr: ValueRef, vec_ty: ty::t,
fill: ValueRef, f: iter_vec_block) -> block {
return mme;
}
-pub struct LookupContext {
+pub struct LookupContext<'self> {
fcx: @mut FnCtxt,
expr: @ast::expr,
self_expr: @ast::expr,
}
}
- fn can_unify_universally_quantified(&self,
- a: &'a UniversalQuantificationResult,
- b: &'a UniversalQuantificationResult)
- -> bool {
+ fn can_unify_universally_quantified<'a>
+ (&self,
+ a: &'a UniversalQuantificationResult,
+ b: &'a UniversalQuantificationResult)
+ -> bool {
let mut might_unify = true;
let _ = do self.inference_context.probe {
let result = self.inference_context.sub(true, dummy_sp())
fn glb(cf: &CombineFields, a: &Self, b: &Self) -> cres<Self>;
}
-pub type LatticeOp<T> = &'self fn(cf: &CombineFields, a: &T, b: &T) -> cres<T>;
+pub type LatticeOp<'self, T> =
+ &'self fn(cf: &CombineFields, a: &T, b: &T) -> cres<T>;
impl LatticeValue for ty::t {
fn sub(cf: &CombineFields, a: &ty::t, b: &ty::t) -> ures {
}
}
-pub type LatticeDirOp<T> = &'self fn(a: &T, b: &T) -> cres<T>;
+pub type LatticeDirOp<'self, T> = &'self fn(a: &T, b: &T) -> cres<T>;
pub enum LatticeVarResult<V,T> {
VarResult(V),
}
pub trait UnifyVid<T> {
- fn appropriate_vals_and_bindings(infcx: &'v mut InferCtxt)
- -> &'v mut ValsAndBindings<Self, T>;
+ fn appropriate_vals_and_bindings<'v>(infcx: &'v mut InferCtxt)
+ -> &'v mut ValsAndBindings<Self, T>;
}
pub impl InferCtxt {
// ______________________________________________________________________
impl UnifyVid<Bounds<ty::t>> for ty::TyVid {
- fn appropriate_vals_and_bindings(infcx: &'v mut InferCtxt)
+ fn appropriate_vals_and_bindings<'v>(infcx: &'v mut InferCtxt)
-> &'v mut ValsAndBindings<ty::TyVid, Bounds<ty::t>> {
return &mut infcx.ty_var_bindings;
}
}
impl UnifyVid<Option<IntVarValue>> for ty::IntVid {
- fn appropriate_vals_and_bindings(infcx: &'v mut InferCtxt)
+ fn appropriate_vals_and_bindings<'v>(infcx: &'v mut InferCtxt)
-> &'v mut ValsAndBindings<ty::IntVid, Option<IntVarValue>> {
return &mut infcx.int_var_bindings;
}
}
impl UnifyVid<Option<ast::float_ty>> for ty::FloatVid {
- fn appropriate_vals_and_bindings(infcx: &'v mut InferCtxt)
+ fn appropriate_vals_and_bindings<'v>(infcx: &'v mut InferCtxt)
-> &'v mut ValsAndBindings<ty::FloatVid, Option<ast::float_ty>> {
return &mut infcx.float_var_bindings;
}
ast_map: ast_map::map
}
-type SrvOwner<T> = &'self fn(srv: Srv) -> T;
+type SrvOwner<'self,T> = &'self fn(srv: Srv) -> T;
pub type CtxtHandler<T> = ~fn(ctxt: Ctxt) -> T;
type Parser = ~fn(Session, s: ~str) -> @ast::crate;
* Access the underlying data in an atomically reference counted
* wrapper.
*/
-pub fn get<T:Const + Owned>(rc: &'a ARC<T>) -> &'a T {
+pub fn get<'a, T:Const + Owned>(rc: &'a ARC<T>) -> &'a T {
unsafe { get_shared_immutable_state(&rc.x) }
}
/// As access(), but with a condvar, as sync::mutex.lock_cond().
#[inline(always)]
- unsafe fn access_cond<U>(
+ unsafe fn access_cond<'x, 'c, U>(
&self,
blk: &fn(x: &'x mut T, c: &'c Condvar) -> U) -> U
{
}
}
-fn PoisonOnFail(failed: &'r mut bool) -> PoisonOnFail {
+fn PoisonOnFail<'r>(failed: &'r mut bool) -> PoisonOnFail {
PoisonOnFail {
failed: ptr::to_mut_unsafe_ptr(failed)
}
}
/// As write(), but with a condvar, as sync::rwlock.write_cond().
#[inline(always)]
- fn write_cond<U>(&self, blk: &fn(x: &'x mut T, c: &'c Condvar) -> U) -> U {
+ fn write_cond<'x, 'c, U>(&self,
+ blk: &fn(x: &'x mut T, c: &'c Condvar) -> U)
+ -> U {
unsafe {
let state = get_shared_mutable_state(&self.x);
do (*borrow_rwlock(state)).write_cond |cond| {
}
/// To be called inside of the write_downgrade block.
- fn downgrade(&self, token: RWWriteMode<'a, T>) -> RWReadMode<'a, T> {
+ fn downgrade<'a>(&self, token: RWWriteMode<'a, T>) -> RWReadMode<'a, T> {
// The rwlock should assert that the token belongs to us for us.
let state = unsafe { get_shared_immutable_state(&self.x) };
let RWWriteMode {
token: sync::RWlockReadMode<'self>,
}
-pub impl<T:Const + Owned> RWWriteMode<'self, T> {
+pub impl<'self, T:Const + Owned> RWWriteMode<'self, T> {
/// Access the pre-downgrade RWARC in write mode.
fn write<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
match *self {
}
}
/// Access the pre-downgrade RWARC in write mode with a condvar.
- fn write_cond<U>(&self, blk: &fn(x: &'x mut T, c: &'c Condvar) -> U) -> U {
+ fn write_cond<'x, 'c, U>(&self,
+ blk: &fn(x: &'x mut T, c: &'c Condvar) -> U)
+ -> U {
match *self {
RWWriteMode {
data: ref data,
}
}
-pub impl<T:Const + Owned> RWReadMode<'self, T> {
+pub impl<'self, T:Const + Owned> RWReadMode<'self, T> {
/// Access the post-downgrade rwlock in read mode.
fn read<U>(&self, blk: &fn(x: &T) -> U) -> U {
match *self {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
];
-impl ToBase64 for &'self [u8] {
+impl<'self> ToBase64 for &'self [u8] {
fn to_base64(&self) -> ~str {
let mut s = ~"";
unsafe {
}
}
-impl ToBase64 for &'self str {
+impl<'self> ToBase64 for &'self str {
fn to_base64(&self) -> ~str {
str::to_bytes(*self).to_base64()
}
rv
}
-fn get<T>(elts: &'r [Option<T>], i: uint) -> &'r T {
+fn get<'r, T>(elts: &'r [Option<T>], i: uint) -> &'r T {
match elts[i] { Some(ref t) => t, _ => fail!() }
}
fn from_writer(w: @Writer) -> Self;
}
- impl FromReader for json::Decoder<'self> {
+ impl<'self> FromReader for json::Decoder<'self> {
fn from_reader(r: @Reader) -> json::Decoder<'self> {
match json::from_reader(r) {
Ok(json) => {
}
}
-pub struct Decoder {
+pub struct Decoder<'self> {
priv json: Json,
priv mut stack: ~[&'self Json],
}
Decoder { json: json, stack: ~[] }
}
-priv impl Decoder<'self> {
+priv impl<'self> Decoder<'self> {
fn peek(&self) -> &'self Json {
if vec::uniq_len(&const self.stack) == 0 {
self.stack.push(&self.json);
}
}
-impl serialize::Decoder for Decoder<'self> {
+impl<'self> serialize::Decoder for Decoder<'self> {
fn read_nil(&self) -> () {
debug!("read_nil");
match *self.pop() {
}
}
-impl<S:Encoder> Encodable<S> for &'self str {
+impl<'self, S:Encoder> Encodable<S> for &'self str {
fn encode(&self, s: &S) { s.emit_borrowed_str(*self) }
}
}
}
-impl<S:Encoder,T:Encodable<S>> Encodable<S> for &'self T {
+impl<'self, S:Encoder,T:Encodable<S>> Encodable<S> for &'self T {
fn encode(&self, s: &S) {
s.emit_borrowed(|| (**self).encode(s))
}
}
}
-impl<S:Encoder,T:Encodable<S>> Encodable<S> for &'self [T] {
+impl<'self, S:Encoder,T:Encodable<S>> Encodable<S> for &'self [T] {
fn encode(&self, s: &S) {
do s.emit_borrowed_vec(self.len()) {
for self.eachi |i, e| {
priv v: ~[Option<T>],
}
-impl<V> BaseIter<(uint, &'self V)> for SmallIntMap<V> {
+impl<'self, V> BaseIter<(uint, &'self V)> for SmallIntMap<V> {
/// Visit all key-value pairs in order
fn each(&self, it: &fn(&(uint, &'self V)) -> bool) {
for uint::range(0, self.v.len()) |i| {
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
-impl<V> ReverseIter<(uint, &'self V)> for SmallIntMap<V> {
+impl<'self, V> ReverseIter<(uint, &'self V)> for SmallIntMap<V> {
/// Visit all key-value pairs in reverse order
fn each_reverse(&self, it: &fn(&(uint, &'self V)) -> bool) {
for uint::range_rev(self.v.len(), 0) |i| {
use core::vec::{len, push};
use core::vec;
-type Le<T> = &'self fn(v1: &T, v2: &T) -> bool;
+type Le<'self, T> = &'self fn(v1: &T, v2: &T) -> bool;
/**
* Merge sort. Returns a new vector containing the sorted list.
fn qsort(self);
}
-impl<T:Copy + Ord + Eq> Sort for &'self mut [T] {
+impl<'self, T:Copy + Ord + Eq> Sort for &'self mut [T] {
fn qsort(self) { quick_sort3(self); }
}
}
}
- struct LVal {
+ struct LVal<'self> {
val: uint,
key: &'self fn(@uint),
}
}
impl<'self> Ord for LVal<'self> {
- fn lt(&self, other: &'a LVal<'self>) -> bool {
+ fn lt<'a>(&self, other: &'a LVal<'self>) -> bool {
(*self).val < other.val
}
- fn le(&self, other: &'a LVal<'self>) -> bool {
+ fn le<'a>(&self, other: &'a LVal<'self>) -> bool {
(*self).val <= other.val
}
- fn gt(&self, other: &'a LVal<'self>) -> bool {
+ fn gt<'a>(&self, other: &'a LVal<'self>) -> bool {
(*self).val > other.val
}
- fn ge(&self, other: &'a LVal<'self>) -> bool {
+ fn ge<'a>(&self, other: &'a LVal<'self>) -> bool {
(*self).val >= other.val
}
}
fn median_abs_dev_pct(self) -> f64;
}
-impl Stats for &'self [f64] {
+impl<'self> Stats for &'self [f64] {
fn sum(self) -> f64 {
vec::foldl(0.0, self, |p,q| p + *q)
}
// FIXME(#3588) should go inside of access()
#[doc(hidden)]
-type SemRelease = SemReleaseGeneric<'self, ()>;
-type SemAndSignalRelease = SemReleaseGeneric<'self, ~[Waitqueue]>;
-struct SemReleaseGeneric<Q> { sem: &'self Sem<Q> }
+type SemRelease<'self> = SemReleaseGeneric<'self, ()>;
+type SemAndSignalRelease<'self> = SemReleaseGeneric<'self, ~[Waitqueue]>;
+struct SemReleaseGeneric<'self, Q> { sem: &'self Sem<Q> }
#[unsafe_destructor]
-impl<Q:Owned> Drop for SemReleaseGeneric<'self, Q> {
+impl<'self, Q:Owned> Drop for SemReleaseGeneric<'self, Q> {
fn finalize(&self) {
unsafe {
self.sem.release();
}
}
-fn SemRelease(sem: &'r Sem<()>) -> SemRelease<'r> {
+fn SemRelease<'r>(sem: &'r Sem<()>) -> SemRelease<'r> {
SemReleaseGeneric {
sem: sem
}
}
-fn SemAndSignalRelease(sem: &'r Sem<~[Waitqueue]>)
- -> SemAndSignalRelease<'r> {
+fn SemAndSignalRelease<'r>(sem: &'r Sem<~[Waitqueue]>)
+ -> SemAndSignalRelease<'r> {
SemReleaseGeneric {
sem: sem
}
#[unsafe_destructor]
impl<'self> Drop for Condvar<'self> { fn finalize(&self) {} }
-pub impl Condvar<'self> {
+pub impl<'self> Condvar<'self> {
/**
* Atomically drop the associated lock, and block until a signal is sent.
*
// This is needed for a failing condition variable to reacquire the
// mutex during unwinding. As long as the wrapper (mutex, etc) is
// bounded in when it gets released, this shouldn't hang forever.
- struct SemAndSignalReacquire {
+ struct SemAndSignalReacquire<'self> {
sem: &'self Sem<~[Waitqueue]>,
}
}
}
- fn SemAndSignalReacquire(sem: &'r Sem<~[Waitqueue]>)
- -> SemAndSignalReacquire<'r> {
+ fn SemAndSignalReacquire<'r>(sem: &'r Sem<~[Waitqueue]>)
+ -> SemAndSignalReacquire<'r> {
SemAndSignalReacquire {
sem: sem
}
// FIXME(#3588) should go inside of read()
#[doc(hidden)]
-struct RWlockReleaseRead {
+struct RWlockReleaseRead<'self> {
lock: &'self RWlock,
}
// FIXME(#3588) should go inside of downgrade()
#[doc(hidden)]
#[unsafe_destructor]
-struct RWlockReleaseDowngrade {
+struct RWlockReleaseDowngrade<'self> {
lock: &'self RWlock,
}
impl<'self> Drop for RWlockWriteMode<'self> { fn finalize(&self) {} }
/// The "read permission" token used for rwlock.write_downgrade().
-pub struct RWlockReadMode { priv lock: &'self RWlock }
+pub struct RWlockReadMode<'self> { priv lock: &'self RWlock }
#[unsafe_destructor]
impl<'self> Drop for RWlockReadMode<'self> { fn finalize(&self) {} }
}
/// Lazy forward iterator over a map
-pub struct TreeMapIterator<K, V> {
+pub struct TreeMapIterator<'self, K, V> {
priv stack: ~[&'self ~TreeNode<K, V>],
priv node: &'self Option<~TreeNode<K, V>>
}
}
}
-fn each<K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>,
- f: &fn(&(&'r K, &'r V)) -> bool) {
+fn each<'r, K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>,
+ f: &fn(&(&'r K, &'r V)) -> bool) {
for node.each |x| {
each(&x.left, f);
if f(&(&x.key, &x.value)) { each(&x.right, f) }
}
}
-fn each_reverse<K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>,
- f: &fn(&(&'r K, &'r V)) -> bool) {
+fn each_reverse<'r, K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>,
+ f: &fn(&(&'r K, &'r V)) -> bool) {
for node.each |x| {
each_reverse(&x.right, f);
if f(&(&x.key, &x.value)) { each_reverse(&x.left, f) }
}
}
-fn mutate_values<K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>,
- f: &fn(&'r K, &'r mut V) -> bool) -> bool {
+fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>,
+ f: &fn(&'r K, &'r mut V) -> bool)
+ -> bool {
match *node {
Some(~TreeNode{key: ref key, value: ref mut value, left: ref mut left,
right: ref mut right, _}) => {
}
}
-fn find_mut<K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>, key: &K) -> Option<&'r mut V> {
+fn find_mut<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>,
+ key: &K)
+ -> Option<&'r mut V> {
match *node {
Some(ref mut x) => {
match key.cmp(&x.key) {
pub struct TyClosure {
sigil: Sigil,
region: Option<@Lifetime>,
+ lifetimes: OptVec<Lifetime>,
purity: purity,
onceness: Onceness,
decl: fn_decl
pub mod eq;
pub mod iter_bytes;
-type ExpandDerivingStructDefFn = &'self fn(@ext_ctxt,
- span,
- x: &struct_def,
- ident,
- y: &Generics) -> @item;
-type ExpandDerivingEnumDefFn = &'self fn(@ext_ctxt,
- span,
- x: &enum_def,
- ident,
- y: &Generics) -> @item;
+type ExpandDerivingStructDefFn<'self> = &'self fn(@ext_ctxt,
+ span,
+ x: &struct_def,
+ ident,
+ y: &Generics)
+ -> @item;
+type ExpandDerivingEnumDefFn<'self> = &'self fn(@ext_ctxt,
+ span,
+ x: &enum_def,
+ ident,
+ y: &Generics)
+ -> @item;
pub fn expand_meta_deriving(cx: @ext_ctxt,
_span: span,
purity: f.purity,
region: f.region,
onceness: f.onceness,
- decl: fold_fn_decl(&f.decl, fld)
+ decl: fold_fn_decl(&f.decl, fld),
+ lifetimes: f.lifetimes,
})
}
ty_bare_fn(ref f) => {
let purity = self.parse_purity();
self.expect_keyword(&~"fn");
+ let (decl, _) = self.parse_ty_fn_decl();
return ty_bare_fn(@TyBareFn {
abi: RustAbi,
purity: purity,
- decl: self.parse_ty_fn_decl()
+ decl: decl
});
}
ObsoletePostFnTySigil);
}
+ let (decl, lifetimes) = self.parse_ty_fn_decl();
+
return ty_closure(@TyClosure {
sigil: sigil,
region: region,
purity: purity,
onceness: onceness,
- decl: self.parse_ty_fn_decl()
+ decl: decl,
+ lifetimes: lifetimes,
});
fn parse_onceness(self: &Parser) -> Onceness {
}
}
- fn parse_ty_fn_decl(&self) -> fn_decl {
+ fn parse_ty_fn_decl(&self) -> (fn_decl, OptVec<ast::Lifetime>) {
/*
(fn) <'lt> (S) -> T
Lifetimes
*/
- if self.eat(&token::LT) {
- let _lifetimes = self.parse_lifetimes();
+ let lifetimes = if self.eat(&token::LT) {
+ let lifetimes = self.parse_lifetimes();
self.expect_gt();
- }
+ lifetimes
+ } else {
+ opt_vec::Empty
+ };
+
let inputs = self.parse_unspanned_seq(
&token::LPAREN,
&token::RPAREN,
|p| p.parse_arg_general(false)
);
let (ret_style, ret_ty) = self.parse_ret_ty();
- ast::fn_decl { inputs: inputs, output: ret_ty, cf: ret_style }
+ let decl = ast::fn_decl {
+ inputs: inputs,
+ output: ret_ty,
+ cf: ret_style
+ };
+ (decl, lifetimes)
}
fn parse_trait_methods(&self) -> ~[trait_method] {
fn printme(self);
}
-impl Stuff for &'self mut Foo {
+impl<'self> Stuff for &'self mut Foo {
fn printme(self) {
io::println(fmt!("%d", self.x));
}
fn test_mut(&mut self);
}
-impl MyIter for &'self [int] {
+impl<'self> MyIter for &'self [int] {
fn test_mut(&mut self) { }
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct defer {
+struct defer<'self> {
x: &'self [&'self str],
}
#[unsafe_destructor]
-impl Drop for defer<'self> {
+impl<'self> Drop for defer<'self> {
fn finalize(&self) {
unsafe {
error!("%?", self.x);
}
}
-fn defer(x: &'r [&'r str]) -> defer<'r> {
+fn defer<'r>(x: &'r [&'r str]) -> defer<'r> {
defer {
x: x
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct boxedFn { theFn: &'self fn() -> uint }
+struct boxedFn<'self> { theFn: &'self fn() -> uint }
fn createClosure (closedUint: uint) -> boxedFn {
let theFn: @fn() -> uint = || closedUint;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct thing<Q> {
+struct thing<'self, Q> {
x: &'self Q
}
// except according to those terms.
#[legacy_mode]
-struct Foo {
+struct Foo<'self> {
s: &'self str,
u: ~()
}
-pub impl Foo<'self> {
+pub impl<'self> Foo<'self> {
fn get_s(&self) -> &'self str {
self.s
}
// n.b. This should be a run-pass test, but for now I'm testing
// that we don't see an "unknown scope" error.
-fn vec_peek<T>(v: &'r [T]) -> Option< (&'r T, &'r [T]) > {
+fn vec_peek<'r, T>(v: &'r [T]) -> Option< (&'r T, &'r [T]) > {
if v.len() == 0 {
None
} else {
fn main() {
fn bar(n: int) {
- let _x: [int * n]; //~ ERROR expected constant expr for vector length: Non-constant path in constant expr
+ let _x: [int, ..n]; //~ ERROR expected constant expr for vector length: Non-constant path in constant expr
}
}
// nominal types (but not on other types) and that they are type
// checked.
-struct an_enum(&'self int);
-struct a_class { x:&'self int }
+struct an_enum<'self>(&'self int);
+struct a_class<'self> { x:&'self int }
-fn a_fn1(e: an_enum<'a>) -> an_enum<'b> {
+fn a_fn1<'a,'b>(e: an_enum<'a>) -> an_enum<'b> {
return e; //~ ERROR mismatched types: expected `an_enum/&'b ` but found `an_enum/&'a `
}
-fn a_fn3(e: a_class<'a>) -> a_class<'b> {
+fn a_fn3<'a,'b>(e: a_class<'a>) -> a_class<'b> {
return e; //~ ERROR mismatched types: expected `a_class/&'b ` but found `a_class/&'a `
}
-fn a_fn4(e: int<'a>) -> int<'b> {
+fn a_fn4<'a,'b>(e: int<'a>) -> int<'b> {
//~^ ERROR region parameters are not allowed on this type
//~^^ ERROR region parameters are not allowed on this type
return e;
#[legacy_modes];
-enum ast {
+enum ast<'self> {
num(uint),
add(&'self ast<'self>, &'self ast<'self>)
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-enum ast {
+enum ast<'self> {
num(uint),
add(&'self ast<'self>, &'self ast<'self>)
}
-fn mk_add_bad1(x: &'a ast<'a>, y: &'b ast<'b>) -> ast<'a> {
+fn mk_add_bad1<'a,'b>(x: &'a ast<'a>, y: &'b ast<'b>) -> ast<'a> {
add(x, y) //~ ERROR cannot infer an appropriate lifetime
}
add(&'self ast<'self>, &'self ast<'self>)
}
-fn mk_add_bad2(x: &'a ast<'a>, y: &'a ast<'a>, z: &ast) -> ast {
+fn mk_add_bad2<'a>(x: &'a ast<'a>, y: &'a ast<'a>, z: &ast) -> ast {
add(x, y)
//~^ ERROR cannot infer an appropriate lifetime
}
fn get(self) -> int;
}
-impl deref for &'self int {
+impl<'self> deref for &'self int {
fn get(self) -> int {
*self
}
fn of<T>() -> @fn(T) { fail!(); }
fn subtype<T>(x: @fn(T)) { fail!(); }
-fn test_fn<T>(_x: &'x T, _y: &'y T, _z: &'z T) {
+fn test_fn<'x,'y,'z,T>(_x: &'x T, _y: &'y T, _z: &'z T) {
// Here, x, y, and z are free. Other letters
// are bound. Note that the arrangement
// subtype::<T1>(of::<T2>()) will typecheck
// iff T1 <: T2.
- subtype::<&fn(&'a T)>(
- of::<&fn(&'a T)>());
+ subtype::<&fn<'a>(&'a T)>(
+ of::<&fn<'a>(&'a T)>());
- subtype::<&fn(&'a T)>(
- of::<&fn(&'b T)>());
+ subtype::<&fn<'a>(&'a T)>(
+ of::<&fn<'b>(&'b T)>());
- subtype::<&fn(&'b T)>(
- of::<&fn(&'x T)>());
+ subtype::<&fn<'b>(&'b T)>(
+ of::<&fn<'x>(&'x T)>());
- subtype::<&fn(&'x T)>(
- of::<&fn(&'b T)>()); //~ ERROR mismatched types
+ subtype::<&fn<'x>(&'x T)>(
+ of::<&fn<'b>(&'b T)>()); //~ ERROR mismatched types
- subtype::<&fn(&'a T, &'b T)>(
- of::<&fn(&'a T, &'a T)>());
+ subtype::<&fn<'a,'b>(&'a T, &'b T)>(
+ of::<&fn<'a>(&'a T, &'a T)>());
- subtype::<&fn(&'a T, &'a T)>(
- of::<&fn(&'a T, &'b T)>()); //~ ERROR mismatched types
+ subtype::<&fn<'a>(&'a T, &'a T)>(
+ of::<&fn<'a,'b>(&'a T, &'b T)>()); //~ ERROR mismatched types
- subtype::<&fn(&'a T, &'b T)>(
- of::<&fn(&'x T, &'y T)>());
+ subtype::<&fn<'a,'b>(&'a T, &'b T)>(
+ of::<&fn<'x,'y>(&'x T, &'y T)>());
- subtype::<&fn(&'x T, &'y T)>(
- of::<&fn(&'a T, &'b T)>()); //~ ERROR mismatched types
+ subtype::<&fn<'x,'y>(&'x T, &'y T)>(
+ of::<&fn<'a,'b>(&'a T, &'b T)>()); //~ ERROR mismatched types
- subtype::<&fn(&'x T) -> @fn(&'a T)>(
- of::<&fn(&'x T) -> @fn(&'a T)>());
+ subtype::<&fn<'x,'a>(&'x T) -> @fn(&'a T)>(
+ of::<&fn<'x,'a>(&'x T) -> @fn(&'a T)>());
- subtype::<&fn(&'a T) -> @fn(&'a T)>(
- of::<&fn(&'a T) -> @fn(&'b T)>()); //~ ERROR mismatched types
+ subtype::<&fn<'a>(&'a T) -> @fn(&'a T)>(
+ of::<&fn<'a,'b>(&'a T) -> @fn(&'b T)>()); //~ ERROR mismatched types
- subtype::<&fn(&'a T) -> @fn(&'a T)>(
- of::<&fn(&'x T) -> @fn(&'b T)>()); //~ ERROR mismatched types
+ subtype::<&fn<'a>(&'a T) -> @fn(&'a T)>(
+ of::<&fn<'x,'b>(&'x T) -> @fn(&'b T)>()); //~ ERROR mismatched types
- subtype::<&fn(&'a T) -> @fn(&'b T)>(
- of::<&fn(&'a T) -> @fn(&'a T)>());
+ subtype::<&fn<'a,'b>(&'a T) -> @fn(&'b T)>(
+ of::<&fn<'a>(&'a T) -> @fn(&'a T)>());
}
fn main() {}
// Before fn subtyping was properly implemented,
// we reported errors in this case:
-fn not_ok(a: &uint, b: &'b uint) {
+fn not_ok<'b>(a: &uint, b: &'b uint) {
let mut g: @fn(x: &uint) = |x: &'b uint| {};
//~^ ERROR mismatched types
g(a);
value: uint
}
- pub fn flag(name: &'r str, desc: &'r str) -> Flag<'r> {
+ pub fn flag<'r>(name: &'r str, desc: &'r str) -> Flag<'r> {
Flag { name: name, desc: desc, max_count: 1, value: 0 }
}
- pub impl Flag<'self> {
+ pub impl<'self> Flag<'self> {
fn set_desc(self, s: &str) -> Flag<'self> {
Flag { //~ ERROR cannot infer an appropriate lifetime
name: self.name,
enum yes0<'lt> {
// This will eventually be legal (and in fact the only way):
- X3(&'lt uint) //~ ERROR Illegal lifetime 'lt: only 'self is allowed allowed as part of a type declaration
+ X3(&'lt uint) //~ ERROR Illegal lifetime 'lt: this lifetime must be declared
}
-enum yes1 {
+enum yes1<'self> {
X4(&'self uint)
}
enum yes2 {
- X5(&'foo uint) //~ ERROR Illegal lifetime 'foo: only 'self is allowed allowed as part of a type declaration
+ X5(&'foo uint) //~ ERROR Illegal lifetime 'foo: this lifetime must be declared
}
fn main() {}
}
struct yes2<'self> {
- x: &'foo uint, //~ ERROR Illegal lifetime 'foo: only 'self is allowed allowed as part of a type declaration
+ x: &'foo uint, //~ ERROR Illegal lifetime 'foo: this lifetime must be declared
}
fn main() {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct item_ty_yes0 {
+struct item_ty_yes0<'self> {
x: &'self uint
}
-struct item_ty_yes1 {
+struct item_ty_yes1<'self> {
x: &'self uint
}
struct item_ty_yes2 {
- x: &'a uint //~ ERROR only 'self is allowed
+ x: &'a uint //~ ERROR this lifetime must be declared
}
fn main() {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct parameterized1 {
+struct parameterized1<'self> {
g: &'self fn()
}
y: int,
}
-fn x_coord(p: &'r point) -> &'r int {
+fn x_coord<'r>(p: &'r point) -> &'r int {
return &p.x;
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn borrow<T>(x: &'r T) -> &'r T {x}
+fn borrow<'r, T>(x: &'r T) -> &'r T {x}
fn foo(cond: &fn() -> bool, box: &fn() -> @int) {
let mut y: ∫
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn select(x: &'r int, y: &'r int) -> &'r int { x }
+fn select<'r>(x: &'r int, y: &'r int) -> &'r int { x }
fn with<T>(f: &fn(x: &int) -> T) -> T {
f(&20)
}
-fn manip(x: &'a int) -> int {
+fn manip<'a>(x: &'a int) -> int {
let z = do with |y| { select(x, y) };
//~^ ERROR cannot infer an appropriate lifetime
*z
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct contravariant {
+struct contravariant<'self> {
f: &'self int
}
-fn to_same_lifetime(bi: contravariant<'r>) {
+fn to_same_lifetime<'r>(bi: contravariant<'r>) {
let bj: contravariant<'r> = bi;
}
-fn to_shorter_lifetime(bi: contravariant<'r>) {
+fn to_shorter_lifetime<'r>(bi: contravariant<'r>) {
let bj: contravariant<'blk> = bi;
}
-fn to_longer_lifetime(bi: contravariant<'r>) -> contravariant<'static> {
+fn to_longer_lifetime<'r>(bi: contravariant<'r>) -> contravariant<'static> {
bi //~ ERROR mismatched types
}
//
// You can upcast to a *larger region* but not a smaller one.
-struct covariant {
+struct covariant<'self> {
f: @fn(x: &'self int) -> int
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct invariant {
+struct invariant<'self> {
f: @mut &'self int
}
-fn to_same_lifetime(bi: invariant<'r>) {
+fn to_same_lifetime<'r>(bi: invariant<'r>) {
let bj: invariant<'r> = bi;
}
-fn to_shorter_lifetime(bi: invariant<'r>) {
- let bj: invariant<'blk> = bi; //~ ERROR mismatched types
-}
-
-fn to_longer_lifetime(bi: invariant<'r>) -> invariant<'static> {
+fn to_longer_lifetime<'r>(bi: invariant<'r>) -> invariant<'static> {
bi //~ ERROR mismatched types
}
f: @mut [&'self int]
}
-fn to_same_lifetime(bi: invariant<'r>) {
+fn to_same_lifetime<'r>(bi: invariant<'r>) {
let bj: invariant<'r> = bi;
}
-fn to_shorter_lifetime(bi: invariant<'r>) {
- let bj: invariant<'blk> = bi; //~ ERROR mismatched types
-}
-
-fn to_longer_lifetime(bi: invariant<'r>) -> invariant<'static> {
+fn to_longer_lifetime<'r>(bi: invariant<'r>) -> invariant<'static> {
bi //~ ERROR mismatched types
}
let bj: invariant<'r> = bi;
}
-fn to_shorter_lifetime(bi: invariant<'r>) {
- let bj: invariant<'blk> = bi; //~ ERROR mismatched types
-}
-
-fn to_longer_lifetime(bi: invariant<'r>) -> invariant<'static> {
+fn to_longer_lifetime<'r>(bi: invariant<'r>) -> invariant<'static> {
bi //~ ERROR mismatched types
}
f: @fn() -> @mut &'self int
}
-fn to_same_lifetime(bi: invariant<'r>) {
+fn to_same_lifetime<'r>(bi: invariant<'r>) {
let bj: invariant<'r> = bi;
}
-fn to_shorter_lifetime(bi: invariant<'r>) {
- let bj: invariant<'blk> = bi; //~ ERROR mismatched types
-}
-
-fn to_longer_lifetime(bi: invariant<'r>) -> invariant<'static> {
+fn to_longer_lifetime<'r>(bi: invariant<'r>) -> invariant<'static> {
bi //~ ERROR mismatched types
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn ignore<T>(_t: T) {}
+fn ignore(_f: &fn<'z>(&'z int) -> &'z int) {}
fn nested() {
let y = 3;
- ignore(|z: &'z int| -> &'z int {
+ ignore(|z| {
if false { &y } else { z } //~ ERROR illegal borrow
});
}
fn ignore<T>(t: T) {}
-fn nested(x: &'x int) {
+fn nested<'x>(x: &'x int) {
let y = 3;
let mut ay = &y; //~ ERROR cannot infer an appropriate lifetime
- ignore(|z: &'z int| {
+ ignore::<&fn<'z>(&'z int)>(|z| {
ay = x;
ay = &y; //~ ERROR cannot infer an appropriate lifetime
ay = z;
});
- ignore(|z: &'z int| -> &'z int {
+ ignore::<&fn<'z>(&'z int) -> &'z int>(|z| {
if false { return x; } //~ ERROR mismatched types
if false { return ay; }
return z;
// some point regions-ret-borrowed reported an error but this file did
// not, due to special hardcoding around the anonymous region.
-fn with<R>(f: &fn(x: &'a int) -> R) -> R {
+fn with<'a, R>(f: &fn(x: &'a int) -> R) -> R {
f(&3)
}
-fn return_it() -> &'a int {
+fn return_it<'a>() -> &'a int {
with(|o| o) //~ ERROR mismatched types
//~^ ERROR reference is not valid outside of its lifetime
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn f(_x : &'a int) -> &'a int {
+fn f<'a>(_x : &'a int) -> &'a int {
return &3; //~ ERROR illegal borrow
}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn with<T>(t: T, f: &fn(T)) { f(t) }
-
-fn nested<'x>(x: &'x int) { // (1)
- do with(
- |x: &'x int, // Refers to the region `x` at (1)
- y: &'y int, // A fresh region `y` (2)
- z: &fn<'z>(x: &'x int, // Refers to `x` at (1)
- y: &'y int, // Refers to `y` at (2)
- z: &'z int) -> &'z int| // A fresh region `z` (3)
- -> &'x int {
- if false { return z(x, y, x); }
-
- if false { return z(x, y, y); }
- //~^ ERROR cannot infer an appropriate lifetime
-
- return z(y, x, x);
- //~^ ERROR cannot infer an appropriate lifetime
- }
- ) |foo| {
-
- let a: &'x int = foo(x, x, |_x, _y, z| z );
- let b: &'x int = foo(x, a, |_x, _y, z| z );
- let c: &'x int = foo(a, a, |_x, _y, z| z );
-
- let z = 3i;
- let d: &'x int = foo(x, x, |_x, _y, z| z );
- let e: &'x int = foo(x, &z, |_x, _y, z| z );
-
- // This would result in an error, but it is not reported by typeck
- // anymore but rather borrowck. Therefore, it doesn't end up
- // getting printed out since compilation fails after typeck.
- //
- // let f: &'x int = foo(&z, &z, |_x, _y, z| z ); // ERROR mismatched types: expected `&'x int` but found
-
- foo(x, &z, |x, _y, _z| x); //~ ERROR mismatched types: expected `&'z int` but found `&'x int`
-
- // Note: originally I had foo(x, &z, ...) here, but in that
- // case the region inferencer deduced that this was valid if
- // &y==&static, and so inference would succeed but borrow
- // check would fail because the lifetime of &z is not &static.
- foo(x, x, |_x, y, _z| y); //~ ERROR cannot infer an appropriate lifetime
- }
-}
-
-fn main() {}
cl: &'self fn()
}
-fn box_it(x: &'r fn()) -> closure_box<'r> {
+fn box_it<'r>(x: &'r fn()) -> closure_box<'r> {
closure_box {cl: x}
}
fn get_ctxt(&self) -> &ctxt;
}
-struct has_ctxt { c: &'self ctxt }
+struct has_ctxt<'self> { c: &'self ctxt }
-impl get_ctxt for has_ctxt<'self> {
+impl<'self> get_ctxt for has_ctxt<'self> {
// Here an error occurs because we used `&self` but
// the definition used `&`:
fn iterate(&self, blk: &fn(x: &A) -> bool);
}
-impl<A> iterable<A> for &'self [A] {
+impl<'self,A> iterable<A> for &'self [A] {
fn iterate(&self, f: &fn(x: &A) -> bool) {
for vec::each(*self) |e| {
if !f(e) { break; }
fn test_const(&const self);
}
-impl MyIter for &'self [int] {
+impl<'self> MyIter for &'self [int] {
fn test_imm(&self) { fail_unless!(self[0] == 1) }
fn test_const(&const self) { fail_unless!(self[0] == 1) }
}
-impl MyIter for &'self str {
+impl<'self> MyIter for &'self str {
fn test_imm(&self) { fail_unless!(*self == "test") }
fn test_const(&const self) { fail_unless!(*self == "test") }
}
fn foo(self);
}
-impl Foo for &'self [int] {
+impl<'self> Foo for &'self [int] {
fn foo(self) {}
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn borrow<T>(x: &'r T) -> &'r T {x}
+fn borrow<'r,T>(x: &'r T) -> &'r T {x}
struct Rec { f: @int }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn foo(s: &'r uint) -> bool {
+fn foo<'r>(s: &'r uint) -> bool {
match s {
&3 => true,
_ => false
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn select(x: &'r Option<int>, y: &'r Option<int>) -> &'r Option<int> {
+fn select<'r>(x: &'r Option<int>, y: &'r Option<int>) -> &'r Option<int> {
match (x, y) {
(&None, &None) => x,
(&Some(_), _) => x,
}
}
-impl<T> BaseIter<(int, &'self T)> for cat<T> {
+impl<'self,T> BaseIter<(int, &'self T)> for cat<T> {
fn each(&self, f: &fn(&(int, &'self T)) -> bool) {
let mut n = int::abs(self.meows);
while n > 0 {
fn reverse(&self);
}
-impl Reverser for &'self mut [uint] {
+impl<'self> Reverser for &'self mut [uint] {
fn reverse(&self) {
vec::reverse(*self);
}
return 0xca7f000d;
}
-struct Bar { f: &'self fn() -> int }
+struct Bar<'self> { f: &'self fn() -> int }
static b : Bar<'static> = Bar { f: foo };
// except according to those terms.
type Big = [u64, ..8];
-struct Pair { a: int, b: &'self Big }
+struct Pair<'self> { a: int, b: &'self Big }
static x: &'static Big = &([13, 14, 10, 13, 11, 14, 14, 15]);
static y: &'static Pair<'static> = &Pair {a: 15, b: x};
// except according to those terms.
-struct Pair { a: int, b: &'self int }
+struct Pair<'self> { a: int, b: &'self int }
static x: &'static int = &10;
pub impl shape {
// self is in the implicit self region
- fn select<T>(&self, threshold: float,
- a: &'r T, b: &'r T) -> &'r T {
+ fn select<'r, T>(&self, threshold: float,
+ a: &'r T, b: &'r T) -> &'r T {
if compute_area(self) > threshold {a} else {b}
}
}
-fn select_based_on_unit_circle<T>(
+fn select_based_on_unit_circle<'r, T>(
threshold: float, a: &'r T, b: &'r T) -> &'r T {
let shape = &circle(Point{x: 0.0, y: 0.0}, 1.0);
fn eat_tup(_r: ~@(int, @fn(Pair) -> int)) {}
fn eat_rec(_r: @~Rec) {}
-struct Rec { a: int, b: &'self fn(Pair) -> int }
+struct Rec<'self> { a: int, b: &'self fn(Pair) -> int }
struct Pair { x: int, y: int }
pub fn main() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct font {
+struct font<'self> {
fontbuf: &'self ~[u8],
}
}
}
-fn font(fontbuf: &'r ~[u8]) -> font<'r> {
+fn font<'r>(fontbuf: &'r ~[u8]) -> font<'r> {
font {
fontbuf: fontbuf
}
// except according to those terms.
// This test should behave exactly like issue-2735-3
-struct defer {
+struct defer<'self> {
b: &'self mut bool,
}
// except according to those terms.
// This test should behave exactly like issue-2735-2
-struct defer {
+struct defer<'self> {
b: &'self mut bool,
}
}
}
-fn defer(b: &'r mut bool) -> defer<'r> {
+fn defer<'r>(b: &'r mut bool) -> defer<'r> {
defer {
b: b
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct CMap {
+struct CMap<'self> {
buf: &'self [u8],
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn thing(x: &'r [int]) -> &'r [int] { x }
+fn thing<'r>(x: &'r [int]) -> &'r [int] { x }
+
pub fn main() {
let x = &[1,2,3];
let y = x;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct list<T> {
+struct list<'self, T> {
element: &'self T,
next: Option<@mut list<'self, T>>
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn vec_peek<T>(v: &'r [T]) -> &'r [T] {
+fn vec_peek<'r, T>(v: &'r [T]) -> &'r [T] {
// This doesn't work, and should.
// v.slice(1, 5)
vec::slice(v, 1, 5)
}
// Note: impl on a slice
-impl sum for &'self [int] {
+impl<'self> sum for &'self [int] {
fn sum(self) -> int {
let mut sum = 0;
for vec::each(self) |e| { sum += *e; }
f: int
}
-fn get_v1(a: &'v A) -> &'v int {
+fn get_v1<'v>(a: &'v A) -> &'v int {
// Region inferencer must deduce that &v < L2 < L1
let foo = &a.value; // L1
&foo.v1 // L2
}
-fn get_v2(a: &'v A, i: uint) -> &'v int {
+fn get_v2<'v>(a: &'v A, i: uint) -> &'v int {
let foo = &a.value;
&foo.v2[i]
}
-fn get_v3(a: &'v A, i: uint) -> &'v int {
+fn get_v3<'v>(a: &'v A, i: uint) -> &'v int {
let foo = &a.value;
&foo.v3[i]
}
-fn get_v4(a: &'v A, i: uint) -> &'v int {
+fn get_v4<'v>(a: &'v A, i: uint) -> &'v int {
let foo = &a.value;
&foo.v4.f
}
-fn get_v5(a: &'v A, i: uint) -> &'v int {
+fn get_v5<'v>(a: &'v A, i: uint) -> &'v int {
let foo = &a.value;
&foo.v5.f
}
-fn get_v6_a(a: &'v A, i: uint) -> &'v int {
+fn get_v6_a<'v>(a: &'v A, i: uint) -> &'v int {
match a.value.v6 {
Some(ref v) => &v.f,
None => fail!()
}
}
-fn get_v6_b(a: &'v A, i: uint) -> &'v int {
+fn get_v6_b<'v>(a: &'v A, i: uint) -> &'v int {
match *a {
A { value: B { v6: Some(ref v), _ } } => &v.f,
_ => fail!()
}
}
-fn get_v6_c(a: &'v A, i: uint) -> &'v int {
+fn get_v6_c<'v>(a: &'v A, i: uint) -> &'v int {
match a {
&A { value: B { v6: Some(ref v), _ } } => &v.f,
_ => fail!()
}
}
-fn get_v5_ref(a: &'v A, i: uint) -> &'v int {
+fn get_v5_ref<'v>(a: &'v A, i: uint) -> &'v int {
match &a.value {
&B {v5: ~C {f: ref v}, _} => v
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn get<T>(opt: &'r Option<T>) -> &'r T {
+fn get<'r, T>(opt: &'r Option<T>) -> &'r T {
match *opt {
Some(ref v) => v,
None => fail!(~"none")
pos: ~Point
}
-fn get_x(x: &'r Character) -> &'r int {
+fn get_x<'r>(x: &'r Character) -> &'r int {
// interesting case because the scope of this
// borrow of the unique pointer is in fact
// larger than the fn itself
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn f(x : &'a int) -> &'a int {
+fn f<'a>(x : &'a int) -> &'a int {
return &*x;
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct closure_box {
+struct closure_box<'self> {
cl: &'self fn(),
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-enum ast {
+enum ast<'self> {
num(uint),
add(&'self ast<'self>, &'self ast<'self>)
}
-fn mk_add_ok(x: &'r ast<'r>, y: &'r ast<'r>) -> ast<'r> {
+fn mk_add_ok<'r>(x: &'r ast<'r>, y: &'r ast<'r>) -> ast<'r> {
add(x, y)
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-enum ast {
+enum ast<'self> {
num(uint),
add(&'self ast<'self>, &'self ast<'self>)
}
-fn mk_add_ok(x: &'a ast<'a>, y: &'a ast<'a>, z: &ast) -> ast<'a> {
+fn mk_add_ok<'a>(x: &'a ast<'a>, y: &'a ast<'a>, z: &ast) -> ast<'a> {
add(x, y)
}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Before fn subtyping was properly implemented,
-// we reported errors in this case:
-
-fn ok(a: &uint) {
- // Here &r is an alias for &:
- let mut g: @fn(x: &uint) = |x: &'r uint| {};
- g(a);
-}
-
-pub fn main() {
-}
-
-
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn foo(x: &'r uint) -> &'r uint { x }
+fn foo<'r>(x: &'r uint) -> &'r uint { x }
fn bar(x: &uint) -> uint { *x }
pub fn main() {
// f's type should be a subtype of g's type), because f can be
// used in any context that expects g's type. But this currently
// fails.
- let mut g: @fn(y: &'r uint) = |x: &'r uint| { };
+ let mut g: @fn<'r>(y: &'r uint) = |x| { };
g = f;
}
// This version is the same as above, except that here, g's type is
// inferred.
fn ok_inferred(f: @fn(x: &uint)) {
- let mut g: @fn(x: &'r uint) = |_| {};
+ let mut g: @fn<'r>(x: &'r uint) = |_| {};
g = f;
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn view<T>(x: &'r [T]) -> &'r [T] {x}
+fn view<'r, T>(x: &'r [T]) -> &'r [T] {x}
pub fn main() {
let v = ~[1, 2, 3];
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn borrow<T>(x: &'r T) -> &'r T {x}
+fn borrow<'r, T>(x: &'r T) -> &'r T {x}
pub fn main() {
let x = @3;
struct Point {x: int, y: int}
-fn x_coord(p: &'r Point) -> &'r int {
+fn x_coord<'r>(p: &'r Point) -> &'r int {
return &p.x;
}
f(&20)
}
-fn has_one(x: &'a int) -> int {
+fn has_one<'a>(x: &'a int) -> int {
do with |y| { takes_two(x, y) }
}
fn takes_two(x: &int, y: &int) -> int { *x + *y }
-fn has_two(x: &'a int, y: &'b int) -> int {
+fn has_two<'a,'b>(x: &'a int, y: &'b int) -> int {
takes_two(x, y)
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct boxed_int {
+struct boxed_int<'self> {
f: &'self int,
}
-fn max(bi: &'r boxed_int, f: &'r int) -> int {
+fn max<'r>(bi: &'r boxed_int, f: &'r int) -> int {
if *bi.f > *f {*bi.f} else {*f}
}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-struct boxed_int {
- f: &'self int,
-}
-
-fn get(bi: &'r boxed_int<'r>) -> &'r int {
- bi.f
-}
-
-fn with(bi: &'r boxed_int) {
- // Here, the upcast is allowed because the `boxed_int` type is
- // contravariant with respect to `&r`. See also
- // compile-fail/regions-infer-invariance-due-to-mutability.rs
- let bi: &'blk boxed_int<'blk> = bi;
- fail_unless!(*get(bi) == 22);
-}
-
-pub fn main() {
- let g = 22;
- let foo = boxed_int { f: &g };
- with(&foo);
-}
use core::cast;
use std::arena::Arena;
-struct Bcx {
+struct Bcx<'self> {
fcx: &'self Fcx<'self>
}
-struct Fcx {
+struct Fcx<'self> {
arena: &'self Arena,
ccx: &'self Ccx
}
x: int
}
-fn h(bcx : &'r Bcx<'r>) -> &'r Bcx<'r> {
+fn h<'r>(bcx : &'r Bcx<'r>) -> &'r Bcx<'r> {
return bcx.fcx.arena.alloc(|| Bcx { fcx: bcx.fcx });
}
struct arena(());
-struct Bcx {
+struct Bcx<'self> {
fcx: &'self Fcx<'self>
}
-struct Fcx {
+struct Fcx<'self> {
arena: &'self arena,
ccx: &'self Ccx
}
x: int
}
-fn alloc(_bcx : &'a arena) -> &'a Bcx<'a> {
+fn alloc<'a>(_bcx : &'a arena) -> &'a Bcx<'a> {
unsafe {
return cast::reinterpret_cast(
&libc::malloc(sys::size_of::<Bcx<'blk>>() as libc::size_t));
}
}
-fn h(bcx : &'a Bcx<'a>) -> &'a Bcx<'a> {
+fn h<'a>(bcx : &'a Bcx<'a>) -> &'a Bcx<'a> {
return alloc(bcx.fcx.arena);
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-enum roption {
+enum roption<'self> {
a, b(&'self uint)
}
-fn mk(cond: bool, ptr: &'r uint) -> roption<'r> {
+fn mk<'r>(cond: bool, ptr: &'r uint) -> roption<'r> {
if cond {a} else {b(ptr)}
}
// xfail-fast
-fn region_identity(x: &'r uint) -> &'r uint { x }
+fn region_identity<'r>(x: &'r uint) -> &'r uint { x }
fn apply<T>(t: T, f: &fn(T) -> T) -> T { f(t) }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-enum int_wrapper {
+enum int_wrapper<'self> {
int_wrapper_ctor(&'self int)
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct closure_box {
+struct closure_box<'self> {
cl: &'self fn(),
}
-fn box_it(+x: &'r fn()) -> closure_box<'r> {
+fn box_it<'r>(+x: &'r fn()) -> closure_box<'r> {
closure_box {cl: x}
}
struct Ctxt { v: uint }
-trait get_ctxt {
+trait get_ctxt<'self> {
fn get_ctxt(&self) -> &'self Ctxt;
}
-struct HasCtxt { c: &'self Ctxt }
+struct HasCtxt<'self> { c: &'self Ctxt }
-impl get_ctxt for HasCtxt<'self> {
+impl<'self> get_ctxt for HasCtxt<'self> {
fn get_ctxt(&self) -> &'self Ctxt {
self.c
}
-struct Foo {
+struct Foo<'self> {
x: &'self int
}