From b8621cfb062992592c8541441bfb7e1b5240b0a1 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 25 Mar 2013 13:21:04 -0700 Subject: [PATCH] librustc: Modify all code to use new lifetime binder syntax --- doc/rust.md | 2 +- doc/tutorial-borrowed-ptr.md | 20 ++--- src/libcore/at_vec.rs | 2 +- src/libcore/cast.rs | 14 ++-- src/libcore/cleanup.rs | 4 +- src/libcore/condition.rs | 12 +-- src/libcore/gc.rs | 2 +- src/libcore/hashmap.rs | 7 +- src/libcore/io.rs | 4 +- src/libcore/iter.rs | 2 +- src/libcore/option.rs | 12 +-- src/libcore/pipes.rs | 2 +- src/libcore/ptr.rs | 6 +- src/libcore/result.rs | 2 +- src/libcore/rt/uv/mod.rs | 2 +- src/libcore/str.rs | 82 ++++++++++--------- src/libcore/sys.rs | 2 +- src/libcore/task/local_data.rs | 2 +- src/libcore/task/spawn.rs | 2 +- src/libcore/to_bytes.rs | 10 +-- src/libcore/to_str.rs | 2 +- src/libcore/trie.rs | 7 +- src/libcore/tuple.rs | 2 +- src/libcore/unstable.rs | 2 +- src/libcore/unstable/finally.rs | 2 +- src/libcore/unstable/global.rs | 2 +- src/libcore/vec.rs | 69 ++++++++-------- src/librust/rust.rc | 4 +- src/librustc/metadata/decoder.rs | 4 +- src/librustc/metadata/filesearch.rs | 2 +- src/librustc/metadata/tydecode.rs | 3 +- src/librustc/middle/borrowck/preserve.rs | 2 +- src/librustc/middle/lang_items.rs | 2 +- src/librustc/middle/lint.rs | 4 +- src/librustc/middle/trans/_match.rs | 18 ++-- src/librustc/middle/trans/callee.rs | 2 +- src/librustc/middle/trans/tvec.rs | 2 +- src/librustc/middle/typeck/check/method.rs | 2 +- src/librustc/middle/typeck/coherence.rs | 9 +- src/librustc/middle/typeck/infer/lattice.rs | 5 +- src/librustc/middle/typeck/infer/unify.rs | 10 +-- src/librustdoc/astsrv.rs | 2 +- src/libstd/arc.rs | 20 +++-- src/libstd/base64.rs | 4 +- src/libstd/deque.rs | 2 +- src/libstd/flatpipes.rs | 2 +- src/libstd/json.rs | 6 +- src/libstd/serialize.rs | 6 +- src/libstd/smallintmap.rs | 4 +- src/libstd/sort.rs | 14 ++-- src/libstd/stats.rs | 2 +- src/libstd/sync.rs | 28 +++---- src/libstd/treemap.rs | 19 +++-- src/libsyntax/ast.rs | 1 + src/libsyntax/ext/deriving/mod.rs | 22 ++--- src/libsyntax/fold.rs | 3 +- src/libsyntax/parse/parser.rs | 27 ++++-- .../compile-fail/auto-ref-borrowck-failure.rs | 2 +- .../compile-fail/auto-ref-slice-plus-ref.rs | 2 +- .../borrowck-borrowed-uniq-rvalue-2.rs | 6 +- src/test/compile-fail/issue-1896-1.rs | 2 +- src/test/compile-fail/issue-3154.rs | 2 +- src/test/compile-fail/issue-3311.rs | 4 +- src/test/compile-fail/issue-3888.rs | 2 +- .../non-constant-expr-for-fixed-len-vec.rs | 2 +- src/test/compile-fail/regions-bounds.rs | 10 +-- .../compile-fail/regions-creating-enums.rs | 2 +- .../compile-fail/regions-creating-enums3.rs | 4 +- .../compile-fail/regions-creating-enums4.rs | 2 +- .../regions-escape-via-trait-or-not.rs | 2 +- src/test/compile-fail/regions-fn-subtyping.rs | 50 +++++------ src/test/compile-fail/regions-fns.rs | 2 +- .../compile-fail/regions-glb-free-free.rs | 4 +- src/test/compile-fail/regions-in-enums.rs | 6 +- src/test/compile-fail/regions-in-structs.rs | 2 +- .../compile-fail/regions-in-type-items.rs | 6 +- .../regions-infer-at-fn-not-param.rs | 2 +- .../regions-infer-borrow-scope-too-big.rs | 2 +- .../regions-infer-borrow-scope-within-loop.rs | 2 +- src/test/compile-fail/regions-infer-call-3.rs | 4 +- ...nfer-contravariance-due-to-immutability.rs | 8 +- .../regions-infer-covariance-due-to-arg.rs | 2 +- ...ns-infer-invariance-due-to-mutability-1.rs | 10 +-- ...ns-infer-invariance-due-to-mutability-2.rs | 8 +- ...ns-infer-invariance-due-to-mutability-3.rs | 6 +- ...ns-infer-invariance-due-to-mutability-4.rs | 8 +- src/test/compile-fail/regions-nested-fns-2.rs | 4 +- src/test/compile-fail/regions-nested-fns.rs | 6 +- .../compile-fail/regions-ret-borrowed-1.rs | 4 +- src/test/compile-fail/regions-ret.rs | 2 +- src/test/compile-fail/regions-scoping.rs | 55 ------------- .../compile-fail/regions-steal-closure.rs | 2 +- src/test/compile-fail/regions-trait-1.rs | 4 +- src/test/run-pass/assignability-trait.rs | 2 +- src/test/run-pass/auto-ref-slice-plus-ref.rs | 4 +- .../run-pass/borrow-by-val-method-receiver.rs | 2 +- src/test/run-pass/borrowck-root-while-cond.rs | 2 +- src/test/run-pass/borrowed-ptr-pattern-3.rs | 2 +- .../run-pass/borrowed-ptr-pattern-option.rs | 2 +- .../class-impl-very-parameterized-trait.rs | 2 +- .../run-pass/coerce-reborrow-mut-vec-rcvr.rs | 2 +- src/test/run-pass/const-fn-val.rs | 2 +- .../run-pass/const-region-ptrs-noncopy.rs | 2 +- src/test/run-pass/const-region-ptrs.rs | 2 +- src/test/run-pass/explicit-self.rs | 6 +- src/test/run-pass/infer-with-expected.rs | 2 +- src/test/run-pass/issue-2502.rs | 4 +- src/test/run-pass/issue-2735-2.rs | 2 +- src/test/run-pass/issue-2735-3.rs | 4 +- src/test/run-pass/issue-2748-a.rs | 2 +- src/test/run-pass/issue-2748-b.rs | 3 +- src/test/run-pass/issue-3447.rs | 2 +- src/test/run-pass/issue-3888-2.rs | 2 +- src/test/run-pass/rcvr-borrowed-to-slice.rs | 2 +- src/test/run-pass/region-dependent-addr-of.rs | 18 ++-- .../region-return-interior-of-option.rs | 2 +- .../regions-addr-of-interior-of-unique-box.rs | 2 +- src/test/run-pass/regions-addr-of-ret.rs | 2 +- src/test/run-pass/regions-copy-closure.rs | 2 +- src/test/run-pass/regions-creating-enums2.rs | 4 +- src/test/run-pass/regions-creating-enums5.rs | 4 +- src/test/run-pass/regions-equiv-fns.rs | 23 ------ .../run-pass/regions-escape-into-other-fn.rs | 2 +- src/test/run-pass/regions-fn-subtyping.rs | 4 +- .../regions-infer-borrow-scope-view.rs | 2 +- ...gions-infer-borrow-scope-within-loop-ok.rs | 2 +- .../run-pass/regions-infer-borrow-scope.rs | 2 +- src/test/run-pass/regions-infer-call-2.rs | 2 +- src/test/run-pass/regions-infer-call.rs | 2 +- ...regions-infer-contravariance-due-to-ret.rs | 4 +- .../run-pass/regions-infer-contravariance.rs | 31 ------- src/test/run-pass/regions-mock-trans-impls.rs | 6 +- src/test/run-pass/regions-mock-trans.rs | 8 +- src/test/run-pass/regions-nullary-variant.rs | 4 +- src/test/run-pass/regions-params.rs | 2 +- src/test/run-pass/regions-self-in-enums.rs | 2 +- src/test/run-pass/regions-static-closure.rs | 4 +- src/test/run-pass/regions-trait.rs | 6 +- .../run-pass/struct-field-assignability.rs | 2 +- 139 files changed, 427 insertions(+), 517 deletions(-) delete mode 100644 src/test/compile-fail/regions-scoping.rs delete mode 100644 src/test/run-pass/regions-equiv-fns.rs delete mode 100644 src/test/run-pass/regions-infer-contravariance.rs diff --git a/doc/rust.md b/doc/rust.md index 3847b0b975583..2684f25e90981 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -1116,7 +1116,7 @@ static bit2: uint = 1 << 1; static bits: [uint, ..2] = [bit1, bit2]; static string: &'static str = "bitstring"; -struct BitsNStrings { +struct BitsNStrings<'self> { mybits: [uint, ..2], mystring: &'self str } diff --git a/doc/tutorial-borrowed-ptr.md b/doc/tutorial-borrowed-ptr.md index e8b5ab9dda22f..039721fb12e63 100644 --- a/doc/tutorial-borrowed-ptr.md +++ b/doc/tutorial-borrowed-ptr.md @@ -485,7 +485,7 @@ For example, we could write a subroutine like this: ~~~ 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 @@ -571,8 +571,8 @@ function: # Rectangle(Point, Size) // upper-left, dimensions # } # fn compute_area(shape: &Shape) -> float { 0f } -fn select(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} } ~~~ @@ -591,12 +591,12 @@ example: # Rectangle(Point, Size) // upper-left, dimensions # } # fn compute_area(shape: &Shape) -> float { 0f } -# fn select(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( // |-+ 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.); // | | @@ -628,8 +628,8 @@ returned. Here is how the new `select()` might look: # Rectangle(Point, Size) // upper-left, dimensions # } # fn compute_area(shape: &Shape) -> float { 0f } -fn select(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} } ~~~ @@ -647,8 +647,8 @@ concise to just omit the named lifetime for `shape` altogether: # Rectangle(Point, Size) // upper-left, dimensions # } # fn compute_area(shape: &Shape) -> float { 0f } -fn select(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} } ~~~ diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 9a8645723a42f..c96a6502eecf7 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -174,7 +174,7 @@ pub mod traits { use kinds::Copy; use ops::Add; - impl 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)) diff --git a/src/libcore/cast.rs b/src/libcore/cast.rs index c1c7bd237702a..6d8674caf870b 100644 --- a/src/libcore/cast.rs +++ b/src/libcore/cast.rs @@ -61,17 +61,19 @@ pub unsafe fn transmute(thing: L) -> G { /// Coerce an immutable reference to be mutable. #[inline(always)] -pub unsafe fn transmute_mut(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(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(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)] @@ -87,19 +89,19 @@ pub unsafe fn transmute_immut_unsafe(ptr: *const T) -> *T { /// Coerce a borrowed mutable pointer to have an arbitrary associated region. #[inline(always)] -pub unsafe fn transmute_mut_region(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(_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(_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) } diff --git a/src/libcore/cleanup.rs b/src/libcore/cleanup.rs index 3beb1add3eac9..8223ab650f2a3 100644 --- a/src/libcore/cleanup.rs +++ b/src/libcore/cleanup.rs @@ -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> = &'self fn(**TypeDesc, *c_void); +type FreeGlue<'self> = &'self fn(**TypeDesc, *c_void); type TaskID = uintptr_t; diff --git a/src/libcore/condition.rs b/src/libcore/condition.rs index 6b5d8b91439e7..41504f1a0e109 100644 --- a/src/libcore/condition.rs +++ b/src/libcore/condition.rs @@ -22,12 +22,12 @@ pub struct Handler { prev: Option<@Handler>, } -pub struct Condition { +pub struct Condition<'self, T, U> { name: &'static str, key: task::local_data::LocalDataKey<'self, Handler> } -pub impl 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); @@ -66,12 +66,12 @@ pub impl Condition<'self, T, U> { } } -struct Trap { +struct Trap<'self, T, U> { cond: &'self Condition<'self, T, U>, handler: @Handler } -pub impl Trap<'self, T, U> { +pub impl<'self, T, U> Trap<'self, T, U> { fn in(&self, inner: &'self fn() -> V) -> V { unsafe { let _g = Guard { cond: self.cond }; @@ -82,12 +82,12 @@ pub impl Trap<'self, T, U> { } } -struct Guard { +struct Guard<'self, T, U> { cond: &'self Condition<'self, T, U> } #[unsafe_destructor] -impl 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"); diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs index 6b25611466321..482613ec812be 100644 --- a/src/libcore/gc.rs +++ b/src/libcore/gc.rs @@ -122,7 +122,7 @@ unsafe fn is_safe_point(pc: *Word) -> Option { 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. diff --git a/src/libcore/hashmap.rs b/src/libcore/hashmap.rs index 8c290553a4599..ee350f5528760 100644 --- a/src/libcore/hashmap.rs +++ b/src/libcore/hashmap.rs @@ -278,9 +278,8 @@ pub mod linear { } } - impl - BaseIter<(&'self K, &'self V)> for LinearMap - { + impl<'self,K:Hash + IterBytes + Eq,V> + BaseIter<(&'self K, &'self V)> for LinearMap { /// Visit all key-value pairs fn each(&self, blk: &fn(&(&'self K, &'self V)) -> bool) { for uint::range(0, self.buckets.len()) |i| { @@ -315,7 +314,7 @@ pub mod linear { } } - impl Map for LinearMap { + impl<'self,K:Hash + IterBytes + Eq,V> Map for LinearMap { /// 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) { diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 2b66fdb38ab11..9ad6693c8d02c 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -616,12 +616,12 @@ pub fn file_reader(path: &Path) -> Result<@Reader, ~str> { // 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); diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 58a514dc0eeeb..7ed4c3c36ea6d 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -20,7 +20,7 @@ use option::{None, Option, Some}; use vec; /// A function used to initialize the elements of a sequence -pub type InitOp = &'self fn(uint) -> T; +pub type InitOp<'self,T> = &'self fn(uint) -> T; pub trait BaseIter { fn each(&self, blk: &fn(v: &A) -> bool); diff --git a/src/libcore/option.rs b/src/libcore/option.rs index bb636636953b3..e7829da76bfee 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -122,7 +122,7 @@ pub fn get(opt: Option) -> T { } #[inline(always)] -pub fn get_ref(opt: &'r Option) -> &'r T { +pub fn get_ref<'r,T>(opt: &'r Option) -> &'r T { /*! Gets an immutable reference to the value inside an option. @@ -143,7 +143,7 @@ pub fn get_ref(opt: &'r Option) -> &'r T { } } -pub fn get_mut_ref(opt: &'r mut Option) -> &'r mut T { +pub fn get_mut_ref<'r,T>(opt: &'r mut Option) -> &'r mut T { /*! Gets a mutable reference to the value inside an option. @@ -165,7 +165,7 @@ pub fn get_mut_ref(opt: &'r mut Option) -> &'r mut T { } #[inline(always)] -pub fn map(opt: &'r Option, f: &fn(x: &'r T) -> U) -> Option { +pub fn map<'r, T, U>(opt: &'r Option, f: &fn(x: &'r T) -> U) -> Option { //! Maps a `some` value by reference from one type to another match *opt { Some(ref x) => Some(f(x)), None => None } @@ -256,8 +256,10 @@ pub fn get_or_default(opt: Option, def: T) -> T { } #[inline(always)] -pub fn map_default(opt: &'r Option, def: U, - f: &fn(&'r T) -> U) -> U { +pub fn map_default<'r, T, U>(opt: &'r Option, + 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) } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 350a1de629cd4..b9972f7b2ebe4 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -440,7 +440,7 @@ pub fn try_recv(p: RecvPacketBuffered) let p = unsafe { &*p_ }; #[unsafe_destructor] - struct DropState { + struct DropState<'self> { p: &'self PacketHeader, drop { diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index fa96467cb0f67..69e7b401431bb 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -178,7 +178,7 @@ pub fn to_uint(thing: &T) -> uint { /// Determine if two borrowed pointers point to the same thing. #[inline(always)] -pub fn ref_eq(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) } @@ -312,7 +312,7 @@ impl Ord for *const T { // Equality for region pointers #[cfg(notest)] -impl 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); @@ -325,7 +325,7 @@ impl Eq for &'self const T { // Comparison for region pointers #[cfg(notest)] -impl 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) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 0df9f78a3d6d7..0a2c803ff0714 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -53,7 +53,7 @@ pub fn get(res: &Result) -> T { * If the result is an error */ #[inline(always)] -pub fn get_ref(res: &'a Result) -> &'a T { +pub fn get_ref<'a, T, U>(res: &'a Result) -> &'a T { match *res { Ok(ref t) => t, Err(ref the_err) => unsafe { diff --git a/src/libcore/rt/uv/mod.rs b/src/libcore/rt/uv/mod.rs index 28d695273e7c7..a9f2211fe084e 100644 --- a/src/libcore/rt/uv/mod.rs +++ b/src/libcore/rt/uv/mod.rs @@ -322,7 +322,7 @@ pub fn install_watcher_data>(watcher: &mut W) { } } -pub fn get_watcher_data>( +pub fn get_watcher_data<'r, H, W: Watcher + NativeHandle<*H>>( watcher: &'r mut W) -> &'r mut WatcherData { unsafe { diff --git a/src/libcore/str.rs b/src/libcore/str.rs index a159351a77433..859c59411ee96 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -58,7 +58,7 @@ impl ToStr for ~str { #[inline(always)] fn to_str(&self) -> ~str { copy *self } } -impl ToStr for &'self str { +impl<'self> ToStr for &'self str { #[inline(always)] fn to_str(&self) -> ~str { ::str::from_slice(*self) } } @@ -293,7 +293,7 @@ pub fn shift_char(s: &mut ~str) -> char { * 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); @@ -313,7 +313,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) { * * 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)) { @@ -331,7 +331,7 @@ pub fn trim_left_chars(s: &'a str, chars_to_trim: &[char]) -> &'a str { * * 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)) { @@ -352,12 +352,12 @@ pub fn trim_right_chars(s: &'a str, chars_to_trim: &[char]) -> &'a str { * * 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)) } @@ -365,7 +365,7 @@ pub fn trim_left(s: &'a str) -> &'a str { } /// 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) => { @@ -376,7 +376,7 @@ pub fn trim_right(s: &'a str) -> &'a str { } /// 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 @@ -421,7 +421,7 @@ pub fn chars(s: &str) -> ~[char] { * Returns a string containing `n` characters starting at 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)) } @@ -431,7 +431,7 @@ pub fn substr(s: &'a str, begin: uint, n: uint) -> &'a str { * 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) } @@ -551,7 +551,7 @@ fn split_inner(s: &str, sepfn: &fn(cc: char) -> bool, count: uint, } // See Issue #1932 for why this is a naive search -fn iter_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint)) { +fn iter_matches<'a,'b>(s: &'a str, sep: &'b str, f: &fn(uint, uint)) { let sep_len = len(sep), l = len(s); fail_unless!(sep_len > 0u); let mut i = 0u, match_start = 0u, match_i = 0u; @@ -578,7 +578,7 @@ fn iter_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint)) { } } -fn iter_between_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint)) { +fn iter_between_matches<'a,'b>(s: &'a str, sep: &'b str, f: &fn(uint, uint)) { let mut last_end = 0u; do iter_matches(s, sep) |from, to| { f(last_end, from); @@ -596,7 +596,7 @@ fn iter_between_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint)) { * fail_unless!(["", "XXX", "YYY", ""] == split_str(".XXX.YYY.", ".")) * ~~~ */ -pub fn split_str(s: &'a str, sep: &'b str) -> ~[~str] { +pub fn split_str<'a,'b>(s: &'a str, sep: &'b str) -> ~[~str] { let mut result = ~[]; do iter_between_matches(s, sep) |from, to| { unsafe { result.push(raw::slice_bytes_unique(s, from, to)); } @@ -604,7 +604,7 @@ pub fn split_str(s: &'a str, sep: &'b str) -> ~[~str] { result } -pub fn split_str_nonempty(s: &'a str, sep: &'b str) -> ~[~str] { +pub fn split_str_nonempty<'a,'b>(s: &'a str, sep: &'b str) -> ~[~str] { let mut result = ~[]; do iter_between_matches(s, sep) |from, to| { if to > from { @@ -814,7 +814,7 @@ fn cmp(a: &str, b: &str) -> Ordering { } #[cfg(notest)] -impl TotalOrd for &'self str { +impl<'self> TotalOrd for &'self str { fn cmp(&self, other: & &'self str) -> Ordering { cmp(*self, *other) } } @@ -860,7 +860,7 @@ fn gt(a: &str, b: &str) -> bool { } #[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)) @@ -902,7 +902,7 @@ impl Ord for ~str { } #[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)] @@ -926,7 +926,7 @@ impl Ord for @str { } #[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) } } @@ -1389,7 +1389,7 @@ pub fn rfind_between(s: &str, start: uint, end: uint, } // 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; @@ -1408,7 +1408,7 @@ fn match_at(haystack: &'a str, needle: &'b str, at: uint) -> bool { * 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 { +pub fn find_str<'a,'b>(haystack: &'a str, needle: &'b str) -> Option { find_str_between(haystack, needle, 0u, len(haystack)) } @@ -1431,8 +1431,8 @@ pub fn find_str(haystack: &'a str, needle: &'b str) -> Option { * * `start` must be less than or equal to `len(s)` */ -pub fn find_str_from(haystack: &'a str, needle: &'b str, start: uint) - -> Option { +pub fn find_str_from<'a,'b>(haystack: &'a str, needle: &'b str, start: uint) + -> Option { find_str_between(haystack, needle, start, len(haystack)) } @@ -1456,9 +1456,11 @@ pub fn find_str_from(haystack: &'a str, needle: &'b str, start: uint) * `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 { +pub fn find_str_between<'a,'b>(haystack: &'a str, + needle: &'b str, + start: uint, + end: uint) + -> Option { // See Issue #1932 for why this is a naive search fail_unless!(end <= len(haystack)); let needle_len = len(needle); @@ -1482,7 +1484,7 @@ pub fn find_str_between(haystack: &'a str, needle: &'b str, start: uint, * * 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() } @@ -1506,7 +1508,7 @@ pub fn contains_char(haystack: &str, needle: char) -> bool { * * 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 } @@ -1521,7 +1523,7 @@ pub fn starts_with(haystack: &'a str, needle: &'b str) -> bool { * * 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 } @@ -1703,7 +1705,7 @@ pub fn count_chars(s: &str, start: uint, end: uint) -> uint { } /// 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); @@ -1951,7 +1953,7 @@ pub fn as_bytes(s: &const ~str, f: &fn(&~[u8]) -> T) -> T { * * 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); @@ -2260,7 +2262,7 @@ pub mod traits { 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)) @@ -2274,7 +2276,7 @@ pub mod traits {} pub trait StrSlice { 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); @@ -2293,8 +2295,8 @@ pub trait StrSlice { fn slice(&self, begin: uint, end: uint) -> &'self str; fn split(&self, sepfn: &fn(char) -> bool) -> ~[~str]; fn split_char(&self, sep: char) -> ~[~str]; - fn split_str(&self, sep: &'a str) -> ~[~str]; - fn starts_with(&self, needle: &'a str) -> bool; + fn split_str<'a>(&self, sep: &'a str) -> ~[~str]; + 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; @@ -2314,7 +2316,7 @@ pub trait StrSlice { } /// Extension methods for strings -impl StrSlice for &'self str { +impl<'self> StrSlice for &'self str { /** * Return true if a predicate matches all characters or if the string * contains no characters @@ -2329,7 +2331,7 @@ impl StrSlice for &'self str { 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 @@ -2426,10 +2428,10 @@ impl StrSlice for &'self str { * string */ #[inline] - fn split_str(&self, sep: &'a str) -> ~[~str] { split_str(*self, sep) } + fn split_str<'a>(&self, sep: &'a str) -> ~[~str] { split_str(*self, sep) } /// 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) } /** @@ -2720,8 +2722,8 @@ mod tests { #[test] fn test_split_str() { - fn t(s: &str, sep: &'a str, i: int, k: &str) { - fn borrow(x: &'a str) -> &'a str { x } + fn t<'a>(s: &str, sep: &'a str, i: int, k: &str) { + fn borrow<'a>(x: &'a str) -> &'a str { x } let v = split_str(s, sep); fail_unless!(borrow(v[i]) == k); } diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index 69991259cf29e..f8905e4faa796 100644 --- a/src/libcore/sys.rs +++ b/src/libcore/sys.rs @@ -19,7 +19,7 @@ use libc::{c_void, c_char, size_t}; 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 { diff --git a/src/libcore/task/local_data.rs b/src/libcore/task/local_data.rs index ccd9170947989..e386f93a42900 100644 --- a/src/libcore/task/local_data.rs +++ b/src/libcore/task/local_data.rs @@ -44,7 +44,7 @@ use task::rt; * * These two cases aside, the interface is safe. */ -pub type LocalDataKey = &'self fn(v: @T); +pub type LocalDataKey<'self,T> = &'self fn(v: @T); /** * Remove a task-local data value from the table, returning the diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index b97a682c4e5ca..52957b7fe46bd 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -123,7 +123,7 @@ struct TaskGroupData { } type TaskGroupArc = unstable::Exclusive>; -type TaskGroupInner = &'self mut Option; +type TaskGroupInner<'self> = &'self mut Option; // A taskgroup is 'dead' when nothing can cause it to fail; only members can. fn taskgroup_is_dead(tg: &TaskGroupData) -> bool { diff --git a/src/libcore/to_bytes.rs b/src/libcore/to_bytes.rs index 32b123979cd5a..7b4b6994e50a5 100644 --- a/src/libcore/to_bytes.rs +++ b/src/libcore/to_bytes.rs @@ -19,7 +19,7 @@ use io::Writer; 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; @@ -197,7 +197,7 @@ impl IterBytes for int { } } -impl 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| { @@ -231,7 +231,7 @@ impl IterBytes for (A,B,C) { } // Move this to vec, probably. -fn borrow(a: &'x [A]) -> &'x [A] { +fn borrow<'x,A>(a: &'x [A]) -> &'x [A] { a } @@ -352,7 +352,7 @@ pub fn iter_bytes_7 IterBytes for &'self str { #[inline(always)] fn iter_bytes(&self, _lsb0: bool, f: Cb) { do str::byte_slice(*self) |bytes| { @@ -389,7 +389,7 @@ impl IterBytes for Option { } } -impl 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); diff --git a/src/libcore/to_str.rs b/src/libcore/to_str.rs index 576f794483d20..3d0d3fde1d0ec 100644 --- a/src/libcore/to_str.rs +++ b/src/libcore/to_str.rs @@ -60,7 +60,7 @@ impl ToStr for (A, B, C) { } } -impl ToStr for &'self [A] { +impl<'self,A:ToStr> ToStr for &'self [A] { #[inline(always)] fn to_str(&self) -> ~str { unsafe { diff --git a/src/libcore/trie.rs b/src/libcore/trie.rs index 4c4be33ea1730..52298992bd17f 100644 --- a/src/libcore/trie.rs +++ b/src/libcore/trie.rs @@ -28,7 +28,7 @@ pub struct TrieMap { priv length: uint } -impl BaseIter<(uint, &'self T)> for TrieMap { +impl<'self,T> BaseIter<(uint, &'self T)> for TrieMap { /// Visit all key-value pairs in order #[inline(always)] fn each(&self, f: &fn(&(uint, &'self T)) -> bool) { @@ -38,7 +38,7 @@ impl BaseIter<(uint, &'self T)> for TrieMap { fn size_hint(&self) -> Option { Some(self.len()) } } -impl ReverseIter<(uint, &'self T)> for TrieMap { +impl<'self,T> ReverseIter<(uint, &'self T)> for TrieMap { /// Visit all key-value pairs in reverse order #[inline(always)] fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) { @@ -282,7 +282,8 @@ fn chunk(n: uint, idx: uint) -> uint { (n >> sh) & MASK } -fn find_mut(child: &'r mut Child, key: uint, idx: uint) -> Option<&'r mut T> { +fn find_mut<'r, T>(child: &'r mut Child, 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)), diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs index fc7834a7514ac..18a0f44299355 100644 --- a/src/libcore/tuple.rs +++ b/src/libcore/tuple.rs @@ -71,7 +71,7 @@ pub trait ExtendedTupleOps { fn map(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C]; } -impl ExtendedTupleOps for (&'self [A], &'self [B]) { +impl<'self,A:Copy,B:Copy> ExtendedTupleOps for (&'self [A], &'self [B]) { #[inline(always)] fn zip(&self) -> ~[(A, B)] { match *self { diff --git a/src/libcore/unstable.rs b/src/libcore/unstable.rs index 6f0c9ba23dfd5..70172edc432b0 100644 --- a/src/libcore/unstable.rs +++ b/src/libcore/unstable.rs @@ -171,7 +171,7 @@ pub unsafe fn get_shared_mutable_state( } } #[inline(always)] -pub unsafe fn get_shared_immutable_state( +pub unsafe fn get_shared_immutable_state<'a,T:Owned>( rc: &'a SharedMutableState) -> &'a T { unsafe { let ptr: ~ArcData = cast::reinterpret_cast(&(*rc).data); diff --git a/src/libcore/unstable/finally.rs b/src/libcore/unstable/finally.rs index 04d1d6f11b929..93cc4a4342d8e 100644 --- a/src/libcore/unstable/finally.rs +++ b/src/libcore/unstable/finally.rs @@ -31,7 +31,7 @@ pub trait Finally { fn finally(&self, dtor: &fn()) -> T; } -impl Finally for &'self fn() -> T { +impl<'self,T> Finally for &'self fn() -> T { fn finally(&self, dtor: &fn()) -> T { let _d = Finallyalizer { dtor: dtor diff --git a/src/libcore/unstable/global.rs b/src/libcore/unstable/global.rs index 32e1b35d7db9f..f160a350e0dd5 100644 --- a/src/libcore/unstable/global.rs +++ b/src/libcore/unstable/global.rs @@ -42,7 +42,7 @@ use sys::Closure; #[cfg(test)] use task::spawn; #[cfg(test)] use uint; -pub type GlobalDataKey = &'self fn(v: T); +pub type GlobalDataKey<'self,T> = &'self fn(v: T); pub unsafe fn global_data_clone_create( key: GlobalDataKey, create: &fn() -> ~T) -> T { diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 256b4c4922e50..702ae73852ee3 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -225,46 +225,46 @@ pub fn build_sized_opt(size: Option, // Accessors /// Returns the first element of a vector -pub fn head(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(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(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(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(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(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(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(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(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| { @@ -278,7 +278,8 @@ pub fn slice(v: &'r [T], start: uint, end: uint) -> &'r [T] { /// Return a slice that points into another slice. #[inline(always)] -pub fn mut_slice(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| { @@ -292,8 +293,8 @@ pub fn mut_slice(v: &'r mut [T], start: uint, end: uint) -> &'r mut [T] { /// Return a slice that points into another slice. #[inline(always)] -pub fn const_slice(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| { @@ -1343,7 +1344,7 @@ pub fn reversed(v: &const [T]) -> ~[T] { * ~~~ */ #[inline(always)] -pub fn each(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 @@ -1367,7 +1368,7 @@ pub fn each(v: &'r [T], f: &fn(&'r T) -> bool) { /// a vector with mutable contents and you would like /// to mutate the contents as you iterate. #[inline(always)] -pub fn each_mut(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 { @@ -1398,7 +1399,7 @@ pub fn each_const(v: &const [T], f: &fn(elem: &const T) -> bool) { * Return true to continue, false to break. */ #[inline(always)] -pub fn eachi(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; } @@ -1412,7 +1413,7 @@ pub fn eachi(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) { * Return true to continue, false to break. */ #[inline(always)] -pub fn each_reverse(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)) } @@ -1422,7 +1423,7 @@ pub fn each_reverse(v: &'r [T], blk: &fn(v: &'r T) -> bool) { * Return true to continue, false to break. */ #[inline(always)] -pub fn eachi_reverse(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; @@ -1560,7 +1561,7 @@ fn eq(a: &[T], b: &[T]) -> bool { } #[cfg(notest)] -impl 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)] @@ -1585,7 +1586,7 @@ impl Eq for @[T] { } #[cfg(notest)] -impl 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) } } @@ -1607,7 +1608,7 @@ fn cmp(a: &[T], b: &[T]) -> Ordering { } #[cfg(notest)] -impl TotalOrd for &'self [T] { +impl<'self,T:TotalOrd> TotalOrd for &'self [T] { #[inline(always)] fn cmp(&self, other: & &'self [T]) -> Ordering { cmp(*self, *other) } } @@ -1644,7 +1645,7 @@ fn ge(a: &[T], b: &[T]) -> bool { !lt(a, b) } fn gt(a: &[T], b: &[T]) -> bool { lt(b, a) } #[cfg(notest)] -impl 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)] @@ -1685,7 +1686,7 @@ pub mod traits { use ops::Add; use vec::append; - impl 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)) @@ -1693,7 +1694,7 @@ pub mod traits { } } -impl 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) } @@ -1708,7 +1709,7 @@ pub trait CopyableVector { } /// Extension methods for vectors -impl CopyableVector for &'self const [T] { +impl<'self,T:Copy> CopyableVector for &'self const [T] { /// Returns a copy of `v`. #[inline] fn to_owned(&self) -> ~[T] { @@ -1747,7 +1748,7 @@ pub trait ImmutableVector { } /// Extension methods for vectors -impl ImmutableVector for &'self [T] { +impl<'self,T> ImmutableVector for &'self [T] { /// Return a slice that points into another slice. #[inline] fn slice(&self, start: uint, end: uint) -> &'self [T] { @@ -1862,7 +1863,7 @@ pub trait ImmutableEqVector { fn rposition_elem(&self, t: &T) -> Option; } -impl ImmutableEqVector for &'self [T] { +impl<'self,T:Eq> ImmutableEqVector for &'self [T] { /** * Find the first index matching some predicate * @@ -1907,7 +1908,7 @@ pub trait ImmutableCopyableVector { } /// Extension methods for vectors -impl ImmutableCopyableVector for &'self [T] { +impl<'self,T:Copy> ImmutableCopyableVector for &'self [T] { /** * Construct a new vector from the elements of a vector for which some * predicate holds. @@ -2309,7 +2310,7 @@ pub mod bytes { // ___________________________________________________________________________ // ITERATION TRAIT METHODS -impl iter::BaseIter for &'self [A] { +impl<'self,A> iter::BaseIter for &'self [A] { #[inline(always)] fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) } #[inline(always)] @@ -2332,7 +2333,7 @@ impl iter::BaseIter for @[A] { fn size_hint(&self) -> Option { Some(self.len()) } } -impl iter::MutableIter for &'self mut [A] { +impl<'self,A> iter::MutableIter for &'self mut [A] { #[inline(always)] fn each_mut(&mut self, blk: &fn(v: &'self mut A) -> bool) { each_mut(*self, blk) @@ -2355,7 +2356,7 @@ impl iter::MutableIter for @mut [A] { } } -impl iter::ExtendedIter for &'self [A] { +impl<'self,A> iter::ExtendedIter for &'self [A] { pub fn eachi(&self, blk: &fn(uint, v: &A) -> bool) { iter::eachi(self, blk) } @@ -2432,7 +2433,7 @@ impl iter::ExtendedIter for @[A] { } } -impl iter::EqIter for &'self [A] { +impl<'self,A:Eq> iter::EqIter 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) } } @@ -2449,7 +2450,7 @@ impl iter::EqIter for @[A] { pub fn count(&self, x: &A) -> uint { iter::count(self, x) } } -impl iter::CopyableIter for &'self [A] { +impl<'self,A:Copy> iter::CopyableIter for &'self [A] { fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] { iter::filter_to_vec(self, pred) } @@ -2481,7 +2482,7 @@ impl iter::CopyableIter for @[A] { } } -impl iter::CopyableOrderedIter for &'self [A] { +impl<'self,A:Copy + Ord> iter::CopyableOrderedIter for &'self [A] { fn min(&self) -> A { iter::min(self) } fn max(&self) -> A { iter::max(self) } } @@ -2498,7 +2499,7 @@ impl iter::CopyableOrderedIter for @[A] { fn max(&self) -> A { iter::max(self) } } -impl iter::CopyableNonstrictIter for &'self [A] { +impl<'self,A:Copy> iter::CopyableNonstrictIter for &'self [A] { fn each_val(&const self, f: &fn(A) -> bool) { let mut i = 0; while i < self.len() { diff --git a/src/librust/rust.rc b/src/librust/rust.rc index e590586abbb39..db3a61a3ac35a 100644 --- a/src/librust/rust.rc +++ b/src/librust/rust.rc @@ -35,12 +35,12 @@ impl ValidUsage { }} } -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) } diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index b952aff9e1ce1..4549250a5b701 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -66,7 +66,7 @@ fn lookup_hash(d: ebml::Doc, eq_fn: &fn(x:&[u8]) -> bool, hash: uint) -> 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 { fn eq_item(bytes: &[u8], item_id: int) -> bool { @@ -548,7 +548,7 @@ pub fn get_item_path(intr: @ident_interner, cdata: cmd, id: ast::node_id) 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, diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index ad5b0274c0d5d..1e58ac5e94a84 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -21,7 +21,7 @@ use core::result::Result; use core::result; use core::str; -pub type pick = &'self fn(path: &Path) -> Option; +pub type pick<'self, T> = &'self fn(path: &Path) -> Option; pub fn pick_file(file: Path, path: &Path) -> Option { if path.file_path() == file { option::Some(copy *path) } diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index f12cc140d8ab9..e50e7444c926c 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -49,7 +49,8 @@ pub enum DefIdSource { // Identifies a type parameter (`fn foo() { ... }`). 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], diff --git a/src/librustc/middle/borrowck/preserve.rs b/src/librustc/middle/borrowck/preserve.rs index 0440f4525ff36..fe4872d0f4905 100644 --- a/src/librustc/middle/borrowck/preserve.rs +++ b/src/librustc/middle/borrowck/preserve.rs @@ -63,7 +63,7 @@ pub impl BorrowckCtxt { } } -struct PreserveCtxt { +struct PreserveCtxt<'self> { bccx: &'self BorrowckCtxt, // the region scope for which we must preserve the memory diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 98d534bab0c93..b4aefad592c00 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -311,7 +311,7 @@ fn LanguageItemCollector<'r>(crate: @crate, } } -struct LanguageItemCollector { +struct LanguageItemCollector<'self> { items: &'self mut LanguageItems, crate: @crate, diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 2b16ccdd1d220..e2450cc1ddf8b 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -886,14 +886,14 @@ fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) { !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 diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 7529b2132fd9e..495cad55dbfc9 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -325,7 +325,7 @@ pub struct BindingInfo { pub type BindingsMap = HashMap; -pub struct ArmData { +pub struct ArmData<'self> { bodycx: block, arm: &'self ast::arm, bindings_map: BindingsMap @@ -393,7 +393,7 @@ pub fn expand_nested_bindings<'r>(bcx: block, } } -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) { @@ -610,13 +610,13 @@ pub fn enter_opt<'r>(bcx: block, } } -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), diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 607d4cff8d6a4..eaea54f68b10a 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -552,7 +552,7 @@ pub fn trans_call_inner( } -pub enum CallArgs { +pub enum CallArgs<'self> { ArgExprs(&'self [@ast::expr]), ArgVals(&'self [ValueRef]) } diff --git a/src/librustc/middle/trans/tvec.rs b/src/librustc/middle/trans/tvec.rs index 90f6bf8757865..35d0e03724ff6 100644 --- a/src/librustc/middle/trans/tvec.rs +++ b/src/librustc/middle/trans/tvec.rs @@ -548,7 +548,7 @@ pub fn get_base_and_len(bcx: block, 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 { diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index c550e5c71e491..c6cda6d0e8122 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -151,7 +151,7 @@ pub fn lookup( return mme; } -pub struct LookupContext { +pub struct LookupContext<'self> { fcx: @mut FnCtxt, expr: @ast::expr, self_expr: @ast::expr, diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 0b3eca7c07df0..b399d5b83d484 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -567,10 +567,11 @@ pub impl CoherenceChecker { } } - 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()) diff --git a/src/librustc/middle/typeck/infer/lattice.rs b/src/librustc/middle/typeck/infer/lattice.rs index a83d6f1755ecc..27d3b3ddd86a1 100644 --- a/src/librustc/middle/typeck/infer/lattice.rs +++ b/src/librustc/middle/typeck/infer/lattice.rs @@ -56,7 +56,8 @@ pub trait LatticeValue { fn glb(cf: &CombineFields, a: &Self, b: &Self) -> cres; } -pub type LatticeOp = &'self fn(cf: &CombineFields, a: &T, b: &T) -> cres; +pub type LatticeOp<'self, T> = + &'self fn(cf: &CombineFields, a: &T, b: &T) -> cres; impl LatticeValue for ty::t { fn sub(cf: &CombineFields, a: &ty::t, b: &ty::t) -> ures { @@ -374,7 +375,7 @@ pub fn super_lattice_tys( } } -pub type LatticeDirOp = &'self fn(a: &T, b: &T) -> cres; +pub type LatticeDirOp<'self, T> = &'self fn(a: &T, b: &T) -> cres; pub enum LatticeVarResult { VarResult(V), diff --git a/src/librustc/middle/typeck/infer/unify.rs b/src/librustc/middle/typeck/infer/unify.rs index 7711794d91db5..f31568a50a365 100644 --- a/src/librustc/middle/typeck/infer/unify.rs +++ b/src/librustc/middle/typeck/infer/unify.rs @@ -35,8 +35,8 @@ pub struct Node { } pub trait UnifyVid { - fn appropriate_vals_and_bindings(infcx: &'v mut InferCtxt) - -> &'v mut ValsAndBindings; + fn appropriate_vals_and_bindings<'v>(infcx: &'v mut InferCtxt) + -> &'v mut ValsAndBindings; } pub impl InferCtxt { @@ -235,14 +235,14 @@ pub impl InferCtxt { // ______________________________________________________________________ impl UnifyVid> 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> { return &mut infcx.ty_var_bindings; } } impl UnifyVid> 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> { return &mut infcx.int_var_bindings; } @@ -255,7 +255,7 @@ impl SimplyUnifiable for IntVarValue { } impl UnifyVid> 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> { return &mut infcx.float_var_bindings; } diff --git a/src/librustdoc/astsrv.rs b/src/librustdoc/astsrv.rs index b5793cc0abde2..8f02b789121be 100644 --- a/src/librustdoc/astsrv.rs +++ b/src/librustdoc/astsrv.rs @@ -36,7 +36,7 @@ pub struct Ctxt { ast_map: ast_map::map } -type SrvOwner = &'self fn(srv: Srv) -> T; +type SrvOwner<'self,T> = &'self fn(srv: Srv) -> T; pub type CtxtHandler = ~fn(ctxt: Ctxt) -> T; type Parser = ~fn(Session, s: ~str) -> @ast::crate; diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs index d037acff0ede7..02c50cc7c9858 100644 --- a/src/libstd/arc.rs +++ b/src/libstd/arc.rs @@ -95,7 +95,7 @@ pub fn ARC(data: T) -> ARC { * Access the underlying data in an atomically reference counted * wrapper. */ -pub fn get(rc: &'a ARC) -> &'a T { +pub fn get<'a, T:Const + Owned>(rc: &'a ARC) -> &'a T { unsafe { get_shared_immutable_state(&rc.x) } } @@ -191,7 +191,7 @@ pub impl MutexARC { /// As access(), but with a condvar, as sync::mutex.lock_cond(). #[inline(always)] - unsafe fn access_cond( + unsafe fn access_cond<'x, 'c, U>( &self, blk: &fn(x: &'x mut T, c: &'c Condvar) -> U) -> U { @@ -239,7 +239,7 @@ impl Drop for PoisonOnFail { } } -fn PoisonOnFail(failed: &'r mut bool) -> PoisonOnFail { +fn PoisonOnFail<'r>(failed: &'r mut bool) -> PoisonOnFail { PoisonOnFail { failed: ptr::to_mut_unsafe_ptr(failed) } @@ -313,7 +313,9 @@ pub impl RWARC { } /// As write(), but with a condvar, as sync::rwlock.write_cond(). #[inline(always)] - fn write_cond(&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| { @@ -375,7 +377,7 @@ pub impl RWARC { } /// 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 { @@ -420,7 +422,7 @@ pub struct RWReadMode<'self, T> { token: sync::RWlockReadMode<'self>, } -pub impl RWWriteMode<'self, T> { +pub impl<'self, T:Const + Owned> RWWriteMode<'self, T> { /// Access the pre-downgrade RWARC in write mode. fn write(&self, blk: &fn(x: &mut T) -> U) -> U { match *self { @@ -436,7 +438,9 @@ pub impl RWWriteMode<'self, T> { } } /// Access the pre-downgrade RWARC in write mode with a condvar. - fn write_cond(&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, @@ -458,7 +462,7 @@ pub impl RWWriteMode<'self, T> { } } -pub impl RWReadMode<'self, T> { +pub impl<'self, T:Const + Owned> RWReadMode<'self, T> { /// Access the post-downgrade rwlock in read mode. fn read(&self, blk: &fn(x: &T) -> U) -> U { match *self { diff --git a/src/libstd/base64.rs b/src/libstd/base64.rs index ff026324404ab..4d0393d6adba1 100644 --- a/src/libstd/base64.rs +++ b/src/libstd/base64.rs @@ -16,7 +16,7 @@ pub trait ToBase64 { fn to_base64(&self) -> ~str; } -impl ToBase64 for &'self [u8] { +impl<'self> ToBase64 for &'self [u8] { fn to_base64(&self) -> ~str { let chars = str::chars( ~"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" @@ -69,7 +69,7 @@ impl ToBase64 for &'self [u8] { } } -impl ToBase64 for &'self str { +impl<'self> ToBase64 for &'self str { fn to_base64(&self) -> ~str { str::to_bytes(*self).to_base64() } diff --git a/src/libstd/deque.rs b/src/libstd/deque.rs index e6fcbdc84c877..72b68f8fe3aff 100644 --- a/src/libstd/deque.rs +++ b/src/libstd/deque.rs @@ -132,7 +132,7 @@ fn grow(nelts: uint, lo: uint, elts: &mut [Option]) -> ~[Option] { rv } -fn get(elts: &'r [Option], i: uint) -> &'r T { +fn get<'r, T>(elts: &'r [Option], i: uint) -> &'r T { match elts[i] { Some(ref t) => t, _ => fail!() } } diff --git a/src/libstd/flatpipes.rs b/src/libstd/flatpipes.rs index 01a7cbfe604fa..1a3a28f749279 100644 --- a/src/libstd/flatpipes.rs +++ b/src/libstd/flatpipes.rs @@ -466,7 +466,7 @@ pub mod flatteners { 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) => { diff --git a/src/libstd/json.rs b/src/libstd/json.rs index a9b9b2977cded..0cbef3dc4a40c 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -741,7 +741,7 @@ pub fn from_str(s: &str) -> Result { } } -pub struct Decoder { +pub struct Decoder<'self> { priv json: Json, priv mut stack: ~[&'self Json], } @@ -750,7 +750,7 @@ pub fn Decoder(json: Json) -> Decoder { 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); @@ -766,7 +766,7 @@ priv impl Decoder<'self> { } } -impl serialize::Decoder for Decoder<'self> { +impl<'self> serialize::Decoder for Decoder<'self> { fn read_nil(&self) -> () { debug!("read_nil"); match *self.pop() { diff --git a/src/libstd/serialize.rs b/src/libstd/serialize.rs index d288c06d2935c..326b9e4dc07e9 100644 --- a/src/libstd/serialize.rs +++ b/src/libstd/serialize.rs @@ -213,7 +213,7 @@ impl Decodable for i64 { } } -impl Encodable for &'self str { +impl<'self, S:Encoder> Encodable for &'self str { fn encode(&self, s: &S) { s.emit_borrowed_str(*self) } } @@ -286,7 +286,7 @@ impl Decodable for () { } } -impl> Encodable for &'self T { +impl<'self, S:Encoder,T:Encodable> Encodable for &'self T { fn encode(&self, s: &S) { s.emit_borrowed(|| (**self).encode(s)) } @@ -316,7 +316,7 @@ impl> Decodable for @T { } } -impl> Encodable for &'self [T] { +impl<'self, S:Encoder,T:Encodable> Encodable for &'self [T] { fn encode(&self, s: &S) { do s.emit_borrowed_vec(self.len()) { for self.eachi |i, e| { diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index 4ad8d38b072b1..16f7c0ba860be 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -22,7 +22,7 @@ pub struct SmallIntMap { priv v: ~[Option], } -impl BaseIter<(uint, &'self V)> for SmallIntMap { +impl<'self, V> BaseIter<(uint, &'self V)> for SmallIntMap { /// Visit all key-value pairs in order fn each(&self, it: &fn(&(uint, &'self V)) -> bool) { for uint::range(0, self.v.len()) |i| { @@ -36,7 +36,7 @@ impl BaseIter<(uint, &'self V)> for SmallIntMap { fn size_hint(&self) -> Option { Some(self.len()) } } -impl ReverseIter<(uint, &'self V)> for SmallIntMap { +impl<'self, V> ReverseIter<(uint, &'self V)> for SmallIntMap { /// 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| { diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs index 7e528f96ca72b..c52f0da08c53c 100644 --- a/src/libstd/sort.rs +++ b/src/libstd/sort.rs @@ -16,7 +16,7 @@ use core::util; use core::vec::{len, push}; use core::vec; -type Le = &'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. @@ -173,7 +173,7 @@ pub trait Sort { fn qsort(self); } -impl Sort for &'self mut [T] { +impl<'self, T:Copy + Ord + Eq> Sort for &'self mut [T] { fn qsort(self) { quick_sort3(self); } } @@ -1192,7 +1192,7 @@ mod big_tests { } } - struct LVal { + struct LVal<'self> { val: uint, key: &'self fn(@uint), } @@ -1213,16 +1213,16 @@ mod big_tests { } 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 } } diff --git a/src/libstd/stats.rs b/src/libstd/stats.rs index cecf9686327d1..04059a4951190 100644 --- a/src/libstd/stats.rs +++ b/src/libstd/stats.rs @@ -30,7 +30,7 @@ pub trait Stats { 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) } diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index 569c67eac93fb..ba0412ad90199 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -163,12 +163,12 @@ pub impl Sem<~[Waitqueue]> { // FIXME(#3588) should go inside of access() #[doc(hidden)] -type SemRelease = SemReleaseGeneric<'self, ()>; -type SemAndSignalRelease = SemReleaseGeneric<'self, ~[Waitqueue]>; -struct SemReleaseGeneric { sem: &'self Sem } +type SemRelease<'self> = SemReleaseGeneric<'self, ()>; +type SemAndSignalRelease<'self> = SemReleaseGeneric<'self, ~[Waitqueue]>; +struct SemReleaseGeneric<'self, Q> { sem: &'self Sem } #[unsafe_destructor] -impl Drop for SemReleaseGeneric<'self, Q> { +impl<'self, Q:Owned> Drop for SemReleaseGeneric<'self, Q> { fn finalize(&self) { unsafe { self.sem.release(); @@ -176,14 +176,14 @@ impl Drop for SemReleaseGeneric<'self, Q> { } } -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 } @@ -195,7 +195,7 @@ pub struct Condvar<'self> { priv sem: &'self Sem<~[Waitqueue]> } #[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. * @@ -261,7 +261,7 @@ pub impl Condvar<'self> { // 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]>, } @@ -277,8 +277,8 @@ pub impl Condvar<'self> { } } - fn SemAndSignalReacquire(sem: &'r Sem<~[Waitqueue]>) - -> SemAndSignalReacquire<'r> { + fn SemAndSignalReacquire<'r>(sem: &'r Sem<~[Waitqueue]>) + -> SemAndSignalReacquire<'r> { SemAndSignalReacquire { sem: sem } @@ -616,7 +616,7 @@ pub impl RWlock { // FIXME(#3588) should go inside of read() #[doc(hidden)] -struct RWlockReleaseRead { +struct RWlockReleaseRead<'self> { lock: &'self RWlock, } @@ -652,7 +652,7 @@ fn RWlockReleaseRead<'r>(lock: &'r RWlock) -> RWlockReleaseRead<'r> { // FIXME(#3588) should go inside of downgrade() #[doc(hidden)] #[unsafe_destructor] -struct RWlockReleaseDowngrade { +struct RWlockReleaseDowngrade<'self> { lock: &'self RWlock, } @@ -700,7 +700,7 @@ pub struct RWlockWriteMode<'self> { priv 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) {} } diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index fccf58ddb6f74..9a184ca868234 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -198,7 +198,7 @@ pub impl TreeMap { } /// Lazy forward iterator over a map -pub struct TreeMapIterator { +pub struct TreeMapIterator<'self, K, V> { priv stack: ~[&'self ~TreeNode], priv node: &'self Option<~TreeNode> } @@ -537,24 +537,25 @@ pub impl TreeNode { } } -fn each(node: &'r Option<~TreeNode>, - f: &fn(&(&'r K, &'r V)) -> bool) { +fn each<'r, K: TotalOrd, V>(node: &'r Option<~TreeNode>, + 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(node: &'r Option<~TreeNode>, - f: &fn(&(&'r K, &'r V)) -> bool) { +fn each_reverse<'r, K: TotalOrd, V>(node: &'r Option<~TreeNode>, + 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(node: &'r mut Option<~TreeNode>, - f: &fn(&'r K, &'r mut V) -> bool) -> bool { +fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode>, + 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, _}) => { @@ -590,7 +591,9 @@ fn split(node: &mut ~TreeNode) { } } -fn find_mut(node: &'r mut Option<~TreeNode>, key: &K) -> Option<&'r mut V> { +fn find_mut<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode>, + key: &K) + -> Option<&'r mut V> { match *node { Some(ref mut x) => { match key.cmp(&x.key) { diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index bef88e58a1795..6071cc643a367 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -892,6 +892,7 @@ impl to_bytes::IterBytes for Onceness { pub struct TyClosure { sigil: Sigil, region: Option<@Lifetime>, + lifetimes: OptVec, purity: purity, onceness: Onceness, decl: fn_decl diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 57fddd623d474..e879bcdc4764f 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -34,16 +34,18 @@ pub mod clone; 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, diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 159b23f4f9997..ea13a6a1df01b 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -610,7 +610,8 @@ pub fn noop_fold_ty(t: &ty_, fld: @ast_fold) -> ty_ { 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) => { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 45a8cf1ee5fd5..48aa27f5ca297 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -362,10 +362,11 @@ pub impl Parser { 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 }); } @@ -400,12 +401,15 @@ pub impl Parser { 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 { @@ -424,7 +428,7 @@ pub impl Parser { } } - fn parse_ty_fn_decl(&self) -> fn_decl { + fn parse_ty_fn_decl(&self) -> (fn_decl, OptVec) { /* (fn) <'lt> (S) -> T @@ -435,10 +439,14 @@ pub impl Parser { 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, @@ -446,7 +454,12 @@ pub impl Parser { |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] { diff --git a/src/test/compile-fail/auto-ref-borrowck-failure.rs b/src/test/compile-fail/auto-ref-borrowck-failure.rs index 9fe7ae40dbbc3..90b9b44cfbea3 100644 --- a/src/test/compile-fail/auto-ref-borrowck-failure.rs +++ b/src/test/compile-fail/auto-ref-borrowck-failure.rs @@ -18,7 +18,7 @@ trait Stuff { 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)); } diff --git a/src/test/compile-fail/auto-ref-slice-plus-ref.rs b/src/test/compile-fail/auto-ref-slice-plus-ref.rs index 609e8de87d68b..d8164be6ea63c 100644 --- a/src/test/compile-fail/auto-ref-slice-plus-ref.rs +++ b/src/test/compile-fail/auto-ref-slice-plus-ref.rs @@ -23,6 +23,6 @@ trait MyIter { fn test_mut(&mut self); } -impl MyIter for &'self [int] { +impl<'self> MyIter for &'self [int] { fn test_mut(&mut self) { } } diff --git a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs index fe7b29cf9a868..4a6a90ae5167f 100644 --- a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs +++ b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs @@ -8,12 +8,12 @@ // 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); @@ -21,7 +21,7 @@ impl Drop for defer<'self> { } } -fn defer(x: &'r [&'r str]) -> defer<'r> { +fn defer<'r>(x: &'r [&'r str]) -> defer<'r> { defer { x: x } diff --git a/src/test/compile-fail/issue-1896-1.rs b/src/test/compile-fail/issue-1896-1.rs index bf130addb6bf6..e42382fc2aa48 100644 --- a/src/test/compile-fail/issue-1896-1.rs +++ b/src/test/compile-fail/issue-1896-1.rs @@ -8,7 +8,7 @@ // 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; diff --git a/src/test/compile-fail/issue-3154.rs b/src/test/compile-fail/issue-3154.rs index 615bf64eed54e..bcbf90b660eff 100644 --- a/src/test/compile-fail/issue-3154.rs +++ b/src/test/compile-fail/issue-3154.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct thing { +struct thing<'self, Q> { x: &'self Q } diff --git a/src/test/compile-fail/issue-3311.rs b/src/test/compile-fail/issue-3311.rs index 1b83cefbf3398..07800c0a762a5 100644 --- a/src/test/compile-fail/issue-3311.rs +++ b/src/test/compile-fail/issue-3311.rs @@ -9,12 +9,12 @@ // 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 } diff --git a/src/test/compile-fail/issue-3888.rs b/src/test/compile-fail/issue-3888.rs index c9a5507f8de0f..d9ea384d820c4 100644 --- a/src/test/compile-fail/issue-3888.rs +++ b/src/test/compile-fail/issue-3888.rs @@ -10,7 +10,7 @@ // 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(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 { diff --git a/src/test/compile-fail/non-constant-expr-for-fixed-len-vec.rs b/src/test/compile-fail/non-constant-expr-for-fixed-len-vec.rs index 86262008ff943..857b53a2c226e 100644 --- a/src/test/compile-fail/non-constant-expr-for-fixed-len-vec.rs +++ b/src/test/compile-fail/non-constant-expr-for-fixed-len-vec.rs @@ -12,6 +12,6 @@ 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 } } diff --git a/src/test/compile-fail/regions-bounds.rs b/src/test/compile-fail/regions-bounds.rs index 3821035a0f6e3..cccd135e9f836 100644 --- a/src/test/compile-fail/regions-bounds.rs +++ b/src/test/compile-fail/regions-bounds.rs @@ -12,18 +12,18 @@ // 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; diff --git a/src/test/compile-fail/regions-creating-enums.rs b/src/test/compile-fail/regions-creating-enums.rs index 88f2eefd36905..7a8038bbb887a 100644 --- a/src/test/compile-fail/regions-creating-enums.rs +++ b/src/test/compile-fail/regions-creating-enums.rs @@ -10,7 +10,7 @@ #[legacy_modes]; -enum ast { +enum ast<'self> { num(uint), add(&'self ast<'self>, &'self ast<'self>) } diff --git a/src/test/compile-fail/regions-creating-enums3.rs b/src/test/compile-fail/regions-creating-enums3.rs index de0f18392e643..08243bace90af 100644 --- a/src/test/compile-fail/regions-creating-enums3.rs +++ b/src/test/compile-fail/regions-creating-enums3.rs @@ -8,12 +8,12 @@ // 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 } diff --git a/src/test/compile-fail/regions-creating-enums4.rs b/src/test/compile-fail/regions-creating-enums4.rs index d9a6c48fa27e5..1cb378cf406f8 100644 --- a/src/test/compile-fail/regions-creating-enums4.rs +++ b/src/test/compile-fail/regions-creating-enums4.rs @@ -13,7 +13,7 @@ enum ast<'self> { 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 } diff --git a/src/test/compile-fail/regions-escape-via-trait-or-not.rs b/src/test/compile-fail/regions-escape-via-trait-or-not.rs index 1b737c273dbf0..fb9d963dc80a7 100644 --- a/src/test/compile-fail/regions-escape-via-trait-or-not.rs +++ b/src/test/compile-fail/regions-escape-via-trait-or-not.rs @@ -12,7 +12,7 @@ trait deref { fn get(self) -> int; } -impl deref for &'self int { +impl<'self> deref for &'self int { fn get(self) -> int { *self } diff --git a/src/test/compile-fail/regions-fn-subtyping.rs b/src/test/compile-fail/regions-fn-subtyping.rs index a90b3d0f42970..face9c742141d 100644 --- a/src/test/compile-fail/regions-fn-subtyping.rs +++ b/src/test/compile-fail/regions-fn-subtyping.rs @@ -11,47 +11,47 @@ fn of() -> @fn(T) { fail!(); } fn subtype(x: @fn(T)) { fail!(); } -fn test_fn(_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::(of::()) 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() {} diff --git a/src/test/compile-fail/regions-fns.rs b/src/test/compile-fail/regions-fns.rs index 50eba71ac5647..4f6cbdfdd6556 100644 --- a/src/test/compile-fail/regions-fns.rs +++ b/src/test/compile-fail/regions-fns.rs @@ -11,7 +11,7 @@ // 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); diff --git a/src/test/compile-fail/regions-glb-free-free.rs b/src/test/compile-fail/regions-glb-free-free.rs index f5e304dbe722c..1ae97d690ac24 100644 --- a/src/test/compile-fail/regions-glb-free-free.rs +++ b/src/test/compile-fail/regions-glb-free-free.rs @@ -18,11 +18,11 @@ mod argparse { 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, diff --git a/src/test/compile-fail/regions-in-enums.rs b/src/test/compile-fail/regions-in-enums.rs index 0adfaccdc0174..0111be367c228 100644 --- a/src/test/compile-fail/regions-in-enums.rs +++ b/src/test/compile-fail/regions-in-enums.rs @@ -10,15 +10,15 @@ 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() {} diff --git a/src/test/compile-fail/regions-in-structs.rs b/src/test/compile-fail/regions-in-structs.rs index b425a40114a3d..977c9fc55196c 100644 --- a/src/test/compile-fail/regions-in-structs.rs +++ b/src/test/compile-fail/regions-in-structs.rs @@ -17,7 +17,7 @@ struct yes1<'self> { } 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() {} diff --git a/src/test/compile-fail/regions-in-type-items.rs b/src/test/compile-fail/regions-in-type-items.rs index 2a72744c9b6fe..65bc64815b61a 100644 --- a/src/test/compile-fail/regions-in-type-items.rs +++ b/src/test/compile-fail/regions-in-type-items.rs @@ -8,16 +8,16 @@ // 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() {} diff --git a/src/test/compile-fail/regions-infer-at-fn-not-param.rs b/src/test/compile-fail/regions-infer-at-fn-not-param.rs index bde0e3f80c0fd..c8813b73e6b3a 100644 --- a/src/test/compile-fail/regions-infer-at-fn-not-param.rs +++ b/src/test/compile-fail/regions-infer-at-fn-not-param.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct parameterized1 { +struct parameterized1<'self> { g: &'self fn() } diff --git a/src/test/compile-fail/regions-infer-borrow-scope-too-big.rs b/src/test/compile-fail/regions-infer-borrow-scope-too-big.rs index 6402982a9e154..7e96ecd4142a7 100644 --- a/src/test/compile-fail/regions-infer-borrow-scope-too-big.rs +++ b/src/test/compile-fail/regions-infer-borrow-scope-too-big.rs @@ -13,7 +13,7 @@ struct point { y: int, } -fn x_coord(p: &'r point) -> &'r int { +fn x_coord<'r>(p: &'r point) -> &'r int { return &p.x; } diff --git a/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs b/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs index c873e2519bd02..d982d3c95a578 100644 --- a/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs +++ b/src/test/compile-fail/regions-infer-borrow-scope-within-loop.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn borrow(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: ∫ diff --git a/src/test/compile-fail/regions-infer-call-3.rs b/src/test/compile-fail/regions-infer-call-3.rs index a3bc55228d853..585b56d5a420b 100644 --- a/src/test/compile-fail/regions-infer-call-3.rs +++ b/src/test/compile-fail/regions-infer-call-3.rs @@ -8,13 +8,13 @@ // 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(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 diff --git a/src/test/compile-fail/regions-infer-contravariance-due-to-immutability.rs b/src/test/compile-fail/regions-infer-contravariance-due-to-immutability.rs index 0b7477a30989e..83e39ebd9f4d0 100644 --- a/src/test/compile-fail/regions-infer-contravariance-due-to-immutability.rs +++ b/src/test/compile-fail/regions-infer-contravariance-due-to-immutability.rs @@ -8,19 +8,19 @@ // 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 } diff --git a/src/test/compile-fail/regions-infer-covariance-due-to-arg.rs b/src/test/compile-fail/regions-infer-covariance-due-to-arg.rs index c92d770b1b6e4..85cc6e6ce2487 100644 --- a/src/test/compile-fail/regions-infer-covariance-due-to-arg.rs +++ b/src/test/compile-fail/regions-infer-covariance-due-to-arg.rs @@ -12,7 +12,7 @@ // // You can upcast to a *larger region* but not a smaller one. -struct covariant { +struct covariant<'self> { f: @fn(x: &'self int) -> int } diff --git a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-1.rs b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-1.rs index b1d0249380f46..a5eeb83989f82 100644 --- a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-1.rs +++ b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-1.rs @@ -8,19 +8,15 @@ // 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 } diff --git a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-2.rs b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-2.rs index ae62ef6f39a26..8adf353bb82f6 100644 --- a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-2.rs +++ b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-2.rs @@ -12,15 +12,11 @@ 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 } diff --git a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs index 4c9d397f971da..92447c1ef8d45 100644 --- a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs +++ b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs @@ -16,11 +16,7 @@ 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 } diff --git a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs index 6789476974b7a..61adba3aec134 100644 --- a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs +++ b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs @@ -12,15 +12,11 @@ struct invariant<'self> { 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 } diff --git a/src/test/compile-fail/regions-nested-fns-2.rs b/src/test/compile-fail/regions-nested-fns-2.rs index 26d6bbd530314..2e9a4eb141037 100644 --- a/src/test/compile-fail/regions-nested-fns-2.rs +++ b/src/test/compile-fail/regions-nested-fns-2.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn ignore(_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 }); } diff --git a/src/test/compile-fail/regions-nested-fns.rs b/src/test/compile-fail/regions-nested-fns.rs index 6ef37efeb418e..3089c362a5044 100644 --- a/src/test/compile-fail/regions-nested-fns.rs +++ b/src/test/compile-fail/regions-nested-fns.rs @@ -10,17 +10,17 @@ fn ignore(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; diff --git a/src/test/compile-fail/regions-ret-borrowed-1.rs b/src/test/compile-fail/regions-ret-borrowed-1.rs index 7218dcf379b95..f916b0d95c2ee 100644 --- a/src/test/compile-fail/regions-ret-borrowed-1.rs +++ b/src/test/compile-fail/regions-ret-borrowed-1.rs @@ -12,11 +12,11 @@ // some point regions-ret-borrowed reported an error but this file did // not, due to special hardcoding around the anonymous region. -fn with(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 } diff --git a/src/test/compile-fail/regions-ret.rs b/src/test/compile-fail/regions-ret.rs index cecd847843ca5..be7b28f6ef4b5 100644 --- a/src/test/compile-fail/regions-ret.rs +++ b/src/test/compile-fail/regions-ret.rs @@ -8,7 +8,7 @@ // 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 } diff --git a/src/test/compile-fail/regions-scoping.rs b/src/test/compile-fail/regions-scoping.rs deleted file mode 100644 index f0c81d16b03c7..0000000000000 --- a/src/test/compile-fail/regions-scoping.rs +++ /dev/null @@ -1,55 +0,0 @@ -// 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn with(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() {} diff --git a/src/test/compile-fail/regions-steal-closure.rs b/src/test/compile-fail/regions-steal-closure.rs index 8b12813447ef2..be034eda67dcf 100644 --- a/src/test/compile-fail/regions-steal-closure.rs +++ b/src/test/compile-fail/regions-steal-closure.rs @@ -12,7 +12,7 @@ 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} } diff --git a/src/test/compile-fail/regions-trait-1.rs b/src/test/compile-fail/regions-trait-1.rs index 74afdf117588c..2f455e89dff90 100644 --- a/src/test/compile-fail/regions-trait-1.rs +++ b/src/test/compile-fail/regions-trait-1.rs @@ -15,9 +15,9 @@ trait get_ctxt { 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 `&`: diff --git a/src/test/run-pass/assignability-trait.rs b/src/test/run-pass/assignability-trait.rs index 78bdee1430c69..c9e42aadfd446 100644 --- a/src/test/run-pass/assignability-trait.rs +++ b/src/test/run-pass/assignability-trait.rs @@ -16,7 +16,7 @@ trait iterable { fn iterate(&self, blk: &fn(x: &A) -> bool); } -impl iterable for &'self [A] { +impl<'self,A> iterable for &'self [A] { fn iterate(&self, f: &fn(x: &A) -> bool) { for vec::each(*self) |e| { if !f(e) { break; } diff --git a/src/test/run-pass/auto-ref-slice-plus-ref.rs b/src/test/run-pass/auto-ref-slice-plus-ref.rs index 65366a350efa3..36c4ac2ad4939 100644 --- a/src/test/run-pass/auto-ref-slice-plus-ref.rs +++ b/src/test/run-pass/auto-ref-slice-plus-ref.rs @@ -16,12 +16,12 @@ trait MyIter { 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") } } diff --git a/src/test/run-pass/borrow-by-val-method-receiver.rs b/src/test/run-pass/borrow-by-val-method-receiver.rs index 02dbfeda25869..fdb51124f0eb9 100644 --- a/src/test/run-pass/borrow-by-val-method-receiver.rs +++ b/src/test/run-pass/borrow-by-val-method-receiver.rs @@ -12,7 +12,7 @@ trait Foo { fn foo(self); } -impl Foo for &'self [int] { +impl<'self> Foo for &'self [int] { fn foo(self) {} } diff --git a/src/test/run-pass/borrowck-root-while-cond.rs b/src/test/run-pass/borrowck-root-while-cond.rs index a8823c477aa3c..77e4f512ebf4b 100644 --- a/src/test/run-pass/borrowck-root-while-cond.rs +++ b/src/test/run-pass/borrowck-root-while-cond.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn borrow(x: &'r T) -> &'r T {x} +fn borrow<'r,T>(x: &'r T) -> &'r T {x} struct Rec { f: @int } diff --git a/src/test/run-pass/borrowed-ptr-pattern-3.rs b/src/test/run-pass/borrowed-ptr-pattern-3.rs index 1e9175ac1963c..4bdecd5eeec0e 100644 --- a/src/test/run-pass/borrowed-ptr-pattern-3.rs +++ b/src/test/run-pass/borrowed-ptr-pattern-3.rs @@ -8,7 +8,7 @@ // 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 diff --git a/src/test/run-pass/borrowed-ptr-pattern-option.rs b/src/test/run-pass/borrowed-ptr-pattern-option.rs index 42c0795b3dd29..ebd5cf41db550 100644 --- a/src/test/run-pass/borrowed-ptr-pattern-option.rs +++ b/src/test/run-pass/borrowed-ptr-pattern-option.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn select(x: &'r Option, y: &'r Option) -> &'r Option { +fn select<'r>(x: &'r Option, y: &'r Option) -> &'r Option { match (x, y) { (&None, &None) => x, (&Some(_), _) => x, diff --git a/src/test/run-pass/class-impl-very-parameterized-trait.rs b/src/test/run-pass/class-impl-very-parameterized-trait.rs index 281d520be0f60..bc6972bfb2753 100644 --- a/src/test/run-pass/class-impl-very-parameterized-trait.rs +++ b/src/test/run-pass/class-impl-very-parameterized-trait.rs @@ -49,7 +49,7 @@ pub impl cat { } } -impl BaseIter<(int, &'self T)> for cat { +impl<'self,T> BaseIter<(int, &'self T)> for cat { fn each(&self, f: &fn(&(int, &'self T)) -> bool) { let mut n = int::abs(self.meows); while n > 0 { diff --git a/src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs b/src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs index 2ca19b2299ac2..c656dfd1530d5 100644 --- a/src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs +++ b/src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs @@ -2,7 +2,7 @@ trait Reverser { fn reverse(&self); } -impl Reverser for &'self mut [uint] { +impl<'self> Reverser for &'self mut [uint] { fn reverse(&self) { vec::reverse(*self); } diff --git a/src/test/run-pass/const-fn-val.rs b/src/test/run-pass/const-fn-val.rs index b3667d4f81ebe..f08fc3be0742a 100644 --- a/src/test/run-pass/const-fn-val.rs +++ b/src/test/run-pass/const-fn-val.rs @@ -12,7 +12,7 @@ fn foo() -> int { return 0xca7f000d; } -struct Bar { f: &'self fn() -> int } +struct Bar<'self> { f: &'self fn() -> int } static b : Bar<'static> = Bar { f: foo }; diff --git a/src/test/run-pass/const-region-ptrs-noncopy.rs b/src/test/run-pass/const-region-ptrs-noncopy.rs index 46f9fdb08217b..a0d16a3ec3ab1 100644 --- a/src/test/run-pass/const-region-ptrs-noncopy.rs +++ b/src/test/run-pass/const-region-ptrs-noncopy.rs @@ -9,7 +9,7 @@ // 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}; diff --git a/src/test/run-pass/const-region-ptrs.rs b/src/test/run-pass/const-region-ptrs.rs index 32c5f65bf3ade..6c501ebf9389a 100644 --- a/src/test/run-pass/const-region-ptrs.rs +++ b/src/test/run-pass/const-region-ptrs.rs @@ -9,7 +9,7 @@ // 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; diff --git a/src/test/run-pass/explicit-self.rs b/src/test/run-pass/explicit-self.rs index 3e48b8f05baee..c41fa52bf15f4 100644 --- a/src/test/run-pass/explicit-self.rs +++ b/src/test/run-pass/explicit-self.rs @@ -28,13 +28,13 @@ fn compute_area(shape: &shape) -> float { pub impl shape { // self is in the implicit self region - fn select(&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( +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); diff --git a/src/test/run-pass/infer-with-expected.rs b/src/test/run-pass/infer-with-expected.rs index 1bd6304fabc26..9dfe7e45c1194 100644 --- a/src/test/run-pass/infer-with-expected.rs +++ b/src/test/run-pass/infer-with-expected.rs @@ -16,7 +16,7 @@ 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() { diff --git a/src/test/run-pass/issue-2502.rs b/src/test/run-pass/issue-2502.rs index 6dd8e3d83de87..34eb591b73aa4 100644 --- a/src/test/run-pass/issue-2502.rs +++ b/src/test/run-pass/issue-2502.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct font { +struct font<'self> { fontbuf: &'self ~[u8], } @@ -18,7 +18,7 @@ pub impl<'self> font<'self> { } } -fn font(fontbuf: &'r ~[u8]) -> font<'r> { +fn font<'r>(fontbuf: &'r ~[u8]) -> font<'r> { font { fontbuf: fontbuf } diff --git a/src/test/run-pass/issue-2735-2.rs b/src/test/run-pass/issue-2735-2.rs index 3f13b9f9e67ad..396175716b210 100644 --- a/src/test/run-pass/issue-2735-2.rs +++ b/src/test/run-pass/issue-2735-2.rs @@ -9,7 +9,7 @@ // except according to those terms. // This test should behave exactly like issue-2735-3 -struct defer { +struct defer<'self> { b: &'self mut bool, } diff --git a/src/test/run-pass/issue-2735-3.rs b/src/test/run-pass/issue-2735-3.rs index 40c71eec4d38a..7b5f19f1434dc 100644 --- a/src/test/run-pass/issue-2735-3.rs +++ b/src/test/run-pass/issue-2735-3.rs @@ -9,7 +9,7 @@ // except according to those terms. // This test should behave exactly like issue-2735-2 -struct defer { +struct defer<'self> { b: &'self mut bool, } @@ -22,7 +22,7 @@ impl<'self> Drop for defer<'self> { } } -fn defer(b: &'r mut bool) -> defer<'r> { +fn defer<'r>(b: &'r mut bool) -> defer<'r> { defer { b: b } diff --git a/src/test/run-pass/issue-2748-a.rs b/src/test/run-pass/issue-2748-a.rs index 8a0f64b32d497..63807de22dd42 100644 --- a/src/test/run-pass/issue-2748-a.rs +++ b/src/test/run-pass/issue-2748-a.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct CMap { +struct CMap<'self> { buf: &'self [u8], } diff --git a/src/test/run-pass/issue-2748-b.rs b/src/test/run-pass/issue-2748-b.rs index 62016abf74b35..630448d278214 100644 --- a/src/test/run-pass/issue-2748-b.rs +++ b/src/test/run-pass/issue-2748-b.rs @@ -8,7 +8,8 @@ // 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; diff --git a/src/test/run-pass/issue-3447.rs b/src/test/run-pass/issue-3447.rs index 816678fa3208e..191259e5a57e2 100644 --- a/src/test/run-pass/issue-3447.rs +++ b/src/test/run-pass/issue-3447.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct list { +struct list<'self, T> { element: &'self T, next: Option<@mut list<'self, T>> } diff --git a/src/test/run-pass/issue-3888-2.rs b/src/test/run-pass/issue-3888-2.rs index 38aeab0888c60..2992d9a4ac837 100644 --- a/src/test/run-pass/issue-3888-2.rs +++ b/src/test/run-pass/issue-3888-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn vec_peek(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) diff --git a/src/test/run-pass/rcvr-borrowed-to-slice.rs b/src/test/run-pass/rcvr-borrowed-to-slice.rs index 9328189c47cc3..fc62ea67eab21 100644 --- a/src/test/run-pass/rcvr-borrowed-to-slice.rs +++ b/src/test/run-pass/rcvr-borrowed-to-slice.rs @@ -13,7 +13,7 @@ trait sum { } // 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; } diff --git a/src/test/run-pass/region-dependent-addr-of.rs b/src/test/run-pass/region-dependent-addr-of.rs index 982515b61219f..e7edeca3b9a19 100644 --- a/src/test/run-pass/region-dependent-addr-of.rs +++ b/src/test/run-pass/region-dependent-addr-of.rs @@ -25,54 +25,54 @@ struct C { 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 } diff --git a/src/test/run-pass/region-return-interior-of-option.rs b/src/test/run-pass/region-return-interior-of-option.rs index ced2948545f4a..5fd3da67a1779 100644 --- a/src/test/run-pass/region-return-interior-of-option.rs +++ b/src/test/run-pass/region-return-interior-of-option.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn get(opt: &'r Option) -> &'r T { +fn get<'r, T>(opt: &'r Option) -> &'r T { match *opt { Some(ref v) => v, None => fail!(~"none") diff --git a/src/test/run-pass/regions-addr-of-interior-of-unique-box.rs b/src/test/run-pass/regions-addr-of-interior-of-unique-box.rs index 40a8b6164dc75..1fb9c126e74e2 100644 --- a/src/test/run-pass/regions-addr-of-interior-of-unique-box.rs +++ b/src/test/run-pass/regions-addr-of-interior-of-unique-box.rs @@ -17,7 +17,7 @@ struct Character { 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 diff --git a/src/test/run-pass/regions-addr-of-ret.rs b/src/test/run-pass/regions-addr-of-ret.rs index 622a1eb9954cf..a9c65d012954c 100644 --- a/src/test/run-pass/regions-addr-of-ret.rs +++ b/src/test/run-pass/regions-addr-of-ret.rs @@ -8,7 +8,7 @@ // 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; } diff --git a/src/test/run-pass/regions-copy-closure.rs b/src/test/run-pass/regions-copy-closure.rs index 0fc8cb49f0777..54cfb5f5fcc75 100644 --- a/src/test/run-pass/regions-copy-closure.rs +++ b/src/test/run-pass/regions-copy-closure.rs @@ -8,7 +8,7 @@ // 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(), } diff --git a/src/test/run-pass/regions-creating-enums2.rs b/src/test/run-pass/regions-creating-enums2.rs index c0bbdca07aafb..a9a6aa0c70917 100644 --- a/src/test/run-pass/regions-creating-enums2.rs +++ b/src/test/run-pass/regions-creating-enums2.rs @@ -8,12 +8,12 @@ // 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) } diff --git a/src/test/run-pass/regions-creating-enums5.rs b/src/test/run-pass/regions-creating-enums5.rs index aeb167c5b6d18..1c8ed8a3dcd5b 100644 --- a/src/test/run-pass/regions-creating-enums5.rs +++ b/src/test/run-pass/regions-creating-enums5.rs @@ -8,12 +8,12 @@ // 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) } diff --git a/src/test/run-pass/regions-equiv-fns.rs b/src/test/run-pass/regions-equiv-fns.rs deleted file mode 100644 index 86b997a6008a7..0000000000000 --- a/src/test/run-pass/regions-equiv-fns.rs +++ /dev/null @@ -1,23 +0,0 @@ -// 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 or the MIT license -// , 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() { -} - - diff --git a/src/test/run-pass/regions-escape-into-other-fn.rs b/src/test/run-pass/regions-escape-into-other-fn.rs index e38bd64da64fa..d9e5831024615 100644 --- a/src/test/run-pass/regions-escape-into-other-fn.rs +++ b/src/test/run-pass/regions-escape-into-other-fn.rs @@ -8,7 +8,7 @@ // 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() { diff --git a/src/test/run-pass/regions-fn-subtyping.rs b/src/test/run-pass/regions-fn-subtyping.rs index 981eace675498..652a7a3339617 100644 --- a/src/test/run-pass/regions-fn-subtyping.rs +++ b/src/test/run-pass/regions-fn-subtyping.rs @@ -18,14 +18,14 @@ fn ok(f: @fn(x: &uint)) { // 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; } diff --git a/src/test/run-pass/regions-infer-borrow-scope-view.rs b/src/test/run-pass/regions-infer-borrow-scope-view.rs index 5aff0274dc47c..7c970253b98ab 100644 --- a/src/test/run-pass/regions-infer-borrow-scope-view.rs +++ b/src/test/run-pass/regions-infer-borrow-scope-view.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn view(x: &'r [T]) -> &'r [T] {x} +fn view<'r, T>(x: &'r [T]) -> &'r [T] {x} pub fn main() { let v = ~[1, 2, 3]; diff --git a/src/test/run-pass/regions-infer-borrow-scope-within-loop-ok.rs b/src/test/run-pass/regions-infer-borrow-scope-within-loop-ok.rs index fd48402dd10ab..a184f47b65f57 100644 --- a/src/test/run-pass/regions-infer-borrow-scope-within-loop-ok.rs +++ b/src/test/run-pass/regions-infer-borrow-scope-within-loop-ok.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn borrow(x: &'r T) -> &'r T {x} +fn borrow<'r, T>(x: &'r T) -> &'r T {x} pub fn main() { let x = @3; diff --git a/src/test/run-pass/regions-infer-borrow-scope.rs b/src/test/run-pass/regions-infer-borrow-scope.rs index b5dbf0fde5cdf..a3cb1e32eb5e6 100644 --- a/src/test/run-pass/regions-infer-borrow-scope.rs +++ b/src/test/run-pass/regions-infer-borrow-scope.rs @@ -10,7 +10,7 @@ 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; } diff --git a/src/test/run-pass/regions-infer-call-2.rs b/src/test/run-pass/regions-infer-call-2.rs index 74c4c4260fc1a..9933d55f7476e 100644 --- a/src/test/run-pass/regions-infer-call-2.rs +++ b/src/test/run-pass/regions-infer-call-2.rs @@ -14,7 +14,7 @@ fn with(f: &fn(x: &int) -> T) -> T { f(&20) } -fn has_one(x: &'a int) -> int { +fn has_one<'a>(x: &'a int) -> int { do with |y| { takes_two(x, y) } } diff --git a/src/test/run-pass/regions-infer-call.rs b/src/test/run-pass/regions-infer-call.rs index 66baaf4010895..e83f11de31d12 100644 --- a/src/test/run-pass/regions-infer-call.rs +++ b/src/test/run-pass/regions-infer-call.rs @@ -10,7 +10,7 @@ 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) } diff --git a/src/test/run-pass/regions-infer-contravariance-due-to-ret.rs b/src/test/run-pass/regions-infer-contravariance-due-to-ret.rs index c45212eaa6264..d45925229fa7c 100644 --- a/src/test/run-pass/regions-infer-contravariance-due-to-ret.rs +++ b/src/test/run-pass/regions-infer-contravariance-due-to-ret.rs @@ -8,11 +8,11 @@ // 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} } diff --git a/src/test/run-pass/regions-infer-contravariance.rs b/src/test/run-pass/regions-infer-contravariance.rs deleted file mode 100644 index ef2be398b64d1..0000000000000 --- a/src/test/run-pass/regions-infer-contravariance.rs +++ /dev/null @@ -1,31 +0,0 @@ -// 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 or the MIT license -// , 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); -} diff --git a/src/test/run-pass/regions-mock-trans-impls.rs b/src/test/run-pass/regions-mock-trans-impls.rs index df8a4f6f770b6..c1f7a713ca679 100644 --- a/src/test/run-pass/regions-mock-trans-impls.rs +++ b/src/test/run-pass/regions-mock-trans-impls.rs @@ -16,11 +16,11 @@ use core::sys; 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 } @@ -29,7 +29,7 @@ struct 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 }); } diff --git a/src/test/run-pass/regions-mock-trans.rs b/src/test/run-pass/regions-mock-trans.rs index 717588ab4cb9d..a74bc82569bf0 100644 --- a/src/test/run-pass/regions-mock-trans.rs +++ b/src/test/run-pass/regions-mock-trans.rs @@ -10,11 +10,11 @@ struct arena(()); -struct Bcx { +struct Bcx<'self> { fcx: &'self Fcx<'self> } -struct Fcx { +struct Fcx<'self> { arena: &'self arena, ccx: &'self Ccx } @@ -23,14 +23,14 @@ struct 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::>() 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); } diff --git a/src/test/run-pass/regions-nullary-variant.rs b/src/test/run-pass/regions-nullary-variant.rs index da03864338bdc..e842ed585be80 100644 --- a/src/test/run-pass/regions-nullary-variant.rs +++ b/src/test/run-pass/regions-nullary-variant.rs @@ -8,11 +8,11 @@ // 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)} } diff --git a/src/test/run-pass/regions-params.rs b/src/test/run-pass/regions-params.rs index 1066c5fd4ca70..cc5b89405aac9 100644 --- a/src/test/run-pass/regions-params.rs +++ b/src/test/run-pass/regions-params.rs @@ -10,7 +10,7 @@ // 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, f: &fn(T) -> T) -> T { f(t) } diff --git a/src/test/run-pass/regions-self-in-enums.rs b/src/test/run-pass/regions-self-in-enums.rs index e71dbb0054bcc..78045e5e5d410 100644 --- a/src/test/run-pass/regions-self-in-enums.rs +++ b/src/test/run-pass/regions-self-in-enums.rs @@ -8,7 +8,7 @@ // 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) } diff --git a/src/test/run-pass/regions-static-closure.rs b/src/test/run-pass/regions-static-closure.rs index 5673a1e50f070..5221bc28fb838 100644 --- a/src/test/run-pass/regions-static-closure.rs +++ b/src/test/run-pass/regions-static-closure.rs @@ -8,11 +8,11 @@ // 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} } diff --git a/src/test/run-pass/regions-trait.rs b/src/test/run-pass/regions-trait.rs index 481f25745cd4d..92ef18967b361 100644 --- a/src/test/run-pass/regions-trait.rs +++ b/src/test/run-pass/regions-trait.rs @@ -10,13 +10,13 @@ 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 } diff --git a/src/test/run-pass/struct-field-assignability.rs b/src/test/run-pass/struct-field-assignability.rs index 61b09239bc1d9..f877a766ead6f 100644 --- a/src/test/run-pass/struct-field-assignability.rs +++ b/src/test/run-pass/struct-field-assignability.rs @@ -1,4 +1,4 @@ -struct Foo { +struct Foo<'self> { x: &'self int }