diff --git a/doc/rust.md b/doc/rust.md index 287dcb950f772..26ea276dd7c8c 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/compiletest/compiletest.rc b/src/compiletest/compiletest.rc index 738045705a2b5..e213f4fc6da34 100644 --- a/src/compiletest/compiletest.rc +++ b/src/compiletest/compiletest.rc @@ -22,12 +22,6 @@ extern mod std(vers = "0.6"); use core::*; -pub mod procsrv; -pub mod util; -pub mod header; -pub mod runtest; -pub mod common; -pub mod errors; use std::getopts; use std::test; @@ -43,6 +37,13 @@ use common::mode_debug_info; use common::mode; use util::logv; +pub mod procsrv; +pub mod util; +pub mod header; +pub mod runtest; +pub mod common; +pub mod errors; + pub fn main() { let args = os::args(); let config = parse_config(args); diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index dbc132899d90e..c96a6502eecf7 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -38,7 +38,7 @@ pub mod rustrt { /// Returns the number of elements the vector can hold without reallocating #[inline(always)] -pub fn capacity(v: @[const T]) -> uint { +pub fn capacity(v: @[T]) -> uint { unsafe { let repr: **raw::VecRepr = ::cast::reinterpret_cast(&addr_of(&v)); @@ -60,7 +60,7 @@ pub fn capacity(v: @[const T]) -> uint { */ #[inline(always)] pub fn build_sized(size: uint, builder: &fn(push: &fn(v: A))) -> @[A] { - let mut vec: @[const A] = @[]; + let mut vec: @[A] = @[]; unsafe { raw::reserve(&mut vec, size); } builder(|+x| unsafe { raw::push(&mut vec, x) }); return unsafe { transmute(vec) }; @@ -102,7 +102,7 @@ pub fn build_sized_opt(size: Option, // Appending #[inline(always)] -pub fn append(lhs: @[T], rhs: &[const T]) -> @[T] { +pub fn append(lhs: @[T], rhs: &const [T]) -> @[T] { do build_sized(lhs.len() + rhs.len()) |push| { for vec::each(lhs) |x| { push(*x); } for uint::range(0, rhs.len()) |i| { push(rhs[i]); } @@ -174,9 +174,9 @@ 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] { + fn add(&self, rhs: & &'self const [T]) -> @[T] { append(*self, (*rhs)) } } @@ -207,13 +207,13 @@ pub mod raw { * the vector is actually the specified size. */ #[inline(always)] - pub unsafe fn set_len(v: @[const T], new_len: uint) { + pub unsafe fn set_len(v: @[T], new_len: uint) { let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(&v)); (**repr).unboxed.fill = new_len * sys::size_of::(); } #[inline(always)] - pub unsafe fn push(v: &mut @[const T], initval: T) { + pub unsafe fn push(v: &mut @[T], initval: T) { let repr: **VecRepr = ::cast::reinterpret_cast(&v); let fill = (**repr).unboxed.fill; if (**repr).unboxed.alloc > fill { @@ -225,7 +225,7 @@ pub mod raw { } #[inline(always)] // really pretty please - pub unsafe fn push_fast(v: &mut @[const T], initval: T) { + pub unsafe fn push_fast(v: &mut @[T], initval: T) { let repr: **VecRepr = ::cast::reinterpret_cast(&v); let fill = (**repr).unboxed.fill; (**repr).unboxed.fill += sys::size_of::(); @@ -234,7 +234,7 @@ pub mod raw { move_val_init(&mut(*p), initval); } - pub unsafe fn push_slow(v: &mut @[const T], initval: T) { + pub unsafe fn push_slow(v: &mut @[T], initval: T) { reserve_at_least(&mut *v, v.len() + 1u); push_fast(v, initval); } @@ -250,7 +250,7 @@ pub mod raw { * * v - A vector * * n - The number of elements to reserve space for */ - pub unsafe fn reserve(v: &mut @[const T], n: uint) { + pub unsafe fn reserve(v: &mut @[T], n: uint) { // Only make the (slow) call into the runtime if we have to if capacity(*v) < n { let ptr: **VecRepr = transmute(v); @@ -274,7 +274,7 @@ pub mod raw { * * v - A vector * * n - The number of elements to reserve space for */ - pub unsafe fn reserve_at_least(v: &mut @[const T], n: uint) { + pub unsafe fn reserve_at_least(v: &mut @[T], n: uint) { reserve(v, uint::next_power_of_two(n)); } 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 66eeb339700e8..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; @@ -38,12 +38,12 @@ struct MemoryRegion { priv opaque: () } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] struct Registers { - data: [u32 * 16] + data: [u32, ..16] } #[cfg(target_arch="mips")] struct Registers { - data: [u32 * 32] + data: [u32, ..32] } #[cfg(target_arch="x86")] @@ -52,12 +52,12 @@ struct Registers { struct Context { regs: Registers, next: *Context, - pad: [u32 * 3] + pad: [u32, ..3] } #[cfg(target_arch="x86_64")] struct Registers { - data: [u64 * 22] + data: [u64, ..22] } #[cfg(target_arch="x86_64")] @@ -80,7 +80,7 @@ struct Task { // Public fields refcount: intptr_t, // 0 id: TaskID, // 4 - pad: [u32 * 2], // 8 + pad: [u32, ..2], // 8 ctx: Context, // 16 stack_segment: *StackSegment, // 96 runtime_sp: uintptr_t, // 100 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/core.rc b/src/libcore/core.rc index 35a016c3cb097..4d91e8f2993db 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -65,6 +65,45 @@ they contained the following prologue: #[allow(deprecated_mutable_fields)]; #[allow(deprecated_drop)]; +// Make core testable by not duplicating lang items. See #2912 +#[cfg(test)] extern mod realcore(name = "core", vers = "0.6"); +#[cfg(test)] pub use kinds = realcore::kinds; +#[cfg(test)] pub use ops = realcore::ops; +#[cfg(test)] pub use cmp = realcore::cmp; + +/* Reexported core operators */ + +pub use kinds::{Const, Copy, Owned, Durable}; +pub use ops::{Drop}; +pub use ops::{Add, Sub, Mul, Div, Modulo, Neg, Not}; +pub use ops::{BitAnd, BitOr, BitXor}; +pub use ops::{Shl, Shr, Index}; + + +/* Reexported types and traits */ + +pub use option::{Option, Some, None}; +pub use result::{Result, Ok, Err}; + +pub use path::Path; +pub use path::GenericPath; +pub use path::WindowsPath; +pub use path::PosixPath; + +pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps}; +pub use str::{StrSlice}; +pub use container::{Container, Mutable}; +pub use vec::{CopyableVector, ImmutableVector}; +pub use vec::{ImmutableEqVector, ImmutableCopyableVector}; +pub use vec::{OwnedVector, OwnedCopyableVector}; +pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter}; +pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times}; + +pub use num::NumCast; +pub use ptr::Ptr; +pub use to_str::ToStr; +pub use clone::Clone; + // On Linux, link to the runtime with -lrt. #[cfg(target_os = "linux")] #[doc(hidden)] @@ -130,12 +169,6 @@ pub mod managed; #[cfg(notest)] pub mod ops; #[cfg(notest)] pub mod cmp; -// Make core testable by not duplicating lang items. See #2912 -#[cfg(test)] extern mod realcore(name = "core", vers = "0.6"); -#[cfg(test)] pub use kinds = realcore::kinds; -#[cfg(test)] pub use ops = realcore::ops; -#[cfg(test)] pub use cmp = realcore::cmp; - /* Common traits */ @@ -189,39 +222,6 @@ pub mod condition; pub mod logging; pub mod util; -/* Reexported core operators */ - -pub use kinds::{Const, Copy, Owned, Durable}; -pub use ops::{Drop}; -pub use ops::{Add, Sub, Mul, Div, Modulo, Neg, Not}; -pub use ops::{BitAnd, BitOr, BitXor}; -pub use ops::{Shl, Shr, Index}; - - -/* Reexported types and traits */ - -pub use option::{Option, Some, None}; -pub use result::{Result, Ok, Err}; - -pub use path::Path; -pub use path::GenericPath; -pub use path::WindowsPath; -pub use path::PosixPath; - -pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps}; -pub use str::{StrSlice}; -pub use container::{Container, Mutable}; -pub use vec::{CopyableVector, ImmutableVector}; -pub use vec::{ImmutableEqVector, ImmutableCopyableVector}; -pub use vec::{OwnedVector, OwnedCopyableVector}; -pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter}; -pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times}; - -pub use num::NumCast; -pub use ptr::Ptr; -pub use to_str::ToStr; -pub use clone::Clone; - /* Unsupported interfaces */ @@ -241,7 +241,7 @@ pub mod rt; // 'core' so that macro-expanded references to core::error and such // can be resolved within libcore. #[doc(hidden)] -pub mod core { +mod core { pub use clone; pub use cmp; pub use condition; diff --git a/src/libcore/flate.rs b/src/libcore/flate.rs index 2ddf927709693..d1647ea36fd78 100644 --- a/src/libcore/flate.rs +++ b/src/libcore/flate.rs @@ -46,7 +46,7 @@ static lz_fast : c_int = 0x1; // LZ with only one probe static lz_norm : c_int = 0x80; // LZ with 128 probes, "normal" static lz_best : c_int = 0xfff; // LZ with 4095 probes, "best" -pub fn deflate_bytes(bytes: &[const u8]) -> ~[u8] { +pub fn deflate_bytes(bytes: &const [u8]) -> ~[u8] { do vec::as_const_buf(bytes) |b, len| { unsafe { let mut outsz : size_t = 0; @@ -64,7 +64,7 @@ pub fn deflate_bytes(bytes: &[const u8]) -> ~[u8] { } } -pub fn inflate_bytes(bytes: &[const u8]) -> ~[u8] { +pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] { do vec::as_const_buf(bytes) |b, len| { unsafe { let mut outsz : size_t = 0; diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs index f2fe73e501e2d..85d288dda6cc4 100644 --- a/src/libcore/gc.rs +++ b/src/libcore/gc.rs @@ -124,7 +124,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/hash.rs b/src/libcore/hash.rs index 1bfa0e9522ddd..7b3b49b7ee908 100644 --- a/src/libcore/hash.rs +++ b/src/libcore/hash.rs @@ -65,7 +65,7 @@ impl HashUtil for A { /// Streaming hash-functions should implement this. pub trait Streaming { - fn input(&self, (&[const u8])); + fn input(&self, (&const [u8])); // These can be refactored some when we have default methods. fn result_bytes(&self) -> ~[u8]; fn result_str(&self) -> ~str; @@ -162,7 +162,7 @@ struct SipState { mut v1: u64, mut v2: u64, mut v3: u64, - mut tail: [u8 * 8], // unprocessed bytes + mut tail: [u8, ..8], // unprocessed bytes mut ntail: uint, // how many bytes in tail are valid } @@ -221,7 +221,7 @@ impl io::Writer for SipState { // Methods for io::writer #[inline(always)] - fn write(&self, msg: &[const u8]) { + fn write(&self, msg: &const [u8]) { let length = msg.len(); self.length += length; @@ -299,7 +299,7 @@ impl io::Writer for SipState { impl Streaming for SipState { #[inline(always)] - fn input(&self, buf: &[const u8]) { + fn input(&self, buf: &const [u8]) { self.write(buf); } @@ -369,7 +369,7 @@ impl Streaming for SipState { #[test] pub fn test_siphash() { - let vecs : [[u8 * 8] * 64] = [ + let vecs : [[u8, ..8], ..64] = [ [ 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, ], [ 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, ], [ 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, ], @@ -443,7 +443,7 @@ pub fn test_siphash() { let stream_inc = &State(k0,k1); let stream_full = &State(k0,k1); - fn to_hex_str(r: &[u8 * 8]) -> ~str { + fn to_hex_str(r: &[u8, ..8]) -> ~str { let mut s = ~""; for vec::each(*r) |b| { s += uint::to_str_radix(*b as uint, 16u); diff --git a/src/libcore/hashmap.rs b/src/libcore/hashmap.rs index 6f97bf6dde231..7d9320b9b0f93 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 fb305560ba333..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); @@ -667,7 +667,7 @@ pub enum WriterType { Screen, File } pub trait Writer { /// Write all of the given bytes. - fn write(&self, v: &[const u8]); + fn write(&self, v: &const [u8]); /// Move the current position within the stream. The second parameter /// determines the position that the first parameter is relative to. @@ -684,7 +684,7 @@ pub trait Writer { } impl Writer for @Writer { - fn write(&self, v: &[const u8]) { self.write(v) } + fn write(&self, v: &const [u8]) { self.write(v) } fn seek(&self, a: int, b: SeekStyle) { self.seek(a, b) } fn tell(&self) -> uint { self.tell() } fn flush(&self) -> int { self.flush() } @@ -692,7 +692,7 @@ impl Writer for @Writer { } impl Writer for Wrapper { - fn write(&self, bs: &[const u8]) { self.base.write(bs); } + fn write(&self, bs: &const [u8]) { self.base.write(bs); } fn seek(&self, off: int, style: SeekStyle) { self.base.seek(off, style); } fn tell(&self) -> uint { self.base.tell() } fn flush(&self) -> int { self.base.flush() } @@ -700,7 +700,7 @@ impl Writer for Wrapper { } impl Writer for *libc::FILE { - fn write(&self, v: &[const u8]) { + fn write(&self, v: &const [u8]) { unsafe { do vec::as_const_buf(v) |vbuf, len| { let nout = libc::fwrite(vbuf as *c_void, @@ -750,7 +750,7 @@ pub fn FILE_writer(f: *libc::FILE, cleanup: bool) -> @Writer { } impl Writer for fd_t { - fn write(&self, v: &[const u8]) { + fn write(&self, v: &const [u8]) { unsafe { let mut count = 0u; do vec::as_const_buf(v) |vbuf, len| { @@ -907,8 +907,10 @@ pub fn u64_to_be_bytes(n: u64, size: uint, } } -pub fn u64_from_be_bytes(data: &[const u8], - start: uint, size: uint) -> u64 { +pub fn u64_from_be_bytes(data: &const [u8], + start: uint, + size: uint) + -> u64 { let mut sz = size; fail_unless!((sz <= 8u)); let mut val = 0_u64; @@ -1140,7 +1142,7 @@ pub struct BytesWriter { } impl Writer for BytesWriter { - fn write(&self, v: &[const u8]) { + fn write(&self, v: &const [u8]) { let v_len = v.len(); let bytes_len = vec::uniq_len(&const self.bytes); 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/libc.rs b/src/libcore/libc.rs index 47eece81ce1c9..084437354fba4 100644 --- a/src/libcore/libc.rs +++ b/src/libcore/libc.rs @@ -342,7 +342,7 @@ pub mod types { st_mtime_nsec: c_long, st_ctime: time_t, st_ctime_nsec: c_long, - __unused: [c_long * 3], + __unused: [c_long, ..3], } } pub mod posix08 { @@ -430,7 +430,7 @@ pub mod types { st_lspare: int32_t, st_birthtime: time_t, st_birthtime_nsec: c_long, - __unused: [uint8_t * 2], + __unused: [uint8_t, ..2], } } pub mod posix08 { @@ -631,7 +631,7 @@ pub mod types { st_flags: uint32_t, st_gen: uint32_t, st_lspare: int32_t, - st_qspare: [int64_t * 2], + st_qspare: [int64_t, ..2], } } pub mod posix08 { @@ -712,7 +712,7 @@ pub mod types { st_flags: uint32_t, st_gen: uint32_t, st_lspare: int32_t, - st_qspare: [int64_t * 2], + st_qspare: [int64_t, ..2], } } pub mod posix08 { diff --git a/src/libcore/managed.rs b/src/libcore/managed.rs index 4eda5e7b5e8c6..4de9f32e7320e 100644 --- a/src/libcore/managed.rs +++ b/src/libcore/managed.rs @@ -15,13 +15,12 @@ use ptr; #[cfg(notest)] use cmp::{Eq, Ord}; pub mod raw { + use intrinsic::TyDesc; pub static RC_EXCHANGE_UNIQUE : uint = (-1) as uint; pub static RC_MANAGED_UNIQUE : uint = (-2) as uint; pub static RC_IMMORTAL : uint = 0x77777777; - use intrinsic::TyDesc; - pub struct BoxHeaderRepr { ref_count: uint, type_desc: *TyDesc, diff --git a/src/libcore/num/strconv.rs b/src/libcore/num/strconv.rs index ce6c015c13168..5299203eb4273 100644 --- a/src/libcore/num/strconv.rs +++ b/src/libcore/num/strconv.rs @@ -132,10 +132,12 @@ impl_NumStrConv_Integer!(u64) // Special value strings as [u8] consts. -static inf_buf: [u8*3] = ['i' as u8, 'n' as u8, 'f' as u8]; -static positive_inf_buf: [u8*4] = ['+' as u8, 'i' as u8, 'n' as u8, 'f' as u8]; -static negative_inf_buf: [u8*4] = ['-' as u8, 'i' as u8, 'n' as u8, 'f' as u8]; -static nan_buf: [u8*3] = ['N' as u8, 'a' as u8, 'N' as u8]; +static inf_buf: [u8, ..3] = ['i' as u8, 'n' as u8, 'f' as u8]; +static positive_inf_buf: [u8, ..4] = ['+' as u8, 'i' as u8, 'n' as u8, + 'f' as u8]; +static negative_inf_buf: [u8, ..4] = ['-' as u8, 'i' as u8, 'n' as u8, + 'f' as u8]; +static nan_buf: [u8, ..3] = ['N' as u8, 'a' as u8, 'N' as u8]; /** * Converts a number to its string representation as a byte vector. diff --git a/src/libcore/os.rs b/src/libcore/os.rs index e93888f3eaf6e..b2e3606eff9de 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -1167,14 +1167,6 @@ pub mod consts { #[cfg(windows)] pub use os::consts::windows::*; - pub mod unix { - pub static FAMILY: &'static str = "unix"; - } - - pub mod windows { - pub static FAMILY: &'static str = "windows"; - } - #[cfg(target_os = "macos")] pub use os::consts::macos::*; @@ -1190,6 +1182,26 @@ pub mod consts { #[cfg(target_os = "win32")] pub use os::consts::win32::*; + #[cfg(target_arch = "x86")] + pub use os::consts::x86::*; + + #[cfg(target_arch = "x86_64")] + pub use os::consts::x86_64::*; + + #[cfg(target_arch = "arm")] + pub use os::consts::arm::*; + + #[cfg(target_arch = "mips")] + use os::consts::mips::*; + + pub mod unix { + pub static FAMILY: &'static str = "unix"; + } + + pub mod windows { + pub static FAMILY: &'static str = "windows"; + } + pub mod macos { pub static SYSNAME: &'static str = "macos"; pub static DLL_PREFIX: &'static str = "lib"; @@ -1226,18 +1238,6 @@ pub mod consts { } - #[cfg(target_arch = "x86")] - pub use os::consts::x86::*; - - #[cfg(target_arch = "x86_64")] - pub use os::consts::x86_64::*; - - #[cfg(target_arch = "arm")] - pub use os::consts::arm::*; - - #[cfg(target_arch = "mips")] - use os::consts::mips::*; - pub mod x86 { pub static ARCH: &'static str = "x86"; } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index ae01a3d57f347..5e995d777c9b0 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -439,7 +439,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/context.rs b/src/libcore/rt/context.rs index 527acd4d1b1ba..7237fe118d8b5 100644 --- a/src/libcore/rt/context.rs +++ b/src/libcore/rt/context.rs @@ -123,7 +123,7 @@ fn initialize_call_frame(regs: &mut Registers, fptr: *c_void, arg: *c_void, sp: } #[cfg(target_arch = "x86_64")] -type Registers = [uint * 22]; +type Registers = [uint, ..22]; #[cfg(target_arch = "x86_64")] fn new_regs() -> ~Registers { ~[0, .. 22] } @@ -157,7 +157,7 @@ fn initialize_call_frame(regs: &mut Registers, fptr: *c_void, arg: *c_void, sp: } #[cfg(target_arch = "arm")] -type Registers = [uint * 32]; +type Registers = [uint, ..32]; #[cfg(target_arch = "arm")] fn new_regs() -> ~Registers { ~[0, .. 32] } @@ -175,7 +175,7 @@ fn initialize_call_frame(regs: &mut Registers, fptr: *c_void, arg: *c_void, sp: } #[cfg(target_arch = "mips")] -type Registers = [uint * 32]; +type Registers = [uint, ..32]; #[cfg(target_arch = "mips")] fn new_regs() -> ~Registers { ~[0, .. 32] } diff --git a/src/libcore/rt/uv/mod.rs b/src/libcore/rt/uv/mod.rs index 94a3b562fd875..5965a767763cb 100644 --- a/src/libcore/rt/uv/mod.rs +++ b/src/libcore/rt/uv/mod.rs @@ -321,7 +321,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 0f393dee59779..8ca65606fe285 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -44,7 +44,7 @@ Section: Creating a string * * Fails if invalid UTF-8 */ -pub fn from_bytes(vv: &[const u8]) -> ~str { +pub fn from_bytes(vv: &const [u8]) -> ~str { fail_unless!(is_utf8(vv)); return unsafe { raw::from_bytes(vv) }; } @@ -58,7 +58,7 @@ impl ToStr for ~str { #[inline(always)] fn to_str(&self) -> ~str { from_slice(*self) } } -impl ToStr for &'self str { +impl<'self> ToStr for &'self str { #[inline(always)] fn to_str(&self) -> ~str { from_slice(*self) } } @@ -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 @@ -418,7 +418,7 @@ pub fn to_chars(s: &str) -> ~[char] { * Returns a slice pointing at `n` characters starting from byte offset * `begin`. */ -pub fn substr(s: &'a str, begin: uint, n: uint) -> &'a str { +pub fn substr<'a>(s: &'a str, begin: uint, n: uint) -> &'a str { slice(s, begin, begin + count_bytes(s, begin, n)) } @@ -428,19 +428,21 @@ 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) } } /// Splits a string into substrings at each occurrence of a given character -pub fn each_split_char(s: &'a str, sep: char, it: &fn(&'a str) -> bool) { +pub fn each_split_char<'a>(s: &'a str, sep: char, it: &fn(&'a str) -> bool) { each_split_char_inner(s, sep, len(s), true, true, it) } /// Like `each_split_char`, but a trailing empty string is omitted -pub fn each_split_char_no_trailing(s: &'a str, sep: char, it: &fn(&'a str) -> bool) { +pub fn each_split_char_no_trailing<'a>(s: &'a str, + sep: char, + it: &fn(&'a str) -> bool) { each_split_char_inner(s, sep, len(s), true, false, it) } @@ -450,17 +452,26 @@ pub fn each_split_char_no_trailing(s: &'a str, sep: char, it: &fn(&'a str) -> bo * * The character must be a valid UTF-8/ASCII character */ -pub fn each_splitn_char(s: &'a str, sep: char, count: uint, it: &fn(&'a str) -> bool) { +pub fn each_splitn_char<'a>(s: &'a str, + sep: char, + count: uint, + it: &fn(&'a str) -> bool) { each_split_char_inner(s, sep, count, true, true, it) } /// Like `each_split_char`, but omits empty strings -pub fn each_split_char_nonempty(s: &'a str, sep: char, it: &fn(&'a str) -> bool) { +pub fn each_split_char_nonempty<'a>(s: &'a str, + sep: char, + it: &fn(&'a str) -> bool) { each_split_char_inner(s, sep, len(s), false, false, it) } -fn each_split_char_inner(s: &'a str, sep: char, count: uint, allow_empty: bool, - allow_trailing_empty: bool, it: &fn(&'a str) -> bool) { +fn each_split_char_inner<'a>(s: &'a str, + sep: char, + count: uint, + allow_empty: bool, + allow_trailing_empty: bool, + it: &fn(&'a str) -> bool) { if sep < 128u as char { let b = sep as u8, l = len(s); let mut done = 0u; @@ -485,12 +496,16 @@ fn each_split_char_inner(s: &'a str, sep: char, count: uint, allow_empty: bool, } /// Splits a string into substrings using a character function -pub fn each_split(s: &'a str, sepfn: &fn(char) -> bool, it: &fn(&'a str) -> bool) { +pub fn each_split<'a>(s: &'a str, + sepfn: &fn(char) -> bool, + it: &fn(&'a str) -> bool) { each_split_inner(s, sepfn, len(s), true, true, it) } /// Like `each_split`, but a trailing empty string is omitted -pub fn each_split_no_trailing(s: &'a str, sepfn: &fn(char) -> bool, it: &fn(&'a str) -> bool) { +pub fn each_split_no_trailing<'a>(s: &'a str, + sepfn: &fn(char) -> bool, + it: &fn(&'a str) -> bool) { each_split_inner(s, sepfn, len(s), true, false, it) } @@ -498,17 +513,26 @@ pub fn each_split_no_trailing(s: &'a str, sepfn: &fn(char) -> bool, it: &fn(&'a * Splits a string into substrings using a character function, cutting at * most `count` times. */ -pub fn each_splitn(s: &'a str, sepfn: &fn(char) -> bool, count: uint, it: &fn(&'a str) -> bool) { +pub fn each_splitn<'a>(s: &'a str, + sepfn: &fn(char) -> bool, + count: uint, + it: &fn(&'a str) -> bool) { each_split_inner(s, sepfn, count, true, true, it) } /// Like `each_split`, but omits empty strings -pub fn each_split_nonempty(s: &'a str, sepfn: &fn(char) -> bool, it: &fn(&'a str) -> bool) { +pub fn each_split_nonempty<'a>(s: &'a str, + sepfn: &fn(char) -> bool, + it: &fn(&'a str) -> bool) { each_split_inner(s, sepfn, len(s), false, false, it) } -fn each_split_inner(s: &'a str, sepfn: &fn(cc: char) -> bool, count: uint, - allow_empty: bool, allow_trailing_empty: bool, it: &fn(&'a str) -> bool) { +fn each_split_inner<'a>(s: &'a str, + sepfn: &fn(cc: char) -> bool, + count: uint, + allow_empty: bool, + allow_trailing_empty: bool, + it: &fn(&'a str) -> bool) { let l = len(s); let mut i = 0u, start = 0u, done = 0u; while i < l && done < count { @@ -528,7 +552,7 @@ fn each_split_inner(s: &'a 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) -> bool) { +fn iter_matches<'a,'b>(s: &'a str, sep: &'b str, f: &fn(uint, uint) -> bool) { let sep_len = len(sep), l = len(s); fail_unless!(sep_len > 0u); let mut i = 0u, match_start = 0u, match_i = 0u; @@ -555,7 +579,9 @@ fn iter_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint) -> bool) { } } -fn iter_between_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint) -> bool) { +fn iter_between_matches<'a,'b>(s: &'a str, + sep: &'b str, + f: &fn(uint, uint) -> bool) { let mut last_end = 0u; for iter_matches(s, sep) |from, to| { if !f(last_end, from) { return; } @@ -575,13 +601,17 @@ fn iter_between_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint) -> bool) { * fail_unless!(v == ["", "XXX", "YYY", ""]); * ~~~ */ -pub fn each_split_str(s: &'a str, sep: &'b str, it: &fn(&'a str) -> bool) { +pub fn each_split_str<'a,'b>(s: &'a str, + sep: &'b str, + it: &fn(&'a str) -> bool) { for iter_between_matches(s, sep) |from, to| { if !it( unsafe { raw::slice_bytes(s, from, to) } ) { return; } } } -pub fn each_split_str_nonempty(s: &'a str, sep: &'b str, it: &fn(&'a str) -> bool) { +pub fn each_split_str_nonempty<'a,'b>(s: &'a str, + sep: &'b str, + it: &fn(&'a str) -> bool) { for iter_between_matches(s, sep) |from, to| { if to > from { if !it( unsafe { raw::slice_bytes(s, from, to) } ) { return; } @@ -626,7 +656,7 @@ pub fn levdistance(s: &str, t: &str) -> uint { /** * Splits a string into substrings separated by LF ('\n'). */ -pub fn each_line(s: &'a str, it: &fn(&'a str) -> bool) { +pub fn each_line<'a>(s: &'a str, it: &fn(&'a str) -> bool) { each_split_char_no_trailing(s, '\n', it) } @@ -634,7 +664,7 @@ pub fn each_line(s: &'a str, it: &fn(&'a str) -> bool) { * Splits a string into substrings separated by LF ('\n') * and/or CR LF ("\r\n") */ -pub fn each_line_any(s: &'a str, it: &fn(&'a str) -> bool) { +pub fn each_line_any<'a>(s: &'a str, it: &fn(&'a str) -> bool) { for each_line(s) |s| { let l = s.len(); if l > 0u && s[l - 1u] == '\r' as u8 { @@ -646,7 +676,7 @@ pub fn each_line_any(s: &'a str, it: &fn(&'a str) -> bool) { } /// Splits a string into substrings separated by whitespace -pub fn each_word(s: &'a str, it: &fn(&'a str) -> bool) { +pub fn each_word<'a>(s: &'a str, it: &fn(&'a str) -> bool) { each_split_nonempty(s, char::is_whitespace, it) } @@ -659,7 +689,9 @@ pub fn each_word(s: &'a str, it: &fn(&'a str) -> bool) { * Fails during iteration if the string contains a non-whitespace * sequence longer than the limit. */ -pub fn each_split_within(ss: &'a str, lim: uint, it: &fn(&'a str) -> bool) { +pub fn each_split_within<'a>(ss: &'a str, + lim: uint, + it: &fn(&'a str) -> bool) { // Just for fun, let's write this as an state machine: enum SplitWithinState { @@ -823,7 +855,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) } } @@ -869,7 +901,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)) @@ -911,7 +943,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)] @@ -935,7 +967,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) } } @@ -1370,7 +1402,7 @@ pub fn rfind_between(s: &str, start: uint, end: uint, f: &fn(char) -> bool) -> O } // 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; @@ -1389,7 +1421,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)) } @@ -1412,7 +1444,10 @@ 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)) } @@ -1436,8 +1471,11 @@ pub fn find_str_from(haystack: &'a str, needle: &'b str, start: uint) -> Option< * `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); @@ -1461,7 +1499,7 @@ pub fn find_str_between(haystack: &'a str, needle: &'b str, start: uint, end:uin * * 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() } @@ -1485,7 +1523,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 } @@ -1500,7 +1538,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 } @@ -1552,7 +1590,7 @@ Section: Misc */ /// Determines if a vector of bytes contains valid UTF-8 -pub fn is_utf8(v: &[const u8]) -> bool { +pub fn is_utf8(v: &const [u8]) -> bool { let mut i = 0u; let total = vec::len::(v); while i < total { @@ -1681,7 +1719,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); @@ -1921,7 +1959,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); @@ -2099,7 +2137,7 @@ pub mod raw { } /// Converts a vector of bytes to a string. - pub unsafe fn from_bytes(v: &[const u8]) -> ~str { + pub unsafe fn from_bytes(v: &const [u8]) -> ~str { do vec::as_const_buf(v) |buf, len| { from_buf_len(buf, len) } @@ -2229,7 +2267,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)) @@ -2243,7 +2281,7 @@ pub mod traits {} pub trait StrSlice<'self> { fn all(&self, it: &fn(char) -> bool) -> bool; fn any(&self, it: &fn(char) -> bool) -> bool; - fn contains(&self, needle: &'a str) -> bool; + fn contains<'a>(&self, needle: &'a str) -> bool; fn contains_char(&self, needle: char) -> bool; fn each(&self, it: &fn(u8) -> bool); fn eachi(&self, it: &fn(uint, u8) -> bool); @@ -2262,8 +2300,8 @@ pub trait StrSlice<'self> { fn slice(&self, begin: uint, end: uint) -> &'self str; fn each_split(&self, sepfn: &fn(char) -> bool, it: &fn(&'self str) -> bool); fn each_split_char(&self, sep: char, it: &fn(&'self str) -> bool); - fn each_split_str(&self, sep: &'a str, it: &fn(&'self str) -> bool); - fn starts_with(&self, needle: &'a str) -> bool; + fn each_split_str<'a>(&self, sep: &'a str, it: &fn(&'self str) -> bool); + fn starts_with<'a>(&self, needle: &'a str) -> bool; fn substr(&self, begin: uint, n: uint) -> &'self str; fn to_lower(&self) -> ~str; fn to_upper(&self) -> ~str; @@ -2283,7 +2321,7 @@ pub trait StrSlice<'self> { } /// Extension methods for strings -impl StrSlice<'self> for &'self str { +impl<'self> StrSlice<'self> for &'self str { /** * Return true if a predicate matches all characters or if the string * contains no characters @@ -2298,7 +2336,7 @@ impl StrSlice<'self> 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 @@ -2397,12 +2435,12 @@ impl StrSlice<'self> for &'self str { * string */ #[inline] - fn each_split_str(&self, sep: &'a str, it: &fn(&'self str) -> bool) { + fn each_split_str<'a>(&self, sep: &'a str, it: &fn(&'self str) -> bool) { each_split_str(*self, sep, it) } /// Returns true if one string starts with another #[inline] - fn starts_with(&self, needle: &'a str) -> bool { + fn starts_with<'a>(&self, needle: &'a str) -> bool { starts_with(*self, needle) } /** @@ -2710,7 +2748,7 @@ mod tests { #[test] fn test_split_str() { - fn t(s: &str, sep: &'a str, u: &[~str]) { + fn t<'a>(s: &str, sep: &'a str, u: &[~str]) { let mut v = ~[]; for each_split_str(s, sep) |s| { v.push(s.to_owned()) } fail_unless!(vec::all2(v, u, |a,b| a == b)); diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index 706cb10dba9f7..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 { @@ -194,7 +194,7 @@ pub mod tests { #[test] pub fn nonzero_size_of_basic() { - type Z = [i8 * 0]; + type Z = [i8, ..0]; fail_unless!(size_of::() == 0u); fail_unless!(nonzero_size_of::() == 1u); fail_unless!(nonzero_size_of::() == size_of::()); 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 f353db5ae7098..cc075ed2a9291 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -122,7 +122,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 f379878c8eb0b..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 c942f508be841..fa4074047b90a 100644 --- a/src/libcore/to_str.rs +++ b/src/libcore/to_str.rs @@ -69,7 +69,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 012e005567434..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) { @@ -223,7 +223,7 @@ pub impl TrieSet { struct TrieNode { count: uint, - children: [Child * SIZE] + children: [Child, ..SIZE] } impl TrieNode { @@ -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 1762c2c64262c..6fbcee959cea5 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 5daccd9f879f4..b5cf4766af046 100644 --- a/src/libcore/unstable.rs +++ b/src/libcore/unstable.rs @@ -170,7 +170,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 5c976756d137d..702ae73852ee3 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -47,12 +47,12 @@ pub mod rustrt { } /// Returns true if a vector contains no elements -pub fn is_empty(v: &[const T]) -> bool { +pub fn is_empty(v: &const [T]) -> bool { as_const_buf(v, |_p, len| len == 0u) } /// Returns true if two vectors have the same length -pub fn same_length(xs: &[const T], ys: &[const U]) -> bool { +pub fn same_length(xs: &const [T], ys: &const [U]) -> bool { xs.len() == ys.len() } @@ -114,7 +114,7 @@ pub fn capacity(v: &const ~[T]) -> uint { /// Returns the length of a vector #[inline(always)] -pub fn len(v: &[const T]) -> uint { +pub fn len(v: &const [T]) -> uint { as_const_buf(v, |_p, len| len) } @@ -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| { @@ -624,7 +625,7 @@ fn push_slow(v: &mut ~[T], initval: T) { } #[inline(always)] -pub fn push_all(v: &mut ~[T], rhs: &[const T]) { +pub fn push_all(v: &mut ~[T], rhs: &const [T]) { let new_len = v.len() + rhs.len(); reserve(&mut *v, new_len); @@ -708,7 +709,7 @@ pub fn dedup(v: &mut ~[T]) { // Appending #[inline(always)] -pub fn append(lhs: ~[T], rhs: &[const T]) -> ~[T] { +pub fn append(lhs: ~[T], rhs: &const [T]) -> ~[T] { let mut v = lhs; unsafe { v.push_all(rhs); @@ -1242,7 +1243,7 @@ pub fn unzip(v: ~[(T, U)]) -> (~[T], ~[U]) { /** * Convert two vectors to a vector of pairs, by reference. As zip(). */ -pub fn zip_slice(v: &[const T], u: &[const U]) +pub fn zip_slice(v: &const [T], u: &const [U]) -> ~[(T, U)] { let mut zipped = ~[]; let sz = len(v); @@ -1293,7 +1294,7 @@ pub fn reverse(v: &mut [T]) { } /// Returns a vector with the order of elements reversed -pub fn reversed(v: &[const T]) -> ~[T] { +pub fn reversed(v: &const [T]) -> ~[T] { let mut rs: ~[T] = ~[]; let mut i = len::(v); if i == 0 { return (rs); } else { i -= 1; } @@ -1343,9 +1344,9 @@ 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 + // NB---this CANNOT be &const [T]! The reason // is that you are passing it to `f()` using // an immutable. @@ -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 { @@ -1381,7 +1382,7 @@ pub fn each_mut(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) { /// Like `each()`, but for the case where you have a vector that *may or may /// not* have mutable contents. #[inline(always)] -pub fn each_const(v: &[const T], f: &fn(elem: &const T) -> bool) { +pub fn each_const(v: &const [T], f: &fn(elem: &const 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; @@ -1508,7 +1509,7 @@ pub fn as_imm_buf(s: &[T], /* NB---this CANNOT be const, see below */ f: &fn(*T, uint) -> U) -> U { - // NB---Do not change the type of s to `&[const T]`. This is + // NB---Do not change the type of s to `&const [T]`. This is // unsound. The reason is that we are going to create immutable pointers // into `s` and pass them to `f()`, but in fact they are potentially // pointing at *mutable memory*. Use `as_const_buf` or `as_mut_buf` @@ -1524,7 +1525,7 @@ pub fn as_imm_buf(s: &[T], /// Similar to `as_imm_buf` but passing a `*const T` #[inline(always)] -pub fn as_const_buf(s: &[const T], f: &fn(*const T, uint) -> U) -> U { +pub fn as_const_buf(s: &const [T], f: &fn(*const T, uint) -> U) -> U { unsafe { let v : *(*const T,uint) = ::cast::reinterpret_cast(&addr_of(&s)); @@ -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,15 +1686,15 @@ 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] { + fn add(&self, rhs: & &'self const [T]) -> ~[T] { append(copy *self, (*rhs)) } } } -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. @@ -2041,14 +2042,14 @@ impl Mutable for ~[T] { } pub trait OwnedCopyableVector { - fn push_all(&mut self, rhs: &[const T]); + fn push_all(&mut self, rhs: &const [T]); fn grow(&mut self, n: uint, initval: &T); fn grow_set(&mut self, index: uint, initval: &T, val: T); } impl OwnedCopyableVector for ~[T] { #[inline] - fn push_all(&mut self, rhs: &[const T]) { + fn push_all(&mut self, rhs: &const [T]) { push_all(self, rhs); } @@ -2146,7 +2147,7 @@ pub mod raw { /** see `to_ptr()` */ #[inline(always)] - pub unsafe fn to_const_ptr(v: &[const T]) -> *const T { + pub unsafe fn to_const_ptr(v: &const [T]) -> *const T { let repr: **SliceRepr = ::cast::transmute(&v); ::cast::reinterpret_cast(&addr_of(&((**repr).data))) } @@ -2190,7 +2191,7 @@ pub mod raw { * Unchecked vector indexing. */ #[inline(always)] - pub unsafe fn get(v: &[const T], i: uint) -> T { + pub unsafe fn get(v: &const [T], i: uint) -> T { as_const_buf(v, |p, _len| *ptr::const_offset(p, i)) } @@ -2234,7 +2235,7 @@ pub mod raw { * may overlap. */ #[inline(always)] - pub unsafe fn copy_memory(dst: &mut [T], src: &[const T], + pub unsafe fn copy_memory(dst: &mut [T], src: &const [T], count: uint) { fail_unless!(dst.len() >= count); fail_unless!(src.len() >= count); @@ -2300,7 +2301,7 @@ pub mod bytes { * may overlap. */ #[inline(always)] - pub fn copy_memory(dst: &mut [u8], src: &[const u8], count: uint) { + pub fn copy_memory(dst: &mut [u8], src: &const [u8], count: uint) { // Bound checks are done at vec::raw::copy_memory. unsafe { vec::raw::copy_memory(dst, src, count) } } @@ -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() { @@ -2636,7 +2637,7 @@ mod tests { #[test] fn test_len_divzero() { - type Z = [i8 * 0]; + type Z = [i8, ..0]; let v0 : &[Z] = &[]; let v1 : &[Z] = &[[]]; let v2 : &[Z] = &[[], []]; diff --git a/src/librust/rust.rc b/src/librust/rust.rc index ffd7669c2d2ee..d407cf216a88e 100644 --- a/src/librust/rust.rc +++ b/src/librust/rust.rc @@ -37,12 +37,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 5f74dcb27ac60..14b455651a571 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 { @@ -547,7 +547,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 1eb82c6277eb5..8b88b39a84c23 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 2ce47d8d0a17c..3056edea233fb 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 9de7b5088f3a0..f2534bad58853 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -78,7 +78,7 @@ pub enum LangItem { } pub struct LanguageItems { - items: [ Option * 35 ] + items: [Option, ..35] } pub impl LanguageItems { @@ -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 a75ade0c585d3..c6d9b5068dce4 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -889,14 +889,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/resolve.rs b/src/librustc/middle/resolve.rs index bd507f4cf2289..afc2c9f3352d3 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -127,6 +127,7 @@ pub enum PatternBindingMode { ArgumentIrrefutableMode(mode) } +#[deriving(Eq)] pub enum Namespace { TypeNS, ValueNS @@ -161,7 +162,6 @@ pub enum NameDefinition { NoNameDefinition, //< The name was unbound. ChildNameDefinition(def), //< The name identifies an immediate child. ImportNameDefinition(def) //< The name identifies an import. - } #[deriving(Eq)] @@ -177,15 +177,9 @@ pub enum SelfBinding { pub type ResolveVisitor = vt<()>; -#[deriving(Eq)] -pub enum ImportDirectiveNS { - TypeNSOnly, - AnyNS -} - /// Contains data for specific types of import directives. pub enum ImportDirectiveSubclass { - SingleImport(ident /* target */, ident /* source */, ImportDirectiveNS), + SingleImport(ident /* target */, ident /* source */), GlobImport } @@ -210,9 +204,9 @@ pub impl ResolveResult { } pub enum TypeParameters<'self> { - NoTypeParameters, //< No type parameters. + NoTypeParameters, //< No type parameters. HasTypeParameters(&'self Generics, //< Type parameters. - node_id, //< ID of the enclosing item + node_id, //< ID of the enclosing item // The index to start numbering the type parameters at. // This is zero if this is the outermost set of type @@ -458,6 +452,10 @@ pub struct Module { children: @mut LinearMap, imports: @mut ~[@ImportDirective], + // The external module children of this node that were declared with + // `extern mod`. + external_module_children: @mut LinearMap, + // The anonymous children of this node. Anonymous children are pseudo- // modules that are implicitly created around items contained within // blocks. @@ -495,6 +493,7 @@ pub fn Module(parent_link: ParentLink, kind: kind, children: @mut LinearMap::new(), imports: @mut ~[], + external_module_children: @mut LinearMap::new(), anonymous_children: @mut LinearMap::new(), import_resolutions: @mut LinearMap::new(), glob_count: 0, @@ -968,17 +967,23 @@ pub impl Resolver { return (child, new_parent); } Some(child) => { - // Enforce the duplicate checking mode. If we're requesting - // duplicate module checking, check that there isn't a module - // in the module with the same name. If we're requesting - // duplicate type checking, check that there isn't a type in - // the module with the same name. If we're requesting - // duplicate value checking, check that there isn't a value in - // the module with the same name. If we're requesting - // duplicate type checking and duplicate value checking, check - // that there isn't a duplicate type and a duplicate value - // with the same name. If no duplicate checking was requested - // at all, do nothing. + // Enforce the duplicate checking mode: + // + // * If we're requesting duplicate module checking, check that + // there isn't a module in the module with the same name. + // + // * If we're requesting duplicate type checking, check that + // there isn't a type in the module with the same name. + // + // * If we're requesting duplicate value checking, check that + // there isn't a value in the module with the same name. + // + // * If we're requesting duplicate type checking and duplicate + // value checking, check that there isn't a duplicate type + // and a duplicate value with the same name. + // + // * If no duplicate checking was requested at all, do + // nothing. let mut is_duplicate = false; match duplicate_checking_mode { @@ -1432,16 +1437,10 @@ pub impl Resolver { let module_ = self.get_module_from_parent(parent); let state = @mut ImportState(); match view_path.node { - view_path_simple(binding, full_path, ns, _) => { - let ns = match ns { - module_ns => TypeNSOnly, - type_value_ns => AnyNS - }; - + view_path_simple(binding, full_path, _, _) => { let source_ident = *full_path.idents.last(); let subclass = @SingleImport(binding, - source_ident, - ns); + source_ident); self.build_import_directive(privacy, module_, module_path, @@ -1452,9 +1451,7 @@ pub impl Resolver { view_path_list(_, ref source_idents, _) => { for (*source_idents).each |source_ident| { let name = source_ident.node.name; - let subclass = @SingleImport(name, - name, - AnyNS); + let subclass = @SingleImport(name, name); self.build_import_directive(privacy, module_, copy module_path, @@ -1479,25 +1476,21 @@ pub impl Resolver { match find_extern_mod_stmt_cnum(self.session.cstore, node_id) { Some(crate_id) => { - let (child_name_bindings, new_parent) = - self.add_child(name, parent, ForbidDuplicateTypes, - view_item.span); - let def_id = def_id { crate: crate_id, node: 0 }; let parent_link = ModuleParentLink - (self.get_module_from_parent(new_parent), name); - - child_name_bindings.define_module(Public, - parent_link, + (self.get_module_from_parent(parent), name); + let external_module = @mut Module(parent_link, Some(def_id), - NormalModuleKind, - view_item.span); - self.build_reduced_graph_for_external_crate - (child_name_bindings.get_module()); - } - None => { - /* Ignore. */ + NormalModuleKind); + + parent.external_module_children.insert( + name, + external_module); + + self.build_reduced_graph_for_external_crate( + external_module); } + None => {} // Ignore. } } } @@ -1869,7 +1862,7 @@ pub impl Resolver { // the appropriate flag. match *subclass { - SingleImport(target, _, _) => { + SingleImport(target, _) => { debug!("(building import directive) building import \ directive: privacy %? %s::%s", privacy, @@ -2020,7 +2013,7 @@ pub impl Resolver { subclass: ImportDirectiveSubclass) -> @~str { match subclass { - SingleImport(_target, source, _ns) => self.session.str_of(source), + SingleImport(_target, source) => self.session.str_of(source), GlobImport => @~"*" } } @@ -2080,21 +2073,13 @@ pub impl Resolver { // within. Attempt to resolve the import within it. match *import_directive.subclass { - SingleImport(target, source, AnyNS) => { + SingleImport(target, source) => { resolution_result = self.resolve_single_import(module_, containing_module, target, source); } - SingleImport(target, source, TypeNSOnly) => { - resolution_result = - self.resolve_single_module_import( - module_, - containing_module, - target, - source); - } GlobImport => { let span = import_directive.span; let privacy = import_directive.privacy; @@ -2139,6 +2124,19 @@ pub impl Resolver { return resolution_result; } + fn create_name_bindings_from_module(module: @mut Module) -> NameBindings { + NameBindings { + type_def: Some(TypeNsDef { + privacy: Public, + module_def: Some(module), + type_def: None, + }), + value_def: None, + type_span: None, + value_span: None, + } + } + fn resolve_single_import(@mut self, module_: @mut Module, containing_module: @mut Module, @@ -2261,6 +2259,25 @@ pub impl Resolver { } } + // If we didn't find a result in the type namespace, search the + // external modules. + match type_result { + BoundResult(*) => {} + _ => { + match containing_module.external_module_children + .find(&source) { + None => {} // Continue. + Some(module) => { + let name_bindings = + @mut Resolver::create_name_bindings_from_module( + *module); + type_result = BoundResult(containing_module, + name_bindings); + } + } + } + } + // We've successfully resolved the import. Write the results in. fail_unless!(module_.import_resolutions.contains_key(&target)); let import_resolution = module_.import_resolutions.get(&target); @@ -2332,135 +2349,9 @@ pub impl Resolver { return Success(()); } - fn resolve_single_module_import(@mut self, - module_: @mut Module, - containing_module: @mut Module, - target: ident, - source: ident) - -> ResolveResult<()> { - debug!("(resolving single module import) resolving `%s` = `%s::%s` \ - from `%s`", - *self.session.str_of(target), - self.module_to_str(containing_module), - *self.session.str_of(source), - self.module_to_str(module_)); - - // We need to resolve the module namespace for this to succeed. - let mut module_result = UnknownResult; - - // Search for direct children of the containing module. - match containing_module.children.find(&source) { - None => { - // Continue. - } - Some(child_name_bindings) => { - if child_name_bindings.defined_in_namespace(TypeNS) { - module_result = BoundResult(containing_module, - *child_name_bindings); - } - } - } - - // Unless we managed to find a result, search imports as well. - match module_result { - BoundResult(*) => { - // Continue. - } - _ => { - // If there is an unresolved glob at this point in the - // containing module, bail out. We don't know enough to be - // able to resolve this import. - - if containing_module.glob_count > 0 { - debug!("(resolving single module import) unresolved \ - glob; bailing out"); - return Indeterminate; - } - - // Now search the exported imports within the containing - // module. - match containing_module.import_resolutions.find(&source) { - None => { - // The containing module definitely doesn't have an - // exported import with the name in question. We can - // therefore accurately report that the names are - // unbound. - - if module_result.is_unknown() { - module_result = UnboundResult; - } - } - Some(import_resolution) - if import_resolution.outstanding_references - == 0 => { - // The name is an import which has been fully - // resolved. We can, therefore, just follow it. - - if module_result.is_unknown() { - match (*import_resolution).target_for_namespace( - TypeNS) { - None => { - module_result = UnboundResult; - } - Some(target) => { - import_resolution.state.used = true; - module_result = BoundResult - (target.target_module, - target.bindings); - } - } - } - } - Some(_) => { - // The import is unresolved. Bail out. - debug!("(resolving single module import) unresolved \ - import; bailing out"); - return Indeterminate; - } - } - } - } - - // We've successfully resolved the import. Write the results in. - fail_unless!(module_.import_resolutions.contains_key(&target)); - let import_resolution = module_.import_resolutions.get(&target); - - match module_result { - BoundResult(target_module, name_bindings) => { - debug!("(resolving single import) found module binding"); - import_resolution.type_target = - Some(Target(target_module, name_bindings)); - } - UnboundResult => { - debug!("(resolving single import) didn't find module \ - binding"); - } - UnknownResult => { - fail!(~"module result should be known at this point"); - } - } - - let i = import_resolution; - if i.type_target.is_none() { - // If this name wasn't found in the type namespace, it's - // definitely unresolved. - return Failed; - } - - fail_unless!(import_resolution.outstanding_references >= 1); - import_resolution.outstanding_references -= 1; - - debug!("(resolving single module import) successfully resolved \ - import"); - return Success(()); - } - - - /** - * Resolves a glob import. Note that this function cannot fail; it either - * succeeds or bails out (as importing * from an empty module or a module - * that exports nothing is valid). - */ + // Resolves a glob import. Note that this function cannot fail; it either + // succeeds or bails out (as importing * from an empty module or a module + // that exports nothing is valid). fn resolve_glob_import(@mut self, privacy: Privacy, module_: @mut Module, @@ -2535,8 +2426,8 @@ pub impl Resolver { } } - // Add all children from the containing module. - for containing_module.children.each |&(ident, name_bindings)| { + let merge_import_resolution = |ident, + name_bindings: @mut NameBindings| { let mut dest_import_resolution; match module_.import_resolutions.find(ident) { None => { @@ -2563,13 +2454,26 @@ pub impl Resolver { if name_bindings.defined_in_public_namespace(ValueNS) { debug!("(resolving glob import) ... for value target"); dest_import_resolution.value_target = - Some(Target(containing_module, *name_bindings)); + Some(Target(containing_module, name_bindings)); } if name_bindings.defined_in_public_namespace(TypeNS) { debug!("(resolving glob import) ... for type target"); dest_import_resolution.type_target = - Some(Target(containing_module, *name_bindings)); + Some(Target(containing_module, name_bindings)); } + }; + + // Add all children from the containing module. + for containing_module.children.each |&(ident, name_bindings)| { + merge_import_resolution(ident, *name_bindings); + } + + // Add external module children from the containing module. + for containing_module.external_module_children.each + |&(ident, module)| { + let name_bindings = + @mut Resolver::create_name_bindings_from_module(*module); + merge_import_resolution(ident, name_bindings); } debug!("(resolving glob import) successfully resolved import"); @@ -2759,7 +2663,6 @@ pub impl Resolver { // The current module node is handled specially. First, check for // its immediate children. - match module_.children.find(&name) { Some(name_bindings) if name_bindings.defined_in_namespace(namespace) => { @@ -2772,7 +2675,6 @@ pub impl Resolver { // all its imports in the usual way; this is because chains of // adjacent import statements are processed as though they mutated the // current scope. - match module_.import_resolutions.find(&name) { None => { // Not found; continue. @@ -2795,6 +2697,19 @@ pub impl Resolver { } } + // Search for external modules. + if namespace == TypeNS { + match module_.external_module_children.find(&name) { + None => {} + Some(module) => { + let name_bindings = + @mut Resolver::create_name_bindings_from_module( + *module); + return Success(Target(module_, name_bindings)); + } + } + } + // Finally, proceed up the scope chain looking for parent modules. let mut search_module = module_; loop { @@ -3027,7 +2942,8 @@ pub impl Resolver { // Check the list of resolved imports. match module_.import_resolutions.find(&name) { Some(import_resolution) => { - if import_resolution.outstanding_references != 0 { + if import_resolution.privacy == Public && + import_resolution.outstanding_references != 0 { debug!("(resolving name in module) import \ unresolved; bailing out"); return Indeterminate; @@ -3054,8 +2970,19 @@ pub impl Resolver { } } } - None => { - // Continue. + None => {} // Continue. + } + + // Finally, search through external children. + if namespace == TypeNS { + match module_.external_module_children.find(&name) { + None => {} + Some(module) => { + let name_bindings = + @mut Resolver::create_name_bindings_from_module( + *module); + return Success(Target(module_, name_bindings)); + } } } @@ -4541,20 +4468,31 @@ pub impl Resolver { (Some(_), _) | (None, _) => { // This can happen with external impls, due to // the imperfect way we read the metadata. - - return NoNameDefinition; } } } - None => { - return NoNameDefinition; - } + None => {} } } - Some(_) | None => { - return NoNameDefinition; + Some(_) | None => {} // Continue. + } + + // Finally, search through external children. + if namespace == TypeNS { + match containing_module.external_module_children.find(&name) { + None => {} + Some(module) => { + match module.def_id { + None => {} // Continue. + Some(def_id) => { + return ChildNameDefinition(def_mod(def_id)); + } + } + } } } + + return NoNameDefinition; } fn intern_module_part_of_path(@mut self, path: @path) -> ~[ident] { diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index d4081352468da..f324640ef2cf4 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 = LinearMap; -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 7ba0b706e436e..8a22e90b8474b 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -560,7 +560,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/datum.rs b/src/librustc/middle/trans/datum.rs index bb7fae9ae33aa..f81973e169daa 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -679,7 +679,6 @@ pub impl Datum { } let repr = adt::represent_type(ccx, self.ty); - fail_unless!(adt::is_newtypeish(repr)); let ty = ty::subst(ccx.tcx, substs, variants[0].args[0]); return match self.mode { ByRef => { @@ -719,7 +718,6 @@ pub impl Datum { } let repr = adt::represent_type(ccx, self.ty); - fail_unless!(adt::is_newtypeish(repr)); let ty = fields[0].mt.ty; return match self.mode { ByRef => { diff --git a/src/librustc/middle/trans/reachable.rs b/src/librustc/middle/trans/reachable.rs index 4ac3ac0555f5e..e1e6f557c8376 100644 --- a/src/librustc/middle/trans/reachable.rs +++ b/src/librustc/middle/trans/reachable.rs @@ -32,7 +32,7 @@ use syntax::{visit, ast_util, ast_map}; pub type map = @LinearSet; -struct ctx { +struct ctx<'self> { exp_map2: resolve::ExportMap2, tcx: ty::ctxt, method_map: typeck::method_map, @@ -152,7 +152,7 @@ fn mk_ty_visitor() -> visit::vt { ..*visit::default_visitor()}) } -fn traverse_ty(ty: @Ty, cx: ctx<'a>, v: visit::vt>) { +fn traverse_ty<'a>(ty: @Ty, cx: ctx<'a>, v: visit::vt>) { // XXX: it shouldn't be necessary to do this let rmap: &mut LinearSet = cx.rmap; if rmap.contains(&ty.id) { return; } @@ -176,7 +176,7 @@ fn traverse_ty(ty: @Ty, cx: ctx<'a>, v: visit::vt>) { } fn traverse_inline_body(cx: ctx, body: &blk) { - fn traverse_expr(e: @expr, cx: ctx<'a>, v: visit::vt>) { + fn traverse_expr<'a>(e: @expr, cx: ctx<'a>, v: visit::vt>) { match e.node { expr_path(_) => { match cx.tcx.def_map.find(&e.id) { diff --git a/src/librustc/middle/trans/tvec.rs b/src/librustc/middle/trans/tvec.rs index 5bb94a18e7227..30a7648e7eafb 100644 --- a/src/librustc/middle/trans/tvec.rs +++ b/src/librustc/middle/trans/tvec.rs @@ -547,7 +547,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/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 4f8f600485e54..dad660e8c7053 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -58,13 +58,15 @@ use middle::const_eval; use middle::ty::{arg, field, substs}; use middle::ty::{ty_param_substs_and_ty}; use middle::ty; -use middle::typeck::rscope::{in_binding_rscope}; +use middle::typeck::rscope::{in_binding_rscope, in_binding_rscope_ext}; use middle::typeck::rscope::{region_scope, type_rscope, RegionError}; +use middle::typeck::rscope::{RegionParamNames}; use core::result; use core::vec; use syntax::{ast, ast_util}; use syntax::codemap::span; +use syntax::opt_vec::OptVec; use syntax::print::pprust::{lifetime_to_str, path_to_str}; use syntax::parse::token::special_idents; use util::common::indenter; @@ -348,9 +350,15 @@ pub fn ast_ty_to_ty( bf.abi, &bf.decl)) } ast::ty_closure(ref f) => { - let fn_decl = ty_of_closure(self, rscope, f.sigil, - f.purity, f.onceness, - f.region, &f.decl, None, + let fn_decl = ty_of_closure(self, + rscope, + f.sigil, + f.purity, + f.onceness, + f.region, + &f.decl, + None, + &f.lifetimes, ast_ty.span); ty::mk_closure(tcx, fn_decl) } @@ -507,7 +515,7 @@ pub fn ty_of_bare_fn( abi: ast::Abi, decl: &ast::fn_decl) -> ty::BareFnTy { - debug!("ty_of_fn_decl"); + debug!("ty_of_bare_fn"); // new region names that appear inside of the fn decl are bound to // that function type @@ -526,6 +534,33 @@ pub fn ty_of_bare_fn( } } +pub fn ty_of_bare_fn_ext( + self: &AC, + rscope: &RS, + purity: ast::purity, + abi: ast::Abi, + decl: &ast::fn_decl, + +region_param_names: RegionParamNames) + -> ty::BareFnTy { + debug!("ty_of_bare_fn_ext"); + + // new region names that appear inside of the fn decl are bound to + // that function type + let rb = in_binding_rscope_ext(rscope, region_param_names); + + let input_tys = decl.inputs.map(|a| ty_of_arg(self, &rb, *a, None)); + let output_ty = match decl.output.node { + ast::ty_infer => self.ty_infer(decl.output.span), + _ => ast_ty_to_ty(self, &rb, decl.output) + }; + + ty::BareFnTy { + purity: purity, + abi: abi, + sig: ty::FnSig {inputs: input_tys, output: output_ty} + } +} + pub fn ty_of_closure( self: &AC, rscope: &RS, @@ -535,6 +570,7 @@ pub fn ty_of_closure( opt_lifetime: Option<@ast::Lifetime>, decl: &ast::fn_decl, expected_tys: Option, + lifetimes: &OptVec, span: span) -> ty::ClosureTy { debug!("ty_of_fn_decl"); @@ -563,7 +599,8 @@ pub fn ty_of_closure( // new region names that appear inside of the fn decl are bound to // that function type - let rb = in_binding_rscope(rscope); + let region_param_names = RegionParamNames::from_lifetimes(lifetimes); + let rb = in_binding_rscope_ext(rscope, region_param_names); let input_tys = do decl.inputs.mapi |i, a| { let expected_arg_ty = do expected_tys.chain_ref |e| { diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index fcaf1c08342be..aefd95ab78726 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -152,7 +152,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/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 17a67838bbe8b..75c6bfd5d6405 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -100,7 +100,7 @@ use middle::typeck::CrateCtxt; use middle::typeck::infer::{resolve_type, force_tvar, mk_eqty}; use middle::typeck::infer; use middle::typeck::rscope::{binding_rscope, bound_self_region}; -use middle::typeck::rscope::{RegionError}; +use middle::typeck::rscope::{RegionError, RegionParameterization}; use middle::typeck::rscope::{in_binding_rscope, region_scope, type_rscope}; use middle::typeck::rscope; use middle::typeck::{isr_alist, lookup_def_ccx, method_map_entry}; @@ -126,10 +126,11 @@ use syntax::ast_util::{Private, Public, is_local, local_def}; use syntax::ast_util; use syntax::codemap::{span, spanned, respan}; use syntax::codemap; +use syntax::opt_vec::OptVec; +use syntax::opt_vec; use syntax::parse::token::special_idents; use syntax::print::pprust; use syntax::visit; -use syntax::opt_vec::OptVec; use syntax; pub mod _match; @@ -570,10 +571,12 @@ pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) { ast::item_fn(ref decl, _, _, ref body) => { check_bare_fn(ccx, decl, body, it.id, None); } - ast::item_impl(_, _, ty, ref ms) => { + ast::item_impl(ref generics, _, ty, ref ms) => { let rp = ccx.tcx.region_paramd_items.find(&it.id).map_consume(|x| *x); debug!("item_impl %s with id %d rp %?", *ccx.tcx.sess.str_of(it.ident), it.id, rp); + let rp = RegionParameterization::from_variance_and_generics( + rp, generics); let self_ty = ccx.to_ty(&rscope::type_rscope(rp), ty); for ms.each |m| { check_method(ccx, *m, self_ty); @@ -1069,9 +1072,13 @@ pub fn impl_self_ty(vcx: &VtableContext, node: ast::item_impl(ref ts, _, st, _), _ }, _)) => { + let region_parameterization = + RegionParameterization::from_variance_and_generics( + region_param, + ts); (ts.ty_params.len(), region_param, - vcx.ccx.to_ty(&rscope::type_rscope(region_param), st)) + vcx.ccx.to_ty(&rscope::type_rscope(region_parameterization), st)) } Some(&ast_map::node_item(@ast::item { node: ast::item_struct(_, ref ts), @@ -1654,10 +1661,16 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, }; // construct the function type - let mut fn_ty = astconv::ty_of_closure( - fcx, fcx, - sigil, purity, expected_onceness, - None, decl, expected_tys, expr.span); + let mut fn_ty = astconv::ty_of_closure(fcx, + fcx, + sigil, + purity, + expected_onceness, + None, + decl, + expected_tys, + &opt_vec::Empty, + expr.span); let mut fty_sig; let fty = if error_happened { diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 7e97edf8f8aa6..7089ac4dd1283 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -566,10 +566,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/collect.rs b/src/librustc/middle/typeck/collect.rs index a1fcf1029880b..6d304247c5d5d 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -166,12 +166,15 @@ pub fn get_enum_variant_types(ccx: &CrateCtxt, // Create a set of parameter types shared among all the variants. for variants.each |variant| { + let region_parameterization = + RegionParameterization::from_variance_and_generics(rp, generics); + // Nullary enum constructors get turned into constants; n-ary enum // constructors get turned into functions. let result_ty; match variant.node.kind { ast::tuple_variant_kind(ref args) if args.len() > 0 => { - let rs = type_rscope(rp); + let rs = type_rscope(region_parameterization); let input_tys = args.map(|va| ccx.to_ty(&rs, va.ty)); result_ty = Some(ty::mk_ctor_fn(tcx, input_tys, enum_ty)); } @@ -301,7 +304,8 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, ccx, &ty_m, region_paramd, - def_id + def_id, + generics ); if ty_m.self_ty.node == ast::sty_static { make_static_method_ty(ccx, &ty_m, region_paramd, @@ -319,13 +323,14 @@ pub fn ensure_supertraits(ccx: &CrateCtxt, id: ast::node_id, sp: codemap::span, rp: Option, - trait_refs: &[@ast::trait_ref]) { + trait_refs: &[@ast::trait_ref], + generics: &ast::Generics) { let tcx = ccx.tcx; if tcx.supertraits.contains_key(&local_def(id)) { return; } let mut instantiated = ~[]; for trait_refs.each |trait_ref| { - let (did, tpt) = instantiate_trait_ref(ccx, *trait_ref, rp); + let (did, tpt) = instantiate_trait_ref(ccx, *trait_ref, rp, generics); if instantiated.any(|other_trait: &InstantiatedTraitRef| { other_trait.def_id == did }) { // This means a trait inherited from the same supertrait more @@ -506,7 +511,7 @@ pub fn check_methods_against_trait(ccx: &CrateCtxt, impl_ms: &[ConvertedMethod]) { let tcx = ccx.tcx; - let (did, tpt) = instantiate_trait_ref(ccx, a_trait_ty, rp); + let (did, tpt) = instantiate_trait_ref(ccx, a_trait_ty, rp, generics); if did.crate == ast::local_crate { // NB: This is subtle. We need to do this on the type of the trait @@ -553,8 +558,11 @@ pub fn check_methods_against_trait(ccx: &CrateCtxt, pub fn convert_field(ccx: &CrateCtxt, rp: Option, bounds: @~[ty::param_bounds], - v: @ast::struct_field) { - let tt = ccx.to_ty(&type_rscope(rp), v.node.ty); + v: @ast::struct_field, + generics: &ast::Generics) { + let region_parameterization = + RegionParameterization::from_variance_and_generics(rp, generics); + let tt = ccx.to_ty(&type_rscope(region_parameterization), v.node.ty); write_ty_to_tcx(ccx.tcx, v.node.id, tt); /* add the field to the tcache */ ccx.tcx.tcache.insert(local_def(v.node.id), @@ -575,13 +583,14 @@ pub struct ConvertedMethod { pub fn convert_methods(ccx: &CrateCtxt, ms: &[@ast::method], rp: Option, - rcvr_bounds: @~[ty::param_bounds]) + rcvr_bounds: @~[ty::param_bounds], + rcvr_generics: &ast::Generics) -> ~[ConvertedMethod] { let tcx = ccx.tcx; do vec::map(ms) |m| { let bounds = ty_param_bounds(ccx, &m.generics); - let mty = ty_of_method(ccx, *m, rp); + let mty = ty_of_method(ccx, *m, rp, rcvr_generics, &m.generics); let fty = ty::mk_bare_fn(tcx, copy mty.fty); tcx.tcache.insert( local_def(m.id), @@ -633,7 +642,9 @@ pub fn convert(ccx: &CrateCtxt, it: @ast::item) { } ast::item_impl(ref generics, trait_ref, selfty, ref ms) => { let i_bounds = ty_param_bounds(ccx, generics); - let selfty = ccx.to_ty(&type_rscope(rp), selfty); + let region_parameterization = + RegionParameterization::from_variance_and_generics(rp, generics); + let selfty = ccx.to_ty(&type_rscope(region_parameterization), selfty); write_ty_to_tcx(tcx, it.id, selfty); tcx.tcache.insert(local_def(it.id), ty_param_bounds_and_ty { @@ -642,7 +653,7 @@ pub fn convert(ccx: &CrateCtxt, it: @ast::item) { ty: selfty}); // XXX: Bad copy of `ms` below. - let cms = convert_methods(ccx, *ms, rp, i_bounds); + let cms = convert_methods(ccx, *ms, rp, i_bounds, generics); for trait_ref.each |t| { check_methods_against_trait(ccx, generics, rp, selfty, *t, cms); } @@ -653,12 +664,12 @@ pub fn convert(ccx: &CrateCtxt, it: @ast::item) { it.id, ppaux::ty_to_str(tcx, tpt.ty)); write_ty_to_tcx(tcx, it.id, tpt.ty); ensure_trait_methods(ccx, it.id, tpt.ty); - ensure_supertraits(ccx, it.id, it.span, rp, *supertraits); + ensure_supertraits(ccx, it.id, it.span, rp, *supertraits, generics); let (_, provided_methods) = split_trait_methods(*trait_methods); let (bounds, _) = mk_substs(ccx, generics, rp); - let _ = convert_methods(ccx, provided_methods, rp, bounds); + let _ = convert_methods(ccx, provided_methods, rp, bounds, generics); } ast::item_struct(struct_def, ref generics) => { ensure_no_ty_param_bounds(ccx, it.span, generics, "structure"); @@ -694,12 +705,17 @@ pub fn convert_struct(ccx: &CrateCtxt, let tcx = ccx.tcx; for struct_def.dtor.each |dtor| { + let region_parameterization = + RegionParameterization::from_variance_and_generics(rp, generics); + // Write the dtor type let t_dtor = ty::mk_bare_fn( tcx, astconv::ty_of_bare_fn( - ccx, &type_rscope(rp), - ast::impure_fn, ast::RustAbi, + ccx, + &type_rscope(region_parameterization), + ast::impure_fn, + ast::RustAbi, &ast_util::dtor_dec())); write_ty_to_tcx(tcx, dtor.node.id, t_dtor); tcx.tcache.insert(local_def(dtor.node.id), @@ -711,7 +727,7 @@ pub fn convert_struct(ccx: &CrateCtxt, // Write the type of each of the members for struct_def.fields.each |f| { - convert_field(ccx, rp, tpt.bounds, *f); + convert_field(ccx, rp, tpt.bounds, *f, generics); } let (_, substs) = mk_substs(ccx, generics, rp); let selfty = ty::mk_struct(tcx, local_def(id), substs); @@ -754,17 +770,23 @@ pub fn convert_foreign(ccx: &CrateCtxt, i: @ast::foreign_item) { pub fn ty_of_method(ccx: &CrateCtxt, m: @ast::method, - rp: Option) -> ty::method { - let rscope = MethodRscope { - self_ty: m.self_ty.node, - region_parameterization: rp - }; - + rp: Option, + rcvr_generics: &ast::Generics, + method_generics: &ast::Generics) + -> ty::method { + let rscope = MethodRscope::new(m.self_ty.node, + rp, + rcvr_generics, + method_generics); ty::method { ident: m.ident, tps: ty_param_bounds(ccx, &m.generics), - fty: astconv::ty_of_bare_fn(ccx, &rscope, m.purity, - ast::RustAbi, &m.decl), + fty: astconv::ty_of_bare_fn_ext(ccx, + &rscope, + m.purity, + ast::RustAbi, + &m.decl, + rscope.region_param_names()), self_ty: m.self_ty.node, vis: m.vis, def_id: local_def(m.id) @@ -774,17 +796,19 @@ pub fn ty_of_method(ccx: &CrateCtxt, pub fn ty_of_ty_method(self: &CrateCtxt, m: &ast::ty_method, rp: Option, - id: ast::def_id) -> ty::method { - let rscope = MethodRscope { - self_ty: m.self_ty.node, - region_parameterization: rp - }; - + id: ast::def_id, + generics: &ast::Generics) + -> ty::method { + let rscope = MethodRscope::new(m.self_ty.node, rp, generics, &m.generics); ty::method { ident: m.ident, tps: ty_param_bounds(self, &m.generics), - fty: astconv::ty_of_bare_fn(self, &rscope, m.purity, - ast::RustAbi, &m.decl), + fty: astconv::ty_of_bare_fn_ext(self, + &rscope, + m.purity, + ast::RustAbi, + &m.decl, + rscope.region_param_names()), // assume public, because this is only invoked on trait methods self_ty: m.self_ty.node, vis: ast::public, @@ -797,13 +821,17 @@ pub fn ty_of_ty_method(self: &CrateCtxt, it's bound to a valid trait type. Returns the def_id for the defining trait. Fails if the type is a type other than an trait type. */ -pub fn instantiate_trait_ref(ccx: &CrateCtxt, t: @ast::trait_ref, - rp: Option) +pub fn instantiate_trait_ref(ccx: &CrateCtxt, + t: @ast::trait_ref, + rp: Option, + generics: &ast::Generics) -> (ast::def_id, ty_param_substs_and_ty) { let sp = t.path.span, err = ~"can only implement trait types", sess = ccx.tcx.sess; + let rp = RegionParameterization::from_variance_and_generics(rp, generics); + let rscope = type_rscope(rp); match lookup_def_tcx(ccx.tcx, t.path.span, t.ref_id) { @@ -841,8 +869,13 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: @ast::item) } ast::item_fn(ref decl, purity, ref generics, _) => { let bounds = ty_param_bounds(ccx, generics); - let tofd = astconv::ty_of_bare_fn(ccx, &empty_rscope, purity, - ast::RustAbi, decl); + let region_param_names = RegionParamNames::from_generics(generics); + let tofd = astconv::ty_of_bare_fn_ext(ccx, + &empty_rscope, + purity, + ast::RustAbi, + decl, + region_param_names); let tpt = ty_param_bounds_and_ty { bounds: bounds, region_param: None, @@ -862,9 +895,11 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: @ast::item) } let rp = tcx.region_paramd_items.find(&it.id).map_consume(|x| *x); + let region_parameterization = + RegionParameterization::from_variance_and_generics(rp, generics); let tpt = { let ty = { - let t0 = ccx.to_ty(&type_rscope(rp), t); + let t0 = ccx.to_ty(&type_rscope(region_parameterization), t); // Do not associate a def id with a named, parameterized type // like "foo". This is because otherwise ty_to_str will // print the name as merely "foo", as it has no way to @@ -1007,7 +1042,8 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt, generics: &ast::Generics) -> ty::ty_param_bounds_and_ty { let bounds = ty_param_bounds(ccx, generics); - let rb = in_binding_rscope(&empty_rscope); + let region_param_names = RegionParamNames::from_generics(generics); + let rb = in_binding_rscope_ext(&empty_rscope, region_param_names); let input_tys = decl.inputs.map(|a| ty_of_arg(ccx, &rb, *a, None) ); let output_ty = ast_ty_to_ty(ccx, &rb, decl.output); 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/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index 45c7ad2f8f81d..031363469cd0a 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -1201,11 +1201,11 @@ struct GraphNode { span: span, classification: Classification, value: GraphNodeValue, - head_edge: [uint * 2], + head_edge: [uint, ..2], } struct GraphEdge { - next_edge: [uint * 2], + next_edge: [uint, ..2], constraint: Constraint, span: span, } 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/librustc/middle/typeck/rscope.rs b/src/librustc/middle/typeck/rscope.rs index e29e63c41ecca..135993e18a20a 100644 --- a/src/librustc/middle/typeck/rscope.rs +++ b/src/librustc/middle/typeck/rscope.rs @@ -16,6 +16,9 @@ use core::result::Result; use core::result; use syntax::ast; use syntax::codemap::span; +use syntax::opt_vec::OptVec; +use syntax::opt_vec; +use syntax::parse::token::special_idents; pub struct RegionError { msg: ~str, @@ -47,10 +50,130 @@ impl region_scope for empty_rscope { } } +pub struct RegionParamNames(OptVec); + +impl RegionParamNames { + fn has_self(&self) -> bool { + self.has_ident(special_idents::self_) + } + + fn has_ident(&self, ident: ast::ident) -> bool { + for self.each |region_param_name| { + if *region_param_name == ident { + return true; + } + } + false + } + + pub fn add_generics(&mut self, generics: &ast::Generics) { + match generics.lifetimes { + opt_vec::Empty => {} + opt_vec::Vec(ref new_lifetimes) => { + match **self { + opt_vec::Empty => { + *self = RegionParamNames( + opt_vec::Vec(new_lifetimes.map(|lt| lt.ident))); + } + opt_vec::Vec(ref mut existing_lifetimes) => { + for new_lifetimes.each |new_lifetime| { + existing_lifetimes.push(new_lifetime.ident); + } + } + } + } + } + } + + // Convenience function to produce the error for an unresolved name. The + // optional argument specifies a custom replacement. + pub fn undeclared_name(custom_replacement: Option) + -> Result { + let replacement = match custom_replacement { + None => ty::re_bound(ty::br_self), + Some(custom_replacement) => custom_replacement + }; + Err(RegionError { + msg: ~"this lifetime must be declared", + replacement: replacement + }) + } + + pub fn from_generics(generics: &ast::Generics) -> RegionParamNames { + match generics.lifetimes { + opt_vec::Empty => RegionParamNames(opt_vec::Empty), + opt_vec::Vec(ref lifetimes) => { + RegionParamNames(opt_vec::Vec(lifetimes.map(|lt| lt.ident))) + } + } + } + + pub fn from_lifetimes(lifetimes: &opt_vec::OptVec) + -> RegionParamNames { + match *lifetimes { + opt_vec::Empty => RegionParamNames::new(), + opt_vec::Vec(ref v) => { + RegionParamNames(opt_vec::Vec(v.map(|lt| lt.ident))) + } + } + } + + fn new() -> RegionParamNames { + RegionParamNames(opt_vec::Empty) + } +} + +struct RegionParameterization { + variance: ty::region_variance, + region_param_names: RegionParamNames, +} + +impl RegionParameterization { + pub fn from_variance_and_generics(variance: Option, + generics: &ast::Generics) + -> Option { + match variance { + None => None, + Some(variance) => { + Some(RegionParameterization { + variance: variance, + region_param_names: + RegionParamNames::from_generics(generics), + }) + } + } + } +} + pub struct MethodRscope { self_ty: ast::self_ty_, - region_parameterization: Option + variance: Option, + region_param_names: RegionParamNames, +} + +impl MethodRscope { + // `generics` here refers to the generics of the outer item (impl or + // trait). + pub fn new(self_ty: ast::self_ty_, + variance: Option, + rcvr_generics: &ast::Generics, + method_generics: &ast::Generics) + -> MethodRscope { + let mut region_param_names = + RegionParamNames::from_generics(rcvr_generics); + region_param_names.add_generics(method_generics); + MethodRscope { + self_ty: self_ty, + variance: variance, + region_param_names: region_param_names + } + } + + pub fn region_param_names(&self) -> RegionParamNames { + copy self.region_param_names + } } + impl region_scope for MethodRscope { fn anon_region(&self, _span: span) -> Result { result::Err(RegionError { @@ -59,12 +182,26 @@ impl region_scope for MethodRscope { }) } fn self_region(&self, _span: span) -> Result { - fail_unless!(self.region_parameterization.is_some() || - self.self_ty.is_borrowed()); + fail_unless!(self.variance.is_some() || self.self_ty.is_borrowed()); + match self.variance { + None => {} // must be borrowed self, so this is OK + Some(_) => { + if !self.self_ty.is_borrowed() && + !self.region_param_names.has_self() { + return Err(RegionError { + msg: ~"the `self` lifetime must be declared", + replacement: ty::re_bound(ty::br_self) + }) + } + } + } result::Ok(ty::re_bound(ty::br_self)) } fn named_region(&self, span: span, id: ast::ident) -> Result { + if !self.region_param_names.has_ident(id) { + return RegionParamNames::undeclared_name(None); + } do empty_rscope.named_region(span, id).chain_err |_e| { result::Err(RegionError { msg: ~"lifetime is not in scope", @@ -74,7 +211,7 @@ impl region_scope for MethodRscope { } } -pub struct type_rscope(Option); +pub struct type_rscope(Option); impl type_rscope { priv fn replacement(&self) -> ty::Region { @@ -93,17 +230,29 @@ impl region_scope for type_rscope { }) } fn self_region(&self, _span: span) -> Result { - // if the self region is used, region parameterization should - // have inferred that this type is RP - fail_unless!(self.is_some()); + match **self { + None => { + // if the self region is used, region parameterization should + // have inferred that this type is RP + fail!(~"region parameterization should have inferred that \ + this type is RP"); + } + Some(ref region_parameterization) => { + if !region_parameterization.region_param_names.has_self() { + return Err(RegionError { + msg: ~"the `self` lifetime must be declared", + replacement: ty::re_bound(ty::br_self) + }) + } + } + } result::Ok(ty::re_bound(ty::br_self)) } fn named_region(&self, span: span, id: ast::ident) -> Result { do empty_rscope.named_region(span, id).chain_err |_e| { result::Err(RegionError { - msg: ~"only 'self is allowed allowed as \ - part of a type declaration", + msg: ~"only 'self is allowed as part of a type declaration", replacement: self.replacement() }) } @@ -121,14 +270,33 @@ pub fn bound_self_region(rp: Option) pub struct binding_rscope { base: @region_scope, anon_bindings: @mut uint, + region_param_names: RegionParamNames, } pub fn in_binding_rscope(self: &RS) -> binding_rscope { let base = @copy *self; let base = base as @region_scope; - binding_rscope { base: base, anon_bindings: @mut 0 } + binding_rscope { + base: base, + anon_bindings: @mut 0, + region_param_names: RegionParamNames::new() + } } + +pub fn in_binding_rscope_ext( + self: &RS, + +region_param_names: RegionParamNames) + -> binding_rscope { + let base = @copy *self; + let base = base as @region_scope; + binding_rscope { + base: base, + anon_bindings: @mut 0, + region_param_names: region_param_names, + } +} + impl region_scope for binding_rscope { fn anon_region(&self, _span: span) -> Result { let idx = *self.anon_bindings; @@ -143,7 +311,12 @@ impl region_scope for binding_rscope { id: ast::ident) -> Result { do self.base.named_region(span, id).chain_err |_e| { - result::Ok(ty::re_bound(ty::br_named(id))) + let result = ty::re_bound(ty::br_named(id)); + if self.region_param_names.has_ident(id) { + result::Ok(result) + } else { + RegionParamNames::undeclared_name(Some(result)) + } } } } diff --git a/src/librustc/rustc.rc b/src/librustc/rustc.rc index 5b4d3be126461..e3df3b692fb87 100644 --- a/src/librustc/rustc.rc +++ b/src/librustc/rustc.rc @@ -28,11 +28,26 @@ #[no_core]; extern mod core(vers = "0.6"); -use core::*; - extern mod std(vers = "0.6"); extern mod syntax(vers = "0.6"); +use core::prelude::*; + +use driver::driver::{host_triple, optgroups, early_error}; +use driver::driver::{str_input, file_input, build_session_options}; +use driver::driver::{build_session, build_configuration, parse_pretty}; +use driver::driver::{pp_mode, pretty_print_input, list_metadata}; +use driver::driver::{compile_input}; +use driver::session; +use middle::lint; + +use core::io::ReaderUtil; +use core::result::{Ok, Err}; +use std::getopts::{groups, opt_present}; +use std::getopts; +use syntax::codemap; +use syntax::diagnostic; + pub mod middle { pub mod trans { pub mod macros; @@ -123,23 +138,6 @@ pub mod lib { pub mod llvm; } -use core::prelude::*; - -use driver::driver::{host_triple, optgroups, early_error}; -use driver::driver::{str_input, file_input, build_session_options}; -use driver::driver::{build_session, build_configuration, parse_pretty}; -use driver::driver::{pp_mode, pretty_print_input, list_metadata}; -use driver::driver::{compile_input}; -use driver::session; -use middle::lint; - -use core::io::ReaderUtil; -use core::result::{Ok, Err}; -use std::getopts::{groups, opt_present}; -use std::getopts; -use syntax::codemap; -use syntax::diagnostic; - pub fn version(argv0: &str) { let mut vers = ~"unknown version"; let env_vers = env!("CFG_VERSION"); @@ -202,7 +200,7 @@ pub fn describe_debug_flags() { pub fn run_compiler(args: &~[~str], demitter: diagnostic::Emitter) { // Don't display log spew by default. Can override with RUST_LOG. - logging::console_off(); + ::core::logging::console_off(); let mut args = /*bad*/copy *args; let binary = args.shift(); 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/librustdoc/rustdoc.rc b/src/librustdoc/rustdoc.rc index 9eb3e81662806..9b19063a90866 100644 --- a/src/librustdoc/rustdoc.rc +++ b/src/librustdoc/rustdoc.rc @@ -28,6 +28,10 @@ extern mod std(vers = "0.6"); extern mod rustc(vers = "0.6"); extern mod syntax(vers = "0.6"); +use config::Config; +use doc::Item; +use doc::ItemUtils; + use core::*; pub mod pass; @@ -59,10 +63,6 @@ pub mod escape_pass; pub mod prune_private_pass; pub mod util; -use doc::ItemUtils; -use doc::Item; -use config::Config; - pub fn main() { let args = os::args(); diff --git a/src/librustpkg/rustpkg.rc b/src/librustpkg/rustpkg.rc index 35698bb235a38..50414bf2d1cd7 100644 --- a/src/librustpkg/rustpkg.rc +++ b/src/librustpkg/rustpkg.rc @@ -27,6 +27,7 @@ extern mod rustc(vers = "0.6"); extern mod syntax(vers = "0.6"); use core::*; +use core::container::Map; use core::hashmap::linear::LinearMap; use core::io::{ReaderUtil, WriterUtil}; use rustc::driver::{driver, session}; @@ -35,13 +36,12 @@ use std::net::url; use std::{json, semver, getopts}; use syntax::codemap::spanned; use syntax::{ast, attr, codemap, diagnostic, parse, visit}; -use core::container::Map; + +use util::Package; mod usage; mod util; -use util::Package; - struct PackageScript { id: ~str, name: ~str, 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/arena.rs b/src/libstd/arena.rs index a26132d92ca01..683e4a629756f 100644 --- a/src/libstd/arena.rs +++ b/src/libstd/arena.rs @@ -101,7 +101,7 @@ impl Drop for Arena { } fn chunk(size: uint, is_pod: bool) -> Chunk { - let mut v: @[const u8] = @[]; + let mut v: @[u8] = @[]; unsafe { at_vec::raw::reserve(&mut v, size); } Chunk { data: unsafe { cast::transmute(v) }, diff --git a/src/libstd/base64.rs b/src/libstd/base64.rs index 02858de9b347f..cdc15ae1d45dc 100644 --- a/src/libstd/base64.rs +++ b/src/libstd/base64.rs @@ -16,7 +16,7 @@ pub trait ToBase64 { fn to_base64(&self) -> ~str; } -static CHARS: [char * 64] = [ +static CHARS: [char, ..64] = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', @@ -24,7 +24,7 @@ static CHARS: [char * 64] = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' ]; -impl ToBase64 for &'self [u8] { +impl<'self> ToBase64 for &'self [u8] { fn to_base64(&self) -> ~str { let mut s = ~""; unsafe { @@ -73,7 +73,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 587509af9fa84..1a3a28f749279 100644 --- a/src/libstd/flatpipes.rs +++ b/src/libstd/flatpipes.rs @@ -254,7 +254,7 @@ pub trait ByteChan { fn send(&self, val: ~[u8]); } -static CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD]; +static CONTINUE: [u8, ..4] = [0xAA, 0xBB, 0xCC, 0xDD]; impl,P:BytePort> GenericPort for FlatPort { fn recv(&self) -> T { @@ -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) => { @@ -921,7 +921,7 @@ mod test { } fn test_try_recv_none3(loader: PortLoader

) { - static CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD]; + static CONTINUE: [u8, ..4] = [0xAA, 0xBB, 0xCC, 0xDD]; // The control word is followed by garbage let bytes = CONTINUE.to_vec() + ~[0]; let port = loader(bytes); @@ -940,7 +940,7 @@ mod test { fn test_try_recv_none4(+loader: PortLoader

) { fail_unless!(do task::try || { - static CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD]; + static CONTINUE: [u8, ..4] = [0xAA, 0xBB, 0xCC, 0xDD]; // The control word is followed by a valid length, // then undeserializable garbage let len_bytes = do io::u64_to_be_bytes( diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 8b8771e989a06..7c9b15bfded38 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/net_tcp.rs b/src/libstd/net_tcp.rs index c49f65d0f99b8..c1743c98c9bf1 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -972,7 +972,7 @@ impl io::Reader for TcpSocketBuf { /// Implementation of `io::Reader` trait for a buffered `net::tcp::TcpSocket` impl io::Writer for TcpSocketBuf { - pub fn write(&self, data: &[const u8]) { + pub fn write(&self, data: &const [u8]) { unsafe { let socket_data_ptr = ptr::addr_of(&(*((*(self.data)).sock).socket_data)); 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/sha1.rs b/src/libstd/sha1.rs index 64399defd54f7..b603e2eb1cc66 100644 --- a/src/libstd/sha1.rs +++ b/src/libstd/sha1.rs @@ -35,7 +35,7 @@ use core::vec; /// The SHA-1 interface trait Sha1 { /// Provide message input as bytes - fn input(&mut self, &[const u8]); + fn input(&mut self, &const [u8]); /// Provide message input as string fn input_str(&mut self, &str); /** @@ -73,7 +73,7 @@ pub fn sha1() -> @Sha1 { computed: bool, work_buf: @mut ~[u32]}; - fn add_input(st: &mut Sha1State, msg: &[const u8]) { + fn add_input(st: &mut Sha1State, msg: &const [u8]) { fail_unless!((!st.computed)); for vec::each_const(msg) |element| { st.msg_block[st.msg_block_idx] = *element; @@ -241,7 +241,7 @@ pub fn sha1() -> @Sha1 { self.h[4] = 0xC3D2E1F0u32; self.computed = false; } - fn input(&mut self, msg: &[const u8]) { add_input(self, msg); } + fn input(&mut self, msg: &const [u8]) { add_input(self, msg); } fn input_str(&mut self, msg: &str) { let bs = str::to_bytes(msg); add_input(self, bs); 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 8a239e8b6d8ed..1588d688148d5 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. @@ -24,12 +24,12 @@ type Le = &'self fn(v1: &T, v2: &T) -> bool; * Has worst case O(n log n) performance, best case O(n), but * is not space efficient. This is a stable sort. */ -pub fn merge_sort(v: &[const T], le: Le) -> ~[T] { +pub fn merge_sort(v: &const [T], le: Le) -> ~[T] { type Slice = (uint, uint); unsafe {return merge_sort_(v, (0u, len(v)), le);} - fn merge_sort_(v: &[const T], slice: Slice, le: Le) + fn merge_sort_(v: &const [T], slice: Slice, le: Le) -> ~[T] { let begin = slice.first(); let end = slice.second(); @@ -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); } } @@ -290,8 +290,10 @@ fn count_run_ascending(array: &mut [T]) -> uint { return run; } -fn gallop_left(key: &const T, array: &[const T], - hint: uint) -> uint { +fn gallop_left(key: &const T, + array: &const [T], + hint: uint) + -> uint { let size = array.len(); fail_unless!(size != 0 && hint < size); @@ -339,8 +341,10 @@ fn gallop_left(key: &const T, array: &[const T], return ofs; } -fn gallop_right(key: &const T, array: &[const T], - hint: uint) -> uint { +fn gallop_right(key: &const T, + array: &const [T], + hint: uint) + -> uint { let size = array.len(); fail_unless!(size != 0 && hint < size); @@ -709,8 +713,11 @@ impl MergeState { } #[inline(always)] -fn copy_vec(dest: &mut [T], s1: uint, - from: &[const T], s2: uint, len: uint) { +fn copy_vec(dest: &mut [T], + s1: uint, + from: &const [T], + s2: uint, + len: uint) { fail_unless!(s1+len <= dest.len() && s2+len <= from.len()); let mut slice = ~[]; @@ -1022,7 +1029,7 @@ mod big_tests { tabulate_managed(low, high); } - fn multiplyVec(arr: &[const T], num: uint) -> ~[T] { + fn multiplyVec(arr: &const [T], num: uint) -> ~[T] { let size = arr.len(); let res = do vec::from_fn(num) |i| { arr[i % size] @@ -1038,7 +1045,7 @@ mod big_tests { } fn tabulate_unique(lo: uint, hi: uint) { - fn isSorted(arr: &[const T]) { + fn isSorted(arr: &const [T]) { for uint::range(0, arr.len()-1) |i| { if arr[i] > arr[i+1] { fail!(~"Array not sorted"); @@ -1110,7 +1117,7 @@ mod big_tests { } fn tabulate_managed(lo: uint, hi: uint) { - fn isSorted(arr: &[const @T]) { + fn isSorted(arr: &const [@T]) { for uint::range(0, arr.len()-1) |i| { if arr[i] > arr[i+1] { fail!(~"Array not sorted"); @@ -1181,7 +1188,7 @@ mod big_tests { } } - struct LVal { + struct LVal<'self> { val: uint, key: &'self fn(@uint), } @@ -1202,16 +1209,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/std.rc b/src/libstd/std.rc index 7d46e73a697f8..a0ab714de05f8 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -33,7 +33,7 @@ not required in or otherwise suitable for the core library. #[no_core]; extern mod core(vers = "0.6"); -use core::*; +use core::prelude::*; pub mod uv_ll; diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index 22ba33ba04e43..ea9455b1e981c 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -162,12 +162,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(); @@ -175,14 +175,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 } @@ -194,7 +194,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. * @@ -260,7 +260,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]>, } @@ -276,8 +276,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 } @@ -615,7 +615,7 @@ pub impl RWlock { // FIXME(#3588) should go inside of read() #[doc(hidden)] -struct RWlockReleaseRead { +struct RWlockReleaseRead<'self> { lock: &'self RWlock, } @@ -651,7 +651,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, } @@ -699,7 +699,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/test.rs b/src/libstd/test.rs index ded4d6fd1b4dc..93170668c130d 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -563,7 +563,7 @@ pub fn run_test(force_ignore: bool, fn run_test_inner(desc: TestDesc, monitor_ch: SharedChan, testfn: ~fn()) { - let testfn_cell = ::cell::Cell(testfn); + let testfn_cell = ::core::cell::Cell(testfn); do task::spawn { let mut result_future = None; // task::future_result(builder); task::task().unlinked().future_result(|+r| { 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 b3974acc6741a..017e95ab4c11c 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -609,7 +609,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/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 32c8b88aed8bd..75a3d9ab2b14a 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -61,6 +61,7 @@ pub enum ObsoleteSyntax { ObsoletePurity, ObsoleteStaticMethod, ObsoleteConstItem, + ObsoleteFixedLengthVectorType, } impl to_bytes::IterBytes for ObsoleteSyntax { @@ -209,6 +210,10 @@ pub impl Parser { "`const` items are now `static` items; replace `const` with \ `static`" ), + ObsoleteFixedLengthVectorType => ( + "fixed-length vector notation", + "instead of `[T * N]`, write `[T, ..N]`" + ), }; self.report(sp, kind, kind_str, desc); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 171cd90bcd2b3..53d618e3340a5 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -81,7 +81,7 @@ use parse::obsolete::{ObsoleteBareFnType, ObsoleteNewtypeEnum}; use parse::obsolete::{ObsoleteMode, ObsoleteImplicitSelf}; use parse::obsolete::{ObsoleteLifetimeNotation, ObsoleteConstManagedPointer}; use parse::obsolete::{ObsoletePurity, ObsoleteStaticMethod}; -use parse::obsolete::{ObsoleteConstItem}; +use parse::obsolete::{ObsoleteConstItem, ObsoleteFixedLengthVectorType}; use parse::prec::{as_prec, token_to_binop}; use parse::token::{can_begin_expr, is_ident, is_ident_or_path}; use parse::token::{is_plain_ident, INTERPOLATED, special_idents}; @@ -120,6 +120,7 @@ pub enum item_or_view_item { iovi_view_item(@view_item) } +#[deriving(Eq)] enum view_item_parse_mode { VIEW_ITEMS_AND_ITEMS_ALLOWED, FOREIGN_ITEMS_ALLOWED, @@ -251,7 +252,7 @@ pub struct Parser { token: @mut token::Token, span: @mut span, last_span: @mut span, - buffer: @mut [TokenAndSpan * 4], + buffer: @mut [TokenAndSpan, ..4], buffer_start: @mut int, buffer_end: @mut int, tokens_consumed: @mut uint, @@ -362,10 +363,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 +402,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 +429,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 +440,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 +455,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] { @@ -825,7 +839,7 @@ pub impl Parser { fn maybe_parse_fixed_vstore(&self) -> Option<@ast::expr> { if self.eat(&token::BINOP(token::STAR)) { - // XXX: Obsolete; remove after snapshot. + self.obsolete(*self.last_span, ObsoleteFixedLengthVectorType); Some(self.parse_expr()) } else if *self.token == token::COMMA && self.look_ahead(1) == token::DOTDOT { @@ -1176,7 +1190,7 @@ pub impl Parser { } else if *self.token == token::LBRACKET { self.bump(); let mutbl = self.parse_mutability(); - if mutbl == m_mutbl { // `m_const` too after snapshot + if mutbl == m_mutbl || mutbl == m_const { self.obsolete(*self.last_span, ObsoleteMutVector); } @@ -4311,48 +4325,91 @@ pub impl Parser { VIEW_ITEMS_AND_ITEMS_ALLOWED | IMPORTS_AND_ITEMS_ALLOWED => true, FOREIGN_ITEMS_ALLOWED => false }; - - let restricted_to_imports = match mode { - IMPORTS_AND_ITEMS_ALLOWED => true, - VIEW_ITEMS_AND_ITEMS_ALLOWED | - FOREIGN_ITEMS_ALLOWED => false - }; - let foreign_items_allowed = match mode { FOREIGN_ITEMS_ALLOWED => true, VIEW_ITEMS_AND_ITEMS_ALLOWED | IMPORTS_AND_ITEMS_ALLOWED => false }; + // First, parse view items. let mut (view_items, items, foreign_items) = (~[], ~[], ~[]); - loop { - match self.parse_item_or_view_item(/*bad*/ copy attrs, - items_allowed, - foreign_items_allowed, - macros_allowed) { - iovi_none => - break, - iovi_view_item(view_item) => { - if restricted_to_imports { - match view_item.node { - view_item_use(*) => {} - view_item_extern_mod(*) => - self.fatal(~"\"extern mod\" \ - declarations are not \ - allowed here") + let mut done = false; + if mode != FOREIGN_ITEMS_ALLOWED { + let mut extern_mod_allowed = match mode { + VIEW_ITEMS_AND_ITEMS_ALLOWED => true, + IMPORTS_AND_ITEMS_ALLOWED => false, + FOREIGN_ITEMS_ALLOWED => { + self.bug(~"couldn't get here with FOREIGN_ITEMS_ALLOWED") + } + }; + + loop { + match self.parse_item_or_view_item(/*bad*/ copy attrs, + items_allowed, + foreign_items_allowed, + macros_allowed) { + iovi_none => { + done = true; + break; + } + iovi_view_item(view_item) => { + match view_item.node { + view_item_use(*) => { + // `extern mod` must precede `use`. + extern_mod_allowed = false; + } + view_item_extern_mod(*) + if !extern_mod_allowed => { + self.span_err(view_item.span, + ~"\"extern mod\" \ + declarations are not \ + allowed here"); } + view_item_extern_mod(*) => {} + } + view_items.push(view_item); + } + iovi_item(item) => { + fail_unless!(items_allowed); + items.push(item); + attrs = self.parse_outer_attributes(); + break; + } + iovi_foreign_item(foreign_item) => { + fail_unless!(foreign_items_allowed); + foreign_items.push(foreign_item); + attrs = self.parse_outer_attributes(); + break; } - view_items.push(view_item); - } - iovi_item(item) => { - fail_unless!(items_allowed); - items.push(item) } - iovi_foreign_item(foreign_item) => { - fail_unless!(foreign_items_allowed); - foreign_items.push(foreign_item); + attrs = self.parse_outer_attributes(); + } + } + + // Next, parse items. + if !done { + loop { + match self.parse_item_or_view_item(/*bad*/ copy attrs, + items_allowed, + foreign_items_allowed, + macros_allowed) { + iovi_none => break, + iovi_view_item(view_item) => { + self.span_err(view_item.span, + ~"`use` and `extern mod` declarations \ + must precede items"); + view_items.push(view_item); + } + iovi_item(item) => { + fail_unless!(items_allowed); + items.push(item) + } + iovi_foreign_item(foreign_item) => { + fail_unless!(foreign_items_allowed); + foreign_items.push(foreign_item); + } } + attrs = self.parse_outer_attributes(); } - attrs = self.parse_outer_attributes(); } ParsedItemsAndViewItems { diff --git a/src/libsyntax/syntax.rc b/src/libsyntax/syntax.rc index 19ed68093267a..feff4b0616a44 100644 --- a/src/libsyntax/syntax.rc +++ b/src/libsyntax/syntax.rc @@ -26,10 +26,10 @@ #[no_core]; extern mod core(vers = "0.6"); -use core::*; - extern mod std(vers = "0.6"); +use core::*; + pub mod syntax { pub use ext; pub use parse; diff --git a/src/test/auxiliary/extern_mod_ordering_lib.rs b/src/test/auxiliary/extern_mod_ordering_lib.rs new file mode 100644 index 0000000000000..8276cea465fd5 --- /dev/null +++ b/src/test/auxiliary/extern_mod_ordering_lib.rs @@ -0,0 +1,6 @@ +#[crate_type="lib"]; + +pub mod extern_mod_ordering_lib { + pub fn f() {} +} + diff --git a/src/test/auxiliary/pub_use_mods_xcrate.rs b/src/test/auxiliary/pub_use_mods_xcrate.rs index 162f7de4b1b43..e085f2312dc50 100644 --- a/src/test/auxiliary/pub_use_mods_xcrate.rs +++ b/src/test/auxiliary/pub_use_mods_xcrate.rs @@ -9,13 +9,13 @@ // except according to those terms. pub mod a { + pub use a::b::c; + pub mod b { pub mod c { fn f(){} fn g(){} } } - - pub use a::b::c; } diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs index 7993822afd877..d28382abaa386 100644 --- a/src/test/bench/noise.rs +++ b/src/test/bench/noise.rs @@ -24,8 +24,8 @@ fn gradient(orig: Vec2, grad: Vec2, p: Vec2) -> f32 { } struct Noise2DContext { - rgradients: [Vec2 * 256], - permutations: [int * 256], + rgradients: [Vec2, ..256], + permutations: [int, ..256], } fn Noise2DContext() -> ~Noise2DContext { @@ -50,7 +50,7 @@ pub impl Noise2DContext { } #[inline(always)] - fn get_gradients(&self, gradients: &mut [Vec2 * 4], origins: &mut [Vec2 * 4], x: f32, y: f32) { + fn get_gradients(&self, gradients: &mut [Vec2, ..4], origins: &mut [Vec2, ..4], x: f32, y: f32) { let x0f = f32::floor(x); let y0f = f32::floor(y); let x0 = x0f as int; diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index ada5ff7be2fa8..1764ef48412cc 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -101,7 +101,7 @@ fn chanmb(i: uint, size: uint, depth: uint) -> Line struct Devnull(); impl io::Writer for Devnull { - fn write(&self, _b: &[const u8]) {} + fn write(&self, _b: &const [u8]) {} fn seek(&self, _i: int, _s: io::SeekStyle) {} fn tell(&self) -> uint {0_u} fn flush(&self) -> int {0} diff --git a/src/test/bench/shootout-spectralnorm.rs b/src/test/bench/shootout-spectralnorm.rs index 2b9a030fdf4ce..6e39b755b22af 100644 --- a/src/test/bench/shootout-spectralnorm.rs +++ b/src/test/bench/shootout-spectralnorm.rs @@ -16,7 +16,7 @@ fn eval_A(i: uint, j: uint) -> float { 1.0/(((i+j)*(i+j+1u)/2u+i+1u) as float) } -fn eval_A_times_u(u: &[const float], Au: &mut [float]) { +fn eval_A_times_u(u: &const [float], Au: &mut [float]) { let N = vec::len(u); let mut i = 0u; while i < N { @@ -30,7 +30,7 @@ fn eval_A_times_u(u: &[const float], Au: &mut [float]) { } } -fn eval_At_times_u(u: &[const float], Au: &mut [float]) { +fn eval_At_times_u(u: &const [float], Au: &mut [float]) { let N = vec::len(u); let mut i = 0u; while i < N { @@ -44,7 +44,7 @@ fn eval_At_times_u(u: &[const float], Au: &mut [float]) { } } -fn eval_AtA_times_u(u: &[const float], AtAu: &mut [float]) { +fn eval_AtA_times_u(u: &const [float], AtAu: &mut [float]) { let mut v = vec::from_elem(vec::len(u), 0.0); eval_A_times_u(u, v); eval_At_times_u(v, AtAu); diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index dcc5fe5875522..09c9e27d4dbfe 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -44,7 +44,7 @@ pub impl Sudoku { return Sudoku { grid: g } } - pub fn from_vec(vec: &[[u8 * 9] * 9]) -> Sudoku { + pub fn from_vec(vec: &[[u8, ..9], ..9]) -> Sudoku { let mut g = do vec::from_fn(9u) |i| { do vec::from_fn(9u) |j| { vec[i][j] } }; @@ -183,7 +183,7 @@ impl Colors { } } -static default_sudoku: [[u8 * 9] * 9] = [ +static default_sudoku: [[u8, ..9], ..9] = [ /* 0 1 2 3 4 5 6 7 8 */ /* 0 */ [0u8, 4u8, 0u8, 6u8, 0u8, 0u8, 0u8, 3u8, 2u8], /* 1 */ [0u8, 0u8, 8u8, 0u8, 2u8, 0u8, 0u8, 0u8, 0u8], @@ -197,7 +197,7 @@ static default_sudoku: [[u8 * 9] * 9] = [ ]; #[cfg(test)] -static default_solution: [[u8 * 9] * 9] = [ +static default_solution: [[u8, ..9], ..9] = [ /* 0 1 2 3 4 5 6 7 8 */ /* 0 */ [1u8, 4u8, 9u8, 6u8, 7u8, 5u8, 8u8, 3u8, 2u8], /* 1 */ [5u8, 3u8, 8u8, 1u8, 2u8, 9u8, 7u8, 4u8, 6u8], 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/const-cast-wrong-type.rs b/src/test/compile-fail/const-cast-wrong-type.rs index 677f4318db759..875358ea14201 100644 --- a/src/test/compile-fail/const-cast-wrong-type.rs +++ b/src/test/compile-fail/const-cast-wrong-type.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static a: [u8 * 3] = ['h' as u8, 'i' as u8, 0 as u8]; +static a: [u8, ..3] = ['h' as u8, 'i' as u8, 0 as u8]; static b: *i8 = &a as *i8; //~ ERROR mismatched types fn main() { diff --git a/src/test/compile-fail/evec-subtyping.rs b/src/test/compile-fail/evec-subtyping.rs index 06baf5c834bf0..f9c8ba01f1805 100644 --- a/src/test/compile-fail/evec-subtyping.rs +++ b/src/test/compile-fail/evec-subtyping.rs @@ -10,7 +10,7 @@ fn wants_box(x: @[uint]) { } fn wants_uniq(x: ~[uint]) { } -fn wants_three(x: [uint * 3]) { } +fn wants_three(x: [uint, ..3]) { } fn has_box(x: @[uint]) { wants_box(x); @@ -24,13 +24,13 @@ fn has_uniq(x: ~[uint]) { wants_three(x); //~ ERROR [] storage differs: expected 3 but found ~ } -fn has_three(x: [uint * 3]) { +fn has_three(x: [uint, ..3]) { wants_box(x); //~ ERROR [] storage differs: expected @ but found 3 wants_uniq(x); //~ ERROR [] storage differs: expected ~ but found 3 wants_three(x); } -fn has_four(x: [uint * 4]) { +fn has_four(x: [uint, ..4]) { wants_box(x); //~ ERROR [] storage differs: expected @ but found 4 wants_uniq(x); //~ ERROR [] storage differs: expected ~ but found 4 wants_three(x); //~ ERROR [] storage differs: expected 3 but found 4 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-2150.rs b/src/test/compile-fail/issue-2150.rs index 3ab8f765ad545..9f2f9a855ed52 100644 --- a/src/test/compile-fail/issue-2150.rs +++ b/src/test/compile-fail/issue-2150.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn fail_len(v: ~[const int]) -> uint { +fn fail_len(v: ~[int]) -> uint { let mut i = fail!(); for v.each |x| { i += 1u; } //~^ WARNING unreachable statement 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 295b6c989b5f3..67059e4623e8f 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/issue-4517.rs b/src/test/compile-fail/issue-4517.rs index 18caaa697a17d..23cfeecc520e7 100644 --- a/src/test/compile-fail/issue-4517.rs +++ b/src/test/compile-fail/issue-4517.rs @@ -1,6 +1,6 @@ fn bar(int_param: int) {} fn main() { - let foo: [u8 * 4] = [1u8, ..4u8]; + let foo: [u8, ..4] = [1u8, ..4u8]; bar(foo); //~ ERROR mismatched types: expected `int` but found `[u8 * 4]` (expected int but found vector) } diff --git a/src/test/compile-fail/mutable-huh-vec-assign.rs b/src/test/compile-fail/mutable-huh-vec-assign.rs deleted file mode 100644 index 83cfd2403563a..0000000000000 --- a/src/test/compile-fail/mutable-huh-vec-assign.rs +++ /dev/null @@ -1,20 +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 main() { - fn f(&&v: ~[const int]) { - // This shouldn't be possible - v[0] = 1 //~ ERROR assigning to const vec content - } - - let v = ~[0]; - - f(v); -} 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/compile-fail/tag-that-dare-not-speak-its-name.rs b/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs index a05d6a324de7b..af99c0e5f2953 100644 --- a/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs +++ b/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs @@ -15,7 +15,7 @@ extern mod core; -fn last(v: ~[const &T]) -> core::Option { +fn last(v: ~[&T]) -> core::Option { fail!(); } diff --git a/src/test/compile-fail/vec-add.rs b/src/test/compile-fail/vec-add.rs index 0f51d34fc2ff2..f30a050211ec6 100644 --- a/src/test/compile-fail/vec-add.rs +++ b/src/test/compile-fail/vec-add.rs @@ -14,7 +14,7 @@ // the right hand side in all cases. We are getting compiler errors // about this now, so I'm xfailing the test for now. -eholk -fn add(i: ~[int], mut m: ~[int], c: ~[const int]) { +fn add(i: ~[int], mut m: ~[int]) { // Check that: // (1) vectors of any two mutabilities can be added @@ -36,10 +36,6 @@ fn add(i: ~[int], mut m: ~[int], c: ~[const int]) { m + m, m); - add(i + c, - m + c, - c); - add(m + ~[3], //~ ERROR mismatched types m + ~[3], m + ~[3]); @@ -48,12 +44,6 @@ fn add(i: ~[int], mut m: ~[int], c: ~[const int]) { i + ~[3], //~ ERROR mismatched types i + ~[3]); - add(c + ~[3], //~ ERROR mismatched types - //~^ ERROR binary operation + cannot be applied - c + ~[3], //~ ERROR binary operation + cannot be applied - //~^ mismatched types - ~[3]); - add(m + ~[3], //~ ERROR mismatched types m + ~[3], m + ~[3]); @@ -62,12 +52,6 @@ fn add(i: ~[int], mut m: ~[int], c: ~[const int]) { i + ~[3], //~ ERROR mismatched types i + ~[3]); - add(c + ~[3], //~ ERROR binary operation + cannot be applied - //~^ mismatched types - c + ~[3], //~ ERROR binary operation + cannot be applied - //~^ mismatched types - ~[3]); - add(m + i, //~ ERROR mismatched types m + i, m + i); @@ -76,12 +60,6 @@ fn add(i: ~[int], mut m: ~[int], c: ~[const int]) { i + i, //~ ERROR mismatched types i + i); - add(c + i, //~ ERROR binary operation + cannot be applied - //~^ ERROR mismatched types - c + i, //~ ERROR binary operation + cannot be applied - //~^ ERROR mismatched types - i); - add(m + m, //~ ERROR mismatched types m + m, m + m); @@ -89,26 +67,6 @@ fn add(i: ~[int], mut m: ~[int], c: ~[const int]) { add(i + m, i + m, //~ ERROR mismatched types i + m); - - add(c + m, //~ ERROR binary operation + cannot be applied - //~^ ERROR mismatched types - c + m, //~ ERROR binary operation + cannot be applied - //~^ ERROR mismatched types - m); - - add(m + c, //~ ERROR mismatched types - m + c, - m + c); - - add(i + c, - i + c, //~ ERROR mismatched types - i + c); - - add(c + c, //~ ERROR binary operation + cannot be applied - //~^ ERROR mismatched types - c + c, //~ ERROR binary operation + cannot be applied - //~^ ERROR mismatched types - c); } fn main() { diff --git a/src/test/compile-fail/vec-concat-bug.rs b/src/test/compile-fail/vec-concat-bug.rs deleted file mode 100644 index 478e01ccd042e..0000000000000 --- a/src/test/compile-fail/vec-concat-bug.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. - -fn concat(v: ~[const ~[const T]]) -> ~[T] { - let mut r = ~[]; - - // Earlier versions of our type checker accepted this: - vec::each(v, |inner: &~[T]| { - //~^ ERROR values differ in mutability - r += *inner; true - }); - - return r; -} - -fn main() {} 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-imm-vec-arg.rs b/src/test/run-pass/coerce-reborrow-imm-vec-arg.rs index ad5eb50ccef30..3f12c0d635311 100644 --- a/src/test/run-pass/coerce-reborrow-imm-vec-arg.rs +++ b/src/test/run-pass/coerce-reborrow-imm-vec-arg.rs @@ -14,7 +14,7 @@ fn sum_imm(y: &[int]) -> int { sum(y) } -fn sum_const(y: &[const int]) -> int { +fn sum_const(y: &const [int]) -> int { sum(y) } diff --git a/src/test/run-pass/coerce-reborrow-imm-vec-rcvr.rs b/src/test/run-pass/coerce-reborrow-imm-vec-rcvr.rs index bf86472d900d7..7dcf49ef1ac44 100644 --- a/src/test/run-pass/coerce-reborrow-imm-vec-rcvr.rs +++ b/src/test/run-pass/coerce-reborrow-imm-vec-rcvr.rs @@ -1,6 +1,6 @@ // xfail-test -fn foo(v: &[const uint]) -> ~[uint] { +fn foo(v: &const [uint]) -> ~[uint] { v.to_vec() } 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-autoderef.rs b/src/test/run-pass/const-autoderef.rs index fa482c38d145b..572b961b2f884 100644 --- a/src/test/run-pass/const-autoderef.rs +++ b/src/test/run-pass/const-autoderef.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static A: [u8 * 1] = ['h' as u8]; +static A: [u8, ..1] = ['h' as u8]; static B: u8 = (&A)[0]; -static C: &'static &'static &'static &'static [u8 * 1] = & & & &A; +static C: &'static &'static &'static &'static [u8, ..1] = & & & &A; static D: u8 = (&C)[0]; pub fn main() { diff --git a/src/test/run-pass/const-enum-vector.rs b/src/test/run-pass/const-enum-vector.rs index db7982c451fa0..0e92694dde8ac 100644 --- a/src/test/run-pass/const-enum-vector.rs +++ b/src/test/run-pass/const-enum-vector.rs @@ -9,7 +9,7 @@ // except according to those terms. enum E { V1(int), V0 } -static C: [E * 3] = [V0, V1(0xDEADBEE), V0]; +static C: [E, ..3] = [V0, V1(0xDEADBEE), V0]; pub fn main() { match C[1] { diff --git a/src/test/run-pass/const-expr-in-fixed-length-vec.rs b/src/test/run-pass/const-expr-in-fixed-length-vec.rs index 69585c9d31c9e..dc97c58221983 100644 --- a/src/test/run-pass/const-expr-in-fixed-length-vec.rs +++ b/src/test/run-pass/const-expr-in-fixed-length-vec.rs @@ -14,6 +14,6 @@ fn main() { static FOO: int = 2; - let _v: [int * FOO*3]; + let _v: [int, ..FOO*3]; } diff --git a/src/test/run-pass/const-fields-and-indexing.rs b/src/test/run-pass/const-fields-and-indexing.rs index a3611c5eb2658..658b39509bfbb 100644 --- a/src/test/run-pass/const-fields-and-indexing.rs +++ b/src/test/run-pass/const-fields-and-indexing.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static x : [int * 4] = [1,2,3,4]; +static x : [int, ..4] = [1,2,3,4]; static p : int = x[2]; static y : &'static [int] = &[1,2,3,4]; static q : int = y[2]; 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 23d1d63f18996..a0d16a3ec3ab1 100644 --- a/src/test/run-pass/const-region-ptrs-noncopy.rs +++ b/src/test/run-pass/const-region-ptrs-noncopy.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -type Big = [u64 * 8]; -struct Pair { a: int, b: &'self Big } +type Big = [u64, ..8]; +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/const-str-ptr.rs b/src/test/run-pass/const-str-ptr.rs index 2560431b53209..1f40c57d851b3 100644 --- a/src/test/run-pass/const-str-ptr.rs +++ b/src/test/run-pass/const-str-ptr.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static a: [u8 * 3] = ['h' as u8, 'i' as u8, 0 as u8]; -static c: &'static [u8 * 3] = &a; +static a: [u8, ..3] = ['h' as u8, 'i' as u8, 0 as u8]; +static c: &'static [u8, ..3] = &a; static b: *u8 = c as *u8; fn main() { diff --git a/src/test/run-pass/const-vecs-and-slices.rs b/src/test/run-pass/const-vecs-and-slices.rs index 736335464b24d..f99f2c17ca5df 100644 --- a/src/test/run-pass/const-vecs-and-slices.rs +++ b/src/test/run-pass/const-vecs-and-slices.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static x : [int * 4] = [1,2,3,4]; +static x : [int, ..4] = [1,2,3,4]; static y : &'static [int] = &[1,2,3,4]; pub fn main() { diff --git a/src/test/run-pass/evec-internal-boxes.rs b/src/test/run-pass/evec-internal-boxes.rs index 657a881089779..ec5c5f01e1597 100644 --- a/src/test/run-pass/evec-internal-boxes.rs +++ b/src/test/run-pass/evec-internal-boxes.rs @@ -9,8 +9,8 @@ // except according to those terms. pub fn main() { - let x : [@int * 5] = [@1,@2,@3,@4,@5]; - let _y : [@int * 5] = [@1,@2,@3,@4,@5]; + let x : [@int, ..5] = [@1,@2,@3,@4,@5]; + let _y : [@int, ..5] = [@1,@2,@3,@4,@5]; let mut z = [@1,@2,@3,@4,@5]; z = x; fail_unless!(*z[0] == 1); diff --git a/src/test/run-pass/evec-internal.rs b/src/test/run-pass/evec-internal.rs index 937912e7baf3e..1c23d5ac810a7 100644 --- a/src/test/run-pass/evec-internal.rs +++ b/src/test/run-pass/evec-internal.rs @@ -14,16 +14,16 @@ // Doesn't work; needs a design decision. pub fn main() { - let x : [int * 5] = [1,2,3,4,5]; - let _y : [int * 5] = [1,2,3,4,5]; + let x : [int, ..5] = [1,2,3,4,5]; + let _y : [int, ..5] = [1,2,3,4,5]; let mut z = [1,2,3,4,5]; z = x; fail_unless!(z[0] == 1); fail_unless!(z[4] == 5); - let a : [int * 5] = [1,1,1,1,1]; - let b : [int * 5] = [2,2,2,2,2]; - let c : [int * 5] = [2,2,2,2,3]; + let a : [int, ..5] = [1,1,1,1,1]; + let b : [int, ..5] = [2,2,2,2,2]; + let c : [int, ..5] = [2,2,2,2,3]; log(debug, a); 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/extern-mod-ordering-exe.rs b/src/test/run-pass/extern-mod-ordering-exe.rs new file mode 100644 index 0000000000000..b60302277b326 --- /dev/null +++ b/src/test/run-pass/extern-mod-ordering-exe.rs @@ -0,0 +1,11 @@ +// aux-build:extern_mod_ordering_lib.rs +// xfail-fast + +extern mod extern_mod_ordering_lib; + +use extern_mod_ordering_lib::extern_mod_ordering_lib; + +fn main() { + extern_mod_ordering_lib::f(); +} + diff --git a/src/test/run-pass/fixed_length_vec_glue.rs b/src/test/run-pass/fixed_length_vec_glue.rs index 87fdbf071d2af..a8752f444bfd8 100644 --- a/src/test/run-pass/fixed_length_vec_glue.rs +++ b/src/test/run-pass/fixed_length_vec_glue.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct Struc { a: u8, b: [int * 3], c: int } +struct Struc { a: u8, b: [int, ..3], c: int } pub fn main() { let arr = [1,2,3]; diff --git a/src/test/run-pass/impl-variance.rs b/src/test/run-pass/impl-variance.rs deleted file mode 100644 index 31375edb5de04..0000000000000 --- a/src/test/run-pass/impl-variance.rs +++ /dev/null @@ -1,26 +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. - -trait foo { - fn foo(&self) -> uint; -} - -impl foo for ~[const T] { - fn foo(&self) -> uint { vec::len(*self) } -} - -pub fn main() { - let v = ~[const 0]; - fail_unless!(v.foo() == 1u); - let v = ~[0]; - fail_unless!(v.foo() == 1u); - let mut v = ~[0]; - fail_unless!(v.foo() == 1u); -} 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-2904.rs b/src/test/run-pass/issue-2904.rs index 8a7e2b8a9a9bf..84a4083a62860 100644 --- a/src/test/run-pass/issue-2904.rs +++ b/src/test/run-pass/issue-2904.rs @@ -12,10 +12,10 @@ /// Map representation -use core::io::ReaderUtil; - extern mod std; +use core::io::ReaderUtil; + enum square { bot, wall, 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-3656.rs b/src/test/run-pass/issue-3656.rs index edb9278781fd4..b59810fc18875 100644 --- a/src/test/run-pass/issue-3656.rs +++ b/src/test/run-pass/issue-3656.rs @@ -16,7 +16,7 @@ use core::libc::*; struct KEYGEN { - hash_algorithm: [c_uint * 2], + hash_algorithm: [c_uint, ..2], count: uint32_t, salt: *c_void, salt_size: uint32_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/maybe-mutable.rs b/src/test/run-pass/maybe-mutable.rs deleted file mode 100644 index 155046bccccc6..0000000000000 --- a/src/test/run-pass/maybe-mutable.rs +++ /dev/null @@ -1,26 +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. - - - - -// -*- rust -*- -fn len(v: ~[const int]) -> uint { - let mut i = 0u; - while i < vec::len(v) { i += 1u; } - return i; -} - -pub fn main() { - let v0 = ~[1, 2, 3, 4, 5]; - debug!(len(v0)); - let mut v1 = ~[1, 2, 3, 4, 5]; - debug!(len(v1)); -} diff --git a/src/test/run-pass/mutable-huh-variance-vec1.rs b/src/test/run-pass/mutable-huh-variance-vec1.rs deleted file mode 100644 index 8db2705de2b4e..0000000000000 --- a/src/test/run-pass/mutable-huh-variance-vec1.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. - -// error-pattern: mismatched types - -pub fn main() { - let v = ~[~[0]]; - - // This is ok because the outer vec is covariant with respect - // to the inner vec. If the outer vec was mut then we - // couldn't do this. - fn f(&&v: ~[~[const int]]) { - } - - f(v); -} diff --git a/src/test/run-pass/mutable-huh-variance-vec2.rs b/src/test/run-pass/mutable-huh-variance-vec2.rs deleted file mode 100644 index 7c48744000d4f..0000000000000 --- a/src/test/run-pass/mutable-huh-variance-vec2.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. - -// error-pattern: mismatched types - -pub fn main() { - let v = ~[~[0]]; - - // This is ok because the outer vec is covariant with respect - // to the inner vec. If the outer vec was mut then we - // couldn't do this. - fn f(&&v: ~[const ~[const int]]) { - } - - f(v); -} diff --git a/src/test/run-pass/newtype-struct-with-dtor.rs b/src/test/run-pass/newtype-struct-with-dtor.rs new file mode 100644 index 0000000000000..f4a059018d209 --- /dev/null +++ b/src/test/run-pass/newtype-struct-with-dtor.rs @@ -0,0 +1,17 @@ +use core::libc::c_int; +use core::libc; + +pub struct Fd(c_int); + +impl Drop for Fd { + fn finalize(&self) { + unsafe { + libc::close(**self); + } + } +} + +fn main() { +} + + 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 6cad8c74592e4..e7edeca3b9a19 100644 --- a/src/test/run-pass/region-dependent-addr-of.rs +++ b/src/test/run-pass/region-dependent-addr-of.rs @@ -14,7 +14,7 @@ struct A { struct B { v1: int, - v2: [int * 3], + v2: [int, ..3], v3: ~[int], v4: C, v5: ~C, @@ -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 } diff --git a/src/test/run-pass/trait-inheritance-num.rs b/src/test/run-pass/trait-inheritance-num.rs index 92cb25b8d2be7..b800ffefeb694 100644 --- a/src/test/run-pass/trait-inheritance-num.rs +++ b/src/test/run-pass/trait-inheritance-num.rs @@ -10,10 +10,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +extern mod std; + use core::cmp::{Eq, Ord}; use core::num::NumCast::from; - -extern mod std; use std::cmp::FuzzyEq; pub trait NumExt: NumCast + Eq + Ord {} diff --git a/src/test/run-pass/trait-inheritance-num2.rs b/src/test/run-pass/trait-inheritance-num2.rs index 8f8b83c3d7614..66d7ee96bb250 100644 --- a/src/test/run-pass/trait-inheritance-num2.rs +++ b/src/test/run-pass/trait-inheritance-num2.rs @@ -12,10 +12,10 @@ // A more complex example of numeric extensions +extern mod std; + use core::cmp::{Eq, Ord}; use core::num::NumCast::from; - -extern mod std; use std::cmp::FuzzyEq; pub trait TypeExt {} diff --git a/src/test/run-pass/vec-fixed-length.rs b/src/test/run-pass/vec-fixed-length.rs index 5d0620be28cfa..5ce1b04dbe9a0 100644 --- a/src/test/run-pass/vec-fixed-length.rs +++ b/src/test/run-pass/vec-fixed-length.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let x: [int*4] = [1, 2, 3, 4]; + let x: [int, ..4] = [1, 2, 3, 4]; io::println(fmt!("%d", x[0])); }