diff options
664 files changed, 5222 insertions, 4086 deletions
diff --git a/RELEASES.txt b/RELEASES.txt index 4aeea4fe773..9db4a7954e4 100644 --- a/RELEASES.txt +++ b/RELEASES.txt @@ -10,7 +10,8 @@ Version 0.6 (March 2013) * Remove `static` keyword * Static method syntax * `as Trait` - * `copy` removed? + * `copy` removed, replaced with `Clone`? + * `std::map` removed, replaced with `core::hashmap` * Syntax changes * The self type parameter in traits is now spelled `Self` @@ -38,7 +39,8 @@ Version 0.6 (March 2013) * Trait implementations no longer support visibility modifiers * Semantic changes - * Linear types move by default, eliminating the `move` keyword + * Types with owned pointers or custom destructors move by default, + eliminating the `move` keyword * All foreign functions are considered unsafe * &mut is now unaliasable * Writes to borrowed @mut pointers are prevented dynamically @@ -57,16 +59,19 @@ Version 0.6 (March 2013) improve inference and eliminate unsoundness * Libraries - * Lots of effort to organize the container API's around `core::container` - * `core::send_map` renamed to `core::hashmap` * Added big integers to `std::bigint` * Removed `core::oldcomm` module * Added pipe-based `core::comm` module - * Reimplemented `std::treemap` * Numeric traits have been reorganized under `core::num` - * `core::dvec` removed. Use `@mut ~[T]` or other language types * `vec::slice` finally returns a slice * `debug!` and friends don't require a format string, e.g. `debug!(Foo)` + * Containers reorganized around traits in `core::container` + * `core::dvec` removed, `~[T]` is a drop-in replacement + * `core::send_map` renamed to `core::hashmap` + * `std::treemap` reimplemented as an owned balanced tree + * `std::deque` and `std::smallintmap` reimplemented as owned containers + * `core::trie` added as a fast ordered map for integer keys + * Set types added to `core::hashmap`, `core::trie` and `std::treemap` * Tools * Replaced the 'cargo' package manager with 'rustpkg' diff --git a/doc/rust.md b/doc/rust.md index e559af62e36..6be428ef279 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -212,9 +212,9 @@ do drop else enum extern false fn for if impl -let log loop +let loop match mod mut -priv pub pure +priv pub ref return self static struct super true trait type @@ -805,21 +805,20 @@ Use declarations support a number of "convenience" notations: An example of `use` declarations: ~~~~ -use foo = core::info; use core::float::sin; use core::str::{slice, to_upper}; use core::option::Some; fn main() { - // Equivalent to 'log(core::info, core::float::sin(1.0));' - log(foo, sin(1.0)); + // Equivalent to 'info!(core::float::sin(1.0));' + info!(sin(1.0)); - // Equivalent to 'log(core::info, core::option::Some(1.0));' - log(info, Some(1.0)); + // Equivalent to 'info!(core::option::Some(1.0));' + info!(Some(1.0)); - // Equivalent to 'log(core::info, - // core::str::to_upper(core::str::slice("foo", 0, 1)));' - log(info, to_upper(slice("foo", 0, 1))); + // Equivalent to + // 'info!(core::str::to_upper(core::str::slice("foo", 0, 1)));' + info!(to_upper(slice("foo", 0, 1))); } ~~~~ @@ -937,7 +936,6 @@ Specifically, the following operations are considered unsafe: - Dereferencing a [raw pointer](#pointer-types). - Casting a [raw pointer](#pointer-types) to a safe pointer type. - - Breaking the [purity-checking rules](#pure-functions) in a `pure` function. - Calling an unsafe function. ##### Unsafe blocks @@ -947,42 +945,6 @@ This facility exists because the static semantics of Rust are a necessary approx When a programmer has sufficient conviction that a sequence of unsafe operations is actually safe, they can encapsulate that sequence (taken as a whole) within an `unsafe` block. The compiler will consider uses of such code "safe", to the surrounding context. -#### Pure functions - -A pure function declaration is identical to a function declaration, except that -it is declared with the additional keyword `pure`. In addition, the typechecker -checks the body of a pure function with a restricted set of typechecking rules. -A pure function may only modify data owned by its own stack frame. -So, a pure function may modify a local variable allocated on the stack, but not a mutable reference that it takes as an argument. -A pure function may only call other pure functions, not general functions. - -An example of a pure function: - -~~~~ -pure fn lt_42(x: int) -> bool { - return (x < 42); -} -~~~~ - -Pure functions may call other pure functions: - -~~~~{.xfail-test} -pure fn pure_length<T>(ls: List<T>) -> uint { ... } - -pure fn nonempty_list<T>(ls: List<T>) -> bool { pure_length(ls) > 0u } -~~~~ - -These purity-checking rules approximate the concept of referential transparency: -that a call-expression could be rewritten with the literal-expression of its return value, without changing the meaning of the program. -Since they are an approximation, sometimes these rules are *too* restrictive. -Rust allows programmers to violate these rules using [`unsafe` blocks](#unsafe-blocks), which we already saw. -As with any `unsafe` block, those that violate static purity carry transfer the burden of safety-proof from the compiler to the programmer. -Programmers should exercise caution when breaking such rules. - -For more details on purity, see [the borrowed pointer tutorial][borrow]. - -[borrow]: tutorial-borrowed-ptr.html - #### Diverging functions A special kind of function can be declared with a `!` character where the @@ -990,7 +952,7 @@ output slot type would normally be. For example: ~~~~ fn my_err(s: &str) -> ! { - log(info, s); + info!(s); fail!(); } ~~~~ @@ -1182,8 +1144,8 @@ Traits are implemented for specific types through separate [implementations](#im # type BoundingBox = int; trait Shape { - fn draw(Surface); - fn bounding_box() -> BoundingBox; + fn draw(&self, Surface); + fn bounding_box(&self) -> BoundingBox; } ~~~~ @@ -1196,9 +1158,9 @@ These appear after the trait name, using the same syntax used in [generic functi ~~~~ trait Seq<T> { - fn len() -> uint; - fn elt_at(n: uint) -> T; - fn iter(&fn(T)); + fn len(&self) -> uint; + fn elt_at(&self, n: uint) -> T; + fn iter(&self, &fn(T)); } ~~~~ @@ -1210,7 +1172,7 @@ For example: ~~~~ # type Surface = int; -# trait Shape { fn draw(Surface); } +# trait Shape { fn draw(&self, Surface); } fn draw_twice<T: Shape>(surface: Surface, sh: T) { sh.draw(surface); @@ -1228,7 +1190,7 @@ to pointers to the trait name, used as a type. # impl Shape for int { } # let mycircle = 0; -let myshape: Shape = @mycircle as @Shape; +let myshape: @Shape = @mycircle as @Shape; ~~~~ The resulting value is a managed box containing the value that was cast, @@ -1247,10 +1209,10 @@ For example: ~~~~ trait Num { - static pure fn from_int(n: int) -> Self; + static fn from_int(n: int) -> Self; } impl Num for float { - static pure fn from_int(n: int) -> float { n as float } + static fn from_int(n: int) -> float { n as float } } let x: float = Num::from_int(42); ~~~~ @@ -1272,8 +1234,8 @@ methods of the supertrait may be called on values of subtrait-bound type paramet Refering to the previous example of `trait Circle : Shape`: ~~~ -# trait Shape { fn area() -> float; } -# trait Circle : Shape { fn radius() -> float; } +# trait Shape { fn area(&self) -> float; } +# trait Circle : Shape { fn radius(&self) -> float; } fn radius_times_area<T: Circle>(c: T) -> float { // `c` is both a Circle and a Shape c.radius() * c.area() @@ -1283,10 +1245,10 @@ fn radius_times_area<T: Circle>(c: T) -> float { Likewise, supertrait methods may also be called on trait objects. ~~~ {.xfail-test} -# trait Shape { fn area() -> float; } -# trait Circle : Shape { fn radius() -> float; } -# impl Shape for int { fn area() -> float { 0.0 } } -# impl Circle for int { fn radius() -> float { 0.0 } } +# trait Shape { fn area(&self) -> float; } +# trait Circle : Shape { fn radius(&self) -> float; } +# impl Shape for int { fn area(&self) -> float { 0.0 } } +# impl Circle for int { fn radius(&self) -> float { 0.0 } } # let mycircle = 0; let mycircle: Circle = @mycircle as @Circle; @@ -1303,7 +1265,7 @@ Implementations are defined with the keyword `impl`. # struct Point {x: float, y: float}; # type Surface = int; # struct BoundingBox {x: float, y: float, width: float, height: float}; -# trait Shape { fn draw(Surface); fn bounding_box() -> BoundingBox; } +# trait Shape { fn draw(&self, Surface); fn bounding_box(&self) -> BoundingBox; } # fn do_draw_circle(s: Surface, c: Circle) { } struct Circle { @@ -1312,8 +1274,8 @@ struct Circle { } impl Shape for Circle { - fn draw(s: Surface) { do_draw_circle(s, self); } - fn bounding_box() -> BoundingBox { + fn draw(&self, s: Surface) { do_draw_circle(s, *self); } + fn bounding_box(&self) -> BoundingBox { let r = self.radius; BoundingBox{x: self.center.x - r, y: self.center.y - r, width: 2.0 * r, height: 2.0 * r} @@ -2397,58 +2359,6 @@ fn max(a: int, b: int) -> int { } ~~~~ -### Log expressions - -~~~~~~~~{.ebnf .gram} -log_expr : "log" '(' level ',' expr ')' ; -~~~~~~~~ - -Evaluating a `log` expression may, depending on runtime configuration, cause a -value to be appended to an internal diagnostic logging buffer provided by the -runtime or emitted to a system console. Log expressions are enabled or -disabled dynamically at run-time on a per-task and per-item basis. See -[logging system](#logging-system). - -Each `log` expression must be provided with a *level* argument in -addition to the value to log. The logging level is a `u32` value, where -lower levels indicate more-urgent levels of logging. By default, the lowest -four logging levels (`1_u32 ... 4_u32`) are predefined as the constants -`error`, `warn`, `info` and `debug` in the `core` library. - -Additionally, the macros `error!`, `warn!`, `info!` and `debug!` are defined -in the default syntax-extension namespace. These expand into calls to the -logging facility composed with calls to the `fmt!` string formatting -syntax-extension. - -The following examples all produce the same output, logged at the `error` -logging level: - -~~~~ -# let filename = "bulbasaur"; - -// Full version, logging a value. -log(core::error, ~"file not found: " + filename); - -// Log-level abbreviated, since core::* is used by default. -log(error, ~"file not found: " + filename); - -// Formatting the message using a format-string and fmt! -log(error, fmt!("file not found: %s", filename)); - -// Using the error! macro, that expands to the previous call. -error!("file not found: %s", filename); -~~~~ - -A `log` expression is *not evaluated* when logging at the specified logging-level, module or task is disabled at runtime. -This makes inactive `log` expressions very cheap; -they should be used extensively in Rust code, as diagnostic aids, -as they add little overhead beyond a single integer-compare and branch at runtime. - -Logging is presently implemented as a language built-in feature, -as it makes use of compiler-provided, per-module data tables and flags. -In the future, logging will move into a library, and will no longer be a core expression type. -It is therefore recommended to use the macro forms of logging (`error!`, `debug!`, etc.) to minimize disruption in code that uses logging. - # Type system @@ -2696,7 +2606,7 @@ Raw pointers (`*`) ### Function types The function type-constructor `fn` forms new function types. A function type -consists of a set of function-type modifiers (`pure`, `unsafe`, `extern`, etc.), +consists of a set of function-type modifiers (`unsafe`, `extern`, etc.), a sequence of input slots and an output slot. An example of a `fn` type: @@ -2731,11 +2641,11 @@ An example of an object type: ~~~~~~~~ trait Printable { - fn to_str() -> ~str; + fn to_str(&self) -> ~str; } impl Printable for int { - fn to_str() -> ~str { int::to_str(self) } + fn to_str(&self) -> ~str { int::to_str(*self) } } fn print(a: @Printable) { @@ -2774,11 +2684,11 @@ example, in: ~~~~~~~~ trait Printable { - fn make_string() -> ~str; + fn make_string(&self) -> ~str; } impl Printable for ~str { - fn make_string() -> ~str { copy self } + fn make_string(&self) -> ~str { copy *self } } ~~~~~~~~ @@ -3149,7 +3059,7 @@ communication facilities. The runtime contains a system for directing [logging expressions](#log-expressions) to a logging console and/or internal logging -buffers. Logging expressions can be enabled per module. +buffers. Logging can be enabled per module. Logging output is enabled by setting the `RUST_LOG` environment variable. `RUST_LOG` accepts a logging specification made up of a diff --git a/doc/tutorial-borrowed-ptr.md b/doc/tutorial-borrowed-ptr.md index e638579253f..8e0ca297f65 100644 --- a/doc/tutorial-borrowed-ptr.md +++ b/doc/tutorial-borrowed-ptr.md @@ -486,12 +486,12 @@ 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(p: &'r Point) -> &'r float { &p.x } ~~~ Here, the function `get_x()` returns a pointer into the structure it -was given. The type of the parameter (`&r/Point`) and return type -(`&r/float`) both use a new syntactic form that we have not seen so +was given. The type of the parameter (`&'r Point`) and return type +(`&'r float`) both use a new syntactic form that we have not seen so far. Here the identifier `r` names the lifetime of the pointer explicitly. So in effect, this function declares that it takes a pointer with lifetime `r` and returns a pointer with that same @@ -572,8 +572,8 @@ function: # Rectangle(Point, Size) // upper-left, dimensions # } # fn compute_area(shape: &Shape) -> float { 0f } -fn select<T>(shape: &r/Shape, threshold: float, - a: &r/T, b: &r/T) -> &r/T { +fn select<T>(shape: &'r Shape, threshold: float, + a: &'r T, b: &'r T) -> &'r T { if compute_area(shape) > threshold {a} else {b} } ~~~ @@ -593,17 +593,17 @@ example: # } # fn compute_area(shape: &Shape) -> float { 0f } # fn select<T>(shape: &Shape, threshold: float, -# a: &r/T, b: &r/T) -> &r/T { +# a: &'r T, b: &'r T) -> &'r T { # if compute_area(shape) > threshold {a} else {b} # } - // -+ r -fn select_based_on_unit_circle<T>( // |-+ B - threshold: float, a: &r/T, b: &r/T) -> &r/T { // | | - // | | - let shape = Circle(Point {x: 0., y: 0.}, 1.); // | | - select(&shape, threshold, a, b) // | | -} // |-+ - // -+ + // -+ r +fn select_based_on_unit_circle<T>( // |-+ B + threshold: float, a: &'r T, b: &'r T) -> &'r T { // | | + // | | + let shape = Circle(Point {x: 0., y: 0.}, 1.); // | | + select(&shape, threshold, a, b) // | | +} // |-+ + // -+ ~~~ In this call to `select()`, the lifetime of the first parameter shape @@ -629,8 +629,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<T>(shape: &tmp/Shape, threshold: float, - a: &r/T, b: &r/T) -> &r/T { +fn select<T>(shape: &'tmp Shape, threshold: float, + a: &'r T, b: &'r T) -> &'r T { if compute_area(shape) > threshold {a} else {b} } ~~~ @@ -649,7 +649,7 @@ concise to just omit the named lifetime for `shape` altogether: # } # fn compute_area(shape: &Shape) -> float { 0f } fn select<T>(shape: &Shape, threshold: float, - a: &r/T, b: &r/T) -> &r/T { + a: &'r T, b: &'r T) -> &'r T { if compute_area(shape) > threshold {a} else {b} } ~~~ diff --git a/doc/tutorial.md b/doc/tutorial.md index e4775e1b11b..3e7b9400e17 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -744,7 +744,7 @@ unit, `()`, as the empty tuple if you like). ~~~~ let mytup: (int, int, float) = (10, 20, 30.0); match mytup { - (a, b, c) => log(info, a + b + (c as int)) + (a, b, c) => info!(a + b + (c as int)) } ~~~~ @@ -760,7 +760,7 @@ For example: struct MyTup(int, int, float); let mytup: MyTup = MyTup(10, 20, 30.0); match mytup { - MyTup(a, b, c) => log(info, a + b + (c as int)) + MyTup(a, b, c) => info!(a + b + (c as int)) } ~~~~ @@ -1135,7 +1135,7 @@ can sometimes make code awkward and parenthesis-filled. ~~~ # struct Point { x: float, y: float } # enum Shape { Rectangle(Point, Point) } -# impl Shape { fn area() -> int { 0 } } +# impl Shape { fn area(&self) -> int { 0 } } let start = @Point { x: 10f, y: 20f }; let end = ~Point { x: (*start).x + 100f, y: (*start).y + 100f }; let rect = &Rectangle(*start, *end); @@ -1149,7 +1149,7 @@ dot), so in most cases, explicitly dereferencing the receiver is not necessary. ~~~ # struct Point { x: float, y: float } # enum Shape { Rectangle(Point, Point) } -# impl Shape { fn area() -> int { 0 } } +# impl Shape { fn area(&self) -> int { 0 } } let start = @Point { x: 10f, y: 20f }; let end = ~Point { x: start.x + 100f, y: start.y + 100f }; let rect = &Rectangle(*start, *end); diff --git a/mk/rt.mk b/mk/rt.mk index d104d608e01..d7061f1aced 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -132,7 +132,7 @@ rt/$(1)/%.o: rt/%.S $$(MKFILE_DEPS) \ rt/$(1)/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJ_$(1)) @$$(call E, link: $$@) - $$(Q)ar rcs $$@ $$< + $$(Q)$(AR_$(1)) rcs $$@ $$< rt/$(1)/$(CFG_RUNTIME_$(1)): $$(RUNTIME_OBJS_$(1)) $$(MKFILE_DEPS) \ $$(RUNTIME_DEF_$(1)) \ diff --git a/mk/tests.mk b/mk/tests.mk index 549741ddd65..33a828d6e67 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -386,6 +386,10 @@ ifeq ($(CFG_GDB),) CTEST_DISABLE_debuginfo = "no gdb found" endif +ifeq ($(CFG_OSTYPE),apple-darwin) +CTEST_DISABLE_debuginfo = "gdb on darwing needs root" +endif + define DEF_CTEST_VARS # All the per-stage build rules you might want to call from the diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index f95a530831b..03f3fa9fcf6 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -225,6 +225,15 @@ actual:\n\ } fn run_debuginfo_test(config: config, props: TestProps, testfile: &Path) { + // do not optimize debuginfo tests + let config = match config.rustcflags { + Some(flags) => config { + rustcflags: Some(str::replace(flags, ~"-O", ~"")), + .. config + }, + None => config + }; + // compile test file (it shoud have 'compile-flags:-g' in the header) let mut ProcRes = compile_test(config, props, testfile); if ProcRes.status != 0 { @@ -267,8 +276,8 @@ fn run_debuginfo_test(config: config, props: TestProps, testfile: &Path) { } } if i != num_check_lines { - fatal(fmt!("line not found in debugger output: %s", - props.check_lines[i])); + fatal_ProcRes(fmt!("line not found in debugger output: %s" + props.check_lines[i]), ProcRes); } } } diff --git a/src/compiletest/util.rs b/src/compiletest/util.rs index 736c20969e9..616ca8d4840 100644 --- a/src/compiletest/util.rs +++ b/src/compiletest/util.rs @@ -46,6 +46,6 @@ pub fn path_div() -> ~str { ~":" } pub fn path_div() -> ~str { ~";" } pub fn logv(config: config, s: ~str) { - log(debug, s); + debug!("%s", s); if config.verbose { io::println(s); } } diff --git a/src/etc/tidy.py b/src/etc/tidy.py index 997a9dd50fd..a5cf6141567 100644 --- a/src/etc/tidy.py +++ b/src/etc/tidy.py @@ -5,7 +5,7 @@ import sys, fileinput, subprocess, re from licenseck import * err=0 -cols=78 +cols=100 # Be careful to support Python 2.4, 2.6, and 3.x here! config_proc=subprocess.Popen([ "git", "config", "core.autocrlf" ], diff --git a/src/etc/vim/after/ftplugin/rust.vim b/src/etc/vim/after/ftplugin/rust.vim index 56616de6aa8..f0f1c85ee97 100644 --- a/src/etc/vim/after/ftplugin/rust.vim +++ b/src/etc/vim/after/ftplugin/rust.vim @@ -1,5 +1,5 @@ -"Highlight the 78th text column +"Highlight the 100th text column "Feature became available in v7.3 if version >= 703 - set colorcolumn=78 + set colorcolumn=100 endif diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index fa19e24aa08..8d3c8561957 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -13,7 +13,6 @@ use cast::transmute; use kinds::Copy; use iter; -use libc; use option::Option; use ptr::addr_of; use sys; @@ -175,9 +174,9 @@ pub mod traits { use kinds::Copy; use ops::Add; - impl<T:Copy> Add<&self/[const T],@[T]> for @[T] { + impl<T:Copy> Add<&'self [const T],@[T]> for @[T] { #[inline(always)] - pure fn add(&self, rhs: & &self/[const T]) -> @[T] { + pure fn add(&self, rhs: & &'self [const T]) -> @[T] { append(*self, (*rhs)) } } diff --git a/src/libcore/cast.rs b/src/libcore/cast.rs index f17b04da503..f752f52ce53 100644 --- a/src/libcore/cast.rs +++ b/src/libcore/cast.rs @@ -12,7 +12,7 @@ pub mod rusti { #[abi = "rust-intrinsic"] #[link_name = "rusti"] pub extern { - fn forget<T>(-x: T); + fn forget<T>(+x: T); fn reinterpret_cast<T, U>(&&e: T) -> U; } } @@ -59,17 +59,17 @@ pub unsafe fn transmute<L, G>(thing: L) -> G { /// Coerce an immutable reference to be mutable. #[inline(always)] -pub unsafe fn transmute_mut<T>(ptr: &a/T) -> &a/mut T { transmute(ptr) } +pub unsafe fn transmute_mut<T>(ptr: &'a T) -> &'a mut T { transmute(ptr) } /// Coerce a mutable reference to be immutable. #[inline(always)] -pub unsafe fn transmute_immut<T>(ptr: &a/mut T) -> &a/T { +pub unsafe fn transmute_immut<T>(ptr: &'a mut T) -> &'a T { transmute(ptr) } /// Coerce a borrowed pointer to have an arbitrary associated region. #[inline(always)] -pub unsafe fn transmute_region<T>(ptr: &a/T) -> &b/T { transmute(ptr) } +pub unsafe fn transmute_region<T>(ptr: &'a T) -> &'b T { transmute(ptr) } /// Coerce an immutable reference to be mutable. #[inline(always)] @@ -85,19 +85,19 @@ pub unsafe fn transmute_immut_unsafe<T>(ptr: *const T) -> *T { /// Coerce a borrowed mutable pointer to have an arbitrary associated region. #[inline(always)] -pub unsafe fn transmute_mut_region<T>(ptr: &a/mut T) -> &b/mut T { +pub unsafe fn transmute_mut_region<T>(ptr: &'a mut T) -> &'b mut T { transmute(ptr) } /// Transforms lifetime of the second pointer to match the first. #[inline(always)] -pub unsafe fn copy_lifetime<S,T>(_ptr: &a/S, ptr: &T) -> &a/T { +pub unsafe fn copy_lifetime<S,T>(_ptr: &'a S, ptr: &T) -> &'a T { transmute_region(ptr) } /// Transforms lifetime of the second pointer to match the first. #[inline(always)] -pub unsafe fn copy_lifetime_vec<S,T>(_ptr: &a/[S], ptr: &T) -> &a/T { +pub unsafe fn copy_lifetime_vec<S,T>(_ptr: &'a [S], ptr: &T) -> &'a T { transmute_region(ptr) } diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index da247c648fc..cfd1b8dfef0 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use cast::transmute; use option; use prelude::*; @@ -15,11 +16,21 @@ use prelude::*; /// /// Similar to a mutable option type, but friendlier. -#[deriving_eq] pub struct Cell<T> { mut value: Option<T> } +impl<T:cmp::Eq> cmp::Eq for Cell<T> { + pure fn eq(&self, other: &Cell<T>) -> bool { + unsafe { + let frozen_self: &Option<T> = transmute(&mut self.value); + let frozen_other: &Option<T> = transmute(&mut other.value); + frozen_self == frozen_other + } + } + pure fn ne(&self, other: &Cell<T>) -> bool { !self.eq(other) } +} + /// Creates a new full cell with the given value. pub fn Cell<T>(value: T) -> Cell<T> { Cell { value: Some(value) } diff --git a/src/libcore/cleanup.rs b/src/libcore/cleanup.rs index faa6db45df2..66eeb339700 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 fn(**TypeDesc, *c_void); +type FreeGlue = &'self fn(**TypeDesc, *c_void); type TaskID = uintptr_t; @@ -145,11 +145,7 @@ unsafe fn each_live_alloc(f: &fn(box: *mut BoxRepr, uniq: bool) -> bool) { #[cfg(unix)] fn debug_mem() -> bool { - use os; - use libc; - do os::as_c_charp("RUST_DEBUG_MEM") |p| { - unsafe { libc::getenv(p) != null() } - } + ::rt::env::get().debug_mem } #[cfg(windows)] diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs index 297c4438039..af44f68601b 100644 --- a/src/libcore/clone.rs +++ b/src/libcore/clone.rs @@ -20,6 +20,11 @@ impl Clone for () { fn clone(&self) -> () { () } } +impl<T:Clone> Clone for ~T { + #[inline(always)] + fn clone(&self) -> ~T { ~(**self).clone() } +} + macro_rules! clone_impl( ($t:ty) => { impl Clone for $t { diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 5b189abf4a3..12dc2d7e341 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -8,10 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use cast; use either::{Either, Left, Right}; use kinds::Owned; use option; use option::{Option, Some, None, unwrap}; +use uint; use unstable; use vec; @@ -283,8 +285,12 @@ impl<T: Owned> Peekable<T> for PortSet<T> { pure fn port_set_peek<T:Owned>(self: &PortSet<T>) -> bool { // It'd be nice to use self.port.each, but that version isn't // pure. - for vec::each(self.ports) |p| { - if p.peek() { return true } + for uint::range(0, vec::uniq_len(&const self.ports)) |i| { + // XXX: Botch pending demuting. + unsafe { + let port: &Port<T> = cast::transmute(&mut self.ports[i]); + if port.peek() { return true } + } } false } diff --git a/src/libcore/condition.rs b/src/libcore/condition.rs index 17d15a8886f..56b690ca8af 100644 --- a/src/libcore/condition.rs +++ b/src/libcore/condition.rs @@ -21,12 +21,12 @@ pub struct Handler<T, U> { } pub struct Condition<T, U> { - name: &static/str, + name: &'static str, key: task::local_data::LocalDataKey/&self<Handler<T, U>> } pub impl<T, U> Condition/&self<T, U> { - fn trap(&self, h: &self/fn(T) -> U) -> Trap/&self<T, U> { + fn trap(&self, h: &'self fn(T) -> U) -> Trap/&self<T, U> { unsafe { let p : *RustClosure = ::cast::transmute(&h); let prev = task::local_data::local_data_get(self.key); @@ -65,12 +65,12 @@ pub impl<T, U> Condition/&self<T, U> { } struct Trap<T, U> { - cond: &self/Condition/&self<T, U>, + cond: &'self Condition/&self<T, U>, handler: @Handler<T, U> } pub impl<T, U> Trap/&self<T, U> { - fn in<V>(&self, inner: &self/fn() -> V) -> V { + fn in<V>(&self, inner: &'self fn() -> V) -> V { unsafe { let _g = Guard { cond: self.cond }; debug!("Trap: pushing handler to TLS"); @@ -81,7 +81,7 @@ pub impl<T, U> Trap/&self<T, U> { } struct Guard<T, U> { - cond: &self/Condition/&self<T, U> + cond: &'self Condition/&self<T, U> } impl<T, U> Drop for Guard/&self<T, U> { diff --git a/src/libcore/container.rs b/src/libcore/container.rs index 4f1f6004aad..5044b3a6c5d 100644 --- a/src/libcore/container.rs +++ b/src/libcore/container.rs @@ -14,10 +14,10 @@ use option::Option; pub trait Container { /// Return the number of elements in the container - pure fn len(&self) -> uint; + pure fn len(&const self) -> uint; /// Return true if the container contains no elements - pure fn is_empty(&self) -> bool; + pure fn is_empty(&const self) -> bool; } pub trait Mutable: Container { @@ -35,8 +35,11 @@ pub trait Map<K, V>: Mutable { /// Visit all values pure fn each_value(&self, f: &fn(&V) -> bool); + /// Iterate over the map and mutate the contained values + fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool); + /// Return the value corresponding to the key in the map - pure fn find(&self, key: &K) -> Option<&self/V>; + pure fn find(&self, key: &K) -> Option<&'self V>; /// Insert a key-value pair into the map. An existing value for a /// key is replaced by the new value. Return true if the key did diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 026f49cac45..955c1f46d76 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -56,6 +56,7 @@ Implicitly, all crates behave as if they included the following prologue: // On Linux, link to the runtime with -lrt. #[cfg(target_os = "linux")] +#[doc(hidden)] pub mod linkhack { #[link_args="-lrustrt -lrt"] #[link_args = "-lpthread"] @@ -216,14 +217,17 @@ pub use clone::Clone; * more-verbosity. Error is the bottom level, default logging level is * warn-and-below. */ - /// The error log level +#[cfg(stage0)] pub const error : u32 = 1_u32; /// The warning log level +#[cfg(stage0)] pub const warn : u32 = 2_u32; /// The info log level +#[cfg(stage0)] pub const info : u32 = 3_u32; /// The debug log level +#[cfg(stage0)] pub const debug : u32 = 4_u32; @@ -249,11 +253,15 @@ pub mod rt; // A curious inner-module that's not exported that contains the binding // 'core' so that macro-expanded references to core::error and such // can be resolved within libcore. -#[doc(hidden)] // FIXME #3538 +#[doc(hidden)] pub mod core { + #[cfg(stage0)] pub const error : u32 = 1_u32; + #[cfg(stage0)] pub const warn : u32 = 2_u32; + #[cfg(stage0)] pub const info : u32 = 3_u32; + #[cfg(stage0)] pub const debug : u32 = 4_u32; pub use cmp; diff --git a/src/libcore/flate.rs b/src/libcore/flate.rs index f9348ae5380..c830648e9df 100644 --- a/src/libcore/flate.rs +++ b/src/libcore/flate.rs @@ -17,6 +17,7 @@ Simple compression use libc; use libc::{c_void, size_t, c_int}; use ptr; +use rand::RngUtil; use vec; #[cfg(test)] use rand; diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs index 5f84f7f0d19..3449c5ff4ba 100644 --- a/src/libcore/gc.rs +++ b/src/libcore/gc.rs @@ -122,7 +122,7 @@ unsafe fn is_safe_point(pc: *Word) -> Option<SafePoint> { return None; } -type Visitor = &self/fn(root: **Word, tydesc: *Word) -> bool; +type Visitor = &'self fn(root: **Word, tydesc: *Word) -> bool; // Walks the list of roots for the given safe point, and calls visitor // on each root. diff --git a/src/libcore/hashmap.rs b/src/libcore/hashmap.rs index 2adcee495a7..68a55792077 100644 --- a/src/libcore/hashmap.rs +++ b/src/libcore/hashmap.rs @@ -20,6 +20,7 @@ pub mod linear { use hash::Hash; use iter; use option::{None, Option, Some}; + use rand::RngUtil; use rand; use uint; use vec; @@ -184,7 +185,7 @@ pub mod linear { } #[inline(always)] - pure fn value_for_bucket(&self, idx: uint) -> &self/V { + pure fn value_for_bucket(&self, idx: uint) -> &'self V { match self.buckets[idx] { Some(ref bkt) => &bkt.value, None => fail!(~"LinearMap::find: internal logic error"), @@ -269,10 +270,10 @@ pub mod linear { } impl<K:Hash + IterBytes + Eq,V> - BaseIter<(&self/K, &self/V)> for LinearMap<K, V> + BaseIter<(&'self K, &'self V)> for LinearMap<K, V> { /// Visit all key-value pairs - pure fn each(&self, blk: &fn(&(&self/K, &self/V)) -> bool) { + pure fn each(&self, blk: &fn(&(&'self K, &'self V)) -> bool) { for uint::range(0, self.buckets.len()) |i| { let mut broke = false; do self.buckets[i].map |bucket| { @@ -289,10 +290,10 @@ pub mod linear { impl<K:Hash + IterBytes + Eq,V> Container for LinearMap<K, V> { /// Return the number of elements in the map - pure fn len(&self) -> uint { self.size } + pure fn len(&const self) -> uint { self.size } /// Return true if the map contains no elements - pure fn is_empty(&self) -> bool { self.len() == 0 } + pure fn is_empty(&const self) -> bool { self.len() == 0 } } impl<K:Hash + IterBytes + Eq,V> Mutable for LinearMap<K, V> { @@ -324,8 +325,21 @@ pub mod linear { self.each(|&(_, v)| blk(v)) } + /// Iterate over the map and mutate the contained values + fn mutate_values(&mut self, blk: &fn(&'self K, + &'self mut V) -> bool) { + for uint::range(0, self.buckets.len()) |i| { + match self.buckets[i] { + Some(Bucket{key: ref key, value: ref mut value, _}) => { + if !blk(key, value) { return } + } + None => () + } + } + } + /// Return the value corresponding to the key in the map - pure fn find(&self, k: &K) -> Option<&self/V> { + pure fn find(&self, k: &K) -> Option<&'self V> { match self.bucket_for_key(k) { FoundEntry(idx) => Some(self.value_for_bucket(idx)), TableFull | FoundHole(_) => None, @@ -398,7 +412,7 @@ pub mod linear { /// Return the value corresponding to the key in the map, or insert /// and return the value if it doesn't exist. - fn find_or_insert(&mut self, k: K, v: V) -> &self/V { + fn find_or_insert(&mut self, k: K, v: V) -> &'self V { if self.size >= self.resize_at { // n.b.: We could also do this after searching, so // that we do not resize if this call to insert is @@ -428,7 +442,7 @@ pub mod linear { /// Return the value corresponding to the key in the map, or create, /// insert, and return a new value if it doesn't exist. - fn find_or_insert_with(&mut self, k: K, f: &fn(&K) -> V) -> &self/V { + fn find_or_insert_with(&mut self, k: K, f: &fn(&K) -> V) -> &'self V { if self.size >= self.resize_at { // n.b.: We could also do this after searching, so // that we do not resize if this call to insert is @@ -473,7 +487,7 @@ pub mod linear { } } - pure fn get(&self, k: &K) -> &self/V { + pure fn get(&self, k: &K) -> &'self V { match self.find(k) { Some(v) => v, None => fail!(fmt!("No entry found for key: %?", k)), @@ -495,7 +509,7 @@ pub mod linear { /// Return the value corresponding to the key in the map, using /// equivalence pure fn find_equiv<Q:Hash + IterBytes + Equiv<K>>(&self, k: &Q) - -> Option<&self/V> { + -> Option<&'self V> { match self.bucket_for_key_equiv(k) { FoundEntry(idx) => Some(self.value_for_bucket(idx)), TableFull | FoundHole(_) => None, @@ -541,10 +555,10 @@ pub mod linear { impl<T:Hash + IterBytes + Eq> Container for LinearSet<T> { /// Return the number of elements in the set - pure fn len(&self) -> uint { self.map.len() } + pure fn len(&const self) -> uint { self.map.len() } /// Return true if the set contains no elements - pure fn is_empty(&self) -> bool { self.map.is_empty() } + pure fn is_empty(&const self) -> bool { self.map.is_empty() } } impl<T:Hash + IterBytes + Eq> Mutable for LinearSet<T> { diff --git a/src/libcore/io.rs b/src/libcore/io.rs index b04bb15f5e3..50e7a42b7b1 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -589,11 +589,11 @@ pub fn file_reader(path: &Path) -> Result<@Reader, ~str> { // Byte readers pub struct BytesReader { - bytes: &self/[u8], + bytes: &'self [u8], mut pos: uint } -impl Reader for BytesReader/&self { +impl Reader for BytesReader<'self> { fn read(&self, bytes: &mut [u8], len: uint) -> uint { let count = uint::min(len, self.bytes.len() - self.pos); @@ -683,7 +683,7 @@ impl Writer for *libc::FILE { *self); if nout != len as size_t { error!("error writing buffer"); - log(error, os::last_os_error()); + error!("%s", os::last_os_error()); fail!(); } } @@ -733,7 +733,7 @@ impl Writer for fd_t { let nout = libc::write(*self, vb, len as size_t); if nout < 0 as ssize_t { error!("error writing buffer"); - log(error, os::last_os_error()); + error!("%s", os::last_os_error()); fail!(); } count += nout as uint; @@ -785,8 +785,7 @@ pub fn fd_writer(fd: fd_t, cleanup: bool) -> @Writer { pub fn mk_file_writer(path: &Path, flags: &[FileFlag]) - -> Result<Writer, ~str> { - + -> Result<@Writer, ~str> { #[cfg(windows)] fn wb() -> c_int { (O_WRONLY | libc::consts::os::extra::O_BINARY) as c_int @@ -1079,22 +1078,24 @@ impl<T:Writer> WriterUtil for T { } #[allow(non_implicitly_copyable_typarams)] -pub fn file_writer(path: &Path, flags: &[FileFlag]) -> Result<Writer, ~str> { +pub fn file_writer(path: &Path, flags: &[FileFlag]) -> Result<@Writer, ~str> { mk_file_writer(path, flags).chain(|w| result::Ok(w)) } // FIXME: fileflags // #2004 -pub fn buffered_file_writer(path: &Path) -> Result<Writer, ~str> { +pub fn buffered_file_writer(path: &Path) -> Result<@Writer, ~str> { unsafe { let f = do os::as_c_charp(path.to_str()) |pathbuf| { do os::as_c_charp("w") |modebuf| { libc::fopen(pathbuf, modebuf) } }; - return if f as uint == 0u { result::Err(~"error opening " - + path.to_str()) } - else { result::Ok(FILE_writer(f, true)) } + return if f as uint == 0u { + result::Err(~"error opening " + path.to_str()) + } else { + result::Ok(FILE_writer(f, true)) + } } } @@ -1115,7 +1116,7 @@ pub struct BytesWriter { impl Writer for BytesWriter { fn write(&self, v: &[const u8]) { let v_len = v.len(); - let bytes_len = self.bytes.len(); + let bytes_len = vec::uniq_len(&const self.bytes); let count = uint::max(bytes_len, self.pos + v_len); vec::reserve(&mut self.bytes, count); @@ -1130,7 +1131,7 @@ impl Writer for BytesWriter { } fn seek(&self, offset: int, whence: SeekStyle) { let pos = self.pos; - let len = self.bytes.len(); + let len = vec::uniq_len(&const self.bytes); self.pos = seek_in_buf(offset, pos, len, whence); } fn tell(&self) -> uint { self.pos } @@ -1142,14 +1143,14 @@ pub pure fn BytesWriter() -> BytesWriter { BytesWriter { bytes: ~[], mut pos: 0u } } -pub pure fn with_bytes_writer(f: &fn(Writer)) -> ~[u8] { +pub pure fn with_bytes_writer(f: &fn(@Writer)) -> ~[u8] { let wr = @BytesWriter(); - f(wr as Writer); + f(wr as @Writer); let @BytesWriter{bytes, _} = wr; return bytes; } -pub pure fn with_str_writer(f: &fn(Writer)) -> ~str { +pub pure fn with_str_writer(f: &fn(@Writer)) -> ~str { let mut v = with_bytes_writer(f); // FIXME (#3758): This should not be needed. @@ -1277,8 +1278,8 @@ pub mod fsync { pub trait FSyncable { fn fsync(&self, l: Level) -> int; } // Call o.fsync after executing blk - pub fn obj_sync(o: FSyncable, opt_level: Option<Level>, - blk: &fn(v: Res<FSyncable>)) { + pub fn obj_sync(o: @FSyncable, opt_level: Option<Level>, + blk: &fn(v: Res<@FSyncable>)) { blk(Res(Arg { val: o, opt_level: opt_level, fsync_fn: |o, l| o.fsync(l) @@ -1288,7 +1289,6 @@ pub mod fsync { #[cfg(test)] mod tests { - use debug; use i32; use io::{BytesWriter, SeekCur, SeekEnd, SeekSet}; use io; @@ -1301,19 +1301,19 @@ mod tests { #[test] fn test_simple() { let tmpfile = &Path("tmp/lib-io-test-simple.tmp"); - log(debug, tmpfile); + debug!(tmpfile); let frood: ~str = ~"A hoopy frood who really knows where his towel is."; - log(debug, copy frood); + debug!(copy frood); { - let out: io::Writer = + let out: @io::Writer = result::get( &io::file_writer(tmpfile, ~[io::Create, io::Truncate])); out.write_str(frood); } - let inp: io::Reader = result::get(&io::file_reader(tmpfile)); + let inp: @io::Reader = result::get(&io::file_reader(tmpfile)); let frood2: ~str = inp.read_c_str(); - log(debug, copy frood2); + debug!(copy frood2); fail_unless!(frood == frood2); } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 8931b408826..816dc6d2255 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<T> = &self/fn(uint) -> T; +pub type InitOp<T> = &'self fn(uint) -> T; pub trait BaseIter<A> { pure fn each(&self, blk: &fn(v: &A) -> bool); @@ -31,6 +31,10 @@ pub trait ReverseIter<A>: BaseIter<A> { pure fn each_reverse(&self, blk: &fn(&A) -> bool); } +pub trait MutableIter<A>: BaseIter<A> { + fn each_mut(&mut self, blk: &fn(&mut A) -> bool); +} + pub trait ExtendedIter<A> { pure fn eachi(&self, blk: &fn(uint, v: &A) -> bool); pure fn all(&self, blk: &fn(&A) -> bool) -> bool; diff --git a/src/libcore/mutable.rs b/src/libcore/mutable.rs index 875d378b645..d0aa6e050f5 100644 --- a/src/libcore/mutable.rs +++ b/src/libcore/mutable.rs @@ -46,8 +46,7 @@ pub fn unwrap<T>(m: Mut<T>) -> T { pub impl<T> Data<T> { fn borrow_mut<R>(&self, op: &fn(t: &mut T) -> R) -> R { match self.mode { - Immutable => fail!(fmt!("%? currently immutable", - self.value)), + Immutable => fail!(~"currently immutable"), ReadOnly | Mutable => {} } @@ -62,8 +61,7 @@ pub impl<T> Data<T> { fn borrow_imm<R>(&self, op: &fn(t: &T) -> R) -> R { match self.mode { - Mutable => fail!(fmt!("%? currently mutable", - self.value)), + Mutable => fail!(~"currently mutable"), ReadOnly | Immutable => {} } diff --git a/src/libcore/num/cmath.rs b/src/libcore/num/cmath.rs index 342a02c836a..2f9d4304cba 100644 --- a/src/libcore/num/cmath.rs +++ b/src/libcore/num/cmath.rs @@ -10,10 +10,6 @@ #[doc(hidden)]; // FIXME #3538 -use libc::c_int; -use libc::c_float; -use libc::c_double; - // function names are almost identical to C's libmath, a few have been // renamed, grep for "rename:" diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 64135b3b8e1..5e5396ea121 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -46,7 +46,7 @@ use ops::Add; use kinds::Copy; use util; use num::Zero; -use iter::BaseIter; +use iter::{BaseIter, MutableIter}; #[cfg(test)] use ptr; #[cfg(test)] use str; @@ -122,7 +122,7 @@ pub pure fn get<T:Copy>(opt: Option<T>) -> T { } #[inline(always)] -pub pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T { +pub pure fn get_ref<T>(opt: &'r Option<T>) -> &'r T { /*! Gets an immutable reference to the value inside an option. @@ -143,7 +143,7 @@ pub pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T { } } -pub pure fn get_mut_ref<T>(opt: &r/mut Option<T>) -> &r/mut T { +pub pure fn get_mut_ref<T>(opt: &'r mut Option<T>) -> &'r mut T { /*! Gets a mutable reference to the value inside an option. @@ -165,7 +165,7 @@ pub pure fn get_mut_ref<T>(opt: &r/mut Option<T>) -> &r/mut T { } #[inline(always)] -pub pure fn map<T, U>(opt: &r/Option<T>, f: &fn(x: &r/T) -> U) -> Option<U> { +pub pure fn map<T, U>(opt: &'r Option<T>, f: &fn(x: &'r T) -> U) -> Option<U> { //! Maps a `some` value by reference from one type to another match *opt { Some(ref x) => Some(f(x)), None => None } @@ -228,14 +228,14 @@ pub pure fn while_some<T>(x: Option<T>, blk: &fn(v: T) -> Option<T>) { } #[inline(always)] -pub pure fn is_none<T>(opt: &Option<T>) -> bool { +pub pure fn is_none<T>(opt: &const Option<T>) -> bool { //! Returns true if the option equals `none` match *opt { None => true, Some(_) => false } } #[inline(always)] -pub pure fn is_some<T>(opt: &Option<T>) -> bool { +pub pure fn is_some<T>(opt: &const Option<T>) -> bool { //! Returns true if the option contains some value !is_none(opt) @@ -256,8 +256,8 @@ pub pure fn get_or_default<T:Copy>(opt: Option<T>, def: T) -> T { } #[inline(always)] -pub pure fn map_default<T, U>(opt: &r/Option<T>, def: U, - f: &fn(&r/T) -> U) -> U { +pub pure fn map_default<T, U>(opt: &'r Option<T>, def: U, + f: &fn(&'r T) -> U) -> U { //! Applies a function to the contained value or returns a default match *opt { None => def, Some(ref t) => f(t) } @@ -313,7 +313,7 @@ pub pure fn expect<T>(opt: Option<T>, reason: &str) -> T { impl<T> BaseIter<T> for Option<T> { /// Performs an operation on the contained value by reference #[inline(always)] - pure fn each(&self, f: &fn(x: &self/T) -> bool) { + pure fn each(&self, f: &fn(x: &'self T) -> bool) { match *self { None => (), Some(ref t) => { f(t); } } } @@ -323,14 +323,21 @@ impl<T> BaseIter<T> for Option<T> { } } +impl<T> MutableIter<T> for Option<T> { + #[inline(always)] + fn each_mut(&mut self, f: &fn(&'self mut T) -> bool) { + match *self { None => (), Some(ref mut t) => { f(t); } } + } +} + pub impl<T> Option<T> { /// Returns true if the option equals `none` #[inline(always)] - pure fn is_none(&self) -> bool { is_none(self) } + pure fn is_none(&const self) -> bool { is_none(self) } /// Returns true if the option contains some value #[inline(always)] - pure fn is_some(&self) -> bool { is_some(self) } + pure fn is_some(&const self) -> bool { is_some(self) } /** * Update an optional value by optionally running its content by reference @@ -343,7 +350,7 @@ pub impl<T> Option<T> { /// Maps a `some` value from one type to another by reference #[inline(always)] - pure fn map<U>(&self, f: &fn(&self/T) -> U) -> Option<U> { map(self, f) } + pure fn map<U>(&self, f: &fn(&'self T) -> U) -> Option<U> { map(self, f) } /// As `map`, but consumes the option and gives `f` ownership to avoid /// copying. @@ -354,7 +361,7 @@ pub impl<T> Option<T> { /// Applies a function to the contained value or returns a default #[inline(always)] - pure fn map_default<U>(&self, def: U, f: &fn(&self/T) -> U) -> U { + pure fn map_default<U>(&self, def: U, f: &fn(&'self T) -> U) -> U { map_default(self, def, f) } @@ -396,7 +403,7 @@ pub impl<T> Option<T> { case explicitly. */ #[inline(always)] - pure fn get_ref(&self) -> &self/T { get_ref(self) } + pure fn get_ref(&self) -> &'self T { get_ref(self) } /** Gets a mutable reference to the value inside an option. @@ -413,7 +420,7 @@ pub impl<T> Option<T> { case explicitly. */ #[inline(always)] - pure fn get_mut_ref(&mut self) -> &self/mut T { get_mut_ref(self) } + pure fn get_mut_ref(&mut self) -> &'self mut T { get_mut_ref(self) } /** * Gets the value out of an option without copying. diff --git a/src/libcore/os.rs b/src/libcore/os.rs index aa4a6feb76f..17ec9df9d56 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -208,8 +208,8 @@ pub fn env() -> ~[(~str,~str)] { let mut result = ~[]; ptr::array_each(environ, |e| { let env_pair = str::raw::from_c_str(e); - log(debug, fmt!("get_env_pairs: %s", - env_pair)); + debug!("get_env_pairs: %s", + env_pair); result.push(env_pair); }); result @@ -219,9 +219,8 @@ pub fn env() -> ~[(~str,~str)] { let mut pairs = ~[]; for input.each |p| { let vs = str::splitn_char(*p, '=', 1); - log(debug, - fmt!("splitting: len: %u", - vs.len())); + debug!("splitting: len: %u", + vs.len()); fail_unless!(vs.len() == 2); pairs.push((copy vs[0], copy vs[1])); } @@ -682,10 +681,10 @@ pub fn list_dir(p: &Path) -> ~[~str] { let input = p.to_str(); let mut strings = ~[]; let input_ptr = ::cast::transmute(&input[0]); - log(debug, "os::list_dir -- BEFORE OPENDIR"); + debug!("os::list_dir -- BEFORE OPENDIR"); let dir_ptr = opendir(input_ptr); if (dir_ptr as uint != 0) { - log(debug, "os::list_dir -- opendir() SUCCESS"); + debug!("os::list_dir -- opendir() SUCCESS"); let mut entry_ptr = readdir(dir_ptr); while (entry_ptr as uint != 0) { strings.push( @@ -697,11 +696,11 @@ pub fn list_dir(p: &Path) -> ~[~str] { closedir(dir_ptr); } else { - log(debug, "os::list_dir -- opendir() FAILURE"); + debug!("os::list_dir -- opendir() FAILURE"); } - log(debug, - fmt!("os::list_dir -- AFTER -- #: %?", - strings.len())); + debug!( + "os::list_dir -- AFTER -- #: %?", + strings.len()); strings } #[cfg(windows)] @@ -1171,11 +1170,11 @@ pub mod consts { pub use os::consts::windows::*; pub mod unix { - pub const FAMILY: &static/str = "unix"; + pub const FAMILY: &'static str = "unix"; } pub mod windows { - pub const FAMILY: &static/str = "windows"; + pub const FAMILY: &'static str = "windows"; } #[cfg(target_os = "macos")] @@ -1194,38 +1193,38 @@ pub mod consts { pub use os::consts::win32::*; pub mod macos { - pub const SYSNAME: &static/str = "macos"; - pub const DLL_PREFIX: &static/str = "lib"; - pub const DLL_SUFFIX: &static/str = ".dylib"; - pub const EXE_SUFFIX: &static/str = ""; + pub const SYSNAME: &'static str = "macos"; + pub const DLL_PREFIX: &'static str = "lib"; + pub const DLL_SUFFIX: &'static str = ".dylib"; + pub const EXE_SUFFIX: &'static str = ""; } pub mod freebsd { - pub const SYSNAME: &static/str = "freebsd"; - pub const DLL_PREFIX: &static/str = "lib"; - pub const DLL_SUFFIX: &static/str = ".so"; - pub const EXE_SUFFIX: &static/str = ""; + pub const SYSNAME: &'static str = "freebsd"; + pub const DLL_PREFIX: &'static str = "lib"; + pub const DLL_SUFFIX: &'static str = ".so"; + pub const EXE_SUFFIX: &'static str = ""; } pub mod linux { - pub const SYSNAME: &static/str = "linux"; - pub const DLL_PREFIX: &static/str = "lib"; - pub const DLL_SUFFIX: &static/str = ".so"; - pub const EXE_SUFFIX: &static/str = ""; + pub const SYSNAME: &'static str = "linux"; + pub const DLL_PREFIX: &'static str = "lib"; + pub const DLL_SUFFIX: &'static str = ".so"; + pub const EXE_SUFFIX: &'static str = ""; } pub mod android { - pub const SYSNAME: &static/str = "android"; - pub const DLL_PREFIX: &static/str = "lib"; - pub const DLL_SUFFIX: &static/str = ".so"; - pub const EXE_SUFFIX: &static/str = ""; + pub const SYSNAME: &'static str = "android"; + pub const DLL_PREFIX: &'static str = "lib"; + pub const DLL_SUFFIX: &'static str = ".so"; + pub const EXE_SUFFIX: &'static str = ""; } pub mod win32 { - pub const SYSNAME: &static/str = "win32"; - pub const DLL_PREFIX: &static/str = ""; - pub const DLL_SUFFIX: &static/str = ".dll"; - pub const EXE_SUFFIX: &static/str = ".exe"; + pub const SYSNAME: &'static str = "win32"; + pub const DLL_PREFIX: &'static str = ""; + pub const DLL_SUFFIX: &'static str = ".dll"; + pub const EXE_SUFFIX: &'static str = ".exe"; } @@ -1258,7 +1257,6 @@ pub mod consts { #[cfg(test)] #[allow(non_implicitly_copyable_typarams)] mod tests { - use debug; use libc::{c_int, c_void, size_t}; use libc; use option::{None, Option, Some}; @@ -1267,6 +1265,7 @@ mod tests { use os::{remove_file, setenv}; use os; use path::Path; + use rand::RngUtil; use rand; use run; use str; @@ -1274,7 +1273,7 @@ mod tests { #[test] pub fn last_os_error() { - log(debug, os::last_os_error()); + debug!(os::last_os_error()); } #[test] @@ -1284,7 +1283,7 @@ mod tests { } fn make_rand_name() -> ~str { - let rng: rand::Rng = rand::Rng(); + let rng: @rand::Rng = rand::Rng(); let n = ~"TEST" + rng.gen_str(10u); fail_unless!(getenv(n).is_none()); n @@ -1320,7 +1319,7 @@ mod tests { while i < 100 { s += ~"aaaaaaaaaa"; i += 1; } let n = make_rand_name(); setenv(n, s); - log(debug, copy s); + debug!(copy s); fail_unless!(getenv(n) == option::Some(s)); } @@ -1329,7 +1328,7 @@ mod tests { let path = os::self_exe_path(); fail_unless!(path.is_some()); let path = path.get(); - log(debug, copy path); + debug!(copy path); // Hard to test this function fail_unless!(path.is_absolute); @@ -1342,7 +1341,7 @@ mod tests { fail_unless!(vec::len(e) > 0u); for vec::each(e) |p| { let (n, v) = copy *p; - log(debug, copy n); + debug!(copy n); let v2 = getenv(n); // MingW seems to set some funky environment variables like // "=C:=C:\MinGW\msys\1.0\bin" and "!::=::\" that are returned @@ -1367,10 +1366,10 @@ mod tests { fn test() { fail_unless!((!Path("test-path").is_absolute)); - log(debug, ~"Current working directory: " + getcwd().to_str()); + debug!(~"Current working directory: " + getcwd().to_str()); - log(debug, make_absolute(&Path("test-path"))); - log(debug, make_absolute(&Path("/usr/bin"))); + debug!(make_absolute(&Path("test-path"))); + debug!(make_absolute(&Path("/usr/bin"))); } #[test] @@ -1433,7 +1432,7 @@ mod tests { fail_unless!((vec::len(dirs) > 0u)); for vec::each(dirs) |dir| { - log(debug, copy *dir); + debug!(copy *dir); } } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index fd823e9dda0..eb385d90354 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -446,7 +446,7 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>) let p = unsafe { &*p_ }; struct DropState { - p: &self/PacketHeader, + p: &'self PacketHeader, drop { if task::failing() { diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index 2f575ce7d28..1710373b1e7 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -27,8 +27,9 @@ pub use clone::Clone; pub use cmp::{Eq, Ord, TotalOrd, Ordering, Less, Equal, Greater}; pub use container::{Container, Mutable, Map, Set}; pub use hash::Hash; -pub use iter::{BaseIter, ReverseIter, ExtendedIter, EqIter, CopyableIter}; -pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times}; +pub use iter::{BaseIter, ReverseIter, MutableIter, ExtendedIter, EqIter}; +pub use iter::{CopyableIter, CopyableOrderedIter, CopyableNonstrictIter}; +pub use iter::Times; pub use num::NumCast; pub use path::GenericPath; pub use path::Path; @@ -43,6 +44,10 @@ pub use vec::{CopyableVector, ImmutableVector}; pub use vec::{ImmutableEqVector, ImmutableCopyableVector}; pub use vec::{OwnedVector, OwnedCopyableVector}; +/* Reexported runtime types */ +pub use comm::{stream, Port, Chan, GenericChan, GenericSmartChan, GenericPort, Peekable}; +pub use task::spawn; + /* Reexported modules */ pub use at_vec; @@ -82,18 +87,3 @@ pub use u64; pub use u8; pub use uint; pub use vec; - -/* - * Export the log levels as global constants. Higher levels mean - * more-verbosity. Error is the bottom level, default logging level is - * warn-and-below. - */ - -/// The error log level -pub const error : u32 = 1_u32; -/// The warning log level -pub const warn : u32 = 2_u32; -/// The info log level -pub const info : u32 = 3_u32; -/// The debug log level -pub const debug : u32 = 4_u32; diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index ace70d7f061..c1b6b26d86a 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -19,7 +19,6 @@ use sys; #[cfg(test)] use vec; #[cfg(test)] use str; #[cfg(notest)] use cmp::{Eq, Ord}; -use debug; use uint; pub mod libc_ { @@ -179,7 +178,7 @@ pub pure fn to_uint<T>(thing: &T) -> uint { /// Determine if two borrowed pointers point to the same thing. #[inline(always)] -pub pure fn ref_eq<T>(thing: &a/T, other: &b/T) -> bool { +pub pure fn ref_eq<T>(thing: &'a T, other: &'b T) -> bool { to_uint(thing) == to_uint(other) } @@ -191,7 +190,7 @@ pub pure fn ref_eq<T>(thing: &a/T, other: &b/T) -> bool { SAFETY NOTE: Pointer-arithmetic. Dragons be here. */ pub unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: &fn(*T)) { - log(debug, "array_each_with_len: before iterate"); + debug!("array_each_with_len: before iterate"); if (arr as uint == 0) { fail!(~"ptr::array_each_with_len failure: arr input is null pointer"); } @@ -201,7 +200,7 @@ pub unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: &fn(*T)) { cb(*n); true }); - log(debug, "array_each_with_len: after iterate"); + debug!("array_each_with_len: after iterate"); } /** @@ -218,14 +217,14 @@ pub unsafe fn array_each<T>(arr: **T, cb: &fn(*T)) { fail!(~"ptr::array_each_with_len failure: arr input is null pointer"); } let len = buf_len(arr); - log(debug, fmt!("array_each inferred len: %u", - len)); + debug!("array_each inferred len: %u", + len); array_each_with_len(arr, len, cb); } pub trait Ptr<T> { - pure fn is_null(&self) -> bool; - pure fn is_not_null(&self) -> bool; + pure fn is_null(&const self) -> bool; + pure fn is_not_null(&const self) -> bool; pure fn offset(&self, count: uint) -> Self; } @@ -233,11 +232,11 @@ pub trait Ptr<T> { impl<T> Ptr<T> for *T { /// Returns true if the pointer is equal to the null pointer. #[inline(always)] - pure fn is_null(&self) -> bool { is_null(*self) } + pure fn is_null(&const self) -> bool { is_null(*self) } /// Returns true if the pointer is not equal to the null pointer. #[inline(always)] - pure fn is_not_null(&self) -> bool { is_not_null(*self) } + pure fn is_not_null(&const self) -> bool { is_not_null(*self) } /// Calculates the offset from a pointer. #[inline(always)] @@ -248,11 +247,11 @@ impl<T> Ptr<T> for *T { impl<T> Ptr<T> for *mut T { /// Returns true if the pointer is equal to the null pointer. #[inline(always)] - pure fn is_null(&self) -> bool { is_null(*self) } + pure fn is_null(&const self) -> bool { is_null(*self) } /// Returns true if the pointer is not equal to the null pointer. #[inline(always)] - pure fn is_not_null(&self) -> bool { is_not_null(*self) } + pure fn is_not_null(&const self) -> bool { is_not_null(*self) } /// Calculates the offset from a mutable pointer. #[inline(always)] @@ -313,34 +312,34 @@ impl<T> Ord for *const T { // Equality for region pointers #[cfg(notest)] -impl<T:Eq> Eq for &self/const T { +impl<T:Eq> Eq for &'self const T { #[inline(always)] - pure fn eq(&self, other: & &self/const T) -> bool { + pure fn eq(&self, other: & &'self const T) -> bool { return *(*self) == *(*other); } #[inline(always)] - pure fn ne(&self, other: & &self/const T) -> bool { + pure fn ne(&self, other: & &'self const T) -> bool { return *(*self) != *(*other); } } // Comparison for region pointers #[cfg(notest)] -impl<T:Ord> Ord for &self/const T { +impl<T:Ord> Ord for &'self const T { #[inline(always)] - pure fn lt(&self, other: & &self/const T) -> bool { + pure fn lt(&self, other: & &'self const T) -> bool { *(*self) < *(*other) } #[inline(always)] - pure fn le(&self, other: & &self/const T) -> bool { + pure fn le(&self, other: & &'self const T) -> bool { *(*self) <= *(*other) } #[inline(always)] - pure fn ge(&self, other: & &self/const T) -> bool { + pure fn ge(&self, other: & &'self const T) -> bool { *(*self) >= *(*other) } #[inline(always)] - pure fn gt(&self, other: & &self/const T) -> bool { + pure fn gt(&self, other: & &'self const T) -> bool { *(*self) > *(*other) } } @@ -434,7 +433,6 @@ pub fn test_is_null() { #[cfg(test)] pub mod ptr_tests { - use debug; use ptr; use str; use libc; @@ -460,9 +458,9 @@ pub mod ptr_tests { |e| { let actual = str::raw::from_c_str(e); let expected = copy expected_arr[ctr]; - log(debug, - fmt!("test_ptr_array_each e: %s, a: %s", - expected, actual)); + debug!( + "test_ptr_array_each e: %s, a: %s", + expected, actual); fail_unless!(actual == expected); ctr += 1; iteration_count += 1; @@ -492,9 +490,9 @@ pub mod ptr_tests { ptr::array_each(arr_ptr, |e| { let actual = str::raw::from_c_str(e); let expected = copy expected_arr[ctr]; - log(debug, - fmt!("test_ptr_array_each e: %s, a: %s", - expected, actual)); + debug!( + "test_ptr_array_each e: %s, a: %s", + expected, actual); fail_unless!(actual == expected); ctr += 1; iteration_count += 1; diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index cf90edf86f4..4cb5e58b733 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -22,97 +22,100 @@ use libc::size_t; /// A type that can be randomly generated using an RNG pub trait Rand { - static fn rand(rng: rand::Rng) -> Self; + static fn rand(rng: @rand::Rng) -> Self; } impl Rand for int { - static fn rand(rng: rand::Rng) -> int { + static fn rand(rng: @rand::Rng) -> int { rng.gen_int() } } impl Rand for i8 { - static fn rand(rng: rand::Rng) -> i8 { + static fn rand(rng: @rand::Rng) -> i8 { rng.gen_i8() } } impl Rand for i16 { - static fn rand(rng: rand::Rng) -> i16 { + static fn rand(rng: @rand::Rng) -> i16 { rng.gen_i16() } } impl Rand for i32 { - static fn rand(rng: rand::Rng) -> i32 { + static fn rand(rng: @rand::Rng) -> i32 { rng.gen_i32() } } impl Rand for i64 { - static fn rand(rng: rand::Rng) -> i64 { + static fn rand(rng: @rand::Rng) -> i64 { rng.gen_i64() } } impl Rand for u8 { - static fn rand(rng: rand::Rng) -> u8 { + static fn rand(rng: @rand::Rng) -> u8 { rng.gen_u8() } } impl Rand for u16 { - static fn rand(rng: rand::Rng) -> u16 { + static fn rand(rng: @rand::Rng) -> u16 { rng.gen_u16() } } impl Rand for u32 { - static fn rand(rng: rand::Rng) -> u32 { + static fn rand(rng: @rand::Rng) -> u32 { rng.gen_u32() } } impl Rand for u64 { - static fn rand(rng: rand::Rng) -> u64 { + static fn rand(rng: @rand::Rng) -> u64 { rng.gen_u64() } } impl Rand for float { - static fn rand(rng: rand::Rng) -> float { + static fn rand(rng: @rand::Rng) -> float { rng.gen_float() } } impl Rand for f32 { - static fn rand(rng: rand::Rng) -> f32 { + static fn rand(rng: @rand::Rng) -> f32 { rng.gen_f32() } } impl Rand for f64 { - static fn rand(rng: rand::Rng) -> f64 { + static fn rand(rng: @rand::Rng) -> f64 { rng.gen_f64() } } impl Rand for char { - static fn rand(rng: rand::Rng) -> char { + static fn rand(rng: @rand::Rng) -> char { rng.gen_char() } } impl Rand for bool { - static fn rand(rng: rand::Rng) -> bool { + static fn rand(rng: @rand::Rng) -> bool { rng.gen_bool() } } impl<T:Rand> Rand for Option<T> { - static fn rand(rng: rand::Rng) -> Option<T> { - if rng.gen_bool() { Some(Rand::rand(rng)) } - else { None } + static fn rand(rng: @rand::Rng) -> Option<T> { + if rng.gen_bool() { + Some(Rand::rand(rng)) + } else { + None + } } } @@ -145,8 +148,83 @@ pub struct Weighted<T> { item: T, } +pub trait RngUtil { + fn gen<T:Rand>(&self) -> T; + /// Return a random int + fn gen_int(&self) -> int; + fn gen_int_range(&self, start: int, end: int) -> int; + /// Return a random i8 + fn gen_i8(&self) -> i8; + /// Return a random i16 + fn gen_i16(&self) -> i16; + /// Return a random i32 + fn gen_i32(&self) -> i32; + /// Return a random i64 + fn gen_i64(&self) -> i64; + /// Return a random uint + fn gen_uint(&self) -> uint; + /** + * Return a uint randomly chosen from the range [start, end), + * failing if start >= end + */ + fn gen_uint_range(&self, start: uint, end: uint) -> uint; + /// Return a random u8 + fn gen_u8(&self) -> u8; + /// Return a random u16 + fn gen_u16(&self) -> u16; + /// Return a random u32 + fn gen_u32(&self) -> u32; + /// Return a random u64 + fn gen_u64(&self) -> u64; + /// Return a random float in the interval [0,1] + fn gen_float(&self) -> float; + /// Return a random f32 in the interval [0,1] + fn gen_f32(&self) -> f32; + /// Return a random f64 in the interval [0,1] + fn gen_f64(&self) -> f64; + /// Return a random char + fn gen_char(&self) -> char; + /** + * Return a char randomly chosen from chars, failing if chars is empty + */ + fn gen_char_from(&self, chars: &str) -> char; + /// Return a random bool + fn gen_bool(&self) -> bool; + /// Return a bool with a 1 in n chance of true + fn gen_weighted_bool(&self, n: uint) -> bool; + /** + * Return a random string of the specified length composed of A-Z,a-z,0-9 + */ + fn gen_str(&self, len: uint) -> ~str; + /// Return a random byte string of the specified length + fn gen_bytes(&self, len: uint) -> ~[u8]; + /// Choose an item randomly, failing if values is empty + fn choose<T:Copy>(&self, values: &[T]) -> T; + /// Choose Some(item) randomly, returning None if values is empty + fn choose_option<T:Copy>(&self, values: &[T]) -> Option<T>; + /** + * Choose an item respecting the relative weights, failing if the sum of + * the weights is 0 + */ + fn choose_weighted<T:Copy>(&self, v : &[Weighted<T>]) -> T; + /** + * Choose Some(item) respecting the relative weights, returning none if + * the sum of the weights is 0 + */ + fn choose_weighted_option<T:Copy>(&self, v: &[Weighted<T>]) -> Option<T>; + /** + * Return a vec containing copies of the items, in order, where + * the weight of the item determines how many copies there are + */ + fn weighted_vec<T:Copy>(&self, v: &[Weighted<T>]) -> ~[T]; + /// Shuffle a vec + fn shuffle<T:Copy>(&self, values: &[T]) -> ~[T]; + /// Shuffle a mutable vec in place + fn shuffle_mut<T>(&self, values: &mut [T]); +} + /// Extension methods for random number generators -pub impl Rng { +impl RngUtil for @Rng { /// Return a random value for a Rand type fn gen<T:Rand>(&self) -> T { Rand::rand(*self) @@ -407,7 +485,7 @@ pub fn seed() -> ~[u8] { } /// Create a random number generator with a system specified seed -pub fn Rng() -> Rng { +pub fn Rng() -> @Rng { seeded_rng(seed()) } @@ -449,7 +527,7 @@ impl Rng for XorShiftState { } } -pub pure fn xorshift() -> Rng { +pub pure fn xorshift() -> @Rng { // constants taken from http://en.wikipedia.org/wiki/Xorshift seeded_xorshift(123456789u32, 362436069u32, 521288629u32, 88675123u32) } @@ -467,7 +545,7 @@ fn tls_rng_state(_v: @RandRes) {} * seeded by the system. Intended to be used in method chaining style, ie * task_rng().gen_int(). */ -pub fn task_rng() -> Rng { +pub fn task_rng() -> @Rng { let r : Option<@RandRes>; unsafe { r = task::local_data::local_data_get(tls_rng_state); @@ -494,7 +572,6 @@ pub fn random() -> uint { #[cfg(test)] pub mod tests { - use debug; use option::{None, Option, Some}; use rand; @@ -563,7 +640,7 @@ pub mod tests { let r = rand::Rng(); let a = r.gen_float(); let b = r.gen_float(); - log(debug, (a, b)); + debug!((a, b)); } #[test] @@ -576,9 +653,9 @@ pub mod tests { #[test] pub fn gen_str() { let r = rand::Rng(); - log(debug, r.gen_str(10u)); - log(debug, r.gen_str(10u)); - log(debug, r.gen_str(10u)); + debug!(r.gen_str(10u)); + debug!(r.gen_str(10u)); + debug!(r.gen_str(10u)); fail_unless!(r.gen_str(0u).len() == 0u); fail_unless!(r.gen_str(10u).len() == 10u); fail_unless!(r.gen_str(16u).len() == 16u); diff --git a/src/libcore/reflect.rs b/src/libcore/reflect.rs index 30c46cd3e35..a0f9fa7e08e 100644 --- a/src/libcore/reflect.rs +++ b/src/libcore/reflect.rs @@ -214,9 +214,9 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> { } fn visit_estr_slice(&self) -> bool { - self.align_to::<&static/str>(); + self.align_to::<&'static str>(); if ! self.inner.visit_estr_slice() { return false; } - self.bump_past::<&static/str>(); + self.bump_past::<&'static str>(); true } @@ -251,9 +251,9 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> { } fn visit_rptr(&self, mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<&static/u8>(); + self.align_to::<&'static u8>(); if ! self.inner.visit_rptr(mtbl, inner) { return false; } - self.bump_past::<&static/u8>(); + self.bump_past::<&'static u8>(); true } @@ -285,9 +285,9 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> { } fn visit_evec_slice(&self, mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<&static/[u8]>(); + self.align_to::<&'static [u8]>(); if ! self.inner.visit_evec_slice(mtbl, inner) { return false; } - self.bump_past::<&static/[u8]>(); + self.bump_past::<&'static [u8]>(); true } @@ -465,9 +465,9 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> { } fn visit_self(&self) -> bool { - self.align_to::<&static/u8>(); + self.align_to::<&'static u8>(); if ! self.inner.visit_self() { return false; } - self.align_to::<&static/u8>(); + self.align_to::<&'static u8>(); true } diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs index ad85c5e5cef..83df9b7c00f 100644 --- a/src/libcore/repr.rs +++ b/src/libcore/repr.rs @@ -41,7 +41,7 @@ trait EscapedCharWriter { fn write_escaped_char(&self, ch: char); } -impl EscapedCharWriter for Writer { +impl EscapedCharWriter for @Writer { fn write_escaped_char(&self, ch: char) { match ch { '\t' => self.write_str("\\t"), @@ -499,7 +499,7 @@ impl TyVisitor for ReprVisitor { } fn visit_enum_variant_field(&self, i: uint, inner: *TyDesc) -> bool { - match self.var_stk[self.var_stk.len() - 1] { + match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] { Degenerate | TagMatch => { if i != 0 { self.writer.write_str(", "); @@ -517,7 +517,7 @@ impl TyVisitor for ReprVisitor { _disr_val: int, n_fields: uint, _name: &str) -> bool { - match self.var_stk[self.var_stk.len() - 1] { + match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] { Degenerate | TagMatch => { if n_fields > 0 { self.writer.write_char(')'); diff --git a/src/libcore/result.rs b/src/libcore/result.rs index e3fd279a996..832071a0ba8 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -53,7 +53,7 @@ pub pure fn get<T:Copy,U>(res: &Result<T, U>) -> T { * If the result is an error */ #[inline(always)] -pub pure fn get_ref<T, U>(res: &a/Result<T, U>) -> &a/T { +pub pure fn get_ref<T, U>(res: &'a Result<T, U>) -> &'a T { match *res { Ok(ref t) => t, Err(ref the_err) => unsafe { @@ -229,7 +229,7 @@ pub pure fn map_err<T:Copy,E,F:Copy>(res: &Result<T, E>, op: &fn(&E) -> F) pub impl<T, E> Result<T, E> { #[inline(always)] - pure fn get_ref(&self) -> &self/T { get_ref(self) } + pure fn get_ref(&self) -> &'self T { get_ref(self) } #[inline(always)] pure fn is_ok(&self) -> bool { is_ok(self) } diff --git a/src/libcore/rt/env.rs b/src/libcore/rt/env.rs new file mode 100644 index 00000000000..008e31777b0 --- /dev/null +++ b/src/libcore/rt/env.rs @@ -0,0 +1,47 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Runtime environment settings + +use libc::{size_t, c_char, c_int}; + +pub struct Environment { + /// The number of threads to use by default + num_sched_threads: size_t, + /// The minimum size of a stack segment + min_stack_size: size_t, + /// The maximum amount of total stack per task before aborting + max_stack_size: size_t, + /// The default logging configuration + logspec: *c_char, + /// Record and report detailed information about memory leaks + detailed_leaks: bool, + /// Seed the random number generator + rust_seed: *c_char, + /// Poison allocations on free + poison_on_free: bool, + /// The argc value passed to main + argc: c_int, + /// The argv value passed to main + argv: **c_char, + /// Print GC debugging info + debug_mem: bool +} + +/// Get the global environment settings +/// # Safety Note +/// This will abort the process if run outside of task context +pub fn get() -> &Environment { + unsafe { rust_get_rt_env() } +} + +extern { + fn rust_get_rt_env() -> &Environment; +} \ No newline at end of file diff --git a/src/libcore/rt/io.rs b/src/libcore/rt/io.rs index 3a94c01e0a4..55e062de85b 100644 --- a/src/libcore/rt/io.rs +++ b/src/libcore/rt/io.rs @@ -22,7 +22,7 @@ pub trait EventLoop { fn run(&mut self); fn callback(&mut self, ~fn()); /// The asynchronous I/O services. Not all event loops may provide one - fn io(&mut self) -> Option<&self/mut IoFactoryObject>; + fn io(&mut self) -> Option<&'self mut IoFactoryObject>; } pub trait IoFactory { diff --git a/src/libcore/rt/mod.rs b/src/libcore/rt/mod.rs index ea3878adbf0..a1a9884aeca 100644 --- a/src/libcore/rt/mod.rs +++ b/src/libcore/rt/mod.rs @@ -45,3 +45,4 @@ mod work_queue; mod stack; mod context; mod thread; +pub mod env; diff --git a/src/libcore/rt/sched.rs b/src/libcore/rt/sched.rs index 8f315452e5e..69cbbdd2ad4 100644 --- a/src/libcore/rt/sched.rs +++ b/src/libcore/rt/sched.rs @@ -265,12 +265,12 @@ pub impl Scheduler { } } - // XXX: Hack. This should return &self/mut but I don't know how to + // XXX: Hack. This should return &'self mut but I don't know how to // make the borrowcheck happy fn task_from_last_cleanup_job(&mut self) -> &mut Task { fail_unless!(!self.cleanup_jobs.is_empty()); - let last_job: &self/mut CleanupJob = &mut self.cleanup_jobs[0]; - let last_task: &self/Task = match last_job { + let last_job: &'self mut CleanupJob = &mut self.cleanup_jobs[0]; + let last_task: &'self Task = match last_job { &RescheduleTask(~ref task) => task, &RecycleTask(~ref task) => task, &GiveTask(~ref task, _) => task, @@ -356,7 +356,7 @@ impl ThreadLocalScheduler { } } - fn get_scheduler(&mut self) -> &self/mut Scheduler { + fn get_scheduler(&mut self) -> &'self mut Scheduler { unsafe { let key = match self { &ThreadLocalScheduler(key) => key }; let mut value: *mut c_void = tls::get(key); diff --git a/src/libcore/rt/thread.rs b/src/libcore/rt/thread.rs index cd461274512..be1d86c9cf7 100644 --- a/src/libcore/rt/thread.rs +++ b/src/libcore/rt/thread.rs @@ -22,7 +22,7 @@ struct Thread { impl Thread { static fn start(main: ~fn()) -> Thread { fn substart(main: &fn()) -> *raw_thread { - unsafe { rust_raw_thread_start(main) } + unsafe { rust_raw_thread_start(&main) } } let raw = substart(main); Thread { @@ -39,6 +39,6 @@ impl Drop for Thread { } extern { - pub unsafe fn rust_raw_thread_start(f: &fn()) -> *raw_thread; + pub unsafe fn rust_raw_thread_start(f: &(&fn())) -> *raw_thread; pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread); } diff --git a/src/libcore/rt/thread_local_storage.rs b/src/libcore/rt/thread_local_storage.rs index 58b5a544386..e10551b6b89 100644 --- a/src/libcore/rt/thread_local_storage.rs +++ b/src/libcore/rt/thread_local_storage.rs @@ -10,7 +10,7 @@ use libc::{c_void}; #[cfg(unix)] -use libc::{c_uint, c_int}; +use libc::{c_uint, c_ulong, c_int}; #[cfg(unix)] use ptr::null; #[cfg(windows)] @@ -34,7 +34,13 @@ pub unsafe fn get(key: Key) -> *mut c_void { unsafe { pthread_getspecific(key) } } -#[cfg(unix)] +#[cfg(target_os="macos")] +#[allow(non_camel_case_types)] // foreign type +type pthread_key_t = c_ulong; + +#[cfg(target_os="linux")] +#[cfg(target_os="freebsd")] +#[cfg(target_os="android")] #[allow(non_camel_case_types)] // foreign type type pthread_key_t = c_uint; diff --git a/src/libcore/rt/uv.rs b/src/libcore/rt/uv.rs index c947e4dde4c..80224fa523a 100644 --- a/src/libcore/rt/uv.rs +++ b/src/libcore/rt/uv.rs @@ -659,7 +659,7 @@ fn install_watcher_data<H, W: Watcher + NativeHandle<*H>>(watcher: &mut W) { } fn get_watcher_data<H, W: Watcher + NativeHandle<*H>>( - watcher: &r/mut W) -> &r/mut WatcherData { + watcher: &'r mut W) -> &'r mut WatcherData { unsafe { let data = uvll::get_data_for_uv_handle(watcher.native_handle()); diff --git a/src/libcore/rt/uvio.rs b/src/libcore/rt/uvio.rs index f7275652e7f..a971ed92b7e 100644 --- a/src/libcore/rt/uvio.rs +++ b/src/libcore/rt/uvio.rs @@ -69,7 +69,7 @@ impl EventLoop for UvEventLoop { } } - fn io(&mut self) -> Option<&self/mut IoFactoryObject> { + fn io(&mut self) -> Option<&'self mut IoFactoryObject> { Some(&mut self.uvio) } } @@ -91,7 +91,7 @@ fn test_callback_run_once() { pub struct UvIoFactory(Loop); pub impl UvIoFactory { - fn uv_loop(&mut self) -> &self/mut Loop { + fn uv_loop(&mut self) -> &'self mut Loop { match self { &UvIoFactory(ref mut ptr) => ptr } } } diff --git a/src/libcore/run.rs b/src/libcore/run.rs index a9d96d891c9..d3affbc69fe 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -45,13 +45,13 @@ pub trait Program { fn get_id(&mut self) -> pid_t; /// Returns an io::writer that can be used to write to stdin - fn input(&mut self) -> io::Writer; + fn input(&mut self) -> @io::Writer; /// Returns an io::reader that can be used to read from stdout - fn output(&mut self) -> io::Reader; + fn output(&mut self) -> @io::Reader; /// Returns an io::reader that can be used to read from stderr - fn err(&mut self) -> io::Reader; + fn err(&mut self) -> @io::Reader; /// Closes the handle to the child processes standard input fn close_input(&mut self); @@ -207,7 +207,7 @@ pub fn run_program(prog: &str, args: &[~str]) -> int { * * A class with a <program> field */ -pub fn start_program(prog: &str, args: &[~str]) -> Program { +pub fn start_program(prog: &str, args: &[~str]) -> @Program { let pipe_input = os::pipe(); let pipe_output = os::pipe(); let pipe_err = os::pipe(); @@ -274,13 +274,13 @@ pub fn start_program(prog: &str, args: &[~str]) -> Program { impl Program for ProgRes { fn get_id(&mut self) -> pid_t { return self.r.pid; } - fn input(&mut self) -> io::Writer { + fn input(&mut self) -> @io::Writer { io::fd_writer(self.r.in_fd, false) } - fn output(&mut self) -> io::Reader { + fn output(&mut self) -> @io::Reader { io::FILE_reader(self.r.out_file, false) } - fn err(&mut self) -> io::Reader { + fn err(&mut self) -> @io::Reader { io::FILE_reader(self.r.err_file, false) } fn close_input(&mut self) { close_repr_input(&mut self.r); } @@ -458,7 +458,6 @@ pub fn waitpid(pid: pid_t) -> int { #[cfg(test)] mod tests { - use debug; use option::{None, Some}; use os; use run::{readclose, writeclose}; @@ -494,8 +493,8 @@ mod tests { readclose(pipe_err.in); os::waitpid(pid); - log(debug, copy expected); - log(debug, copy actual); + debug!(copy expected); + debug!(copy actual); fail_unless!((expected == actual)); } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index ae778cb7649..3d591af6d3c 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -20,6 +20,7 @@ use at_vec; use cast; use char; +use clone::Clone; use cmp::{Equiv, TotalOrd, Ordering, Less, Equal, Greater}; use libc; use option::{None, Option, Some}; @@ -278,7 +279,7 @@ pub fn shift_char(s: &mut ~str) -> char { * If the string does not contain any characters */ #[inline] -pub fn view_shift_char(s: &a/str) -> (char, &a/str) { +pub fn view_shift_char(s: &'a str) -> (char, &'a str) { let CharRange {ch, next} = char_range_at(s, 0u); let next_s = unsafe { raw::view_bytes(s, next, len(s)) }; return (ch, next_s); @@ -428,7 +429,7 @@ pub pure fn slice(s: &str, begin: uint, end: uint) -> ~str { * Fails when `begin` and `end` do not point to valid characters or beyond * the last character of the string */ -pub pure fn view(s: &a/str, begin: uint, end: uint) -> &a/str { +pub pure fn view(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::view_bytes(s, begin, end) } @@ -529,7 +530,7 @@ pure fn split_inner(s: &str, sepfn: &fn(cc: char) -> bool, count: uint, } // See Issue #1932 for why this is a naive search -pure fn iter_matches(s: &a/str, sep: &b/str, f: &fn(uint, uint)) { +pure fn iter_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint)) { let sep_len = len(sep), l = len(s); fail_unless!(sep_len > 0u); let mut i = 0u, match_start = 0u, match_i = 0u; @@ -556,7 +557,7 @@ pure fn iter_matches(s: &a/str, sep: &b/str, f: &fn(uint, uint)) { } } -pure fn iter_between_matches(s: &a/str, sep: &b/str, f: &fn(uint, uint)) { +pure fn iter_between_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint)) { let mut last_end = 0u; do iter_matches(s, sep) |from, to| { f(last_end, from); @@ -574,7 +575,7 @@ pure fn iter_between_matches(s: &a/str, sep: &b/str, f: &fn(uint, uint)) { * fail_unless!(["", "XXX", "YYY", ""] == split_str(".XXX.YYY.", ".")) * ~~~ */ -pub pure fn split_str(s: &a/str, sep: &b/str) -> ~[~str] { +pub pure fn split_str(s: &'a str, sep: &'b str) -> ~[~str] { let mut result = ~[]; do iter_between_matches(s, sep) |from, to| { unsafe { result.push(raw::slice_bytes(s, from, to)); } @@ -582,7 +583,7 @@ pub pure fn split_str(s: &a/str, sep: &b/str) -> ~[~str] { result } -pub pure fn split_str_nonempty(s: &a/str, sep: &b/str) -> ~[~str] { +pub pure fn split_str_nonempty(s: &'a str, sep: &'b str) -> ~[~str] { let mut result = ~[]; do iter_between_matches(s, sep) |from, to| { if to > from { @@ -791,7 +792,7 @@ pure fn cmp(a: &str, b: &str) -> Ordering { #[cfg(notest)] impl TotalOrd for &'self str { - pure fn cmp(&self, other: & &self/str) -> Ordering { cmp(*self, *other) } + pure fn cmp(&self, other: & &'self str) -> Ordering { cmp(*self, *other) } } #[cfg(notest)] @@ -836,13 +837,13 @@ pure fn gt(a: &str, b: &str) -> bool { } #[cfg(notest)] -impl Eq for &self/str { +impl Eq for &'self str { #[inline(always)] - pure fn eq(&self, other: & &self/str) -> bool { + pure fn eq(&self, other: & &'self str) -> bool { eq_slice((*self), (*other)) } #[inline(always)] - pure fn ne(&self, other: & &self/str) -> bool { !(*self).eq(other) } + pure fn ne(&self, other: & &'self str) -> bool { !(*self).eq(other) } } #[cfg(notest)] @@ -878,15 +879,15 @@ impl Ord for ~str { } #[cfg(notest)] -impl Ord for &self/str { +impl Ord for &'self str { #[inline(always)] - pure fn lt(&self, other: & &self/str) -> bool { lt((*self), (*other)) } + pure fn lt(&self, other: & &'self str) -> bool { lt((*self), (*other)) } #[inline(always)] - pure fn le(&self, other: & &self/str) -> bool { le((*self), (*other)) } + pure fn le(&self, other: & &'self str) -> bool { le((*self), (*other)) } #[inline(always)] - pure fn ge(&self, other: & &self/str) -> bool { ge((*self), (*other)) } + pure fn ge(&self, other: & &'self str) -> bool { ge((*self), (*other)) } #[inline(always)] - pure fn gt(&self, other: & &self/str) -> bool { gt((*self), (*other)) } + pure fn gt(&self, other: & &'self str) -> bool { gt((*self), (*other)) } } #[cfg(notest)] @@ -1347,7 +1348,7 @@ pub pure fn rfind_between(s: &str, start: uint, end: uint, } // Utility used by various searching functions -pure fn match_at(haystack: &a/str, needle: &b/str, at: uint) -> bool { +pure fn match_at(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; @@ -1366,7 +1367,7 @@ pure 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 pure fn find_str(haystack: &a/str, needle: &b/str) -> Option<uint> { +pub pure fn find_str(haystack: &'a str, needle: &'b str) -> Option<uint> { find_str_between(haystack, needle, 0u, len(haystack)) } @@ -1389,7 +1390,7 @@ pub pure fn find_str(haystack: &a/str, needle: &b/str) -> Option<uint> { * * `start` must be less than or equal to `len(s)` */ -pub pure fn find_str_from(haystack: &a/str, needle: &b/str, start: uint) +pub pure fn find_str_from(haystack: &'a str, needle: &'b str, start: uint) -> Option<uint> { find_str_between(haystack, needle, start, len(haystack)) } @@ -1414,7 +1415,7 @@ pub pure fn find_str_from(haystack: &a/str, needle: &b/str, start: uint) * `start` must be less than or equal to `end` and `end` must be less than * or equal to `len(s)`. */ -pub pure fn find_str_between(haystack: &a/str, needle: &b/str, start: uint, +pub pure fn find_str_between(haystack: &'a str, needle: &'b str, start: uint, end:uint) -> Option<uint> { // See Issue #1932 for why this is a naive search @@ -1440,7 +1441,7 @@ pub pure fn find_str_between(haystack: &a/str, needle: &b/str, start: uint, * * haystack - The string to look in * * needle - The string to look for */ -pub pure fn contains(haystack: &a/str, needle: &b/str) -> bool { +pub pure fn contains(haystack: &'a str, needle: &'b str) -> bool { find_str(haystack, needle).is_some() } @@ -1464,7 +1465,7 @@ pub pure fn contains_char(haystack: &str, needle: char) -> bool { * * haystack - The string to look in * * needle - The string to look for */ -pub pure fn starts_with(haystack: &a/str, needle: &b/str) -> bool { +pub pure fn starts_with(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 } @@ -1479,7 +1480,7 @@ pub pure fn starts_with(haystack: &a/str, needle: &b/str) -> bool { * * haystack - The string to look in * * needle - The string to look for */ -pub pure fn ends_with(haystack: &a/str, needle: &b/str) -> bool { +pub pure fn ends_with(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 } @@ -1661,7 +1662,7 @@ pub pure 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 pure fn count_bytes(s: &b/str, start: uint, n: uint) -> uint { +pub pure fn count_bytes(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); @@ -1904,7 +1905,7 @@ pub pure fn as_bytes<T>(s: &const ~str, f: &fn(&~[u8]) -> T) -> T { * * The byte slice does not include the null terminator. */ -pub pure fn as_bytes_slice(s: &a/str) -> &a/[u8] { +pub pure fn as_bytes_slice(s: &'a str) -> &'a [u8] { unsafe { let (ptr, len): (*u8, uint) = ::cast::reinterpret_cast(&s); let outgoing_tuple: (*u8, uint) = (ptr, len - 1); @@ -2232,9 +2233,9 @@ pub mod traits { use ops::Add; use str::append; - impl Add<&self/str,~str> for ~str { + impl Add<&'self str,~str> for ~str { #[inline(always)] - pure fn add(&self, rhs: & &self/str) -> ~str { + pure fn add(&self, rhs: & &'self str) -> ~str { append(copy *self, (*rhs)) } } @@ -2246,7 +2247,7 @@ pub mod traits {} pub trait StrSlice { pure fn all(&self, it: &fn(char) -> bool) -> bool; pure fn any(&self, it: &fn(char) -> bool) -> bool; - pure fn contains(&self, needle: &a/str) -> bool; + pure fn contains(&self, needle: &'a str) -> bool; pure fn contains_char(&self, needle: char) -> bool; pure fn each(&self, it: &fn(u8) -> bool); pure fn eachi(&self, it: &fn(uint, u8) -> bool); @@ -2260,8 +2261,8 @@ pub trait StrSlice { pure fn slice(&self, begin: uint, end: uint) -> ~str; pure fn split(&self, sepfn: &fn(char) -> bool) -> ~[~str]; pure fn split_char(&self, sep: char) -> ~[~str]; - pure fn split_str(&self, sep: &a/str) -> ~[~str]; - pure fn starts_with(&self, needle: &a/str) -> bool; + pure fn split_str(&self, sep: &'a str) -> ~[~str]; + pure fn starts_with(&self, needle: &'a str) -> bool; pure fn substr(&self, begin: uint, n: uint) -> ~str; pure fn to_lower(&self) -> ~str; pure fn to_upper(&self) -> ~str; @@ -2273,10 +2274,11 @@ pub trait StrSlice { pure fn to_owned(&self) -> ~str; pure fn to_managed(&self) -> @str; pure fn char_at(&self, i: uint) -> char; + fn to_bytes(&self) -> ~[u8]; } /// Extension methods for strings -impl StrSlice for &self/str { +impl StrSlice for &'self str { /** * Return true if a predicate matches all characters or if the string * contains no characters @@ -2291,7 +2293,7 @@ impl StrSlice for &self/str { pure fn any(&self, it: &fn(char) -> bool) -> bool { any(*self, it) } /// Returns true if one string contains another #[inline] - pure fn contains(&self, needle: &a/str) -> bool { + pure fn contains(&self, needle: &'a str) -> bool { contains(*self, needle) } /// Returns true if a string contains a char @@ -2364,10 +2366,10 @@ impl StrSlice for &self/str { * string */ #[inline] - pure fn split_str(&self, sep: &a/str) -> ~[~str] { split_str(*self, sep) } + pure fn split_str(&self, sep: &'a str) -> ~[~str] { split_str(*self, sep) } /// Returns true if one string starts with another #[inline] - pure fn starts_with(&self, needle: &a/str) -> bool { + pure fn starts_with(&self, needle: &'a str) -> bool { starts_with(*self, needle) } /** @@ -2416,6 +2418,8 @@ impl StrSlice for &self/str { #[inline] pure fn char_at(&self, i: uint) -> char { char_at(*self, i) } + + fn to_bytes(&self) -> ~[u8] { to_bytes(*self) } } pub trait OwnedStr { @@ -2433,11 +2437,17 @@ impl OwnedStr for ~str { } } +impl Clone for ~str { + #[inline(always)] + fn clone(&self) -> ~str { + self.to_str() // hilarious + } +} + #[cfg(test)] mod tests { use char; use option::Some; - use debug; use libc::c_char; use libc; use ptr; @@ -2523,7 +2533,7 @@ mod tests { #[test] fn test_split_char() { fn t(s: &str, c: char, u: &[~str]) { - log(debug, ~"split_byte: " + s); + debug!(~"split_byte: " + s); let v = split_char(s, c); debug!("split_byte to: %?", v); fail_unless!(vec::all2(v, u, |a,b| a == b)); @@ -2552,7 +2562,7 @@ mod tests { #[test] fn test_splitn_char() { fn t(s: &str, c: char, n: uint, u: &[~str]) { - log(debug, ~"splitn_byte: " + s); + debug!(~"splitn_byte: " + s); let v = splitn_char(s, c, n); debug!("split_byte to: %?", v); debug!("comparing vs. %?", u); @@ -2602,8 +2612,8 @@ mod tests { #[test] fn test_split_str() { - fn t(s: &str, sep: &a/str, i: int, k: &str) { - fn borrow(x: &a/str) -> &a/str { x } + fn t(s: &str, sep: &'a str, i: int, k: &str) { + fn borrow(x: &'a str) -> &'a str { x } let v = split_str(s, sep); fail_unless!(borrow(v[i]) == k); } @@ -3192,8 +3202,8 @@ mod tests { while i < n1 { let a: u8 = s1[i]; let b: u8 = s2[i]; - log(debug, a); - log(debug, b); + debug!(a); + debug!(b); fail_unless!((a == b)); i += 1u; } diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index 179a33ae43e..f7eceeebc1e 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 fn(*TypeDesc, *c_void); // Corresponds to runtime type_desc type pub struct TypeDesc { diff --git a/src/libcore/task/local_data.rs b/src/libcore/task/local_data.rs index 690b3aedc5a..ccd91709479 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<T> = &self/fn(v: @T); +pub type LocalDataKey<T> = &'self fn(v: @T); /** * Remove a task-local data value from the table, returning the diff --git a/src/libcore/task/local_data_priv.rs b/src/libcore/task/local_data_priv.rs index bb05520e1a3..6a933ef515f 100644 --- a/src/libcore/task/local_data_priv.rs +++ b/src/libcore/task/local_data_priv.rs @@ -23,7 +23,7 @@ use super::rt::rust_task; pub trait LocalData { } impl<T:Durable> LocalData for @T { } -impl Eq for LocalData { +impl Eq for @LocalData { pure fn eq(&self, other: &@LocalData) -> bool { unsafe { let ptr_a: (uint, uint) = cast::reinterpret_cast(&(*self)); @@ -36,7 +36,7 @@ impl Eq for LocalData { // If TLS is used heavily in future, this could be made more efficient with a // proper map. -type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData); +type TaskLocalElement = (*libc::c_void, *libc::c_void, @LocalData); // Has to be a pointer at outermost layer; the foreign call returns void *. type TaskLocalMap = @mut ~[Option<TaskLocalElement>]; diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index a0db2525441..40a6873ad67 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -123,11 +123,11 @@ struct TaskGroupData { } type TaskGroupArc = unstable::Exclusive<Option<TaskGroupData>>; -type TaskGroupInner = &self/mut Option<TaskGroupData>; +type TaskGroupInner = &'self mut Option<TaskGroupData>; // A taskgroup is 'dead' when nothing can cause it to fail; only members can. pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool { - (&tg.members).is_empty() + (&const tg.members).is_empty() } // A list-like structure by which taskgroups keep track of all ancestor groups diff --git a/src/libcore/to_bytes.rs b/src/libcore/to_bytes.rs index 60665bcddf6..e5fbad16717 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 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<A:IterBytes> IterBytes for &self/[A] { +impl<A:IterBytes> IterBytes for &'self [A] { #[inline(always)] pure fn iter_bytes(&self, lsb0: bool, f: Cb) { for (*self).each |elt| { @@ -231,7 +231,7 @@ impl<A:IterBytes,B:IterBytes,C:IterBytes> IterBytes for (A,B,C) { } // Move this to vec, probably. -pure fn borrow<A>(a: &x/[A]) -> &x/[A] { +pure fn borrow<A>(a: &'x [A]) -> &'x [A] { a } @@ -352,7 +352,7 @@ pub pure fn iter_bytes_7<A: IterBytes, g.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag}); } -impl IterBytes for &self/str { +impl IterBytes for &'self str { #[inline(always)] pure fn iter_bytes(&self, _lsb0: bool, f: Cb) { do str::byte_slice(*self) |bytes| { @@ -389,7 +389,7 @@ impl<A:IterBytes> IterBytes for Option<A> { } } -impl<A:IterBytes> IterBytes for &self/A { +impl<A:IterBytes> IterBytes for &'self A { #[inline(always)] pure 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 8215152ef74..0f2fd699604 100644 --- a/src/libcore/to_str.rs +++ b/src/libcore/to_str.rs @@ -32,7 +32,7 @@ impl ToStr for ~str { #[inline(always)] pure fn to_str(&self) -> ~str { copy *self } } -impl ToStr for &self/str { +impl ToStr for &'self str { #[inline(always)] pure fn to_str(&self) -> ~str { ::str::from_slice(*self) } } @@ -72,7 +72,7 @@ impl<A:ToStr,B:ToStr,C:ToStr> ToStr for (A, B, C) { } } -impl<A:ToStr> ToStr for &self/[A] { +impl<A:ToStr> ToStr for &'self [A] { #[inline(always)] pure fn to_str(&self) -> ~str { unsafe { diff --git a/src/libcore/trie.rs b/src/libcore/trie.rs index 7dc85cba297..6b2f2bb6a7d 100644 --- a/src/libcore/trie.rs +++ b/src/libcore/trie.rs @@ -32,7 +32,7 @@ pub struct TrieMap<T> { impl<T> BaseIter<(uint, &'self T)> for TrieMap<T> { /// Visit all key-value pairs in order #[inline(always)] - pure fn each(&self, f: &fn(&(uint, &self/T)) -> bool) { + pure fn each(&self, f: &fn(&(uint, &'self T)) -> bool) { self.root.each(f); } #[inline(always)] @@ -42,7 +42,7 @@ impl<T> BaseIter<(uint, &'self T)> for TrieMap<T> { impl<T> ReverseIter<(uint, &'self T)> for TrieMap<T> { /// Visit all key-value pairs in reverse order #[inline(always)] - pure fn each_reverse(&self, f: &fn(&(uint, &self/T)) -> bool) { + pure fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) { self.root.each_reverse(f); } } @@ -50,11 +50,11 @@ impl<T> ReverseIter<(uint, &'self T)> for TrieMap<T> { impl<T> Container for TrieMap<T> { /// Return the number of elements in the map #[inline(always)] - pure fn len(&self) -> uint { self.length } + pure fn len(&const self) -> uint { self.length } /// Return true if the map contains no elements #[inline(always)] - pure fn is_empty(&self) -> bool { self.len() == 0 } + pure fn is_empty(&const self) -> bool { self.len() == 0 } } impl<T> Mutable for TrieMap<T> { @@ -81,15 +81,20 @@ impl<T> Map<uint, T> for TrieMap<T> { /// Visit all values in order #[inline(always)] - pure fn each_value(&self, - f: &fn(&T) -> bool) { + pure fn each_value(&self, f: &fn(&T) -> bool) { self.each(|&(_, v)| f(v)) } + /// Iterate over the map and mutate the contained values + #[inline(always)] + fn mutate_values(&mut self, f: &fn(&uint, &mut T) -> bool) { + self.root.mutate_values(f); + } + /// Return the value corresponding to the key in the map #[inline(hint)] - pure fn find(&self, key: &uint) -> Option<&self/T> { - let mut node: &self/TrieNode<T> = &self.root; + pure fn find(&self, key: &uint) -> Option<&'self T> { + let mut node: &'self TrieNode<T> = &self.root; let mut idx = 0; loop { match node.children[chunk(*key, idx)] { @@ -132,6 +137,7 @@ impl<T> Map<uint, T> for TrieMap<T> { } impl<T> TrieMap<T> { + /// Create an empty TrieMap #[inline(always)] static pure fn new() -> TrieMap<T> { TrieMap{root: TrieNode::new(), length: 0} @@ -150,11 +156,6 @@ impl<T> TrieMap<T> { pure fn each_value_reverse(&self, f: &fn(&T) -> bool) { self.each_reverse(|&(_, v)| f(v)) } - - /// Iterate over the map and mutate the contained values - fn mutate_values(&mut self, f: &fn(uint, &mut T) -> bool) { - self.root.mutate_values(f); - } } pub struct TrieSet { @@ -177,11 +178,11 @@ impl ReverseIter<uint> for TrieSet { impl Container for TrieSet { /// Return the number of elements in the set #[inline(always)] - pure fn len(&self) -> uint { self.map.len() } + pure fn len(&const self) -> uint { self.map.len() } /// Return true if the set contains no elements #[inline(always)] - pure fn is_empty(&self) -> bool { self.map.is_empty() } + pure fn is_empty(&const self) -> bool { self.map.is_empty() } } impl Mutable for TrieSet { @@ -191,6 +192,12 @@ impl Mutable for TrieSet { } impl TrieSet { + /// Create an empty TrieSet + #[inline(always)] + static pure fn new() -> TrieSet { + TrieSet{map: TrieMap::new()} + } + /// Return true if the set contains a value #[inline(always)] pure fn contains(&self, value: &uint) -> bool { @@ -226,7 +233,7 @@ impl<T> TrieNode<T> { } impl<T> TrieNode<T> { - pure fn each(&self, f: &fn(&(uint, &self/T)) -> bool) -> bool { + pure fn each(&self, f: &fn(&(uint, &'self T)) -> bool) -> bool { for uint::range(0, self.children.len()) |idx| { match self.children[idx] { Internal(ref x) => if !x.each(f) { return false }, @@ -237,7 +244,7 @@ impl<T> TrieNode<T> { true } - pure fn each_reverse(&self, f: &fn(&(uint, &self/T)) -> bool) -> bool { + pure fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) -> bool { for uint::range_rev(self.children.len(), 0) |idx| { match self.children[idx - 1] { Internal(ref x) => if !x.each_reverse(f) { return false }, @@ -248,13 +255,13 @@ impl<T> TrieNode<T> { true } - fn mutate_values(&mut self, f: &fn(uint, &mut T) -> bool) -> bool { + fn mutate_values(&mut self, f: &fn(&uint, &mut T) -> bool) -> bool { for vec::each_mut(self.children) |child| { match *child { Internal(ref mut x) => if !x.mutate_values(f) { return false }, - External(k, ref mut v) => if !f(k, v) { return false }, + External(k, ref mut v) => if !f(&k, v) { return false }, Nothing => () } } @@ -265,12 +272,12 @@ impl<T> TrieNode<T> { // if this was done via a trait, the key could be generic #[inline(always)] pure fn chunk(n: uint, idx: uint) -> uint { - let real_idx = uint::bytes - 1 - idx; - (n >> (SHIFT * real_idx)) & MASK + let sh = uint::bits - (SHIFT * (idx + 1)); + (n >> sh) & MASK } -fn insert<T>(count: &mut uint, child: &mut Child<T>, key: uint, - value: T, idx: uint) -> bool { +fn insert<T>(count: &mut uint, child: &mut Child<T>, key: uint, value: T, + idx: uint) -> bool { let mut tmp = Nothing; tmp <-> *child; let mut added = false; @@ -462,4 +469,26 @@ mod tests { n -= 1; } } + + #[test] + fn test_sane_chunk() { + let x = 1; + let y = 1 << (uint::bits - 1); + + let mut trie = TrieSet::new(); + + fail_unless!(trie.insert(x)); + fail_unless!(trie.insert(y)); + + fail_unless!(trie.len() == 2); + + let expected = [x, y]; + + let mut i = 0; + + for trie.each |x| { + fail_unless!(expected[i] == *x); + i += 1; + } + } } diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs index e41ff424012..b4f68466c27 100644 --- a/src/libcore/tuple.rs +++ b/src/libcore/tuple.rs @@ -47,19 +47,19 @@ impl<T:Copy,U:Copy> CopyableTuple<T, U> for (T, U) { } pub trait ImmutableTuple<T, U> { - pure fn first_ref(&self) -> &self/T; - pure fn second_ref(&self) -> &self/U; + pure fn first_ref(&self) -> &'self T; + pure fn second_ref(&self) -> &'self U; } impl<T, U> ImmutableTuple<T, U> for (T, U) { #[inline(always)] - pure fn first_ref(&self) -> &self/T { + pure fn first_ref(&self) -> &'self T { match *self { (ref t, _) => t, } } #[inline(always)] - pure fn second_ref(&self) -> &self/U { + pure fn second_ref(&self) -> &'self U { match *self { (_, ref u) => u, } @@ -71,7 +71,7 @@ pub trait ExtendedTupleOps<A,B> { fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C]; } -impl<A:Copy,B:Copy> ExtendedTupleOps<A,B> for (&self/[A], &self/[B]) { +impl<A:Copy,B:Copy> ExtendedTupleOps<A,B> 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 7936b18dbe2..899d01cd996 100644 --- a/src/libcore/unstable.rs +++ b/src/libcore/unstable.rs @@ -47,7 +47,7 @@ mod rustrt { pub unsafe fn rust_lock_little_lock(lock: rust_little_lock); pub unsafe fn rust_unlock_little_lock(lock: rust_little_lock); - pub unsafe fn rust_raw_thread_start(f: &fn()) -> *raw_thread; + pub unsafe fn rust_raw_thread_start(f: &(&fn())) -> *raw_thread; pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread); } } @@ -72,7 +72,7 @@ pub fn run_in_bare_thread(f: ~fn()) { let closure: &fn() = || { f() }; - let thread = rustrt::rust_raw_thread_start(closure); + let thread = rustrt::rust_raw_thread_start(&closure); rustrt::rust_raw_thread_join_delete(thread); chan.send(()); } @@ -173,7 +173,7 @@ pub unsafe fn get_shared_mutable_state<T:Owned>( } #[inline(always)] pub unsafe fn get_shared_immutable_state<T:Owned>( - rc: &a/SharedMutableState<T>) -> &a/T { + rc: &'a SharedMutableState<T>) -> &'a T { unsafe { let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data); fail_unless!(ptr.count > 0); diff --git a/src/libcore/unstable/at_exit.rs b/src/libcore/unstable/at_exit.rs index f878161eca1..99ba5030f83 100644 --- a/src/libcore/unstable/at_exit.rs +++ b/src/libcore/unstable/at_exit.rs @@ -8,12 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use sys; use cast; +use libc::{c_void, size_t}; +use rand::RngUtil; +use rand; +use sys; use task; use vec; -use rand; -use libc::{c_void, size_t}; #[cfg(test)] use uint; diff --git a/src/libcore/unstable/finally.rs b/src/libcore/unstable/finally.rs index 5089470e6ef..e8c27ff7d92 100644 --- a/src/libcore/unstable/finally.rs +++ b/src/libcore/unstable/finally.rs @@ -31,7 +31,7 @@ pub trait Finally<T> { fn finally(&self, dtor: &fn()) -> T; } -impl<T> Finally<T> for &self/fn() -> T { +impl<T> Finally<T> for &'self fn() -> T { fn finally(&self, dtor: &fn()) -> T { let _d = Finallyalizer { dtor: dtor @@ -42,7 +42,7 @@ impl<T> Finally<T> for &self/fn() -> T { } struct Finallyalizer { - dtor: &self/fn() + dtor: &'self fn() } impl Drop for Finallyalizer/&self { diff --git a/src/libcore/unstable/global.rs b/src/libcore/unstable/global.rs index 654bf18a5b6..66033605559 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<T> = &self/fn(v: T); +pub type GlobalDataKey<T> = &'self fn(v: T); pub unsafe fn global_data_clone_create<T:Owned + Clone>( key: GlobalDataKey<T>, create: &fn() -> ~T) -> T { @@ -68,11 +68,11 @@ unsafe fn global_data_clone_create_<T:Owned + Clone>( match value { None => { let value = create(); - clone_value = Some(value.clone()); + clone_value = Some((*value).clone()); Some(value) } Some(value) => { - clone_value = Some(value.clone()); + clone_value = Some((*value).clone()); Some(value) } } @@ -193,7 +193,7 @@ fn get_global_state() -> Exclusive<GlobalState> { // Successfully installed the global pointer // Take a handle to return - let clone = state.clone(); + let clone = (*state).clone(); // Install a runtime exit function to destroy the global object do at_exit { diff --git a/src/libcore/unstable/intrinsics.rs b/src/libcore/unstable/intrinsics.rs index 8f0067b7393..a27ac2ccb6b 100644 --- a/src/libcore/unstable/intrinsics.rs +++ b/src/libcore/unstable/intrinsics.rs @@ -34,8 +34,8 @@ pub extern { pub fn size_of<T>() -> uint; - pub fn move_val<T>(dst: &mut T, -src: T); - pub fn move_val_init<T>(dst: &mut T, -src: T); + pub fn move_val<T>(dst: &mut T, +src: T); + pub fn move_val_init<T>(dst: &mut T, +src: T); pub fn min_align_of<T>() -> uint; pub fn pref_align_of<T>() -> uint; diff --git a/src/libcore/unstable/uvll.rs b/src/libcore/unstable/uvll.rs index 0aed2567a22..80f04cf4ac0 100644 --- a/src/libcore/unstable/uvll.rs +++ b/src/libcore/unstable/uvll.rs @@ -930,8 +930,8 @@ pub unsafe fn tcp_connect(connect_ptr: *uv_connect_t, addr_ptr: *sockaddr_in, after_connect_cb: *u8) -> libc::c_int { - log(debug, fmt!("b4 foreign tcp_connect--addr port: %u cb: %u", - (*addr_ptr).sin_port as uint, after_connect_cb as uint)); + debug!("b4 foreign tcp_connect--addr port: %u cb: %u", + (*addr_ptr).sin_port as uint, after_connect_cb as uint); return rustrt::rust_uv_tcp_connect(connect_ptr, tcp_handle_ptr, after_connect_cb, addr_ptr); } @@ -1021,20 +1021,20 @@ pub unsafe fn async_send(async_handle: *uv_async_t) { pub unsafe fn buf_init(input: *u8, len: uint) -> uv_buf_t { let out_buf = uv_buf_t { base: ptr::null(), len: 0 as libc::size_t }; let out_buf_ptr = ptr::addr_of(&out_buf); - log(debug, fmt!("buf_init - input %u len %u out_buf: %u", + debug!("buf_init - input %u len %u out_buf: %u", input as uint, len as uint, - out_buf_ptr as uint)); + out_buf_ptr as uint); // yuck :/ rustrt::rust_uv_buf_init(out_buf_ptr, input, len as size_t); //let result = rustrt::rust_uv_buf_init_2(input, len as size_t); - log(debug, ~"after rust_uv_buf_init"); + debug!("after rust_uv_buf_init"); let res_base = get_base_from_buf(out_buf); let res_len = get_len_from_buf(out_buf); //let res_base = get_base_from_buf(result); - log(debug, fmt!("buf_init - result %u len %u", + debug!("buf_init - result %u len %u", res_base as uint, - res_len as uint)); + res_len as uint); return out_buf; //return result; } @@ -1078,8 +1078,8 @@ pub unsafe fn ip6_name(src: &sockaddr_in6) -> ~str { 0u8,0u8,0u8,0u8,0u8,0u8]; do vec::as_imm_buf(dst) |dst_buf, size| { let src_unsafe_ptr = to_unsafe_ptr(src); - log(debug, fmt!("val of src *sockaddr_in6: %? sockaddr_in6: %?", - src_unsafe_ptr, src)); + debug!("val of src *sockaddr_in6: %? sockaddr_in6: %?", + src_unsafe_ptr, src); let result = rustrt::rust_uv_ip6_name(src_unsafe_ptr, dst_buf, size as libc::size_t); match result { @@ -1257,20 +1257,20 @@ pub mod test { } extern fn after_close_cb(handle: *libc::c_void) { - log(debug, fmt!("after uv_close! handle ptr: %?", - handle)); + debug!("after uv_close! handle ptr: %?", + handle); } extern fn on_alloc_cb(handle: *libc::c_void, suggested_size: libc::size_t) -> uv_buf_t { unsafe { - log(debug, ~"on_alloc_cb!"); + debug!("on_alloc_cb!"); let char_ptr = malloc_buf_base_of(suggested_size); - log(debug, fmt!("on_alloc_cb h: %? char_ptr: %u sugsize: %u", + debug!("on_alloc_cb h: %? char_ptr: %u sugsize: %u", handle, char_ptr as uint, - suggested_size as uint)); + suggested_size as uint); return buf_init(char_ptr, suggested_size as uint); } } @@ -1280,11 +1280,11 @@ pub mod test { ++buf: uv_buf_t) { unsafe { let nread = nread as int; - log(debug, fmt!("CLIENT entering on_read_cb nred: %d", - nread)); + debug!("CLIENT entering on_read_cb nred: %d", + nread); if (nread > 0) { // we have data - log(debug, fmt!("CLIENT read: data! nread: %d", nread)); + debug!("CLIENT read: data! nread: %d", nread); read_stop(stream); let client_data = get_data_for_uv_handle(stream as *libc::c_void) @@ -1298,65 +1298,65 @@ pub mod test { } else if (nread == -1) { // err .. possibly EOF - log(debug, ~"read: eof!"); + debug!("read: eof!"); } else { // nread == 0 .. do nothing, just free buf as below - log(debug, ~"read: do nothing!"); + debug!("read: do nothing!"); } // when we're done free_base_of_buf(buf); - log(debug, ~"CLIENT exiting on_read_cb"); + debug!("CLIENT exiting on_read_cb"); } } extern fn on_write_complete_cb(write_req: *uv_write_t, status: libc::c_int) { unsafe { - log(debug, - fmt!("CLIENT beginning on_write_complete_cb status: %d", - status as int)); + debug!( + "CLIENT beginning on_write_complete_cb status: %d", + status as int); let stream = get_stream_handle_from_write_req(write_req); - log(debug, - fmt!("CLIENT on_write_complete_cb: tcp:%d write_handle:%d", - stream as int, write_req as int)); + debug!( + "CLIENT on_write_complete_cb: tcp:%d write_handle:%d", + stream as int, write_req as int); let result = read_start(stream, on_alloc_cb, on_read_cb); - log(debug, - fmt!("CLIENT ending on_write_complete_cb .. status: %d", - result as int)); + debug!( + "CLIENT ending on_write_complete_cb .. status: %d", + result as int); } } extern fn on_connect_cb(connect_req_ptr: *uv_connect_t, status: libc::c_int) { unsafe { - log(debug, fmt!("beginning on_connect_cb .. status: %d", - status as int)); + debug!("beginning on_connect_cb .. status: %d", + status as int); let stream = get_stream_handle_from_connect_req(connect_req_ptr); if (status == 0i32) { - log(debug, ~"on_connect_cb: in status=0 if.."); + debug!("on_connect_cb: in status=0 if.."); let client_data = get_data_for_req( connect_req_ptr as *libc::c_void) as *request_wrapper; let write_handle = (*client_data).write_req; - log(debug, fmt!("on_connect_cb: tcp: %d write_hdl: %d", - stream as int, write_handle as int)); + debug!("on_connect_cb: tcp: %d write_hdl: %d", + stream as int, write_handle as int); let write_result = write(write_handle, stream as *libc::c_void, (*client_data).req_buf, on_write_complete_cb); - log(debug, fmt!("on_connect_cb: write() status: %d", - write_result as int)); + debug!("on_connect_cb: write() status: %d", + write_result as int); } else { let test_loop = get_loop_for_uv_handle( stream as *libc::c_void); let err_msg = get_last_err_info(test_loop); - log(debug, err_msg); + debug!("%?", err_msg); fail_unless!(false); } - log(debug, ~"finishing on_connect_cb"); + debug!("finishing on_connect_cb"); } } @@ -1376,7 +1376,7 @@ pub mod test { // data field in our uv_connect_t struct let req_str_bytes = str::to_bytes(req_str); let req_msg_ptr: *u8 = vec::raw::to_ptr(req_str_bytes); - log(debug, fmt!("req_msg ptr: %u", req_msg_ptr as uint)); + debug!("req_msg ptr: %u", req_msg_ptr as uint); let req_msg = ~[ buf_init(req_msg_ptr, vec::len(req_str_bytes)) ]; @@ -1384,9 +1384,9 @@ pub mod test { // this to C.. let write_handle = write_t(); let write_handle_ptr = ptr::addr_of(&write_handle); - log(debug, fmt!("tcp req: tcp stream: %d write_handle: %d", + debug!("tcp req: tcp stream: %d write_handle: %d", tcp_handle_ptr as int, - write_handle_ptr as int)); + write_handle_ptr as int); let client_data = request_wrapper { write_req: write_handle_ptr, req_buf: ptr::addr_of(&req_msg), @@ -1396,18 +1396,18 @@ pub mod test { let tcp_init_result = tcp_init( test_loop as *libc::c_void, tcp_handle_ptr); if (tcp_init_result == 0i32) { - log(debug, ~"sucessful tcp_init_result"); + debug!("sucessful tcp_init_result"); - log(debug, ~"building addr..."); + debug!("building addr..."); let addr = ip4_addr(ip, port); // FIXME ref #2064 let addr_ptr = ptr::addr_of(&addr); - log(debug, fmt!("after build addr in rust. port: %u", - addr.sin_port as uint)); + debug!("after build addr in rust. port: %u", + addr.sin_port as uint); // this should set up the connection request.. - log(debug, fmt!("b4 call tcp_connect connect cb: %u ", - on_connect_cb as uint)); + debug!("b4 call tcp_connect connect cb: %u ", + on_connect_cb as uint); let tcp_connect_result = tcp_connect( connect_req_ptr, tcp_handle_ptr, addr_ptr, on_connect_cb); @@ -1420,17 +1420,17 @@ pub mod test { set_data_for_uv_handle( tcp_handle_ptr as *libc::c_void, ptr::addr_of(&client_data) as *libc::c_void); - log(debug, ~"before run tcp req loop"); + debug!("before run tcp req loop"); run(test_loop); - log(debug, ~"after run tcp req loop"); + debug!("after run tcp req loop"); } else { - log(debug, ~"tcp_connect() failure"); + debug!("tcp_connect() failure"); fail_unless!(false); } } else { - log(debug, ~"tcp_init() failure"); + debug!("tcp_init() failure"); fail_unless!(false); } loop_delete(test_loop); @@ -1439,15 +1439,15 @@ pub mod test { extern fn server_after_close_cb(handle: *libc::c_void) { unsafe { - log(debug, fmt!("SERVER server stream closed, should exit. h: %?", - handle)); + debug!("SERVER server stream closed, should exit. h: %?", + handle); } } extern fn client_stream_after_close_cb(handle: *libc::c_void) { unsafe { - log(debug, - ~"SERVER: closed client stream, now closing server stream"); + debug!( + "SERVER: closed client stream, now closing server stream"); let client_data = get_data_for_uv_handle( handle) as *tcp_server_data; @@ -1460,7 +1460,7 @@ pub mod test { unsafe { let client_stream_ptr = get_stream_handle_from_write_req(req); - log(debug, ~"SERVER: resp sent... closing client stream"); + debug!("SERVER: resp sent... closing client stream"); close(client_stream_ptr as *libc::c_void, client_stream_after_close_cb) } @@ -1473,15 +1473,15 @@ pub mod test { let nread = nread as int; if (nread > 0) { // we have data - log(debug, fmt!("SERVER read: data! nread: %d", nread)); + debug!("SERVER read: data! nread: %d", nread); // pull out the contents of the write from the client let buf_base = get_base_from_buf(buf); let buf_len = get_len_from_buf(buf) as uint; - log(debug, fmt!("SERVER buf base: %u, len: %u, nread: %d", + debug!("SERVER buf base: %u, len: %u, nread: %d", buf_base as uint, buf_len as uint, - nread)); + nread); let bytes = vec::from_buf(buf_base, nread as uint); let request_str = str::from_bytes(bytes); @@ -1491,8 +1491,8 @@ pub mod test { let server_kill_msg = copy (*client_data).server_kill_msg; let write_req = (*client_data).server_write_req; if str::contains(request_str, server_kill_msg) { - log(debug, ~"SERVER: client req contains kill_msg!"); - log(debug, ~"SERVER: sending response to client"); + debug!("SERVER: client req contains kill_msg!"); + debug!("SERVER: sending response to client"); read_stop(client_stream_ptr); let server_chan = (*client_data).server_chan.clone(); server_chan.send(request_str); @@ -1501,31 +1501,31 @@ pub mod test { client_stream_ptr as *libc::c_void, (*client_data).server_resp_buf, after_server_resp_write); - log(debug, fmt!("SERVER: resp write result: %d", - write_result as int)); + debug!("SERVER: resp write result: %d", + write_result as int); if (write_result != 0i32) { - log(debug, ~"bad result for server resp write()"); - log(debug, get_last_err_info( + debug!("bad result for server resp write()"); + debug!("%s", get_last_err_info( get_loop_for_uv_handle(client_stream_ptr as *libc::c_void))); fail_unless!(false); } } else { - log(debug, ~"SERVER: client req !contain kill_msg!"); + debug!("SERVER: client req !contain kill_msg!"); } } else if (nread == -1) { // err .. possibly EOF - log(debug, ~"read: eof!"); + debug!("read: eof!"); } else { // nread == 0 .. do nothing, just free buf as below - log(debug, ~"read: do nothing!"); + debug!("read: do nothing!"); } // when we're done free_base_of_buf(buf); - log(debug, ~"SERVER exiting on_read_cb"); + debug!("SERVER exiting on_read_cb"); } } @@ -1533,13 +1533,13 @@ pub mod test { *uv_stream_t, status: libc::c_int) { unsafe { - log(debug, ~"client connecting!"); + debug!("client connecting!"); let test_loop = get_loop_for_uv_handle( server_stream_ptr as *libc::c_void); if status != 0i32 { let err_msg = get_last_err_info(test_loop); - log(debug, fmt!("server_connect_cb: non-zero status: %?", - err_msg)); + debug!("server_connect_cb: non-zero status: %?", + err_msg); return; } let server_data = get_data_for_uv_handle( @@ -1551,7 +1551,7 @@ pub mod test { client_stream_ptr as *libc::c_void, server_data as *libc::c_void); if (client_init_result == 0i32) { - log(debug, ~"successfully initialized client stream"); + debug!("successfully initialized client stream"); let accept_result = accept(server_stream_ptr as *libc::c_void, client_stream_ptr as @@ -1563,23 +1563,23 @@ pub mod test { on_alloc_cb, on_server_read_cb); if (read_result == 0i32) { - log(debug, ~"successful server read start"); + debug!("successful server read start"); } else { - log(debug, fmt!("server_connection_cb: bad read:%d", - read_result as int)); + debug!("server_connection_cb: bad read:%d", + read_result as int); fail_unless!(false); } } else { - log(debug, fmt!("server_connection_cb: bad accept: %d", - accept_result as int)); + debug!("server_connection_cb: bad accept: %d", + accept_result as int); fail_unless!(false); } } else { - log(debug, fmt!("server_connection_cb: bad client init: %d", - client_init_result as int)); + debug!("server_connection_cb: bad client init: %d", + client_init_result as int); fail_unless!(false); } } @@ -1599,8 +1599,8 @@ pub mod test { } extern fn async_close_cb(handle: *libc::c_void) { - log(debug, fmt!("SERVER: closing async cb... h: %?", - handle)); + debug!("SERVER: closing async cb... h: %?", + handle); } extern fn continue_async_cb(async_handle: *uv_async_t, @@ -1638,7 +1638,7 @@ pub mod test { let resp_str_bytes = str::to_bytes(server_resp_msg); let resp_msg_ptr: *u8 = vec::raw::to_ptr(resp_str_bytes); - log(debug, fmt!("resp_msg ptr: %u", resp_msg_ptr as uint)); + debug!("resp_msg ptr: %u", resp_msg_ptr as uint); let resp_msg = ~[ buf_init(resp_msg_ptr, vec::len(resp_str_bytes)) ]; @@ -1674,7 +1674,7 @@ pub mod test { let bind_result = tcp_bind(tcp_server_ptr, server_addr_ptr); if (bind_result == 0i32) { - log(debug, ~"successful uv_tcp_bind, listening"); + debug!("successful uv_tcp_bind, listening"); // uv_listen() let listen_result = listen(tcp_server_ptr as @@ -1694,29 +1694,29 @@ pub mod test { async_send(continue_async_handle_ptr); // uv_run() run(test_loop); - log(debug, ~"server uv::run() has returned"); + debug!("server uv::run() has returned"); } else { - log(debug, fmt!("uv_async_init failure: %d", - async_result as int)); + debug!("uv_async_init failure: %d", + async_result as int); fail_unless!(false); } } else { - log(debug, fmt!("non-zero result on uv_listen: %d", - listen_result as int)); + debug!("non-zero result on uv_listen: %d", + listen_result as int); fail_unless!(false); } } else { - log(debug, fmt!("non-zero result on uv_tcp_bind: %d", - bind_result as int)); + debug!("non-zero result on uv_tcp_bind: %d", + bind_result as int); fail_unless!(false); } } else { - log(debug, fmt!("non-zero result on uv_tcp_init: %d", - tcp_init_result as int)); + debug!("non-zero result on uv_tcp_init: %d", + tcp_init_result as int); fail_unless!(false); } loop_delete(test_loop); @@ -1751,9 +1751,9 @@ pub mod test { }; // block until the server up is.. possibly a race? - log(debug, ~"before receiving on server continue_port"); + debug!("before receiving on server continue_port"); continue_port.recv(); - log(debug, ~"received on continue port, set up tcp client"); + debug!("received on continue port, set up tcp client"); let kill_server_msg_copy = copy kill_server_msg; do task::spawn_sched(task::ManualThreads(1u)) { @@ -1808,7 +1808,7 @@ pub mod test { let output = fmt!( "STRUCT_SIZE FAILURE: %s -- actual: %u expected: %u", t_name, rust_size, foreign_size as uint); - log(debug, output); + debug!("%s", output); } fail_unless!(sizes_match); } @@ -1869,7 +1869,7 @@ pub mod test { let rust_handle_size = sys::size_of::<sockaddr_in6>(); let output = fmt!("sockaddr_in6 -- foreign: %u rust: %u", foreign_handle_size as uint, rust_handle_size); - log(debug, output); + debug!(output); // FIXME #1645 .. rust appears to pad structs to the nearest // byte..? // .. can't get the uv::ll::sockaddr_in6 to == 28 :/ @@ -1888,7 +1888,7 @@ pub mod test { let rust_handle_size = sys::size_of::<addr_in>(); let output = fmt!("addr_in -- foreign: %u rust: %u", foreign_handle_size as uint, rust_handle_size); - log(debug, output); + debug!(output); // FIXME #1645 .. see note above about struct padding fail_unless!((4u+foreign_handle_size as uint) == rust_handle_size); diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 68dca608a48..dc220eaed1b 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -15,11 +15,11 @@ use container::{Container, Mutable}; use cast; use cmp::{Eq, Equiv, Ord, TotalOrd, Ordering, Less, Equal, Greater}; +use clone::Clone; use iter::BaseIter; use iter; use kinds::Copy; use libc; -use libc::size_t; use option::{None, Option, Some}; use unstable::intrinsics; use ptr; @@ -76,9 +76,9 @@ pub fn reserve<T>(v: &mut ~[T], n: uint) { let td = sys::get_type_desc::<T>(); if ((**ptr).box_header.ref_count == managed::raw::RC_MANAGED_UNIQUE) { - rustrt::vec_reserve_shared_actual(td, ptr, n as size_t); + rustrt::vec_reserve_shared_actual(td, ptr, n as libc::size_t); } else { - rustrt::vec_reserve_shared(td, ptr, n as size_t); + rustrt::vec_reserve_shared(td, ptr, n as libc::size_t); } } } @@ -118,6 +118,14 @@ pub pure fn len<T>(v: &[const T]) -> uint { as_const_buf(v, |_p, len| len) } +// A botch to tide us over until core and std are fully demuted. +pub pure fn uniq_len<T>(v: &const ~[T]) -> uint { + unsafe { + let v: &~[T] = ::cast::transmute(v); + as_const_buf(*v, |_p, len| len) + } +} + /** * Creates and initializes an immutable vector. * @@ -217,46 +225,46 @@ pub pure fn build_sized_opt<A>(size: Option<uint>, // Accessors /// Returns the first element of a vector -pub pure fn head<T>(v: &r/[T]) -> &r/T { +pub pure fn head<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 pure fn head_opt<T>(v: &r/[T]) -> Option<&r/T> { +pub pure fn head_opt<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 pure fn tail<T>(v: &r/[T]) -> &r/[T] { slice(v, 1, v.len()) } +pub pure fn tail<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 pure fn tailn<T>(v: &r/[T], n: uint) -> &r/[T] { slice(v, n, v.len()) } +pub pure fn tailn<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 pure fn init<T>(v: &r/[T]) -> &r/[T] { slice(v, 0, v.len() - 1) } +pub pure fn init<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 pure fn initn<T>(v: &r/[T], n: uint) -> &r/[T] { +pub pure fn initn<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 pure fn last<T>(v: &r/[T]) -> &r/T { +pub pure fn last<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 pure fn last_opt<T>(v: &r/[T]) -> Option<&r/T> { +pub pure fn last_opt<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 pure fn slice<T>(v: &r/[T], start: uint, end: uint) -> &r/[T] { +pub pure fn slice<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| { @@ -270,10 +278,10 @@ pub pure fn slice<T>(v: &r/[T], start: uint, end: uint) -> &r/[T] { /// Return a slice that points into another slice. #[inline(always)] -pub pure fn mut_slice<T>(v: &r/mut [T], +pub pure fn mut_slice<T>(v: &'r mut [T], start: uint, end: uint) - -> &r/mut [T] { + -> &'r mut [T] { fail_unless!(start <= end); fail_unless!(end <= v.len()); do as_mut_buf(v) |p, _len| { @@ -287,10 +295,10 @@ pub pure fn mut_slice<T>(v: &r/mut [T], /// Return a slice that points into another slice. #[inline(always)] -pub pure fn const_slice<T>(v: &r/[const T], +pub pure fn const_slice<T>(v: &'r [const T], start: uint, end: uint) - -> &r/[const T] { + -> &'r [const T] { fail_unless!(start <= end); fail_unless!(end <= len(v)); do as_const_buf(v) |p, _len| { @@ -1334,7 +1342,7 @@ pub pure fn reversed<T:Copy>(v: &[const T]) -> ~[T] { * ~~~ */ #[inline(always)] -pub pure fn each<T>(v: &r/[T], f: &fn(&r/T) -> bool) { +pub pure fn each<T>(v: &'r [T], f: &fn(&'r T) -> bool) { // ^^^^ // NB---this CANNOT be &[const T]! The reason // is that you are passing it to `f()` using @@ -1358,7 +1366,7 @@ pub pure fn each<T>(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<T>(v: &mut [T], f: &fn(elem: &mut T) -> bool) { +pub fn each_mut<T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) { let mut i = 0; let n = v.len(); while i < n { @@ -1389,7 +1397,7 @@ pub pure fn each_const<T>(v: &[const T], f: &fn(elem: &const T) -> bool) { * Return true to continue, false to break. */ #[inline(always)] -pub pure fn eachi<T>(v: &r/[T], f: &fn(uint, v: &r/T) -> bool) { +pub pure fn eachi<T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) { let mut i = 0; for each(v) |p| { if !f(i, p) { return; } @@ -1403,7 +1411,7 @@ pub pure fn eachi<T>(v: &r/[T], f: &fn(uint, v: &r/T) -> bool) { * Return true to continue, false to break. */ #[inline(always)] -pub pure fn rev_each<T>(v: &r/[T], blk: &fn(v: &r/T) -> bool) { +pub pure fn rev_each<T>(v: &'r [T], blk: &fn(v: &'r T) -> bool) { rev_eachi(v, |_i, v| blk(v)) } @@ -1413,7 +1421,7 @@ pub pure fn rev_each<T>(v: &r/[T], blk: &fn(v: &r/T) -> bool) { * Return true to continue, false to break. */ #[inline(always)] -pub pure fn rev_eachi<T>(v: &r/[T], blk: &fn(i: uint, v: &r/T) -> bool) { +pub pure fn rev_eachi<T>(v: &'r [T], blk: &fn(i: uint, v: &'r T) -> bool) { let mut i = v.len(); while i > 0 { i -= 1; @@ -1555,11 +1563,11 @@ pure fn eq<T:Eq>(a: &[T], b: &[T]) -> bool { } #[cfg(notest)] -impl<T:Eq> Eq for &self/[T] { +impl<T:Eq> Eq for &'self [T] { #[inline(always)] - pure fn eq(&self, other: & &self/[T]) -> bool { eq((*self), (*other)) } + pure fn eq(&self, other: & &'self [T]) -> bool { eq((*self), (*other)) } #[inline(always)] - pure fn ne(&self, other: & &self/[T]) -> bool { !(*self).eq(other) } + pure fn ne(&self, other: & &'self [T]) -> bool { !(*self).eq(other) } } @@ -1604,7 +1612,7 @@ pure fn cmp<T: TotalOrd>(a: &[T], b: &[T]) -> Ordering { #[cfg(notest)] impl<T: TotalOrd> TotalOrd for &'self [T] { #[inline(always)] - pure fn cmp(&self, other: & &self/[T]) -> Ordering { cmp(*self, *other) } + pure fn cmp(&self, other: & &'self [T]) -> Ordering { cmp(*self, *other) } } #[cfg(notest)] @@ -1639,15 +1647,15 @@ pure fn ge<T:Ord>(a: &[T], b: &[T]) -> bool { !lt(a, b) } pure fn gt<T:Ord>(a: &[T], b: &[T]) -> bool { lt(b, a) } #[cfg(notest)] -impl<T:Ord> Ord for &self/[T] { +impl<T:Ord> Ord for &'self [T] { #[inline(always)] - pure fn lt(&self, other: & &self/[T]) -> bool { lt((*self), (*other)) } + pure fn lt(&self, other: & &'self [T]) -> bool { lt((*self), (*other)) } #[inline(always)] - pure fn le(&self, other: & &self/[T]) -> bool { le((*self), (*other)) } + pure fn le(&self, other: & &'self [T]) -> bool { le((*self), (*other)) } #[inline(always)] - pure fn ge(&self, other: & &self/[T]) -> bool { ge((*self), (*other)) } + pure fn ge(&self, other: & &'self [T]) -> bool { ge((*self), (*other)) } #[inline(always)] - pure fn gt(&self, other: & &self/[T]) -> bool { gt((*self), (*other)) } + pure fn gt(&self, other: & &'self [T]) -> bool { gt((*self), (*other)) } } #[cfg(notest)] @@ -1680,22 +1688,22 @@ pub mod traits { use ops::Add; use vec::append; - impl<T:Copy> Add<&self/[const T],~[T]> for ~[T] { + impl<T:Copy> Add<&'self [const T],~[T]> for ~[T] { #[inline(always)] - pure fn add(&self, rhs: & &self/[const T]) -> ~[T] { + pure fn add(&self, rhs: & &'self [const T]) -> ~[T] { append(copy *self, (*rhs)) } } } -impl<T> Container for &self/[const T] { +impl<T> Container for &'self [const T] { /// Returns true if a vector contains no elements #[inline] - pure fn is_empty(&self) -> bool { is_empty(*self) } + pure fn is_empty(&const self) -> bool { is_empty(*self) } /// Returns the length of a vector #[inline] - pure fn len(&self) -> uint { len(*self) } + pure fn len(&const self) -> uint { len(*self) } } pub trait CopyableVector<T> { @@ -1707,20 +1715,27 @@ impl<T: Copy> CopyableVector<T> for &'self [const T] { /// Returns a copy of the elements from [`start`..`end`) from `v`. #[inline] pure fn slice(&self, start: uint, end: uint) -> ~[T] { - slice(*self, start, end).to_vec() + // XXX: Purity workaround for stage0. + unsafe { + let mut result = ~[]; + for uint::range(start, end) |i| { + result.push(copy self[i]); + } + result + } } } pub trait ImmutableVector<T> { - pure fn view(&self, start: uint, end: uint) -> &self/[T]; - pure fn head(&self) -> &self/T; - pure fn head_opt(&self) -> Option<&self/T>; - pure fn tail(&self) -> &self/[T]; - pure fn tailn(&self, n: uint) -> &self/[T]; - pure fn init(&self) -> &self/[T]; - pure fn initn(&self, n: uint) -> &self/[T]; - pure fn last(&self) -> &self/T; - pure fn last_opt(&self) -> Option<&self/T>; + pure fn view(&self, start: uint, end: uint) -> &'self [T]; + pure fn head(&self) -> &'self T; + pure fn head_opt(&self) -> Option<&'self T>; + pure fn tail(&self) -> &'self [T]; + pure fn tailn(&self, n: uint) -> &'self [T]; + pure fn init(&self) -> &'self [T]; + pure fn initn(&self, n: uint) -> &'self [T]; + pure fn last(&self) -> &'self T; + pure fn last_opt(&self) -> Option<&'self T>; pure fn foldr<U: Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U; pure fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U]; pure fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U]; @@ -1731,44 +1746,44 @@ pub trait ImmutableVector<T> { } /// Extension methods for vectors -impl<T> ImmutableVector<T> for &self/[T] { +impl<T> ImmutableVector<T> for &'self [T] { /// Return a slice that points into another slice. #[inline] - pure fn view(&self, start: uint, end: uint) -> &self/[T] { + pure fn view(&self, start: uint, end: uint) -> &'self [T] { slice(*self, start, end) } /// Returns the first element of a vector, failing if the vector is empty. #[inline] - pure fn head(&self) -> &self/T { head(*self) } + pure fn head(&self) -> &'self T { head(*self) } /// Returns the first element of a vector #[inline] - pure fn head_opt(&self) -> Option<&self/T> { head_opt(*self) } + pure fn head_opt(&self) -> Option<&'self T> { head_opt(*self) } /// Returns all but the first element of a vector #[inline] - pure fn tail(&self) -> &self/[T] { tail(*self) } + pure fn tail(&self) -> &'self [T] { tail(*self) } /// Returns all but the first `n' elements of a vector #[inline] - pure fn tailn(&self, n: uint) -> &self/[T] { tailn(*self, n) } + pure fn tailn(&self, n: uint) -> &'self [T] { tailn(*self, n) } /// Returns all but the last elemnt of a vector #[inline] - pure fn init(&self) -> &self/[T] { init(*self) } + pure fn init(&self) -> &'self [T] { init(*self) } /// Returns all but the last `n' elemnts of a vector #[inline] - pure fn initn(&self, n: uint) -> &self/[T] { initn(*self, n) } + pure fn initn(&self, n: uint) -> &'self [T] { initn(*self, n) } /// Returns the last element of a `v`, failing if the vector is empty. #[inline] - pure fn last(&self) -> &self/T { last(*self) } + pure fn last(&self) -> &'self T { last(*self) } /// Returns the last element of a `v`, failing if the vector is empty. #[inline] - pure fn last_opt(&self) -> Option<&self/T> { last_opt(*self) } + pure fn last_opt(&self) -> Option<&'self T> { last_opt(*self) } /// Reduce a vector from right to left #[inline] @@ -1834,7 +1849,7 @@ pub trait ImmutableEqVector<T:Eq> { pure fn rposition_elem(&self, t: &T) -> Option<uint>; } -impl<T:Eq> ImmutableEqVector<T> for &self/[T] { +impl<T:Eq> ImmutableEqVector<T> for &'self [T] { /** * Find the first index matching some predicate * @@ -1879,7 +1894,7 @@ pub trait ImmutableCopyableVector<T> { } /// Extension methods for vectors -impl<T:Copy> ImmutableCopyableVector<T> for &self/[T] { +impl<T:Copy> ImmutableCopyableVector<T> for &'self [T] { /** * Construct a new vector from the elements of a vector for which some * predicate holds. @@ -2071,7 +2086,6 @@ pub mod raw { use kinds::Copy; use managed; use option::{None, Some}; - use option; use unstable::intrinsics; use ptr::addr_of; use ptr; @@ -2140,7 +2154,7 @@ pub mod raw { len: uint, f: &fn(v: &[T]) -> U) -> U { let pair = (p, len * sys::nonzero_size_of::<T>()); - let v : *(&blk/[T]) = + let v : *(&'blk [T]) = ::cast::reinterpret_cast(&addr_of(&pair)); f(*v) } @@ -2154,7 +2168,7 @@ pub mod raw { len: uint, f: &fn(v: &mut [T]) -> U) -> U { let pair = (p, len * sys::nonzero_size_of::<T>()); - let v : *(&blk/mut [T]) = + let v : *(&'blk mut [T]) = ::cast::reinterpret_cast(&addr_of(&pair)); f(*v) } @@ -2282,11 +2296,9 @@ pub mod bytes { // ___________________________________________________________________________ // ITERATION TRAIT METHODS -impl<A> iter::BaseIter<A> for &self/[A] { +impl<A> iter::BaseIter<A> for &'self [A] { #[inline(always)] - pub pure fn each(&self, blk: &fn(v: &'self A) -> bool) { - each(*self, blk) - } + pure fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) } #[inline(always)] pure fn size_hint(&self) -> Option<uint> { Some(self.len()) } } @@ -2307,7 +2319,30 @@ impl<A> iter::BaseIter<A> for @[A] { pure fn size_hint(&self) -> Option<uint> { Some(self.len()) } } -impl<A> iter::ExtendedIter<A> for &self/[A] { +impl<A> iter::MutableIter<A> for &'self mut [A] { + #[inline(always)] + fn each_mut(&mut self, blk: &fn(v: &'self mut A) -> bool) { + each_mut(*self, blk) + } +} + +// FIXME(#4148): This should be redundant +impl<A> iter::MutableIter<A> for ~[A] { + #[inline(always)] + fn each_mut(&mut self, blk: &fn(v: &'self mut A) -> bool) { + each_mut(*self, blk) + } +} + +// FIXME(#4148): This should be redundant +impl<A> iter::MutableIter<A> for @mut [A] { + #[inline(always)] + fn each_mut(&mut self, blk: &fn(v: &mut A) -> bool) { + each_mut(*self, blk) + } +} + +impl<A> iter::ExtendedIter<A> for &'self [A] { pub pure fn eachi(&self, blk: &fn(uint, v: &A) -> bool) { iter::eachi(self, blk) } @@ -2384,7 +2419,7 @@ impl<A> iter::ExtendedIter<A> for @[A] { } } -impl<A:Eq> iter::EqIter<A> for &self/[A] { +impl<A:Eq> iter::EqIter<A> for &'self [A] { pub pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) } pub pure fn count(&self, x: &A) -> uint { iter::count(self, x) } } @@ -2401,7 +2436,7 @@ impl<A:Eq> iter::EqIter<A> for @[A] { pub pure fn count(&self, x: &A) -> uint { iter::count(self, x) } } -impl<A:Copy> iter::CopyableIter<A> for &self/[A] { +impl<A:Copy> iter::CopyableIter<A> for &'self [A] { pure fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] { iter::filter_to_vec(self, pred) } @@ -2433,7 +2468,7 @@ impl<A:Copy> iter::CopyableIter<A> for @[A] { } } -impl<A:Copy + Ord> iter::CopyableOrderedIter<A> for &self/[A] { +impl<A:Copy + Ord> iter::CopyableOrderedIter<A> for &'self [A] { pure fn min(&self) -> A { iter::min(self) } pure fn max(&self) -> A { iter::max(self) } } @@ -2450,7 +2485,7 @@ impl<A:Copy + Ord> iter::CopyableOrderedIter<A> for @[A] { pure fn max(&self) -> A { iter::max(self) } } -impl<A:Copy> iter::CopyableNonstrictIter<A> for &self/[A] { +impl<A:Copy> iter::CopyableNonstrictIter<A> for &'self [A] { pure fn each_val(&const self, f: &fn(A) -> bool) { let mut i = 0; while i < self.len() { @@ -2464,7 +2499,7 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for &self/[A] { impl<A:Copy> iter::CopyableNonstrictIter<A> for ~[A] { pure fn each_val(&const self, f: &fn(A) -> bool) { let mut i = 0; - while i < self.len() { + while i < uniq_len(self) { if !f(copy self[i]) { break; } i += 1; } @@ -2482,6 +2517,18 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for @[A] { } } +impl<A:Clone> Clone for ~[A] { + #[inline] + fn clone(&self) -> ~[A] { + let mut dolly = ~[]; + vec::reserve(&mut dolly, self.len()); + for self.each |item| { + dolly.push(item.clone()); + } + return dolly; + } +} + // ___________________________________________________________________________ #[cfg(test)] diff --git a/src/libfuzzer/fuzzer.rc b/src/libfuzzer/fuzzer.rc index 90ada832327..ce554f34731 100644 --- a/src/libfuzzer/fuzzer.rc +++ b/src/libfuzzer/fuzzer.rc @@ -202,10 +202,13 @@ pub fn replace_expr_in_crate(crate: ast::crate, i: uint, newexpr: ast::expr, tm: test_mode) -> ast::crate { let j: @mut uint = @mut 0u; - fn fold_expr_rep(j_: @mut uint, i_: uint, newexpr_: ast::expr_, - original: &ast::expr_, fld: fold::ast_fold, - tm_: test_mode) -> - ast::expr_ { + fn fold_expr_rep(j_: @mut uint, + i_: uint, + newexpr_: ast::expr_, + original: &ast::expr_, + fld: @fold::ast_fold, + tm_: test_mode) + -> ast::expr_ { *j_ += 1u; if i_ + 1u == *j_ && safe_to_replace_expr(original, tm_) { newexpr_ @@ -229,10 +232,13 @@ pub fn replace_expr_in_crate(crate: ast::crate, i: uint, pub fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::Ty, tm: test_mode) -> ast::crate { let j: @mut uint = @mut 0u; - fn fold_ty_rep(j_: @mut uint, i_: uint, newty_: ast::ty_, - original: &ast::ty_, fld: fold::ast_fold, - tm_: test_mode) -> - ast::ty_ { + fn fold_ty_rep(j_: @mut uint, + i_: uint, + newty_: ast::ty_, + original: &ast::ty_, + fld: @fold::ast_fold, + tm_: test_mode) + -> ast::ty_ { *j_ += 1u; if i_ + 1u == *j_ && safe_to_replace_ty(original, tm_) { newty_ @@ -252,7 +258,7 @@ pub fn under(n: uint, it: &fn(uint)) { while i < n { it(i); i += 1u; } } -pub fn as_str(f: @fn(+x: io::Writer)) -> ~str { +pub fn as_str(f: @fn(+x: @io::Writer)) -> ~str { io::with_str_writer(f) } @@ -289,10 +295,10 @@ pub fn check_variants_T<T: Copy>( if L < 100 { do under(uint::min(L, 20)) |i| { - log(error, ~"Replacing... #" + uint::to_str(i)); + error!("Replacing... #%?", uint::to_str(i)); let fname = str::from_slice(filename.to_str()); do under(uint::min(L, 30)) |j| { - log(error, ~"With... " + stringifier(@things[j], intr)); + error!("With... %?", stringifier(@things[j], intr)); let crate2 = @replacer(crate, i, things[j], cx.mode); // It would be best to test the *crate* for stability, but // testing the string for stability is easier and ok for now. @@ -304,7 +310,8 @@ pub fn check_variants_T<T: Copy>( diagnostic::mk_span_handler(handler, codemap), crate2, fname, - rdr, a, + rdr, + a, pprust::no_ann(), false)) }; @@ -363,8 +370,8 @@ pub fn check_whole_compiler(code: ~str, suggested_filename_prefix: &Path, removeDirIfExists(&suggested_filename_prefix.with_filetype("dSYM")); } failed(s) => { - log(error, ~"check_whole_compiler failure: " + s); - log(error, ~"Saved as: " + filename.to_str()); + error!("check_whole_compiler failure: %?", s); + error!("Saved as: %?", filename.to_str()); } } } @@ -387,7 +394,7 @@ pub fn check_running(exe_filename: &Path) -> happiness { ~[exe_filename.to_str()]); let comb = p.out + ~"\n" + p.err; if str::len(comb) > 1u { - log(error, ~"comb comb comb: " + comb); + error!("comb comb comb: %?", comb); } if contains(comb, ~"Assertion failed:") { @@ -433,21 +440,21 @@ pub fn check_compiling(filename: &Path) -> happiness { if contains(p.err, ~"error:") { cleanly_rejected(~"rejected with span_error") } else { - log(error, ~"Stderr: " + p.err); + error!("Stderr: %?", p.err); failed(~"Unfamiliar error message") } } else if contains(p.out, ~"Assertion") && contains(p.out, ~"failed") { - log(error, ~"Stdout: " + p.out); + error!("Stdout: %?", p.out); failed(~"Looks like an llvm assertion failure") } else if contains(p.out, ~"internal compiler error unimplemented") { known_bug(~"Something unimplemented") } else if contains(p.out, ~"internal compiler error") { - log(error, ~"Stdout: " + p.out); + error!("Stdout: %?", p.out); failed(~"internal compiler error") } else { - log(error, p.status); - log(error, ~"!Stdout: " + p.out); + error!("%?", p.status); + error!("!Stdout: %?", p.out); failed(~"What happened?") } } @@ -609,7 +616,7 @@ pub fn check_variants(files: &[Path], cx: Context) { let file_str = file.to_str(); - log(error, ~"check_variants: " + file_str); + error!("check_variants: %?", file_str); let sess = parse::new_parse_sess(option::None); let crate = parse::parse_crate_from_source_str( diff --git a/src/librust/rust.rc b/src/librust/rust.rc index 082861e0ae0..3ca4ef5efbd 100644 --- a/src/librust/rust.rc +++ b/src/librust/rust.rc @@ -9,8 +9,8 @@ // except according to those terms. // rust - central access to other rust tools -// XXX: Make commands run and test emit proper file endings on winds -// XXX: Make run only accept source that emits an executable +// FIXME #2238 Make commands run and test emit proper file endings on winds +// FIXME #2238 Make run only accept source that emits an executable #[deny(deprecated_self)]; @@ -38,23 +38,23 @@ impl ValidUsage { } enum Action { - Exec(&self/str), - Call(&self/fn(args: &[~str]) -> ValidUsage) + Exec(&'self str), + Call(&'self fn(args: &[~str]) -> ValidUsage) } enum UsageSource { - UsgExec(&self/str), - UsgStr(&self/str) + UsgExec(&'self str), + UsgStr(&'self str) } struct Command { - cmd: &self/str, + cmd: &'self str, action: Action/&self, - usage_line: &self/str, + usage_line: &'self str, usage_full: UsageSource/&self } -const commands: &static/[Command/&static] = &[ +const commands: &'static [Command/&static] = &[ Command{ cmd: "build", action: Exec("rustc"), diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 1437a3af7dd..84836568029 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -486,7 +486,7 @@ pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path, // This calculates CMH as defined above fn crate_meta_extras_hash(symbol_hasher: &hash::State, - -cmh_items: ~[@ast::meta_item], + +cmh_items: ~[@ast::meta_item], dep_hashes: ~[~str]) -> @str { fn len_and_str(s: &str) -> ~str { fmt!("%u_%s", s.len(), s) @@ -535,7 +535,7 @@ pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path, name, default)); } - fn crate_meta_name(sess: Session, output: &Path, -opt_name: Option<@str>) + fn crate_meta_name(sess: Session, output: &Path, +opt_name: Option<@str>) -> @str { return match opt_name { Some(v) => v, @@ -758,7 +758,7 @@ pub fn link_binary(sess: Session, /*bad*/copy *out_filename }; - log(debug, ~"output: " + output.to_str()); + debug!("output: %s", output.to_str()); // The default library location, we need this to find the runtime. // The location of crates will be determined as needed. diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 2b61c948045..c4db61842a5 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -132,15 +132,15 @@ pub fn build_configuration(sess: Session, +argv0: ~str, input: input) -> } // Convert strings provided as --cfg [cfgspec] into a crate_cfg -pub fn parse_cfgspecs(cfgspecs: ~[~str]) -> ast::crate_cfg { - // FIXME (#2399): It would be nice to use the parser to parse all - // varieties of meta_item here. At the moment we just support the - // meta_word variant. - let mut words = ~[]; +fn parse_cfgspecs(cfgspecs: ~[~str], + demitter: diagnostic::Emitter) -> ast::crate_cfg { + let mut meta = ~[]; for cfgspecs.each |s| { - words.push(attr::mk_word_item(@/*bad*/copy *s)); + let sess = parse::new_parse_sess(Some(demitter)); + let m = parse::parse_meta_from_source_str(~"cfgspec", @/*bad*/ copy *s, ~[], sess); + meta.push(m) } - return words; + return meta; } pub enum input { @@ -440,7 +440,7 @@ pub fn pretty_print_input(sess: Session, +cfg: ast::crate_cfg, input: input, } } -pub fn get_os(triple: ~str) -> Option<session::os> { +pub fn get_os(triple: &str) -> Option<session::os> { if str::contains(triple, ~"win32") || str::contains(triple, ~"mingw32") { Some(session::os_win32) @@ -455,7 +455,7 @@ pub fn get_os(triple: ~str) -> Option<session::os> { } else { None } } -pub fn get_arch(triple: ~str) -> Option<session::arch> { +pub fn get_arch(triple: &str) -> Option<session::arch> { if str::contains(triple, ~"i386") || str::contains(triple, ~"i486") || str::contains(triple, ~"i586") || @@ -639,7 +639,7 @@ pub fn build_session_options(+binary: ~str, let addl_lib_search_paths = getopts::opt_strs(matches, ~"L") .map(|s| Path(*s)); - let cfg = parse_cfgspecs(getopts::opt_strs(matches, ~"cfg")); + let cfg = parse_cfgspecs(getopts::opt_strs(matches, ~"cfg"), demitter); let test = opt_present(matches, ~"test"); let android_cross_path = getopts::opt_maybe_str( matches, ~"android-cross-path"); @@ -681,7 +681,7 @@ pub fn build_session(sopts: @session::options, pub fn build_session_(sopts: @session::options, cm: @codemap::CodeMap, demitter: diagnostic::Emitter, - span_diagnostic_handler: diagnostic::span_handler) + span_diagnostic_handler: @diagnostic::span_handler) -> Session { let target_cfg = build_target_config(sopts, demitter); let p_s = parse::new_parse_sess_special_handler(span_diagnostic_handler, @@ -870,7 +870,7 @@ pub fn early_error(emitter: diagnostic::Emitter, msg: ~str) -> ! { fail!(); } -pub fn list_metadata(sess: Session, path: &Path, out: io::Writer) { +pub fn list_metadata(sess: Session, path: &Path, out: @io::Writer) { metadata::loader::list_file_metadata( sess.parse_sess.interner, session::sess_os_to_meta_os(sess.targ_cfg.os), path, out); diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index d2d0ceff633..75400c5e324 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -154,8 +154,8 @@ pub struct Session_ { codemap: @codemap::CodeMap, // For a library crate, this is always none main_fn: @mut Option<(node_id, codemap::span)>, - span_diagnostic: diagnostic::span_handler, - filesearch: filesearch::FileSearch, + span_diagnostic: @diagnostic::span_handler, + filesearch: @filesearch::FileSearch, building_library: @mut bool, working_dir: Path, lint_settings: lint::LintSettings @@ -163,50 +163,50 @@ pub struct Session_ { pub type Session = @Session_; -pub impl Session { - fn span_fatal(&self, sp: span, msg: ~str) -> ! { +pub impl Session_ { + fn span_fatal(@self, sp: span, msg: ~str) -> ! { self.span_diagnostic.span_fatal(sp, msg) } - fn fatal(&self, msg: ~str) -> ! { + fn fatal(@self, msg: ~str) -> ! { self.span_diagnostic.handler().fatal(msg) } - fn span_err(&self, sp: span, msg: ~str) { + fn span_err(@self, sp: span, msg: ~str) { self.span_diagnostic.span_err(sp, msg) } - fn err(&self, msg: ~str) { + fn err(@self, msg: ~str) { self.span_diagnostic.handler().err(msg) } - fn has_errors(&self) -> bool { + fn has_errors(@self) -> bool { self.span_diagnostic.handler().has_errors() } - fn abort_if_errors(&self) { + fn abort_if_errors(@self) { self.span_diagnostic.handler().abort_if_errors() } - fn span_warn(&self, sp: span, msg: ~str) { + fn span_warn(@self, sp: span, msg: ~str) { self.span_diagnostic.span_warn(sp, msg) } - fn warn(&self, msg: ~str) { + fn warn(@self, msg: ~str) { self.span_diagnostic.handler().warn(msg) } - fn span_note(&self, sp: span, msg: ~str) { + fn span_note(@self, sp: span, msg: ~str) { self.span_diagnostic.span_note(sp, msg) } - fn note(&self, msg: ~str) { + fn note(@self, msg: ~str) { self.span_diagnostic.handler().note(msg) } - fn span_bug(&self, sp: span, msg: ~str) -> ! { + fn span_bug(@self, sp: span, msg: ~str) -> ! { self.span_diagnostic.span_bug(sp, msg) } - fn bug(&self, msg: ~str) -> ! { + fn bug(@self, msg: ~str) -> ! { self.span_diagnostic.handler().bug(msg) } - fn span_unimpl(&self, sp: span, msg: ~str) -> ! { + fn span_unimpl(@self, sp: span, msg: ~str) -> ! { self.span_diagnostic.span_unimpl(sp, msg) } - fn unimpl(&self, msg: ~str) -> ! { + fn unimpl(@self, msg: ~str) -> ! { self.span_diagnostic.handler().unimpl(msg) } - fn span_lint_level(&self, level: lint::level, sp: span, +msg: ~str) { + fn span_lint_level(@self, level: lint::level, sp: span, +msg: ~str) { match level { lint::allow => { }, lint::warn => self.span_warn(sp, msg), @@ -215,7 +215,7 @@ pub impl Session { } } } - fn span_lint(&self, lint_mode: lint::lint, + fn span_lint(@self, lint_mode: lint::lint, expr_id: ast::node_id, item_id: ast::node_id, span: span, @@ -224,55 +224,55 @@ pub impl Session { self.lint_settings, lint_mode, expr_id, item_id); self.span_lint_level(level, span, msg); } - fn next_node_id(&self) -> ast::node_id { + fn next_node_id(@self) -> ast::node_id { return syntax::parse::next_node_id(self.parse_sess); } - fn diagnostic(&self) -> diagnostic::span_handler { + fn diagnostic(@self) -> @diagnostic::span_handler { self.span_diagnostic } - fn debugging_opt(&self, opt: uint) -> bool { + fn debugging_opt(@self, opt: uint) -> bool { (self.opts.debugging_opts & opt) != 0u } // This exists to help with refactoring to eliminate impossible // cases later on - fn impossible_case(&self, sp: span, msg: &str) -> ! { + fn impossible_case(@self, sp: span, msg: &str) -> ! { self.span_bug(sp, fmt!("Impossible case reached: %s", msg)); } - fn verbose(&self) -> bool { self.debugging_opt(verbose) } - fn time_passes(&self) -> bool { self.debugging_opt(time_passes) } - fn count_llvm_insns(&self) -> bool { + fn verbose(@self) -> bool { self.debugging_opt(verbose) } + fn time_passes(@self) -> bool { self.debugging_opt(time_passes) } + fn count_llvm_insns(@self) -> bool { self.debugging_opt(count_llvm_insns) } - fn count_type_sizes(&self) -> bool { + fn count_type_sizes(@self) -> bool { self.debugging_opt(count_type_sizes) } - fn time_llvm_passes(&self) -> bool { + fn time_llvm_passes(@self) -> bool { self.debugging_opt(time_llvm_passes) } - fn trans_stats(&self) -> bool { self.debugging_opt(trans_stats) } - fn meta_stats(&self) -> bool { self.debugging_opt(meta_stats) } - fn no_asm_comments(&self) -> bool { self.debugging_opt(no_asm_comments) } - fn no_verify(&self) -> bool { self.debugging_opt(no_verify) } - fn trace(&self) -> bool { self.debugging_opt(trace) } - fn coherence(&self) -> bool { self.debugging_opt(coherence) } - fn borrowck_stats(&self) -> bool { self.debugging_opt(borrowck_stats) } - fn borrowck_note_pure(&self) -> bool { + fn trans_stats(@self) -> bool { self.debugging_opt(trans_stats) } + fn meta_stats(@self) -> bool { self.debugging_opt(meta_stats) } + fn no_asm_comments(@self) -> bool { self.debugging_opt(no_asm_comments) } + fn no_verify(@self) -> bool { self.debugging_opt(no_verify) } + fn trace(@self) -> bool { self.debugging_opt(trace) } + fn coherence(@self) -> bool { self.debugging_opt(coherence) } + fn borrowck_stats(@self) -> bool { self.debugging_opt(borrowck_stats) } + fn borrowck_note_pure(@self) -> bool { self.debugging_opt(borrowck_note_pure) } - fn borrowck_note_loan(&self) -> bool { + fn borrowck_note_loan(@self) -> bool { self.debugging_opt(borrowck_note_loan) } - fn no_monomorphic_collapse(&self) -> bool { + fn no_monomorphic_collapse(@self) -> bool { self.debugging_opt(no_monomorphic_collapse) } - fn str_of(&self, id: ast::ident) -> @~str { + fn str_of(@self, id: ast::ident) -> @~str { self.parse_sess.interner.get(id) } - fn ident_of(&self, +st: ~str) -> ast::ident { + fn ident_of(@self, +st: ~str) -> ast::ident { self.parse_sess.interner.intern(@st) } - fn intr(&self) -> @syntax::parse::token::ident_interner { + fn intr(@self) -> @syntax::parse::token::ident_interner { self.parse_sess.interner } } diff --git a/src/librustc/front/config.rs b/src/librustc/front/config.rs index cdf63c49de3..bb0080ba535 100644 --- a/src/librustc/front/config.rs +++ b/src/librustc/front/config.rs @@ -63,7 +63,7 @@ fn filter_view_item(cx: @Context, &&view_item: @ast::view_item } } -fn fold_mod(cx: @Context, m: &ast::_mod, fld: fold::ast_fold) -> ast::_mod { +fn fold_mod(cx: @Context, m: &ast::_mod, fld: @fold::ast_fold) -> ast::_mod { let filtered_items = m.items.filter_mapped(|a| filter_item(cx, *a)); let filtered_view_items = @@ -84,7 +84,7 @@ fn filter_foreign_item(cx: @Context, &&item: @ast::foreign_item) -> fn fold_foreign_mod( cx: @Context, nm: &ast::foreign_mod, - fld: fold::ast_fold + fld: @fold::ast_fold ) -> ast::foreign_mod { let filtered_items = nm.items.filter_mapped(|a| filter_foreign_item(cx, *a)); @@ -99,7 +99,7 @@ fn fold_foreign_mod( } fn fold_item_underscore(cx: @Context, item: &ast::item_, - fld: fold::ast_fold) -> ast::item_ { + fld: @fold::ast_fold) -> ast::item_ { let item = match *item { ast::item_impl(ref a, b, c, ref methods) => { let methods = methods.filtered(|m| method_in_cfg(cx, *m) ); @@ -135,7 +135,7 @@ fn filter_stmt(cx: @Context, &&stmt: @ast::stmt) -> fn fold_block( cx: @Context, b: &ast::blk_, - fld: fold::ast_fold + fld: @fold::ast_fold ) -> ast::blk_ { let filtered_stmts = b.stmts.filter_mapped(|a| filter_stmt(cx, *a)); diff --git a/src/librustc/front/core_inject.rs b/src/librustc/front/core_inject.rs index b53303c5983..0766dcd2450 100644 --- a/src/librustc/front/core_inject.rs +++ b/src/librustc/front/core_inject.rs @@ -19,7 +19,7 @@ use syntax::codemap; use syntax::codemap::dummy_sp; use syntax::fold; -const CORE_VERSION: &static/str = "0.6"; +const CORE_VERSION: &'static str = "0.6"; pub fn maybe_inject_libcore_ref(sess: Session, crate: @ast::crate) -> @ast::crate { diff --git a/src/librustc/front/intrinsic.rs b/src/librustc/front/intrinsic.rs index e7ffc6c55cb..6cfcac3e85a 100644 --- a/src/librustc/front/intrinsic.rs +++ b/src/librustc/front/intrinsic.rs @@ -128,7 +128,7 @@ pub mod intrinsic { #[abi = "rust-intrinsic"] pub extern { pub fn get_tydesc<T>() -> *(); - pub fn visit_tydesc(++td: *TyDesc, &&tv: TyVisitor); + pub fn visit_tydesc(++td: *TyDesc, &&tv: @TyVisitor); } } } diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index d13993bf569..434d992f501 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -39,7 +39,7 @@ struct TestCtxt { sess: session::Session, crate: @ast::crate, path: ~[ast::ident], - ext_cx: ext_ctxt, + ext_cx: @ext_ctxt, testfns: ~[Test] } @@ -102,7 +102,7 @@ fn strip_test_functions(crate: @ast::crate) -> @ast::crate { fn fold_mod(cx: @mut TestCtxt, m: &ast::_mod, - fld: fold::ast_fold) + fld: @fold::ast_fold) -> ast::_mod { // Remove any #[main] from the AST so it doesn't clash with // the one we're going to add. Only if compiling an executable. @@ -125,7 +125,7 @@ fn fold_mod(cx: @mut TestCtxt, fn fold_crate(cx: @mut TestCtxt, c: &ast::crate_, - fld: fold::ast_fold) + fld: @fold::ast_fold) -> ast::crate_ { let folded = fold::noop_fold_crate(c, fld); @@ -138,11 +138,11 @@ fn fold_crate(cx: @mut TestCtxt, } -fn fold_item(cx: @mut TestCtxt, &&i: @ast::item, fld: fold::ast_fold) +fn fold_item(cx: @mut TestCtxt, &&i: @ast::item, fld: @fold::ast_fold) -> Option<@ast::item> { cx.path.push(i.ident); debug!("current path: %s", - ast_util::path_name_i(cx.path, cx.sess.parse_sess.interner)); + ast_util::path_name_i(copy cx.path, cx.sess.parse_sess.interner)); if is_test_fn(i) || is_bench_fn(i) { match i.node { @@ -162,7 +162,7 @@ fn fold_item(cx: @mut TestCtxt, &&i: @ast::item, fld: fold::ast_fold) should_fail: should_fail(i) }; cx.testfns.push(test); - debug!("have %u test/bench functions", cx.testfns.len()); + // debug!("have %u test/bench functions", cx.testfns.len()); } } } @@ -257,7 +257,7 @@ mod __test { std::test::test_main_static(::os::args(), tests) } - const tests : &static/[std::test::TestDescAndFn] = &[ + const tests : &'static [std::test::TestDescAndFn] = &[ ... the list of tests in the crate ... ]; } @@ -352,7 +352,7 @@ fn path_node_global(+ids: ~[ast::ident]) -> @ast::path { types: ~[] } } - +#[cfg(stage0)] fn mk_tests(cx: &TestCtxt) -> @ast::item { let ext_cx = cx.ext_cx; @@ -367,6 +367,22 @@ fn mk_tests(cx: &TestCtxt) -> @ast::item { )).get() } +#[cfg(stage1)] +#[cfg(stage2)] +fn mk_tests(cx: &TestCtxt) -> @ast::item { + + let ext_cx = cx.ext_cx; + + // The vector of test_descs for this crate + let test_descs = mk_test_descs(cx); + + (quote_item!( + pub const tests : &'static [self::std::test::TestDescAndFn] = + $test_descs + ; + )).get() +} + fn is_std(cx: &TestCtxt) -> bool { let is_std = { let items = attr::find_linkage_metas(cx.crate.node.attrs); diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index b0cc18a30a4..23eb6743b9f 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -1443,7 +1443,7 @@ pub mod llvm { /** Prepares inline assembly. */ pub unsafe fn LLVMInlineAsm(Ty: TypeRef, AsmString: *c_char, Constraints: *c_char, SideEffects: Bool, - AlignStack: Bool, Dialect: AsmDialect) + AlignStack: Bool, Dialect: c_uint) -> ValueRef; } } diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 890a58243a1..92de7f3f5e6 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -30,10 +30,10 @@ use std::oldmap::HashMap; // Traverses an AST, reading all the information about use'd crates and extern // libraries necessary for later resolving, typechecking, linking, etc. -pub fn read_crates(diag: span_handler, +pub fn read_crates(diag: @span_handler, crate: ast::crate, cstore: @mut cstore::CStore, - filesearch: FileSearch, + filesearch: @FileSearch, os: loader::os, statik: bool, intr: @ident_interner) { @@ -75,10 +75,12 @@ fn dump_crates(crate_cache: @mut ~[cache_entry]) { } fn warn_if_multiple_versions(e: @mut Env, - diag: span_handler, + diag: @span_handler, crate_cache: @mut ~[cache_entry]) { use core::either::*; + let crate_cache = &mut *crate_cache; + if crate_cache.len() != 0u { let name = loader::crate_name_from_metas( *crate_cache[crate_cache.len() - 1].metas @@ -115,8 +117,8 @@ fn warn_if_multiple_versions(e: @mut Env, } struct Env { - diag: span_handler, - filesearch: FileSearch, + diag: @span_handler, + filesearch: @FileSearch, cstore: @mut cstore::CStore, os: loader::os, statik: bool, @@ -222,7 +224,7 @@ fn metas_with_ident(ident: @~str, +metas: ~[@ast::meta_item]) metas_with(ident, @~"name", metas) } -fn existing_match(e: @mut Env, metas: ~[@ast::meta_item], hash: @~str) +fn existing_match(e: @mut Env, metas: &[@ast::meta_item], hash: @~str) -> Option<int> { for e.crate_cache.each |c| { if loader::metadata_matches(*c.metas, metas) diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index 0909a443736..ee52b48bc32 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -96,6 +96,7 @@ pub fn iter_crate_data(cstore: @mut CStore, } pub fn add_used_crate_file(cstore: @mut CStore, lib: &Path) { + let cstore = &mut *cstore; if !vec::contains(cstore.used_crate_files, lib) { cstore.used_crate_files.push(copy *lib); } @@ -108,6 +109,7 @@ pub fn get_used_crate_files(cstore: @mut CStore) -> ~[Path] { pub fn add_used_library(cstore: @mut CStore, lib: @~str) -> bool { fail_unless!(*lib != ~""); + let cstore = &mut *cstore; if cstore.used_libraries.contains(&*lib) { return false; } cstore.used_libraries.push(/*bad*/ copy *lib); true diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 2643012d30a..1864e1c06ae 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 fn(ast::crate_num) -> cmd; pub fn maybe_find_item(item_id: int, items: ebml::Doc) -> Option<ebml::Doc> { fn eq_item(bytes: &[u8], item_id: int) -> bool { @@ -544,7 +544,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 fn( cdata: @cstore::crate_metadata, tcx: ty::ctxt, path: ast_map::path, @@ -560,7 +560,7 @@ pub fn maybe_get_item_ast(intr: @ident_interner, cdata: cmd, tcx: ty::ctxt, let item_path = item_path(intr, item_doc); vec::from_slice(item_path.init()) }; - match decode_inlined_item(cdata, tcx, path, item_doc) { + match decode_inlined_item(cdata, tcx, copy path, item_doc) { Some(ref ii) => csearch::found((/*bad*/copy *ii)), None => { match item_parent_item(item_doc) { @@ -1017,14 +1017,15 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::attribute] { } fn list_meta_items(intr: @ident_interner, - meta_items: ebml::Doc, out: io::Writer) { + meta_items: ebml::Doc, + out: @io::Writer) { for get_meta_items(meta_items).each |mi| { out.write_str(fmt!("%s\n", pprust::meta_item_to_str(*mi, intr))); } } fn list_crate_attributes(intr: @ident_interner, md: ebml::Doc, hash: &str, - out: io::Writer) { + out: @io::Writer) { out.write_str(fmt!("=Crate Attributes (%s)=\n", hash)); for get_attributes(md).each |attr| { @@ -1063,7 +1064,7 @@ pub fn get_crate_deps(intr: @ident_interner, data: @~[u8]) -> ~[crate_dep] { return deps; } -fn list_crate_deps(intr: @ident_interner, data: @~[u8], out: io::Writer) { +fn list_crate_deps(intr: @ident_interner, data: @~[u8], out: @io::Writer) { out.write_str(~"=External Dependencies=\n"); for get_crate_deps(intr, data).each |dep| { @@ -1106,7 +1107,7 @@ fn iter_crate_items(intr: @ident_interner, cdata: cmd, } pub fn list_crate_metadata(intr: @ident_interner, bytes: @~[u8], - out: io::Writer) { + out: @io::Writer) { let hash = get_crate_hash(bytes); let md = reader::Doc(bytes); list_crate_attributes(intr, md, *hash, out); diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index fc42ac2ffed..efbde04d68e 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -57,7 +57,7 @@ pub type encode_inlined_item = @fn(ecx: @EncodeContext, ii: ast::inlined_item); pub struct EncodeParams { - diag: span_handler, + diag: @span_handler, tcx: ty::ctxt, reachable: HashMap<ast::node_id, ()>, reexports2: middle::resolve::ExportMap2, @@ -83,7 +83,7 @@ struct Stats { } pub struct EncodeContext { - diag: span_handler, + diag: @span_handler, tcx: ty::ctxt, stats: @mut Stats, reachable: HashMap<ast::node_id, ()>, @@ -1054,7 +1054,7 @@ fn create_index<T:Copy + Hash + IterBytes>(index: ~[entry<T>]) -> } fn encode_index<T>(ebml_w: writer::Encoder, buckets: ~[@~[entry<T>]], - write_fn: &fn(io::Writer, T)) { + write_fn: &fn(@io::Writer, T)) { let writer = ebml_w.writer; ebml_w.start_tag(tag_index); let mut bucket_locs: ~[uint] = ~[]; @@ -1081,9 +1081,9 @@ fn encode_index<T>(ebml_w: writer::Encoder, buckets: ~[@~[entry<T>]], ebml_w.end_tag(); } -fn write_str(writer: io::Writer, &&s: ~str) { writer.write_str(s); } +fn write_str(writer: @io::Writer, &&s: ~str) { writer.write_str(s); } -fn write_int(writer: io::Writer, &&n: int) { +fn write_int(writer: @io::Writer, &&n: int) { fail_unless!(n < 0x7fff_ffff); writer.write_be_u32(n as u32); } @@ -1291,7 +1291,7 @@ fn encode_hash(ebml_w: writer::Encoder, hash: &str) { } // NB: Increment this as you change the metadata encoding version. -pub const metadata_encoding_version : &static/[u8] = +pub const metadata_encoding_version : &'static [u8] = &[0x72, //'r' as u8, 0x75, //'u' as u8, 0x73, //'s' as u8, @@ -1326,7 +1326,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] { type_abbrevs: ty::new_ty_hash() }; - let ebml_w = writer::Encoder(wr as io::Writer); + let ebml_w = writer::Encoder(wr as @io::Writer); encode_hash(ebml_w, ecx.link_meta.extras_hash); diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index cd2c26a5ff4..ad5b0274c0d 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<T> = &self/fn(path: &Path) -> Option<T>; +pub type pick<T> = &'self fn(path: &Path) -> Option<T>; pub fn pick_file(file: Path, path: &Path) -> Option<Path> { if path.file_path() == file { option::Some(copy *path) } @@ -37,7 +37,8 @@ pub trait FileSearch { pub fn mk_filesearch(maybe_sysroot: Option<Path>, target_triple: &str, - +addl_lib_search_paths: ~[Path]) -> FileSearch { + +addl_lib_search_paths: ~[Path]) + -> @FileSearch { struct FileSearchImpl { sysroot: Path, addl_lib_search_paths: ~[Path], @@ -78,7 +79,7 @@ pub fn mk_filesearch(maybe_sysroot: Option<Path>, } as @FileSearch } -pub fn search<T:Copy>(filesearch: FileSearch, pick: pick<T>) -> Option<T> { +pub fn search<T:Copy>(filesearch: @FileSearch, pick: pick<T>) -> Option<T> { let mut rslt = None; for filesearch.lib_search_paths().each |lib_search_path| { debug!("searching %s", lib_search_path.to_str()); diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index d45cefdbf08..9c612056677 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -44,8 +44,8 @@ pub enum os { } pub struct Context { - diag: span_handler, - filesearch: FileSearch, + diag: @span_handler, + filesearch: @FileSearch, span: span, ident: ast::ident, metas: ~[@ast::meta_item], @@ -87,7 +87,7 @@ fn libname(cx: Context) -> (~str, ~str) { fn find_library_crate_aux( cx: Context, (prefix, suffix): (~str, ~str), - filesearch: filesearch::FileSearch + filesearch: @filesearch::FileSearch ) -> Option<(~str, @~[u8])> { let crate_name = crate_name_from_metas(cx.metas); let prefix: ~str = prefix + *crate_name + ~"-"; @@ -156,7 +156,8 @@ pub fn crate_name_from_metas(metas: &[@ast::meta_item]) -> @~str { } } -pub fn note_linkage_attrs(intr: @ident_interner, diag: span_handler, +pub fn note_linkage_attrs(intr: @ident_interner, + diag: @span_handler, attrs: ~[ast::attribute]) { for attr::find_linkage_metas(attrs).each |mi| { diag.handler().note(fmt!("meta: %s", @@ -176,7 +177,7 @@ fn crate_matches(crate_data: @~[u8], metadata_matches(linkage_metas, metas) } -pub fn metadata_matches(extern_metas: ~[@ast::meta_item], +pub fn metadata_matches(extern_metas: &[@ast::meta_item], local_metas: &[@ast::meta_item]) -> bool { debug!("matching %u metadata requirements against %u items", @@ -252,7 +253,9 @@ pub fn meta_section_name(os: os) -> ~str { // A diagnostic function for dumping crate metadata to an output stream pub fn list_file_metadata(intr: @ident_interner, - os: os, path: &Path, out: io::Writer) { + os: os, + path: &Path, + out: @io::Writer) { match get_metadata_section(os, path) { option::Some(bytes) => decoder::list_crate_metadata(intr, bytes, out), option::None => { diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 63b14cc51be..c87b09cde08 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -49,7 +49,7 @@ pub enum DefIdSource { // Identifies a type parameter (`fn foo<X>() { ... }`). TypeParameter } -type conv_did = &self/fn(source: DefIdSource, ast::def_id) -> ast::def_id; +type conv_did = &'self fn(source: DefIdSource, ast::def_id) -> ast::def_id; pub struct PState { data: @~[u8], @@ -157,6 +157,16 @@ fn parse_vstore(st: @mut PState) -> ty::vstore { } } +fn parse_trait_store(st: @mut PState) -> ty::TraitStore { + match next(st) { + '~' => ty::UniqTraitStore, + '@' => ty::BoxTraitStore, + '&' => ty::RegionTraitStore(parse_region(st)), + '.' => ty::BareTraitStore, + c => st.tcx.sess.bug(fmt!("parse_trait_store(): bad input '%c'", c)) + } +} + fn parse_substs(st: @mut PState, conv: conv_did) -> ty::substs { let self_r = parse_opt(st, || parse_region(st) ); @@ -269,9 +279,9 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t { fail_unless!(next(st) == '['); let def = parse_def(st, NominalType, conv); let substs = parse_substs(st, conv); - let vstore = parse_vstore(st); + let store = parse_trait_store(st); fail_unless!(next(st) == ']'); - return ty::mk_trait(st.tcx, def, substs, vstore); + return ty::mk_trait(st.tcx, def, substs, store); } 'p' => { let did = parse_def(st, TypeParameter, conv); @@ -427,7 +437,6 @@ fn parse_mode(st: @mut PState) -> ast::mode { let m = ast::expl(match next(st) { '+' => ast::by_copy, '=' => ast::by_ref, - '#' => ast::by_val, _ => fail!(~"bad mode") }); return m; diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index b9cb0b1d4b5..56a96837623 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -27,7 +27,7 @@ use syntax::print::pprust::*; use middle::ty::Vid; pub struct ctxt { - diag: span_handler, + diag: @span_handler, // Def -> str Callback: ds: @fn(def_id) -> ~str, // The type context. @@ -57,7 +57,7 @@ fn cx_uses_abbrevs(cx: @ctxt) -> bool { } } -pub fn enc_ty(w: io::Writer, cx: @ctxt, t: ty::t) { +pub fn enc_ty(w: @io::Writer, cx: @ctxt, t: ty::t) { match cx.abbrevs { ac_no_abbrevs => { let result_str = match cx.tcx.short_names_cache.find(&t) { @@ -113,7 +113,7 @@ pub fn enc_ty(w: io::Writer, cx: @ctxt, t: ty::t) { } } } -fn enc_mt(w: io::Writer, cx: @ctxt, mt: ty::mt) { +fn enc_mt(w: @io::Writer, cx: @ctxt, mt: ty::mt) { match mt.mutbl { m_imm => (), m_mutbl => w.write_char('m'), @@ -122,7 +122,7 @@ fn enc_mt(w: io::Writer, cx: @ctxt, mt: ty::mt) { enc_ty(w, cx, mt.ty); } -fn enc_opt<T>(w: io::Writer, t: Option<T>, enc_f: &fn(T)) { +fn enc_opt<T>(w: @io::Writer, t: Option<T>, enc_f: &fn(T)) { match &t { &None => w.write_char('n'), &Some(ref v) => { @@ -132,7 +132,7 @@ fn enc_opt<T>(w: io::Writer, t: Option<T>, enc_f: &fn(T)) { } } -fn enc_substs(w: io::Writer, cx: @ctxt, substs: ty::substs) { +fn enc_substs(w: @io::Writer, cx: @ctxt, substs: ty::substs) { do enc_opt(w, substs.self_r) |r| { enc_region(w, cx, r) } do enc_opt(w, substs.self_ty) |t| { enc_ty(w, cx, t) } w.write_char('['); @@ -140,7 +140,7 @@ fn enc_substs(w: io::Writer, cx: @ctxt, substs: ty::substs) { w.write_char(']'); } -fn enc_region(w: io::Writer, cx: @ctxt, r: ty::Region) { +fn enc_region(w: @io::Writer, cx: @ctxt, r: ty::Region) { match r { ty::re_bound(br) => { w.write_char('b'); @@ -169,7 +169,7 @@ fn enc_region(w: io::Writer, cx: @ctxt, r: ty::Region) { } } -fn enc_bound_region(w: io::Writer, cx: @ctxt, br: ty::bound_region) { +fn enc_bound_region(w: @io::Writer, cx: @ctxt, br: ty::bound_region) { match br { ty::br_self => w.write_char('s'), ty::br_anon(idx) => { @@ -194,7 +194,7 @@ fn enc_bound_region(w: io::Writer, cx: @ctxt, br: ty::bound_region) { } } -pub fn enc_vstore(w: io::Writer, cx: @ctxt, v: ty::vstore) { +pub fn enc_vstore(w: @io::Writer, cx: @ctxt, v: ty::vstore) { w.write_char('/'); match v { ty::vstore_fixed(u) => { @@ -214,7 +214,19 @@ pub fn enc_vstore(w: io::Writer, cx: @ctxt, v: ty::vstore) { } } -fn enc_sty(w: io::Writer, cx: @ctxt, +st: ty::sty) { +pub fn enc_trait_store(w: @io::Writer, cx: @ctxt, s: ty::TraitStore) { + match s { + ty::UniqTraitStore => w.write_char('~'), + ty::BoxTraitStore => w.write_char('@'), + ty::BareTraitStore => w.write_char('.'), + ty::RegionTraitStore(re) => { + w.write_char('&'); + enc_region(w, cx, re); + } + } +} + +fn enc_sty(w: @io::Writer, cx: @ctxt, +st: ty::sty) { match st { ty::ty_nil => w.write_char('n'), ty::ty_bot => w.write_char('z'), @@ -252,12 +264,12 @@ fn enc_sty(w: io::Writer, cx: @ctxt, +st: ty::sty) { enc_substs(w, cx, (*substs)); w.write_char(']'); } - ty::ty_trait(def, ref substs, vstore) => { + ty::ty_trait(def, ref substs, store) => { w.write_str(&"x["); w.write_str((cx.ds)(def)); w.write_char('|'); enc_substs(w, cx, (*substs)); - enc_vstore(w, cx, vstore); + enc_trait_store(w, cx, store); w.write_char(']'); } ty::ty_tup(ts) => { @@ -325,7 +337,7 @@ fn enc_sty(w: io::Writer, cx: @ctxt, +st: ty::sty) { } } -fn enc_sigil(w: io::Writer, sigil: Sigil) { +fn enc_sigil(w: @io::Writer, sigil: Sigil) { match sigil { ManagedSigil => w.write_str("@"), OwnedSigil => w.write_str("~"), @@ -333,20 +345,19 @@ fn enc_sigil(w: io::Writer, sigil: Sigil) { } } -pub fn enc_arg(w: io::Writer, cx: @ctxt, arg: ty::arg) { +pub fn enc_arg(w: @io::Writer, cx: @ctxt, arg: ty::arg) { enc_mode(w, cx, arg.mode); enc_ty(w, cx, arg.ty); } -pub fn enc_mode(w: io::Writer, cx: @ctxt, m: mode) { +pub fn enc_mode(w: @io::Writer, cx: @ctxt, m: mode) { match ty::resolved_mode(cx.tcx, m) { by_copy => w.write_char('+'), by_ref => w.write_char('='), - by_val => w.write_char('#') } } -fn enc_purity(w: io::Writer, p: purity) { +fn enc_purity(w: @io::Writer, p: purity) { match p { pure_fn => w.write_char('p'), impure_fn => w.write_char('i'), @@ -355,26 +366,26 @@ fn enc_purity(w: io::Writer, p: purity) { } } -fn enc_abi(w: io::Writer, a: Abi) { +fn enc_abi(w: @io::Writer, a: Abi) { match a { RustAbi => w.write_char('r'), } } -fn enc_onceness(w: io::Writer, o: Onceness) { +fn enc_onceness(w: @io::Writer, o: Onceness) { match o { Once => w.write_char('o'), Many => w.write_char('m') } } -fn enc_bare_fn_ty(w: io::Writer, cx: @ctxt, ft: &ty::BareFnTy) { +fn enc_bare_fn_ty(w: @io::Writer, cx: @ctxt, ft: &ty::BareFnTy) { enc_purity(w, ft.purity); enc_abi(w, ft.abi); enc_fn_sig(w, cx, &ft.sig); } -fn enc_closure_ty(w: io::Writer, cx: @ctxt, ft: &ty::ClosureTy) { +fn enc_closure_ty(w: @io::Writer, cx: @ctxt, ft: &ty::ClosureTy) { enc_sigil(w, ft.sigil); enc_purity(w, ft.purity); enc_onceness(w, ft.onceness); @@ -382,7 +393,7 @@ fn enc_closure_ty(w: io::Writer, cx: @ctxt, ft: &ty::ClosureTy) { enc_fn_sig(w, cx, &ft.sig); } -fn enc_fn_sig(w: io::Writer, cx: @ctxt, fsig: &ty::FnSig) { +fn enc_fn_sig(w: @io::Writer, cx: @ctxt, fsig: &ty::FnSig) { w.write_char('['); for fsig.inputs.each |arg| { enc_arg(w, cx, *arg); @@ -391,7 +402,7 @@ fn enc_fn_sig(w: io::Writer, cx: @ctxt, fsig: &ty::FnSig) { enc_ty(w, cx, fsig.output); } -pub fn enc_bounds(w: io::Writer, cx: @ctxt, bs: @~[ty::param_bound]) { +pub fn enc_bounds(w: @io::Writer, cx: @ctxt, bs: @~[ty::param_bound]) { for vec::each(*bs) |bound| { match *bound { ty::bound_owned => w.write_char('S'), diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index c1a8f79b9b1..1dcaa76e9c7 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -105,7 +105,7 @@ pub fn encode_inlined_item(ecx: @e::EncodeContext, pub fn decode_inlined_item(cdata: @cstore::crate_metadata, tcx: ty::ctxt, maps: Maps, - path: ast_map::path, + +path: ast_map::path, par_doc: ebml::Doc) -> Option<ast::inlined_item> { let dcx = @DecodeContext { @@ -292,7 +292,7 @@ fn encode_ast(ebml_w: writer::Encoder, item: ast::inlined_item) { // nested items, as otherwise it would get confused when translating // inlined items. fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item { - fn drop_nested_items(blk: &ast::blk_, fld: fold::ast_fold) -> ast::blk_ { + fn drop_nested_items(blk: &ast::blk_, fld: @fold::ast_fold) -> ast::blk_ { let stmts_sans_items = do blk.stmts.filtered |stmt| { match stmt.node { ast::stmt_expr(_, _) | ast::stmt_semi(_, _) | @@ -1203,8 +1203,8 @@ impl fake_ext_ctxt for fake_session { } #[cfg(test)] -fn mk_ctxt() -> fake_ext_ctxt { - @parse::new_parse_sess(None) as fake_ext_ctxt +fn mk_ctxt() -> @fake_ext_ctxt { + @parse::new_parse_sess(None) as @fake_ext_ctxt } #[cfg(test)] diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 89700427d96..17bdf318e07 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -271,6 +271,7 @@ pub impl CheckLoanCtxt { None => return, Some(loans) => loans }; + let new_loans: &mut ~[Loan] = new_loans; debug!("new_loans has length %?", new_loans.len()); diff --git a/src/librustc/middle/borrowck/gather_loans.rs b/src/librustc/middle/borrowck/gather_loans.rs index 6e998864def..e5f056619cc 100644 --- a/src/librustc/middle/borrowck/gather_loans.rs +++ b/src/librustc/middle/borrowck/gather_loans.rs @@ -129,9 +129,12 @@ fn req_loans_in_expr(ex: @ast::expr, ex.id, pprust::expr_to_str(ex, tcx.sess.intr())); // If this expression is borrowed, have to ensure it remains valid: - if !self.ignore_adjustments.contains(&ex.id) { - for tcx.adjustments.find(&ex.id).each |adjustments| { - self.guarantee_adjustments(ex, *adjustments); + { + let mut this = &mut *self; + if !this.ignore_adjustments.contains(&ex.id) { + for tcx.adjustments.find(&ex.id).each |adjustments| { + this.guarantee_adjustments(ex, *adjustments); + } } } @@ -156,7 +159,7 @@ fn req_loans_in_expr(ex: @ast::expr, let arg_cmt = self.bccx.cat_expr(*arg); self.guarantee_valid(arg_cmt, m_imm, scope_r); } - ast::by_val | ast::by_copy => {} + ast::by_copy => {} } } visit::visit_expr(ex, self, vt); @@ -172,7 +175,7 @@ fn req_loans_in_expr(ex: @ast::expr, let arg_cmt = self.bccx.cat_expr(*arg); self.guarantee_valid(arg_cmt, m_imm, scope_r); } - ast::by_val | ast::by_copy => {} + ast::by_copy => {} } } @@ -288,9 +291,9 @@ fn req_loans_in_expr(ex: @ast::expr, } pub impl GatherLoanCtxt { - fn tcx(@mut self) -> ty::ctxt { self.bccx.tcx } + fn tcx(&mut self) -> ty::ctxt { self.bccx.tcx } - fn guarantee_adjustments(@mut self, + fn guarantee_adjustments(&mut self, expr: @ast::expr, adjustment: &ty::AutoAdjustment) { debug!("guarantee_adjustments(expr=%s, adjustment=%?)", @@ -348,7 +351,7 @@ pub impl GatherLoanCtxt { // out loans, which will be added to the `req_loan_map`. This can // also entail "rooting" GC'd pointers, which means ensuring // dynamically that they are not freed. - fn guarantee_valid(@mut self, + fn guarantee_valid(&mut self, cmt: cmt, req_mutbl: ast::mutability, scope_r: ty::Region) @@ -465,7 +468,7 @@ pub impl GatherLoanCtxt { // has type `@mut{f:int}`, this check might fail because `&x.f` // reqires an immutable pointer, but `f` lives in (aliased) // mutable memory. - fn check_mutbl(@mut self, + fn check_mutbl(&mut self, loan_kind: LoanKind, cmt: cmt) -> bckres<PreserveCondition> { @@ -498,7 +501,7 @@ pub impl GatherLoanCtxt { } } - fn add_loans(@mut self, + fn add_loans(&mut self, cmt: cmt, loan_kind: LoanKind, scope_r: ty::Region, @@ -514,7 +517,7 @@ pub impl GatherLoanCtxt { // consumes one mut pointer and returns a narrower one: // // struct Foo { f: int } - // fn foo(p: &v/mut Foo) -> &v/mut int { &mut p.f } + // fn foo(p: &'v mut Foo) -> &'v mut int { &mut p.f } // // I think this should work fine but there is more subtlety to it than // I at first imagined. Unfortunately it's a very important use case, @@ -563,7 +566,7 @@ pub impl GatherLoanCtxt { } } - fn add_loans_to_scope_id(@mut self, + fn add_loans_to_scope_id(&mut self, scope_id: ast::node_id, +loans: ~[Loan]) { debug!("adding %u loans to scope_id %?: %s", diff --git a/src/librustc/middle/borrowck/preserve.rs b/src/librustc/middle/borrowck/preserve.rs index 328fe1c4f3e..962af48a70c 100644 --- a/src/librustc/middle/borrowck/preserve.rs +++ b/src/librustc/middle/borrowck/preserve.rs @@ -64,7 +64,7 @@ pub impl BorrowckCtxt { } struct PreserveCtxt { - bccx: &self/BorrowckCtxt, + bccx: &'self BorrowckCtxt, // the region scope for which we must preserve the memory scope_region: ty::Region, diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 48d136ce65f..4b1b0d0200f 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -55,7 +55,7 @@ use syntax::{visit, ast_util}; // primitives in the stdlib are explicitly annotated to only take sendable // types. -pub const try_adding: &static/str = "Try adding a move"; +pub const try_adding: &'static str = "Try adding a move"; pub type rval_map = HashMap<node_id, ()>; @@ -462,7 +462,7 @@ pub fn check_cast_for_escaping_regions( pub fn check_kind_bounds_of_cast(cx: Context, source: @expr, target: @expr) { let target_ty = ty::expr_ty(cx.tcx, target); match ty::get(target_ty).sty { - ty::ty_trait(_, _, ty::vstore_uniq) => { + ty::ty_trait(_, _, ty::UniqTraitStore) => { let source_ty = ty::expr_ty(cx.tcx, source); if !ty::type_is_owned(cx.tcx, source_ty) { cx.tcx.sess.span_err( diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 32567d71cd9..f88be89ad00 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -96,7 +96,7 @@ pub impl LanguageItems { } } - static pub fn item_name(&self, index: uint) -> &static/str { + static pub fn item_name(&self, index: uint) -> &'static str { match index { 0 => "const", 1 => "copy", @@ -257,7 +257,7 @@ pub impl LanguageItems { fn LanguageItemCollector(crate: @crate, session: Session, - items: &r/mut LanguageItems) + items: &'r mut LanguageItems) -> LanguageItemCollector/&r { let item_refs = HashMap(); @@ -312,7 +312,7 @@ fn LanguageItemCollector(crate: @crate, } struct LanguageItemCollector { - items: &self/mut LanguageItems, + items: &'self mut LanguageItems, crate: @crate, session: Session, diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 93f0557028e..ccd7e35f817 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -75,9 +75,9 @@ pub enum lint { non_camel_case_types, type_limits, default_methods, - deprecated_self, deprecated_mutable_fields, deprecated_drop, + foreign_mode, managed_heap_memory, owned_heap_memory, @@ -90,7 +90,7 @@ pub enum lint { // dead_assignment } -pub fn level_to_str(lv: level) -> &static/str { +pub fn level_to_str(lv: level) -> &'static str { match lv { allow => "allow", warn => "warn", @@ -106,7 +106,7 @@ pub enum level { struct LintSpec { lint: lint, - desc: &static/str, + desc: &'static str, default: level } @@ -182,6 +182,13 @@ pub fn get_lint_dict() -> LintDict { default: warn }), + (@~"foreign_mode", + @LintSpec { + lint: foreign_mode, + desc: "warn about deprecated uses of modes in foreign fns", + default: warn + }), + (@~"deprecated_pattern", @LintSpec { lint: deprecated_pattern, @@ -238,13 +245,6 @@ pub fn get_lint_dict() -> LintDict { default: deny }), - (@~"deprecated_self", - @LintSpec { - lint: deprecated_self, - desc: "warn about deprecated uses of `self`", - default: warn - }), - (@~"deprecated_mutable_fields", @LintSpec { lint: deprecated_mutable_fields, @@ -489,7 +489,6 @@ fn check_item(i: @ast::item, cx: ty::ctxt) { check_item_deprecated_modes(cx, i); check_item_type_limits(cx, i); check_item_default_methods(cx, i); - check_item_deprecated_self(cx, i); check_item_deprecated_mutable_fields(cx, i); check_item_deprecated_drop(cx, i); } @@ -499,7 +498,12 @@ fn check_item(i: @ast::item, cx: ty::ctxt) { // not traverse into subitems, since that is handled by the outer // lint visitor. fn item_stopping_visitor<E>(v: visit::vt<E>) -> visit::vt<E> { - visit::mk_vt(@visit::Visitor {visit_item: |_i, _e, _v| { },.. **v}) + visit::mk_vt(@visit::Visitor {visit_item: |_i, _e, _v| { }, + .. **(ty_stopping_visitor(v))}) +} + +fn ty_stopping_visitor<E>(v: visit::vt<E>) -> visit::vt<E> { + visit::mk_vt(@visit::Visitor {visit_ty: |_t, _e, _v| { },.. **v}) } fn check_item_while_true(cx: ty::ctxt, it: @ast::item) { @@ -669,46 +673,6 @@ fn check_item_default_methods(cx: ty::ctxt, item: @ast::item) { } } -fn check_item_deprecated_self(cx: ty::ctxt, item: @ast::item) { - fn maybe_warn(cx: ty::ctxt, - item: @ast::item, - self_ty: ast::self_ty) { - match self_ty.node { - ast::sty_by_ref => { - cx.sess.span_lint( - deprecated_self, - item.id, - item.id, - self_ty.span, - ~"this method form is deprecated; use an explicit `self` \ - parameter or mark the method as static"); - } - _ => {} - } - } - - match /*bad*/copy item.node { - ast::item_trait(_, _, methods) => { - for methods.each |method| { - match /*bad*/copy *method { - ast::required(ty_method) => { - maybe_warn(cx, item, ty_method.self_ty); - } - ast::provided(method) => { - maybe_warn(cx, item, method.self_ty); - } - } - } - } - ast::item_impl(_, _, _, methods) => { - for methods.each |method| { - maybe_warn(cx, item, method.self_ty); - } - } - _ => {} - } -} - fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) { match item.node { ast::item_struct(struct_def, _) => { @@ -753,6 +717,20 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) { fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id, decl: &ast::fn_decl) { + // warn about `&&` mode on foreign functions, both because it is + // deprecated and because its semantics have changed recently: + for decl.inputs.eachi |i, arg| { + match ty::resolved_mode(cx, arg.mode) { + ast::by_copy => {} + ast::by_ref => { + cx.sess.span_lint( + foreign_mode, fn_id, fn_id, arg.ty.span, + fmt!("foreign function uses `&&` mode \ + on argument %u", i)); + } + } + } + let tys = vec::map(decl.inputs, |a| a.ty ); for vec::each(vec::append_one(tys, decl.output)) |ty| { match ty.node { @@ -785,7 +763,7 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) { if attr::foreign_abi(it.attrs) != either::Right(ast::foreign_abi_rust_intrinsic) => { for nmod.items.each |ni| { - match /*bad*/copy ni.node { + match ni.node { ast::foreign_item_fn(ref decl, _, _) => { check_foreign_fn(cx, it.id, decl); } @@ -908,14 +886,14 @@ fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) { !ident.contains_char('_') } - fn ident_without_trailing_underscores(ident: &r/str) -> &r/str { + fn ident_without_trailing_underscores(ident: &'r str) -> &'r str { match str::rfind(ident, |c| c != '_') { Some(idx) => str::view(ident, 0, idx + 1), None => ident, // all underscores } } - fn ident_without_leading_underscores(ident: &r/str) -> &r/str { + fn ident_without_leading_underscores(ident: &'r str) -> &'r str { match str::find(ident, |c| c != '_') { Some(idx) => str::view(ident, idx, ident.len()), None => ident // all underscores diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index d300698da59..a8af6a18c00 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -427,7 +427,7 @@ pub impl IrMaps { v.push(id); } Arg(_, _, by_ref) | - Arg(_, _, by_val) | ImplicitRet => { + ImplicitRet => { debug!("--but it is not owned"); } } @@ -825,7 +825,8 @@ pub impl Liveness { } } - fn write_vars(&self, wr: io::Writer, + fn write_vars(&self, + wr: @io::Writer, ln: LiveNode, test: &fn(uint) -> LiveNode) { let node_base_idx = self.idx(ln, Variable(0)); @@ -848,21 +849,24 @@ pub impl Liveness { _ => self.tcx.sess.span_bug(sp, ~"Label on break/loop \ doesn't refer to a loop") }, - None => + None => { // Vanilla 'break' or 'loop', so use the enclosing // loop scope - if self.loop_scope.len() == 0 { + let loop_scope = &mut *self.loop_scope; + if loop_scope.len() == 0 { self.tcx.sess.span_bug(sp, ~"break outside loop"); } else { // FIXME(#5275): this shouldn't have to be a method... self.last_loop_scope() } + } } } fn last_loop_scope(&self) -> node_id { - *self.loop_scope.last() + let loop_scope = &mut *self.loop_scope; + *loop_scope.last() } fn ln_str(&self, ln: LiveNode) -> ~str { @@ -1006,7 +1010,7 @@ pub impl Liveness { // inputs passed by & mode should be considered live on exit: for decl.inputs.each |arg| { match ty::resolved_mode(self.tcx, arg.mode) { - by_val | by_ref => { + by_ref => { // By val and by ref do not own, so register a // read at the end. This will prevent us from // moving out of such variables but also prevent @@ -1346,7 +1350,15 @@ pub impl Liveness { self.propagate_through_expr(e, succ) } - expr_inline_asm(*) | + expr_inline_asm(_, ins, outs, _, _, _) =>{ + let succ = do ins.foldr(succ) |&(_, expr), succ| { + self.propagate_through_expr(expr, succ) + }; + do outs.foldr(succ) |&(_, expr), succ| { + self.propagate_through_expr(expr, succ) + } + } + expr_lit(*) => { succ } @@ -1612,6 +1624,20 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) { visit::visit_expr(expr, self, vt); } + expr_inline_asm(_, ins, outs, _, _, _) => { + for ins.each |&(_, in)| { + (vt.visit_expr)(in, self, vt); + } + + // Output operands must be lvalues + for outs.each |&(_, out)| { + self.check_lvalue(out, vt); + (vt.visit_expr)(out, self, vt); + } + + visit::visit_expr(expr, self, vt); + } + // no correctness conditions related to liveness expr_call(*) | expr_method_call(*) | expr_if(*) | expr_match(*) | expr_while(*) | expr_loop(*) | expr_index(*) | expr_field(*) | @@ -1620,7 +1646,7 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) { expr_cast(*) | expr_unary(*) | expr_ret(*) | expr_break(*) | expr_again(*) | expr_lit(_) | expr_block(*) | expr_swap(*) | expr_mac(*) | expr_addr_of(*) | expr_struct(*) | expr_repeat(*) | - expr_paren(*) | expr_inline_asm(*) => { + expr_paren(*) => { visit::visit_expr(expr, self, vt); } } @@ -1639,8 +1665,8 @@ enum ReadKind { PartiallyMovedValue } -pub impl @Liveness { - fn check_ret(&self, id: node_id, sp: span, _fk: &visit::fn_kind, +pub impl Liveness { + fn check_ret(@self, id: node_id, sp: span, _fk: &visit::fn_kind, entry_ln: LiveNode) { if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() { // if no_ret_var is live, then we fall off the end of the @@ -1660,10 +1686,9 @@ pub impl @Liveness { } } - fn check_move_from_var(&self, ln: LiveNode, + fn check_move_from_var(@self, ln: LiveNode, var: Variable, - move_expr: @expr) - { + move_expr: @expr) { /*! * * Checks whether `var` is live on entry to any of the @@ -1685,7 +1710,7 @@ pub impl @Liveness { } } - fn consider_last_use(&self, expr: @expr, ln: LiveNode, var: Variable) { + fn consider_last_use(@self, expr: @expr, ln: LiveNode, var: Variable) { debug!("consider_last_use(expr.id=%?, ln=%s, var=%s)", expr.id, ln.to_str(), var.to_str()); @@ -1695,7 +1720,7 @@ pub impl @Liveness { } } - fn check_lvalue(&self, expr: @expr, vt: vt<@Liveness>) { + fn check_lvalue(@self, expr: @expr, vt: vt<@Liveness>) { match expr.node { expr_path(_) => { match self.tcx.def_map.get(&expr.id) { @@ -1723,18 +1748,18 @@ pub impl @Liveness { _ => { // For other kinds of lvalues, no checks are required, // and any embedded expressions are actually rvalues - visit::visit_expr(expr, *self, vt); + visit::visit_expr(expr, self, vt); } } } - fn check_for_reassignments_in_pat(&self, pat: @pat) { + fn check_for_reassignments_in_pat(@self, pat: @pat) { do self.pat_bindings(pat) |ln, var, sp| { self.check_for_reassignment(ln, var, sp); } } - fn check_for_reassignment(&self, ln: LiveNode, var: Variable, + fn check_for_reassignment(@self, ln: LiveNode, var: Variable, orig_span: span) { match self.assigned_on_exit(ln, var) { Some(ExprNode(span)) => { @@ -1755,10 +1780,9 @@ pub impl @Liveness { } } - fn report_illegal_move(&self, lnk: LiveNodeKind, + fn report_illegal_move(@self, lnk: LiveNodeKind, var: Variable, - move_expr: @expr) - { + move_expr: @expr) { // the only time that it is possible to have a moved variable // used by ExitNode would be arguments or fields in a ctor. // we give a slightly different error message in those cases. @@ -1821,11 +1845,10 @@ pub impl @Liveness { }; } - fn report_move_location(&self, move_expr: @expr, + fn report_move_location(@self, move_expr: @expr, var: Variable, expr_descr: &str, - pronoun: &str) - { + pronoun: &str) { let move_expr_ty = ty::expr_ty(self.tcx, move_expr); let name = self.ir.variable_name(var); self.tcx.sess.span_note( @@ -1836,7 +1859,7 @@ pub impl @Liveness { ty_to_str(self.tcx, move_expr_ty))); } - fn report_illegal_read(&self, chk_span: span, + fn report_illegal_read(@self, chk_span: span, lnk: LiveNodeKind, var: Variable, rk: ReadKind) { @@ -1867,12 +1890,12 @@ pub impl @Liveness { } } - fn should_warn(&self, var: Variable) -> Option<@~str> { + fn should_warn(@self, var: Variable) -> Option<@~str> { let name = self.ir.variable_name(var); if name[0] == ('_' as u8) { None } else { Some(name) } } - fn warn_about_unused_args(&self, decl: &fn_decl, entry_ln: LiveNode) { + fn warn_about_unused_args(@self, decl: &fn_decl, entry_ln: LiveNode) { for decl.inputs.each |arg| { do pat_util::pat_bindings(self.tcx.def_map, arg.pat) |_bm, p_id, sp, _n| { @@ -1882,7 +1905,7 @@ pub impl @Liveness { } } - fn warn_about_unused_or_dead_vars_in_pat(&self, pat: @pat) { + fn warn_about_unused_or_dead_vars_in_pat(@self, pat: @pat) { do self.pat_bindings(pat) |ln, var, sp| { if !self.warn_about_unused(sp, ln, var) { self.warn_about_dead_assign(sp, ln, var); @@ -1890,7 +1913,7 @@ pub impl @Liveness { } } - fn warn_about_unused(&self, sp: span, ln: LiveNode, var: Variable) + fn warn_about_unused(@self, sp: span, ln: LiveNode, var: Variable) -> bool { if !self.used_on_entry(ln, var) { for self.should_warn(var).each |name| { @@ -1920,7 +1943,7 @@ pub impl @Liveness { return false; } - fn warn_about_dead_assign(&self, sp: span, ln: LiveNode, var: Variable) { + fn warn_about_dead_assign(@self, sp: span, ln: LiveNode, var: Variable) { if self.live_on_exit(ln, var).is_none() { for self.should_warn(var).each |name| { // FIXME(#3266)--make liveness warnings lintable diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 5881f95f298..c25266b4531 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -486,14 +486,6 @@ pub impl mem_categorization_ctxt { let lp = match ty::resolved_mode(self.tcx, mode) { ast::by_copy => Some(@lp_arg(vid)), ast::by_ref => None, - ast::by_val => { - // by-value is this hybrid mode where we have a - // pointer but we do not own it. This is not - // considered loanable because, for example, a by-ref - // and and by-val argument might both actually contain - // the same unique ptr. - None - } }; @cmt_ { id:id, diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index 734f4651f3b..9848c65ac43 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -558,10 +558,10 @@ pub impl VisitContext { self.use_expr(base, Read, visitor); } + expr_inline_asm(*) | expr_break(*) | expr_again(*) | - expr_lit(*) | - expr_inline_asm(*) => {} + expr_lit(*) => {} expr_loop(ref blk, _) => { self.consume_block(blk, visitor); @@ -782,7 +782,7 @@ pub impl VisitContext { */ match arg_mode { - by_val | by_ref => self.use_expr(arg_expr, Read, visitor), + by_ref => self.use_expr(arg_expr, Read, visitor), by_copy => self.consume_expr(arg_expr, visitor) } } diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index a96ed9b8fa6..6dcf1ba8128 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -438,7 +438,7 @@ pub fn join_variance(++variance1: region_variance, /// particular site to yield the final variance of the reference. /// /// Example: if we are checking function arguments then the ambient -/// variance is contravariant. If we then find a `&r/T` pointer, `r` +/// variance is contravariant. If we then find a `&'r T` pointer, `r` /// appears in a co-variant position. This implies that this /// occurrence of `r` is contra-variant with respect to the current /// item, and hence the function returns `rv_contravariant`. @@ -517,9 +517,9 @@ pub impl DetermineRpCtxt { // concrete. // // 1. impl foo for &int { ... } - // 2. impl foo for &self/int { ... } - // 3. impl foo for bar { fn m(@self) -> &self/int { ... } } - // 4. impl foo for bar { fn m(&self) -> &self/int { ... } } + // 2. impl foo for &'self int { ... } + // 3. impl foo for bar { fn m(@self) -> &'self int { ... } } + // 4. impl foo for bar { fn m(&self) -> &'self int { ... } } // 5. impl foo for bar { fn m(&self) -> &int { ... } } // // In case 1, the anonymous region is being referenced, @@ -644,9 +644,9 @@ pub fn determine_rp_in_ty(ty: @ast::Ty, // impl etc. So we can ignore it and its components. if cx.item_id == 0 { return; } - // if this type directly references a region pointer like &r/ty, - // add to the worklist/set. Note that &r/ty is contravariant with - // respect to &r, because &r/ty can be used whereever a *smaller* + // if this type directly references a region pointer like &'r ty, + // add to the worklist/set. Note that &'r ty is contravariant with + // respect to &r, because &'r ty can be used whereever a *smaller* // region is expected (and hence is a supertype of those // locations) let sess = cx.sess; @@ -818,18 +818,21 @@ pub fn determine_rp_in_crate(sess: Session, // C). For each dependent item D, we combine the variance of C // with the ambient variance where the reference occurred and then // update the region-parameterization of D to reflect the result. - while cx.worklist.len() != 0 { - let c_id = cx.worklist.pop(); - let c_variance = cx.region_paramd_items.get(&c_id); - debug!("popped %d from worklist", c_id); - match cx.dep_map.find(&c_id) { - None => {} - Some(deps) => { - for deps.each |dep| { - let v = add_variance(dep.ambient_variance, c_variance); - cx.add_rp(dep.id, v); + { + let cx = &mut *cx; + while cx.worklist.len() != 0 { + let c_id = cx.worklist.pop(); + let c_variance = cx.region_paramd_items.get(&c_id); + debug!("popped %d from worklist", c_id); + match cx.dep_map.find(&c_id) { + None => {} + Some(deps) => { + for deps.each |dep| { + let v = add_variance(dep.ambient_variance, c_variance); + cx.add_rp(dep.id, v); + } + } } - } } } diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 7ac559161af..6561da0862a 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -210,9 +210,9 @@ pub impl<T> ResolveResult<T> { } } -pub enum TypeParameters/& { +pub enum TypeParameters<'self> { NoTypeParameters, //< No type parameters. - HasTypeParameters(&self/Generics, //< Type parameters. + HasTypeParameters(&'self Generics, //< Type parameters. node_id, //< ID of the enclosing item // The index to start numbering the type parameters at. @@ -457,7 +457,7 @@ pub struct Module { kind: ModuleKind, children: @HashMap<ident,@mut NameBindings>, - imports: ~[@ImportDirective], + imports: @mut ~[@ImportDirective], // The anonymous children of this node. Anonymous children are pseudo- // modules that are implicitly created around items contained within @@ -495,7 +495,7 @@ pub fn Module(parent_link: ParentLink, def_id: def_id, kind: kind, children: @HashMap(), - imports: ~[], + imports: @mut ~[], anonymous_children: @HashMap(), import_resolutions: @HashMap(), glob_count: 0, @@ -505,7 +505,8 @@ pub fn Module(parent_link: ParentLink, pub impl Module { fn all_imports_resolved(&self) -> bool { - return self.imports.len() == self.resolved_import_count; + let imports = &mut *self.imports; + return imports.len() == self.resolved_import_count; } } @@ -647,6 +648,7 @@ pub impl NameBindings { None => { match (*type_def).module_def { Some(module_def) => { + let module_def = &mut *module_def; module_def.def_id.map(|def_id| def_mod(*def_id)) } @@ -1978,10 +1980,11 @@ pub impl Resolver { return; } - let import_count = module.imports.len(); + let imports = &mut *module.imports; + let import_count = imports.len(); while module.resolved_import_count < import_count { let import_index = module.resolved_import_count; - let import_directive = module.imports[import_index]; + let import_directive = imports[import_index]; match self.resolve_import_for_module(module, import_directive) { Failed => { // We presumably emitted an error. Continue. @@ -2021,7 +2024,7 @@ pub impl Resolver { } fn import_path_to_str(@mut self, - idents: ~[ident], + idents: &[ident], subclass: ImportDirectiveSubclass) -> @~str { if idents.is_empty() { @@ -2288,7 +2291,8 @@ pub impl Resolver { (None, None) => { return Failed; } // If it's private, it's also unresolved. (Some(t), None) | (None, Some(t)) => { - match t.bindings.type_def { + let bindings = &mut *t.bindings; + match bindings.type_def { Some(ref type_def) => { if type_def.privacy == Private { return Failed; @@ -2296,7 +2300,7 @@ pub impl Resolver { } _ => () } - match t.bindings.value_def { + match bindings.value_def { Some(ref value_def) => { if value_def.privacy == Private { return Failed; @@ -2483,7 +2487,7 @@ pub impl Resolver { debug!("(resolving glob import) writing module resolution \ %? into `%s`", - is_none(&target_import_resolution.type_target), + is_none(&mut target_import_resolution.type_target), self.module_to_str(module_)); // Here we merge two import resolutions. @@ -2551,7 +2555,7 @@ pub impl Resolver { *self.session.str_of(ident), self.module_to_str(containing_module), self.module_to_str(module_), - dest_import_resolution.privacy); + copy dest_import_resolution.privacy); // Merge the child item into the import resolution. if (*name_bindings).defined_in_public_namespace(ValueNS) { @@ -2573,7 +2577,7 @@ pub impl Resolver { /// Resolves the given module path from the given root `module_`. fn resolve_module_path_from_root(@mut self, module_: @mut Module, - module_path: ~[ident], + module_path: &[ident], index: uint, span: span, mut name_search_type: NameSearchType) @@ -2658,7 +2662,7 @@ pub impl Resolver { /// rooted at the given module. fn resolve_module_path_for_import(@mut self, module_: @mut Module, - module_path: ~[ident], + module_path: &[ident], use_lexical_scope: UseLexicalScopeFlag, span: span) -> ResolveResult<@mut Module> { @@ -2864,7 +2868,8 @@ pub impl Resolver { module_, name, TypeNS, DontSearchThroughModules); match resolve_result { Success(target) => { - match target.bindings.type_def { + let bindings = &mut *target.bindings; + match bindings.type_def { Some(ref type_def) => { match (*type_def).module_def { None => { @@ -2944,7 +2949,7 @@ pub impl Resolver { */ fn resolve_module_prefix(@mut self, module_: @mut Module, - module_path: ~[ident]) + module_path: &[ident]) -> ResolveResult<ModulePrefixResult> { let interner = self.session.parse_sess.interner; @@ -3061,10 +3066,10 @@ pub impl Resolver { fn report_unresolved_imports(@mut self, module_: @mut Module) { let index = module_.resolved_import_count; - let import_count = module_.imports.len(); + let imports: &mut ~[@ImportDirective] = &mut *module_.imports; + let import_count = imports.len(); if index != import_count { - self.session.span_err(module_.imports[index].span, - ~"unresolved import"); + self.session.span_err(imports[index].span, ~"unresolved import"); } // Descend into children and anonymous children. @@ -3876,7 +3881,7 @@ pub impl Resolver { generics: &Generics, opt_trait_reference: Option<@trait_ref>, self_type: @Ty, - methods: ~[@method], + methods: &[@method], visitor: ResolveVisitor) { // If applicable, create a rib for the type parameters. let outer_type_parameter_count = generics.ty_params.len(); @@ -4253,10 +4258,10 @@ pub impl Resolver { match bindings_list { Some(bindings_list) - if !bindings_list.contains_key(&ident) - => { - let last_rib = self.value_ribs[ - self.value_ribs.len() - 1]; + if !bindings_list.contains_key(&ident) => { + let this = &mut *self; + let last_rib = this.value_ribs[ + this.value_ribs.len() - 1]; last_rib.bindings.insert(ident, dl_def(def)); bindings_list.insert(ident, pat_id); @@ -4275,8 +4280,9 @@ pub impl Resolver { // Not bound in the same pattern: do nothing } None => { - let last_rib = self.value_ribs[ - self.value_ribs.len() - 1]; + let this = &mut *self; + let last_rib = this.value_ribs[ + this.value_ribs.len() - 1]; last_rib.bindings.insert(ident, dl_def(def)); } @@ -4290,17 +4296,24 @@ pub impl Resolver { } } - pat_ident(_, path, _) | pat_enum(path, _) => { - // These two must be enum variants or structs. + pat_ident(binding_mode, path, _) => { + // This must be an enum variant, struct, or constant. match self.resolve_path(path, ValueNS, false, visitor) { Some(def @ def_variant(*)) | Some(def @ def_struct(*)) => { self.record_def(pattern.id, def); } + Some(def @ def_const(*)) => { + self.enforce_default_binding_mode( + pattern, + binding_mode, + "a constant"); + self.record_def(pattern.id, def); + } Some(_) => { self.session.span_err( path.span, - fmt!("not an enum variant: %s", + fmt!("not an enum variant or constant: %s", *self.session.str_of( *path.idents.last()))); } @@ -4316,6 +4329,33 @@ pub impl Resolver { } } + pat_enum(path, _) => { + // This must be an enum variant or struct. + match self.resolve_path(path, ValueNS, false, visitor) { + Some(def @ def_variant(*)) | + Some(def @ def_struct(*)) => { + self.record_def(pattern.id, def); + } + Some(_) => { + self.session.span_err( + path.span, + fmt!("not an enum variant or struct: %s", + *self.session.str_of( + *path.idents.last()))); + } + None => { + self.session.span_err(path.span, + ~"unresolved enum variant \ + or struct"); + } + } + + // Check the types in the path pattern. + for path.types.each |ty| { + self.resolve_type(*ty, visitor); + } + } + pat_lit(expr) => { self.resolve_expr(expr, visitor); } @@ -4689,14 +4729,16 @@ pub impl Resolver { } fn find_best_match_for_name(@mut self, name: &str) -> Option<~str> { + let this = &mut *self; + let mut maybes: ~[~str] = ~[]; let mut values: ~[uint] = ~[]; - let mut j = self.value_ribs.len(); + let mut j = this.value_ribs.len(); while j != 0 { j -= 1; - for self.value_ribs[j].bindings.each_entry |e| { - vec::push(&mut maybes, copy *self.session.str_of(e.key)); + for this.value_ribs[j].bindings.each_entry |e| { + vec::push(&mut maybes, copy *this.session.str_of(e.key)); vec::push(&mut values, uint::max_value); } } @@ -4724,12 +4766,14 @@ pub impl Resolver { } fn name_exists_in_scope_struct(@mut self, name: &str) -> bool { - let mut i = self.type_ribs.len(); + let this = &mut *self; + + let mut i = this.type_ribs.len(); while i != 0 { i -= 1; - match self.type_ribs[i].kind { + match this.type_ribs[i].kind { MethodRibKind(node_id, _) => - for self.crate.node.module.items.each |item| { + for this.crate.node.module.items.each |item| { if item.id == node_id { match item.node { item_struct(class_def, _) => { @@ -4737,7 +4781,7 @@ pub impl Resolver { match field.node.kind { unnamed_field => {}, named_field(ident, _, _) => { - if str::eq_slice(*self.session.str_of(ident), + if str::eq_slice(*this.session.str_of(ident), name) { return true } @@ -4843,8 +4887,9 @@ pub impl Resolver { expr_loop(_, Some(label)) => { do self.with_label_rib { + let this = &mut *self; let def_like = dl_def(def_label(expr.id)); - let rib = self.label_ribs[self.label_ribs.len() - 1]; + let rib = this.label_ribs[this.label_ribs.len() - 1]; rib.bindings.insert(label, def_like); visit_expr(expr, (), visitor); @@ -5110,21 +5155,21 @@ pub impl Resolver { // be sure that there is only one main function // fn check_duplicate_main(@mut self) { - if self.attr_main_fn.is_none() { - if self.main_fns.len() >= 1u { + let this = &mut *self; + if this.attr_main_fn.is_none() { + if this.main_fns.len() >= 1u { let mut i = 1u; - while i < self.main_fns.len() { - let (_, dup_main_span) = - option::unwrap(self.main_fns[i]); - self.session.span_err( + while i < this.main_fns.len() { + let (_, dup_main_span) = option::unwrap(this.main_fns[i]); + this.session.span_err( dup_main_span, ~"multiple 'main' functions"); i += 1; } - *self.session.main_fn = self.main_fns[0]; + *this.session.main_fn = this.main_fns[0]; } } else { - *self.session.main_fn = self.attr_main_fn; + *this.session.main_fn = this.attr_main_fn; } } diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index d4a7c104500..8f0d9eb953f 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -327,7 +327,7 @@ pub type BindingsMap = HashMap<ident, BindingInfo>; pub struct ArmData { bodycx: block, - arm: &self/ast::arm, + arm: &'self ast::arm, bindings_map: BindingsMap } @@ -391,7 +391,7 @@ pub fn expand_nested_bindings(bcx: block, m: &[@Match/&r], } } -pub type enter_pat = &self/fn(@ast::pat) -> Option<~[@ast::pat]>; +pub type enter_pat = &'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) { @@ -599,7 +599,7 @@ pub fn enter_rec_or_struct(bcx: block, dm: DefMap, m: &[@Match/&r], col: uint, - fields: ~[ast::ident], + fields: &[ast::ident], val: ValueRef) -> ~[@Match/&r] { debug!("enter_rec_or_struct(bcx=%s, m=%s, col=%u, val=%?)", diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index d4ed0004c8f..4836ce062c9 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -802,13 +802,36 @@ pub fn trans_external_path(ccx: @CrateContext, did: ast::def_id, t: ty::t) pub fn invoke(bcx: block, llfn: ValueRef, +llargs: ~[ValueRef]) -> block { let _icx = bcx.insn_ctxt("invoke_"); if bcx.unreachable { return bcx; } + + match bcx.node_info { + None => error!("invoke at ???"), + Some(node_info) => { + error!("invoke at %s", + bcx.sess().codemap.span_to_str(node_info.span)); + } + } + if need_invoke(bcx) { - log(debug, ~"invoking"); + unsafe { + debug!("invoking %x at %x", + ::core::cast::transmute(llfn), + ::core::cast::transmute(bcx.llbb)); + for llargs.each |&llarg| { + debug!("arg: %x", ::core::cast::transmute(llarg)); + } + } let normal_bcx = sub_block(bcx, ~"normal return"); Invoke(bcx, llfn, llargs, normal_bcx.llbb, get_landing_pad(bcx)); return normal_bcx; } else { - log(debug, ~"calling"); + unsafe { + debug!("calling %x at %x", + ::core::cast::transmute(llfn), + ::core::cast::transmute(bcx.llbb)); + for llargs.each |&llarg| { + debug!("arg: %x", ::core::cast::transmute(llarg)); + } + } Call(bcx, llfn, llargs); return bcx; } @@ -831,7 +854,9 @@ pub fn need_invoke(bcx: block) -> bool { // Walk the scopes to look for cleanups let mut cur = bcx; loop { - match *cur.kind { + let current = &mut *cur; + let kind = &mut *current.kind; + match *kind { block_scope(ref mut inf) => { for vec::each((*inf).cleanups) |cleanup| { match *cleanup { @@ -845,7 +870,7 @@ pub fn need_invoke(bcx: block) -> bool { } _ => () } - cur = match cur.parent { + cur = match current.parent { Some(next) => next, None => return false } @@ -867,7 +892,7 @@ pub fn in_lpad_scope_cx(bcx: block, f: &fn(+si: &mut scope_info)) { let mut bcx = bcx; loop { { - // XXX: Borrow check bug workaround. + // FIXME #4280: Borrow check bug workaround. let kind: &mut block_kind = &mut *bcx.kind; match *kind { block_scope(ref mut inf) => { @@ -1272,7 +1297,7 @@ pub fn cleanup_and_leave(bcx: block, } { - // XXX: Borrow check bug workaround. + // FIXME #4280: Borrow check bug workaround. let kind: &mut block_kind = &mut *cur.kind; match *kind { block_scope(ref mut inf) if !inf.cleanups.is_empty() => { @@ -1487,7 +1512,7 @@ pub fn alloc_ty(bcx: block, t: ty::t) -> ValueRef { let _icx = bcx.insn_ctxt("alloc_ty"); let ccx = bcx.ccx(); let llty = type_of::type_of(ccx, t); - if ty::type_has_params(t) { log(error, ty_to_str(ccx.tcx, t)); } + if ty::type_has_params(t) { error!("%s", ty_to_str(ccx.tcx, t)); } fail_unless!(!ty::type_has_params(t)); let val = alloca(bcx, llty); return val; @@ -1682,12 +1707,6 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt, add_clean(bcx, llarg, arg_ty.ty); } - ast::by_val => { - // always by value, also not owned, so don't add a cleanup: - let alloc = alloc_ty(bcx, arg_ty.ty); - Store(bcx, raw_llarg, alloc); - llarg = alloc; - } } bcx = _match::bind_irrefutable_pat(bcx, @@ -1812,7 +1831,7 @@ pub fn trans_fn(ccx: @CrateContext, debug!("trans_fn(ty_self=%?)", ty_self); let _icx = ccx.insn_ctxt("trans_fn"); ccx.stats.n_fns += 1; - let the_path_str = path_str(ccx.sess, &path); + let the_path_str = path_str(ccx.sess, path); trans_closure(ccx, path, decl, body, llfndecl, ty_self, param_substs, id, impl_id, |fcx| { @@ -1850,8 +1869,7 @@ pub fn trans_enum_variant(ccx: @CrateContext, }; let fcx = new_fn_ctxt_w_id(ccx, ~[], llfndecl, variant.node.id, None, param_substs, None); - // XXX: Bad copy. - let raw_llargs = create_llargs_for_fn_args(fcx, no_self, copy fn_args); + let raw_llargs = create_llargs_for_fn_args(fcx, no_self, fn_args); let ty_param_substs = match param_substs { Some(ref substs) => /*bad*/copy substs.tys, None => ~[] diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs index 50a7669a1be..96c124d60de 100644 --- a/src/librustc/middle/trans/build.rs +++ b/src/librustc/middle/trans/build.rs @@ -50,7 +50,7 @@ pub fn count_insn(cx: block, category: &str) { if cx.ccx().sess.count_llvm_insns() { let h = cx.ccx().stats.llvm_insns; - let v = cx.ccx().stats.llvm_insn_ctxt; + let v = &*cx.ccx().stats.llvm_insn_ctxt; // Build version of path with cycles removed. @@ -848,7 +848,7 @@ pub fn add_span_comment(bcx: block, sp: span, text: &str) { let ccx = bcx.ccx(); if !ccx.sess.no_asm_comments() { let s = fmt!("%s (%s)", text, ccx.sess.codemap.span_to_str(sp)); - log(debug, copy s); + debug!("%s", copy s); add_comment(bcx, s); } } @@ -873,6 +873,7 @@ pub fn add_comment(bcx: block, text: &str) { } pub fn InlineAsmCall(cx: block, asm: *c_char, cons: *c_char, + inputs: &[ValueRef], output: TypeRef, volatile: bool, alignstack: bool, dia: AsmDialect) -> ValueRef { unsafe { @@ -883,11 +884,17 @@ pub fn InlineAsmCall(cx: block, asm: *c_char, cons: *c_char, let alignstack = if alignstack { lib::llvm::True } else { lib::llvm::False }; - let llfty = T_fn(~[], T_void()); + let argtys = do inputs.map |v| { + debug!("Asm Input Type: %?", val_str(cx.ccx().tn, *v)); + val_ty(*v) + }; + + debug!("Asm Output Type: %?", ty_str(cx.ccx().tn, output)); + let llfty = T_fn(argtys, output); let v = llvm::LLVMInlineAsm(llfty, asm, cons, volatile, - alignstack, dia); + alignstack, dia as c_uint); - Call(cx, v, ~[]) + Call(cx, v, inputs) } } diff --git a/src/librustc/middle/trans/cabi_x86_64.rs b/src/librustc/middle/trans/cabi_x86_64.rs index d5877ec5631..f7226812b96 100644 --- a/src/librustc/middle/trans/cabi_x86_64.rs +++ b/src/librustc/middle/trans/cabi_x86_64.rs @@ -406,6 +406,6 @@ impl ABIInfo for X86_64_ABIInfo { } } -pub fn x86_64_abi_info() -> ABIInfo { +pub fn x86_64_abi_info() -> @ABIInfo { return @X86_64_ABIInfo as @ABIInfo; } diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 9e38252dc9a..81d85773ccb 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -550,8 +550,8 @@ pub fn trans_call_inner( pub enum CallArgs { - ArgExprs(&self/[@ast::expr]), - ArgVals(&self/[ValueRef]) + ArgExprs(&'self [@ast::expr]), + ArgVals(&'self [ValueRef]) } pub struct Args { @@ -720,14 +720,6 @@ pub fn trans_arg_expr(bcx: block, val = arg_datum.to_ref_llval(bcx); } - ast::by_val => { - // NB: avoid running the take glue. - - fail_unless!(!bcx.ccx().maps.moves_map.contains_key( - &arg_expr.id)); - val = arg_datum.to_value_llval(bcx); - } - ast::by_copy => { debug!("by copy arg with type %s, storing to scratch", bcx.ty_to_str(arg_datum.ty)); @@ -757,7 +749,7 @@ pub fn trans_arg_expr(bcx: block, if formal_ty.ty != arg_datum.ty { // this could happen due to e.g. subtyping - let llformal_ty = type_of::type_of_explicit_arg(ccx, formal_ty); + let llformal_ty = type_of::type_of_explicit_arg(ccx, &formal_ty); debug!("casting actual type (%s) to match formal (%s)", bcx.val_str(val), bcx.llty_str(llformal_ty)); val = PointerCast(bcx, val, llformal_ty); diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index c4b80c504da..04e25bdbf21 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -54,7 +54,7 @@ use core::vec::raw::to_ptr; use core::vec; use std::oldmap::{HashMap, Set}; use syntax::ast::ident; -use syntax::ast_map::path; +use syntax::ast_map::{path, path_elt}; use syntax::codemap::span; use syntax::parse::token::ident_interner; use syntax::{ast, ast_map}; @@ -590,7 +590,7 @@ pub struct block_ { fcx: fn_ctxt } -pub fn block_(llbb: BasicBlockRef, parent: Option<block>, -kind: block_kind, +pub fn block_(llbb: BasicBlockRef, parent: Option<block>, +kind: block_kind, is_lpad: bool, node_info: Option<NodeInfo>, fcx: fn_ctxt) -> block_ { @@ -608,7 +608,7 @@ pub fn block_(llbb: BasicBlockRef, parent: Option<block>, -kind: block_kind, pub type block = @mut block_; -pub fn mk_block(llbb: BasicBlockRef, parent: Option<block>, -kind: block_kind, +pub fn mk_block(llbb: BasicBlockRef, parent: Option<block>, +kind: block_kind, is_lpad: bool, node_info: Option<NodeInfo>, fcx: fn_ctxt) -> block { @mut block_(llbb, parent, kind, is_lpad, node_info, fcx) @@ -677,28 +677,28 @@ pub fn block_parent(cx: block) -> block { // Accessors -pub impl block { - pure fn ccx(&self) -> @CrateContext { *self.fcx.ccx } - pure fn tcx(&self) -> ty::ctxt { self.fcx.ccx.tcx } - pure fn sess(&self) -> Session { self.fcx.ccx.sess } +pub impl block_ { + pure fn ccx(@mut self) -> @CrateContext { *self.fcx.ccx } + pure fn tcx(@mut self) -> ty::ctxt { self.fcx.ccx.tcx } + pure fn sess(@mut self) -> Session { self.fcx.ccx.sess } - fn node_id_to_str(&self, id: ast::node_id) -> ~str { + fn node_id_to_str(@mut self, id: ast::node_id) -> ~str { ast_map::node_id_to_str(self.tcx().items, id, self.sess().intr()) } - fn expr_to_str(&self, e: @ast::expr) -> ~str { + fn expr_to_str(@mut self, e: @ast::expr) -> ~str { expr_repr(self.tcx(), e) } - fn expr_is_lval(&self, e: @ast::expr) -> bool { + fn expr_is_lval(@mut self, e: @ast::expr) -> bool { ty::expr_is_lval(self.tcx(), self.ccx().maps.method_map, e) } - fn expr_kind(&self, e: @ast::expr) -> ty::ExprKind { + fn expr_kind(@mut self, e: @ast::expr) -> ty::ExprKind { ty::expr_kind(self.tcx(), self.ccx().maps.method_map, e) } - fn def(&self, nid: ast::node_id) -> ast::def { + fn def(@mut self, nid: ast::node_id) -> ast::def { match self.tcx().def_map.find(&nid) { Some(v) => v, None => { @@ -708,18 +708,18 @@ pub impl block { } } - fn val_str(&self, val: ValueRef) -> @str { + fn val_str(@mut self, val: ValueRef) -> @str { val_str(self.ccx().tn, val) } - fn llty_str(&self, llty: TypeRef) -> @str { + fn llty_str(@mut self, llty: TypeRef) -> @str { ty_str(self.ccx().tn, llty) } - fn ty_to_str(&self, t: ty::t) -> ~str { + fn ty_to_str(@mut self, t: ty::t) -> ~str { ty_to_str(self.tcx(), t) } - fn to_str(&self) -> ~str { + fn to_str(@mut self) -> ~str { match self.node_info { Some(node_info) => { fmt!("[block %d]", node_info.id) @@ -1033,17 +1033,22 @@ pub fn T_captured_tydescs(cx: @CrateContext, n: uint) -> TypeRef { return T_struct(vec::from_elem::<TypeRef>(n, T_ptr(cx.tydesc_type))); } -pub fn T_opaque_trait(cx: @CrateContext, vstore: ty::vstore) -> TypeRef { - match vstore { - ty::vstore_box => { +pub fn T_opaque_trait(cx: @CrateContext, store: ty::TraitStore) -> TypeRef { + match store { + ty::BoxTraitStore => { T_struct(~[T_ptr(cx.tydesc_type), T_opaque_box_ptr(cx)]) } - ty::vstore_uniq => { + ty::UniqTraitStore => { T_struct(~[T_ptr(cx.tydesc_type), T_unique_ptr(T_unique(cx, T_i8())), T_ptr(cx.tydesc_type)]) } - _ => T_struct(~[T_ptr(cx.tydesc_type), T_ptr(T_i8())]) + ty::RegionTraitStore(_) => { + T_struct(~[T_ptr(cx.tydesc_type), T_ptr(T_i8())]) + } + ty::BareTraitStore => { + cx.sess.bug(~"can't make T_opaque_trait with bare trait store") + } } } @@ -1320,9 +1325,9 @@ pub fn align_to(cx: block, off: ValueRef, align: ValueRef) -> ValueRef { return build::And(cx, bumped, build::Not(cx, mask)); } -pub fn path_str(sess: session::Session, p: &path) -> ~str { +pub fn path_str(sess: session::Session, p: &[path_elt]) -> ~str { let mut r = ~"", first = true; - for vec::each(*p) |e| { + for p.each |e| { match *e { ast_map::path_name(s) | ast_map::path_mod(s) => { if first { first = false; } diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index e60223c9eff..616a5f99499 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -30,7 +30,6 @@ use syntax::ast::ident; use syntax::ast_map::path_mod; use syntax::ast_util; use syntax::codemap::span; -use syntax::print::pprust::expr_to_str; pub fn trans_block(bcx: block, b: &ast::blk, dest: expr::Dest) -> block { let _icx = bcx.insn_ctxt("trans_block"); @@ -187,12 +186,14 @@ pub fn trans_log(log_ex: @ast::expr, return expr::trans_into(bcx, lvl, expr::Ignore); } - let modpath = vec::append( - ~[path_mod(ccx.sess.ident_of(ccx.link_meta.name.to_owned()))], - bcx.fcx.path.filtered(|e| - match *e { path_mod(_) => true, _ => false } - )); - let modname = path_str(ccx.sess, &modpath); + let (modpath, modname) = { + let path = &mut bcx.fcx.path; + let modpath = vec::append( + ~[path_mod(ccx.sess.ident_of(ccx.link_meta.name.to_owned()))], + path.filtered(|e| match *e { path_mod(_) => true, _ => false })); + let modname = path_str(ccx.sess, modpath); + (modpath, modname) + }; let global = if ccx.module_data.contains_key(&modname) { ccx.module_data.get(&modname) diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index 11d3e155202..9b3ec5ef842 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -617,7 +617,7 @@ pub impl Datum { // using `to_ref_llval()`). // Convert to ref, yielding lltype *T. Then create a Rust - // type &static/T (which translates to *T). Construct new + // type &'static T (which translates to *T). Construct new // result (which will be by-value). Note that it is not // significant *which* region we pick here. let llval = self.to_ref_llval(bcx); diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index af54d473431..e4b9d01c509 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -356,7 +356,31 @@ fn create_basic_type(cx: @CrateContext, t: ty::t, span: span) option::None => () } - let (name, encoding) = (~"uint", DW_ATE_unsigned); + let (name, encoding) = match ty::get(t).sty { + ty::ty_nil | ty::ty_bot => (~"uint", DW_ATE_unsigned), + ty::ty_bool => (~"bool", DW_ATE_boolean), + ty::ty_int(int_ty) => match int_ty { + ast::ty_i => (~"int", DW_ATE_signed), + ast::ty_char => (~"char", DW_ATE_signed_char), + ast::ty_i8 => (~"i8", DW_ATE_signed), + ast::ty_i16 => (~"i16", DW_ATE_signed), + ast::ty_i32 => (~"i32", DW_ATE_signed), + ast::ty_i64 => (~"i64", DW_ATE_signed) + }, + ty::ty_uint(uint_ty) => match uint_ty { + ast::ty_u => (~"uint", DW_ATE_unsigned), + ast::ty_u8 => (~"u8", DW_ATE_unsigned), + ast::ty_u16 => (~"i16", DW_ATE_unsigned), + ast::ty_u32 => (~"u32", DW_ATE_unsigned), + ast::ty_u64 => (~"u64", DW_ATE_unsigned) + }, + ty::ty_float(float_ty) => match float_ty { + ast::ty_f => (~"float", DW_ATE_float), + ast::ty_f32 => (~"f32", DW_ATE_float), + ast::ty_f64 => (~"f64", DW_ATE_float) + }, + _ => cx.sess.bug(~"debuginfo::create_basic_type - t is invalid type") + }; let fname = filename_from_span(cx, span); let file_node = create_file(cx, fname); @@ -473,6 +497,53 @@ fn add_member(cx: @mut StructCtxt, cx.total_size += size * 8; } +fn create_struct(cx: @CrateContext, t: ty::t, fields: ~[ty::field], + span: span) -> @Metadata<TyDescMetadata> { + let fname = filename_from_span(cx, span); + let file_node = create_file(cx, fname); + let scx = create_structure(file_node, @ty_to_str(cx.tcx, t), + line_from_span(cx.sess.codemap, span) as int); + for fields.each |field| { + let field_t = field.mt.ty; + let ty_md = create_ty(cx, field_t, span); + let (size, align) = size_and_align_of(cx, field_t); + add_member(scx, *cx.sess.str_of(field.ident), + line_from_span(cx.sess.codemap, span) as int, + size as int, align as int, ty_md.node); + } + let mdval = @Metadata { + node: finish_structure(scx), + data: TyDescMetadata { + hash: ty::type_id(t) + } + }; + return mdval; +} + +fn create_tuple(cx: @CrateContext, t: ty::t, elements: ~[ty::t], span: span) + -> @Metadata<TyDescMetadata> { + let fname = filename_from_span(cx, span); + let file_node = create_file(cx, fname); + let scx = create_structure(file_node, + cx.sess.str_of( + ((/*bad*/copy cx.dbg_cx).get().names) + (~"tuple")), + line_from_span(cx.sess.codemap, span) as int); + for elements.each |element| { + let ty_md = create_ty(cx, *element, span); + let (size, align) = size_and_align_of(cx, *element); + add_member(scx, ~"", line_from_span(cx.sess.codemap, span) as int, + size as int, align as int, ty_md.node); + } + let mdval = @Metadata { + node: finish_structure(scx), + data: TyDescMetadata { + hash: ty::type_id(t) + } + }; + return mdval; +} + fn create_boxed_type(cx: @CrateContext, outer: ty::t, _inner: ty::t, span: span, boxed: @Metadata<TyDescMetadata>) -> @Metadata<TyDescMetadata> { @@ -538,11 +609,10 @@ fn create_composite_type(type_tag: int, name: &str, file: ValueRef, } fn create_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t, - vec_ty_span: codemap::span, elem_ty: @ast::Ty) - -> @Metadata<TyDescMetadata> { + vec_ty_span: codemap::span) -> @Metadata<TyDescMetadata> { let fname = filename_from_span(cx, vec_ty_span); let file_node = create_file(cx, fname); - let elem_ty_md = create_ty(cx, elem_t, elem_ty); + let elem_ty_md = create_ty(cx, elem_t, vec_ty_span); let scx = create_structure(file_node, @/*bad*/ copy ty_to_str(cx.tcx, vec_t), 0); let size_t_type = create_basic_type(cx, ty::mk_uint(cx.tcx), vec_ty_span); @@ -567,8 +637,9 @@ fn create_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t, } } -fn create_ty(_cx: @CrateContext, _t: ty::t, _ty: @ast::Ty) +fn create_ty(cx: @CrateContext, t: ty::t, span: span) -> @Metadata<TyDescMetadata> { + debug!("create_ty: %?", ty::get(t)); /*let cache = get_cache(cx); match cached_metadata::<@Metadata<TyDescMetadata>>( cache, tg, {|md| t == md.data.hash}) { @@ -576,85 +647,50 @@ fn create_ty(_cx: @CrateContext, _t: ty::t, _ty: @ast::Ty) option::None {} }*/ - /* FIXME (#2012): disabled this code as part of the patch that moves - * recognition of named builtin types into resolve. I tried to fix - * it, but it seems to already be broken -- it's only called when - * --xg is given, and compiling with --xg fails on trivial programs. - * - * Generating an ast::ty from a ty::t seems like it should not be - * needed. It is only done to track spans, but you will not get the - * right spans anyway -- types tend to refer to stuff defined - * elsewhere, not be self-contained. - */ - - fail!(); - /* - fn t_to_ty(cx: CrateContext, t: ty::t, span: span) -> @ast::ty { - let ty = match ty::get(t).struct { - ty::ty_nil { ast::ty_nil } - ty::ty_bot { ast::ty_bot } - ty::ty_bool { ast::ty_bool } - ty::ty_int(t) { ast::ty_int(t) } - ty::ty_float(t) { ast::ty_float(t) } - ty::ty_uint(t) { ast::ty_uint(t) } - ty::ty_box(mt) { ast::ty_box({ty: t_to_ty(cx, mt.ty, span), - mutbl: mt.mutbl}) } - ty::ty_uniq(mt) { ast::ty_uniq({ty: t_to_ty(cx, mt.ty, span), - mutbl: mt.mutbl}) } - ty::ty_vec(mt) { ast::ty_vec({ty: t_to_ty(cx, mt.ty, span), - mutbl: mt.mutbl}) } - _ { - cx.sess.span_bug(span, "t_to_ty: Can't handle this type"); - } - }; - return @{node: ty, span: span}; - } - - match ty.node { - ast::ty_box(mt) { - let inner_t = match ty::get(t).struct { - ty::ty_box(boxed) { boxed.ty } - _ { cx.sess.span_bug(ty.span, "t_to_ty was incoherent"); } - }; - let md = create_ty(cx, inner_t, mt.ty); - let box = create_boxed_type(cx, t, inner_t, ty.span, md); - return create_pointer_type(cx, t, ty.span, box); - } - - ast::ty_uniq(mt) { - let inner_t = match ty::get(t).struct { - ty::ty_uniq(boxed) { boxed.ty } - // Hoping we'll have a way to eliminate this check soon. - _ { cx.sess.span_bug(ty.span, "t_to_ty was incoherent"); } - }; - let md = create_ty(cx, inner_t, mt.ty); - return create_pointer_type(cx, t, ty.span, md); - } - - ast::ty_infer { - let inferred = t_to_ty(cx, t, ty.span); - return create_ty(cx, t, inferred); - } - - ast::ty_vec(mt) { - let inner_t = ty::sequence_element_type(cx.tcx, t); - let inner_ast_t = t_to_ty(cx, inner_t, mt.ty.span); - let v = create_vec(cx, t, inner_t, ty.span, inner_ast_t); - return create_pointer_type(cx, t, ty.span, v); - } - - ast::ty_path(_, id) { - match cx.tcx.def_map.get(id) { - ast::def_prim_ty(pty) { - return create_basic_type(cx, t, pty, ty.span); - } - _ {} + let sty = copy ty::get(t).sty; + match copy sty { + ty::ty_nil | ty::ty_bot | ty::ty_bool | ty::ty_int(_) | ty::ty_uint(_) + | ty::ty_float(_) => create_basic_type(cx, t, span), + ty::ty_estr(_vstore) => { + cx.sess.span_bug(span, ~"debuginfo for estr NYI") + }, + ty::ty_enum(_did, _substs) => { + cx.sess.span_bug(span, ~"debuginfo for enum NYI") } - } - - _ {} - }; - */ + ty::ty_box(_mt) => { + cx.sess.span_bug(span, ~"debuginfo for box NYI") + }, + ty::ty_uniq(_mt) => { + cx.sess.span_bug(span, ~"debuginfo for uniq NYI") + }, + ty::ty_evec(_mt, _vstore) => { + cx.sess.span_bug(span, ~"debuginfo for evec NYI") + }, + ty::ty_ptr(mt) => { + let pointee = create_ty(cx, mt.ty, span); + create_pointer_type(cx, t, span, pointee) + }, + ty::ty_rptr(_region, _mt) => { + cx.sess.span_bug(span, ~"debuginfo for rptr NYI") + }, + ty::ty_bare_fn(_barefnty) => { + cx.sess.span_bug(span, ~"debuginfo for bare_fn NYI") + }, + ty::ty_closure(_closurety) => { + cx.sess.span_bug(span, ~"debuginfo for closure NYI") + }, + ty::ty_trait(_did, _substs, _vstore) => { + cx.sess.span_bug(span, ~"debuginfo for trait NYI") + }, + ty::ty_struct(did, substs) => { + let fields = ty::struct_fields(cx.tcx, did, &substs); + create_struct(cx, t, fields, span) + }, + ty::ty_tup(elements) => { + create_tuple(cx, t, elements, span) + }, + _ => cx.sess.bug(~"debuginfo: unexpected type in create_ty") + } } fn filename_from_span(cx: @CrateContext, sp: codemap::span) -> ~str { @@ -693,7 +729,7 @@ pub fn create_local_var(bcx: block, local: @ast::local) }; let loc = cx.sess.codemap.lookup_char_pos(local.span.lo); let ty = node_id_type(bcx, local.node.id); - let tymd = create_ty(cx, ty, local.node.ty); + let tymd = create_ty(cx, ty, local.node.ty.span); let filemd = create_file(cx, /*bad*/copy loc.file.name); let context = match bcx.parent { None => create_function(bcx.fcx).node, @@ -743,8 +779,11 @@ pub fn create_arg(bcx: block, arg: ast::arg, sp: span) } let loc = cx.sess.codemap.lookup_char_pos(sp.lo); + if loc.file.name == ~"<intrinsic>" { + return None; + } let ty = node_id_type(bcx, arg.id); - let tymd = create_ty(cx, ty, arg.ty); + let tymd = create_ty(cx, ty, arg.ty.span); let filemd = create_file(cx, /*bad*/copy loc.file.name); let context = create_function(bcx.fcx); @@ -806,10 +845,11 @@ pub fn create_function(fcx: fn_ctxt) -> @Metadata<SubProgramMetadata> { let dbg_cx = (/*bad*/copy cx.dbg_cx).get(); debug!("~~"); - log(debug, fcx.id); + + let fcx = &mut *fcx; let sp = fcx.span.get(); - log(debug, cx.sess.codemap.span_to_str(sp)); + debug!("%s", cx.sess.codemap.span_to_str(sp)); let (ident, ret_ty, id) = match cx.tcx.items.get(&fcx.id) { ast_map::node_item(item, _) => { @@ -841,8 +881,8 @@ pub fn create_function(fcx: fn_ctxt) -> @Metadata<SubProgramMetadata> { sort of node") }; - log(debug, ident); - log(debug, id); + debug!("%?", ident); + debug!("%?", id); let cache = get_cache(cx); match cached_metadata::<@Metadata<SubProgramMetadata>>( @@ -856,7 +896,8 @@ pub fn create_function(fcx: fn_ctxt) -> @Metadata<SubProgramMetadata> { let ty_node = if cx.sess.opts.extra_debuginfo { match ret_ty.node { ast::ty_nil => llnull(), - _ => create_ty(cx, ty::node_id_to_type(cx.tcx, id), ret_ty).node + _ => create_ty(cx, ty::node_id_to_type(cx.tcx, id), + ret_ty.span).node } } else { llnull() diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index c163183bfc8..fb63f5384fb 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -557,6 +557,109 @@ fn trans_rvalue_stmt_unadjusted(bcx: block, expr: @ast::expr) -> block { ast::expr_paren(a) => { return trans_rvalue_stmt_unadjusted(bcx, a); } + ast::expr_inline_asm(asm, ref ins, ref outs, + clobs, volatile, alignstack) => { + let mut constraints = ~[]; + let mut cleanups = ~[]; + let mut aoutputs = ~[]; + + let outputs = do outs.map |&(c, out)| { + constraints.push(copy *c); + + let aoutty = ty::arg { + mode: ast::expl(ast::by_copy), + ty: expr_ty(bcx, out) + }; + aoutputs.push(unpack_result!(bcx, { + callee::trans_arg_expr(bcx, aoutty, out, &mut cleanups, + None, callee::DontAutorefArg) + })); + + let e = match out.node { + ast::expr_addr_of(_, e) => e, + _ => fail!(~"Expression must be addr of") + }; + + let outty = ty::arg { + mode: ast::expl(ast::by_copy), + ty: expr_ty(bcx, e) + }; + + unpack_result!(bcx, { + callee::trans_arg_expr(bcx, outty, e, &mut cleanups, + None, callee::DontAutorefArg) + }) + + }; + + for cleanups.each |c| { + revoke_clean(bcx, *c); + } + cleanups = ~[]; + + let inputs = do ins.map |&(c, in)| { + constraints.push(copy *c); + + let inty = ty::arg { + mode: ast::expl(ast::by_copy), + ty: expr_ty(bcx, in) + }; + + unpack_result!(bcx, { + callee::trans_arg_expr(bcx, inty, in, &mut cleanups, + None, callee::DontAutorefArg) + }) + + }; + + for cleanups.each |c| { + revoke_clean(bcx, *c); + } + + let mut constraints = str::connect(constraints, ","); + + // Add the clobbers + if *clobs != ~"" { + if constraints == ~"" { + constraints += *clobs; + } else { + constraints += ~"," + *clobs; + } + } else { + constraints += *clobs; + } + + debug!("Asm Constraints: %?", constraints); + + let output = if outputs.len() == 0 { + T_void() + } else if outputs.len() == 1 { + val_ty(outputs[0]) + } else { + T_struct(outputs.map(|o| val_ty(*o))) + }; + + let r = do str::as_c_str(*asm) |a| { + do str::as_c_str(constraints) |c| { + InlineAsmCall(bcx, a, c, inputs, output, volatile, + alignstack, lib::llvm::AD_ATT) + } + }; + + if outputs.len() == 1 { + let op = PointerCast(bcx, aoutputs[0], + T_ptr(val_ty(outputs[0]))); + Store(bcx, r, op); + } else { + for aoutputs.eachi |i, o| { + let v = ExtractValue(bcx, r, i); + let op = PointerCast(bcx, *o, T_ptr(val_ty(outputs[i]))); + Store(bcx, v, op); + } + } + + return bcx; + } _ => { bcx.tcx().sess.span_bug( expr.span, @@ -678,9 +781,9 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr, } ast::expr_cast(val, _) => { match ty::get(node_id_type(bcx, expr.id)).sty { - ty::ty_trait(_, _, vstore) => { + ty::ty_trait(_, _, store) => { return meth::trans_trait_cast(bcx, val, expr.id, dest, - vstore); + store); } _ => { bcx.tcx().sess.span_bug(expr.span, @@ -691,17 +794,6 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr, ast::expr_assign_op(op, dst, src) => { return trans_assign_op(bcx, expr, op, dst, src); } - ast::expr_inline_asm(asm, cons, volatile, alignstack) => { - // XXX: cons doesn't actual contain ALL the stuff we should - // be passing since the constraints for in/outputs aren't included - do str::as_c_str(*asm) |a| { - do str::as_c_str(*cons) |c| { - InlineAsmCall(bcx, a, c, volatile, alignstack, - lib::llvm::AD_ATT); - } - } - return bcx; - } _ => { bcx.tcx().sess.span_bug( expr.span, diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 1e3c4f21bd8..8dd55c9a37b 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -42,7 +42,7 @@ use syntax::{ast, ast_util}; use syntax::{attr, ast_map}; use syntax::parse::token::special_idents; -fn abi_info(arch: session::arch) -> cabi::ABIInfo { +fn abi_info(arch: session::arch) -> @cabi::ABIInfo { return match arch { arch_x86_64 => x86_64_abi_info(), arch_arm => cabi_arm::abi_info(), @@ -58,59 +58,90 @@ pub fn link_name(ccx: @CrateContext, i: @ast::foreign_item) -> @~str { } } -struct c_stack_tys { - arg_tys: ~[TypeRef], - ret_ty: TypeRef, +struct ShimTypes { + fn_sig: ty::FnSig, + + /// LLVM types that will appear on the foreign function + llsig: LlvmSignature, + + /// True if there is a return value (not bottom, not unit) ret_def: bool, + + /// Type of the struct we will use to shuttle values back and forth. + /// This is always derived from the llsig. bundle_ty: TypeRef, + + /// Type of the shim function itself. shim_fn_ty: TypeRef, + + /// Adapter object for handling native ABI rules (trust me, you + /// don't want to know). fn_ty: cabi::FnType } -fn c_arg_and_ret_lltys(ccx: @CrateContext, - id: ast::node_id) -> (~[TypeRef], TypeRef, ty::t) { - match ty::get(ty::node_id_to_type(ccx.tcx, id)).sty { - ty::ty_bare_fn(ref fn_ty) => { - let llargtys = type_of_explicit_args(ccx, fn_ty.sig.inputs); - let llretty = type_of::type_of(ccx, fn_ty.sig.output); - (llargtys, llretty, fn_ty.sig.output) - } - _ => ccx.sess.bug(~"c_arg_and_ret_lltys called on non-function type") - } +struct LlvmSignature { + llarg_tys: ~[TypeRef], + llret_ty: TypeRef, } -fn c_stack_tys(ccx: @CrateContext, - id: ast::node_id) -> @c_stack_tys { - let (llargtys, llretty, ret_ty) = c_arg_and_ret_lltys(ccx, id); - // XXX: Bad copy. - let bundle_ty = T_struct(vec::append_one(copy llargtys, T_ptr(llretty))); - let ret_def = !ty::type_is_bot(ret_ty) && !ty::type_is_nil(ret_ty); - let fn_ty = abi_info(ccx.sess.targ_cfg.arch). - compute_info(llargtys, llretty, ret_def); - return @c_stack_tys { - arg_tys: llargtys, - ret_ty: llretty, +fn foreign_signature(ccx: @CrateContext, + fn_sig: &ty::FnSig) -> LlvmSignature { + /*! + * The ForeignSignature is the LLVM types of the arguments/return type + * of a function. Note that these LLVM types are not quite the same + * as the LLVM types would be for a native Rust function because foreign + * functions just plain ignore modes. They also don't pass aggregate + * values by pointer like we do. + */ + + let llarg_tys = fn_sig.inputs.map(|arg| type_of(ccx, arg.ty)); + let llret_ty = type_of::type_of(ccx, fn_sig.output); + LlvmSignature {llarg_tys: llarg_tys, llret_ty: llret_ty} +} + +fn shim_types(ccx: @CrateContext, id: ast::node_id) -> ShimTypes { + let fn_sig = match ty::get(ty::node_id_to_type(ccx.tcx, id)).sty { + ty::ty_bare_fn(ref fn_ty) => copy fn_ty.sig, + _ => ccx.sess.bug(~"c_arg_and_ret_lltys called on non-function type") + }; + let llsig = foreign_signature(ccx, &fn_sig); + let bundle_ty = T_struct(vec::append_one(copy llsig.llarg_tys, + T_ptr(llsig.llret_ty))); + let ret_def = + !ty::type_is_bot(fn_sig.output) && + !ty::type_is_nil(fn_sig.output); + let fn_ty = + abi_info(ccx.sess.targ_cfg.arch).compute_info( + llsig.llarg_tys, + llsig.llret_ty, + ret_def); + ShimTypes { + fn_sig: fn_sig, + llsig: llsig, ret_def: ret_def, bundle_ty: bundle_ty, shim_fn_ty: T_fn(~[T_ptr(bundle_ty)], T_void()), fn_ty: fn_ty - }; + } } -type shim_arg_builder = &self/fn(bcx: block, tys: @c_stack_tys, - llargbundle: ValueRef) -> ~[ValueRef]; +type shim_arg_builder<'self> = + &'self fn(bcx: block, tys: &ShimTypes, + llargbundle: ValueRef) -> ~[ValueRef]; -type shim_ret_builder = &self/fn(bcx: block, tys: @c_stack_tys, - llargbundle: ValueRef, llretval: ValueRef); +type shim_ret_builder<'self> = + &'self fn(bcx: block, tys: &ShimTypes, + llargbundle: ValueRef, + llretval: ValueRef); fn build_shim_fn_(ccx: @CrateContext, +shim_name: ~str, llbasefn: ValueRef, - tys: @c_stack_tys, + tys: &ShimTypes, cc: lib::llvm::CallConv, arg_builder: shim_arg_builder, - ret_builder: shim_ret_builder) -> ValueRef { - + ret_builder: shim_ret_builder) -> ValueRef +{ let llshimfn = decl_internal_cdecl_fn( ccx.llmod, shim_name, tys.shim_fn_ty); @@ -122,8 +153,7 @@ fn build_shim_fn_(ccx: @CrateContext, let llargvals = arg_builder(bcx, tys, llargbundle); // Create the call itself and store the return value: - let llretval = CallWithConv(bcx, llbasefn, - llargvals, cc); // r + let llretval = CallWithConv(bcx, llbasefn, llargvals, cc); ret_builder(bcx, tys, llargbundle, llretval); @@ -133,21 +163,22 @@ fn build_shim_fn_(ccx: @CrateContext, return llshimfn; } -type wrap_arg_builder = &self/fn(bcx: block, tys: @c_stack_tys, - llwrapfn: ValueRef, - llargbundle: ValueRef); +type wrap_arg_builder<'self> = + &'self fn(bcx: block, tys: &ShimTypes, + llwrapfn: ValueRef, llargbundle: ValueRef); -type wrap_ret_builder = &self/fn(bcx: block, tys: @c_stack_tys, - llargbundle: ValueRef); +type wrap_ret_builder<'self> = + &'self fn(bcx: block, tys: &ShimTypes, + llargbundle: ValueRef); fn build_wrap_fn_(ccx: @CrateContext, - tys: @c_stack_tys, + tys: &ShimTypes, llshimfn: ValueRef, llwrapfn: ValueRef, shim_upcall: ValueRef, arg_builder: wrap_arg_builder, - ret_builder: wrap_ret_builder) { - + ret_builder: wrap_ret_builder) +{ let _icx = ccx.insn_ctxt("foreign::build_wrap_fn_"); let fcx = new_fn_ctxt(ccx, ~[], llwrapfn, None); let bcx = top_scope_block(fcx, None); @@ -199,47 +230,94 @@ fn build_wrap_fn_(ccx: @CrateContext, // F(args->z, args->x, args->y); // } // -// Note: on i386, the layout of the args struct is generally the same as the -// desired layout of the arguments on the C stack. Therefore, we could use -// upcall_alloc_c_stack() to allocate the `args` structure and switch the -// stack pointer appropriately to avoid a round of copies. (In fact, the shim -// function itself is unnecessary). We used to do this, in fact, and will -// perhaps do so in the future. +// Note: on i386, the layout of the args struct is generally the same +// as the desired layout of the arguments on the C stack. Therefore, +// we could use upcall_alloc_c_stack() to allocate the `args` +// structure and switch the stack pointer appropriately to avoid a +// round of copies. (In fact, the shim function itself is +// unnecessary). We used to do this, in fact, and will perhaps do so +// in the future. pub fn trans_foreign_mod(ccx: @CrateContext, foreign_mod: &ast::foreign_mod, - abi: ast::foreign_abi) { - + abi: ast::foreign_abi) +{ let _icx = ccx.insn_ctxt("foreign::trans_foreign_mod"); + let mut cc = match abi { + ast::foreign_abi_rust_intrinsic | + ast::foreign_abi_cdecl => lib::llvm::CCallConv, + ast::foreign_abi_stdcall => lib::llvm::X86StdcallCallConv + }; + + for vec::each(foreign_mod.items) |foreign_item| { + match foreign_item.node { + ast::foreign_item_fn(*) => { + let id = foreign_item.id; + if abi != ast::foreign_abi_rust_intrinsic { + let llwrapfn = get_item_val(ccx, id); + let tys = shim_types(ccx, id); + if attr::attrs_contains_name( + foreign_item.attrs, "rust_stack") + { + build_direct_fn(ccx, llwrapfn, *foreign_item, + &tys, cc); + } else { + let llshimfn = build_shim_fn(ccx, *foreign_item, + &tys, cc); + build_wrap_fn(ccx, &tys, llshimfn, llwrapfn); + } + } else { + // Intrinsics are emitted by monomorphic fn + } + } + ast::foreign_item_const(*) => { + let ident = ccx.sess.parse_sess.interner.get( + foreign_item.ident); + ccx.item_symbols.insert(foreign_item.id, copy *ident); + } + } + } + fn build_shim_fn(ccx: @CrateContext, foreign_item: @ast::foreign_item, - tys: @c_stack_tys, - cc: lib::llvm::CallConv) -> ValueRef { + tys: &ShimTypes, + cc: lib::llvm::CallConv) -> ValueRef + { + /*! + * + * Build S, from comment above: + * + * void S(struct { X x; Y y; Z *z; } *args) { + * F(args->z, args->x, args->y); + * } + */ let _icx = ccx.insn_ctxt("foreign::build_shim_fn"); - fn build_args(bcx: block, tys: @c_stack_tys, + fn build_args(bcx: block, tys: &ShimTypes, llargbundle: ValueRef) -> ~[ValueRef] { let _icx = bcx.insn_ctxt("foreign::shim::build_args"); - return tys.fn_ty.build_shim_args(bcx, tys.arg_tys, llargbundle); + tys.fn_ty.build_shim_args( + bcx, tys.llsig.llarg_tys, llargbundle) } - fn build_ret(bcx: block, tys: @c_stack_tys, + fn build_ret(bcx: block, tys: &ShimTypes, llargbundle: ValueRef, llretval: ValueRef) { let _icx = bcx.insn_ctxt("foreign::shim::build_ret"); - tys.fn_ty.build_shim_ret(bcx, tys.arg_tys, tys.ret_def, - llargbundle, llretval); + tys.fn_ty.build_shim_ret( + bcx, tys.llsig.llarg_tys, + tys.ret_def, llargbundle, llretval); } let lname = link_name(ccx, foreign_item); let llbasefn = base_fn(ccx, *lname, tys, cc); // Name the shim function - let shim_name = lname + ~"__c_stack_shim"; + let shim_name = *lname + ~"__c_stack_shim"; return build_shim_fn_(ccx, shim_name, llbasefn, tys, cc, build_args, build_ret); } - fn base_fn(ccx: @CrateContext, lname: &str, tys: @c_stack_tys, + fn base_fn(ccx: @CrateContext, lname: &str, tys: &ShimTypes, cc: lib::llvm::CallConv) -> ValueRef { // Declare the "prototype" for the base function F: do tys.fn_ty.decl_fn |fnty| { @@ -250,7 +328,7 @@ pub fn trans_foreign_mod(ccx: @CrateContext, // FIXME (#2535): this is very shaky and probably gets ABIs wrong all // over the place fn build_direct_fn(ccx: @CrateContext, decl: ValueRef, - item: @ast::foreign_item, tys: @c_stack_tys, + item: @ast::foreign_item, tys: &ShimTypes, cc: lib::llvm::CallConv) { let fcx = new_fn_ctxt(ccx, ~[], decl, None); let bcx = top_scope_block(fcx, None), lltop = bcx.llbb; @@ -269,66 +347,55 @@ pub fn trans_foreign_mod(ccx: @CrateContext, } fn build_wrap_fn(ccx: @CrateContext, - tys: @c_stack_tys, + tys: &ShimTypes, llshimfn: ValueRef, llwrapfn: ValueRef) { + /*! + * + * Build W, from comment above: + * + * void W(Z* dest, void *env, X x, Y y) { + * struct { X x; Y y; Z *z; } args = { x, y, z }; + * call_on_c_stack_shim(S, &args); + * } + * + * One thing we have to be very careful of is to + * account for the Rust modes. + */ let _icx = ccx.insn_ctxt("foreign::build_wrap_fn"); - fn build_args(bcx: block, tys: @c_stack_tys, + build_wrap_fn_(ccx, tys, llshimfn, llwrapfn, + ccx.upcalls.call_shim_on_c_stack, + build_args, build_ret); + + fn build_args(bcx: block, tys: &ShimTypes, llwrapfn: ValueRef, llargbundle: ValueRef) { let _icx = bcx.insn_ctxt("foreign::wrap::build_args"); - let mut i = 0u; - let n = vec::len(tys.arg_tys); + let ccx = bcx.ccx(); + let n = vec::len(tys.llsig.llarg_tys); let implicit_args = first_real_arg; // return + env - while i < n { - let llargval = get_param(llwrapfn, i + implicit_args); + for uint::range(0, n) |i| { + let mut llargval = get_param(llwrapfn, i + implicit_args); + + // In some cases, Rust will pass a pointer which the + // native C type doesn't have. In that case, just + // load the value from the pointer. + if type_of::arg_is_indirect(ccx, &tys.fn_sig.inputs[i]) { + llargval = Load(bcx, llargval); + } + store_inbounds(bcx, llargval, llargbundle, ~[0u, i]); - i += 1u; } let llretptr = get_param(llwrapfn, 0u); store_inbounds(bcx, llretptr, llargbundle, ~[0u, n]); } - fn build_ret(bcx: block, _tys: @c_stack_tys, + fn build_ret(bcx: block, _tys: &ShimTypes, _llargbundle: ValueRef) { let _icx = bcx.insn_ctxt("foreign::wrap::build_ret"); RetVoid(bcx); } - - build_wrap_fn_(ccx, tys, llshimfn, llwrapfn, - ccx.upcalls.call_shim_on_c_stack, - build_args, build_ret); - } - - let mut cc = match abi { - ast::foreign_abi_rust_intrinsic | - ast::foreign_abi_cdecl => lib::llvm::CCallConv, - ast::foreign_abi_stdcall => lib::llvm::X86StdcallCallConv - }; - - for vec::each(foreign_mod.items) |foreign_item| { - match foreign_item.node { - ast::foreign_item_fn(*) => { - let id = foreign_item.id; - if abi != ast::foreign_abi_rust_intrinsic { - let llwrapfn = get_item_val(ccx, id); - let tys = c_stack_tys(ccx, id); - if attr::attrs_contains_name(foreign_item.attrs, "rust_stack") { - build_direct_fn(ccx, llwrapfn, *foreign_item, tys, cc); - } else { - let llshimfn = build_shim_fn(ccx, *foreign_item, tys, cc); - build_wrap_fn(ccx, tys, llshimfn, llwrapfn); - } - } else { - // Intrinsics are emitted by monomorphic fn - } - } - ast::foreign_item_const(*) => { - let ident = ccx.sess.parse_sess.interner.get(foreign_item.ident); - ccx.item_symbols.insert(foreign_item.id, copy *ident); - } - } } } @@ -842,6 +909,32 @@ pub fn trans_intrinsic(ccx: @CrateContext, finish_fn(fcx, lltop); } +/** + * Translates a "crust" fn, meaning a Rust fn that can be called + * from C code. In this case, we have to perform some adaptation + * to (1) switch back to the Rust stack and (2) adapt the C calling + * convention to our own. + * + * Example: Given a crust fn F(x: X, y: Y) -> Z, we generate a + * Rust function R as normal: + * + * void R(Z* dest, void *env, X x, Y y) {...} + * + * and then we generate a wrapper function W that looks like: + * + * Z W(X x, Y y) { + * struct { X x; Y y; Z *z; } args = { x, y, z }; + * call_on_c_stack_shim(S, &args); + * } + * + * Note that the wrapper follows the foreign (typically "C") ABI. + * The wrapper is the actual "value" of the foreign fn. Finally, + * we generate a shim function S that looks like: + * + * void S(struct { X x; Y y; Z *z; } *args) { + * R(args->z, NULL, args->x, args->y); + * } + */ pub fn trans_foreign_fn(ccx: @CrateContext, +path: ast_map::path, decl: &ast::fn_decl, @@ -867,28 +960,51 @@ pub fn trans_foreign_fn(ccx: @CrateContext, } fn build_shim_fn(ccx: @CrateContext, +path: ast_map::path, - llrustfn: ValueRef, tys: @c_stack_tys) -> ValueRef { + llrustfn: ValueRef, tys: &ShimTypes) -> ValueRef { + /*! + * + * Generate the shim S: + * + * void S(struct { X x; Y y; Z *z; } *args) { + * R(args->z, NULL, &args->x, args->y); + * } + * + * One complication is that we must adapt to the Rust + * calling convention, which introduces indirection + * in some cases. To demonstrate this, I wrote one of the + * entries above as `&args->x`, because presumably `X` is + * one of those types that is passed by pointer in Rust. + */ + let _icx = ccx.insn_ctxt("foreign::foreign::build_shim_fn"); - fn build_args(bcx: block, tys: @c_stack_tys, + fn build_args(bcx: block, tys: &ShimTypes, llargbundle: ValueRef) -> ~[ValueRef] { let _icx = bcx.insn_ctxt("foreign::extern::shim::build_args"); + let ccx = bcx.ccx(); let mut llargvals = ~[]; let mut i = 0u; - let n = vec::len(tys.arg_tys); + let n = tys.fn_sig.inputs.len(); let llretptr = load_inbounds(bcx, llargbundle, ~[0u, n]); llargvals.push(llretptr); let llenvptr = C_null(T_opaque_box_ptr(bcx.ccx())); llargvals.push(llenvptr); while i < n { - let llargval = load_inbounds(bcx, llargbundle, ~[0u, i]); + // Get a pointer to the argument: + let mut llargval = GEPi(bcx, llargbundle, [0u, i]); + + if !type_of::arg_is_indirect(ccx, &tys.fn_sig.inputs[i]) { + // If Rust would pass this by value, load the value. + llargval = Load(bcx, llargval); + } + llargvals.push(llargval); i += 1u; } return llargvals; } - fn build_ret(_bcx: block, _tys: @c_stack_tys, + fn build_ret(_bcx: block, _tys: &ShimTypes, _llargbundle: ValueRef, _llretval: ValueRef) { // Nop. The return pointer in the Rust ABI function // is wired directly into the return slot in the shim struct @@ -904,36 +1020,48 @@ pub fn trans_foreign_fn(ccx: @CrateContext, } fn build_wrap_fn(ccx: @CrateContext, llshimfn: ValueRef, - llwrapfn: ValueRef, tys: @c_stack_tys) { + llwrapfn: ValueRef, tys: &ShimTypes) + { + /*! + * + * Generate the wrapper W: + * + * Z W(X x, Y y) { + * struct { X x; Y y; Z *z; } args = { x, y, z }; + * call_on_c_stack_shim(S, &args); + * } + */ let _icx = ccx.insn_ctxt("foreign::foreign::build_wrap_fn"); - fn build_args(bcx: block, tys: @c_stack_tys, + build_wrap_fn_(ccx, tys, llshimfn, llwrapfn, + ccx.upcalls.call_shim_on_rust_stack, + build_args, build_ret); + + fn build_args(bcx: block, tys: &ShimTypes, llwrapfn: ValueRef, llargbundle: ValueRef) { let _icx = bcx.insn_ctxt("foreign::foreign::wrap::build_args"); - tys.fn_ty.build_wrap_args(bcx, tys.ret_ty, - llwrapfn, llargbundle); + tys.fn_ty.build_wrap_args( + bcx, tys.llsig.llret_ty, + llwrapfn, llargbundle); } - fn build_ret(bcx: block, tys: @c_stack_tys, + fn build_ret(bcx: block, tys: &ShimTypes, llargbundle: ValueRef) { let _icx = bcx.insn_ctxt("foreign::foreign::wrap::build_ret"); - tys.fn_ty.build_wrap_ret(bcx, tys.arg_tys, llargbundle); + tys.fn_ty.build_wrap_ret( + bcx, tys.llsig.llarg_tys, llargbundle); } - - build_wrap_fn_(ccx, tys, llshimfn, llwrapfn, - ccx.upcalls.call_shim_on_rust_stack, - build_args, build_ret); } - let tys = c_stack_tys(ccx, id); + let tys = shim_types(ccx, id); // The internal Rust ABI function - runs on the Rust stack // XXX: Bad copy. let llrustfn = build_rust_fn(ccx, copy path, decl, body, id); // The internal shim function - runs on the Rust stack - let llshimfn = build_shim_fn(ccx, path, llrustfn, tys); + let llshimfn = build_shim_fn(ccx, path, llrustfn, &tys); // The foreign C function - runs on the C stack - build_wrap_fn(ccx, llshimfn, llwrapfn, tys) + build_wrap_fn(ccx, llshimfn, llwrapfn, &tys) } pub fn register_foreign_fn(ccx: @CrateContext, @@ -944,11 +1072,8 @@ pub fn register_foreign_fn(ccx: @CrateContext, -> ValueRef { let _icx = ccx.insn_ctxt("foreign::register_foreign_fn"); let t = ty::node_id_to_type(ccx.tcx, node_id); - let (llargtys, llretty, ret_ty) = c_arg_and_ret_lltys(ccx, node_id); - let ret_def = !ty::type_is_bot(ret_ty) && !ty::type_is_nil(ret_ty); - let fn_ty = abi_info(ccx.sess.targ_cfg.arch). - compute_info(llargtys, llretty, ret_def); - do fn_ty.decl_fn |fnty| { + let tys = shim_types(ccx, node_id); + do tys.fn_ty.decl_fn |fnty| { register_fn_fuller(ccx, sp, /*bad*/copy path, node_id, attrs, t, lib::llvm::CCallConv, fnty) } diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index 7f860bc0c85..284a5eac39d 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -234,18 +234,21 @@ pub fn lazily_emit_simplified_tydesc_glue(ccx: @CrateContext, if simpl != ti.ty { let simpl_ti = get_tydesc(ccx, simpl); lazily_emit_tydesc_glue(ccx, field, simpl_ti); - if field == abi::tydesc_field_take_glue { - ti.take_glue = - simpl_ti.take_glue.map(|v| cast_glue(ccx, ti, *v)); - } else if field == abi::tydesc_field_drop_glue { - ti.drop_glue = - simpl_ti.drop_glue.map(|v| cast_glue(ccx, ti, *v)); - } else if field == abi::tydesc_field_free_glue { - ti.free_glue = - simpl_ti.free_glue.map(|v| cast_glue(ccx, ti, *v)); - } else if field == abi::tydesc_field_visit_glue { - ti.visit_glue = - simpl_ti.visit_glue.map(|v| cast_glue(ccx, ti, *v)); + { + let simpl_ti = &mut *simpl_ti; + if field == abi::tydesc_field_take_glue { + ti.take_glue = + simpl_ti.take_glue.map(|v| cast_glue(ccx, ti, *v)); + } else if field == abi::tydesc_field_drop_glue { + ti.drop_glue = + simpl_ti.drop_glue.map(|v| cast_glue(ccx, ti, *v)); + } else if field == abi::tydesc_field_free_glue { + ti.free_glue = + simpl_ti.free_glue.map(|v| cast_glue(ccx, ti, *v)); + } else if field == abi::tydesc_field_visit_glue { + ti.visit_glue = + simpl_ti.visit_glue.map(|v| cast_glue(ccx, ti, *v)); + } } return true; } @@ -551,11 +554,12 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) { ty::ty_closure(_) => { closure::make_closure_glue(bcx, v0, t, drop_ty) } - ty::ty_trait(_, _, ty::vstore_box) => { + ty::ty_trait(_, _, ty::BoxTraitStore) | + ty::ty_trait(_, _, ty::BareTraitStore) => { let llbox = Load(bcx, GEPi(bcx, v0, [0u, 1u])); decr_refcnt_maybe_free(bcx, llbox, ty::mk_opaque_box(ccx.tcx)) } - ty::ty_trait(_, _, ty::vstore_uniq) => { + ty::ty_trait(_, _, ty::UniqTraitStore) => { let lluniquevalue = GEPi(bcx, v0, [0, 1]); let lltydesc = Load(bcx, GEPi(bcx, v0, [0, 2])); call_tydesc_glue_full(bcx, lluniquevalue, lltydesc, @@ -617,12 +621,13 @@ pub fn make_take_glue(bcx: block, v: ValueRef, t: ty::t) { ty::ty_closure(_) => { closure::make_closure_glue(bcx, v, t, take_ty) } - ty::ty_trait(_, _, ty::vstore_box) => { + ty::ty_trait(_, _, ty::BoxTraitStore) | + ty::ty_trait(_, _, ty::BareTraitStore) => { let llbox = Load(bcx, GEPi(bcx, v, [0u, 1u])); incr_refcnt_of_boxed(bcx, llbox); bcx } - ty::ty_trait(_, _, ty::vstore_uniq) => { + ty::ty_trait(_, _, ty::UniqTraitStore) => { let llval = GEPi(bcx, v, [0, 1]); let lltydesc = Load(bcx, GEPi(bcx, v, [0, 2])); call_tydesc_glue_full(bcx, llval, lltydesc, @@ -708,7 +713,7 @@ pub fn declare_tydesc(ccx: @CrateContext, t: ty::t) -> @mut tydesc_info { free_glue: None, visit_glue: None }; - log(debug, ~"--- declare_tydesc " + ppaux::ty_to_str(ccx.tcx, t)); + debug!("--- declare_tydesc %s", ppaux::ty_to_str(ccx.tcx, t)); return inf; } diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index 2f4e8d715e0..5a46c24b939 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -44,7 +44,7 @@ be generated once they are invoked with specific type parameters, see `trans::base::lval_static_fn()` or `trans::base::monomorphic_fn()`. */ pub fn trans_impl(ccx: @CrateContext, +path: path, name: ast::ident, - methods: ~[@ast::method], generics: &ast::Generics, + methods: &[@ast::method], generics: &ast::Generics, self_ty: Option<ty::t>, id: ast::node_id) { let _icx = ccx.insn_ctxt("impl::trans_impl"); if !generics.ty_params.is_empty() { return; } @@ -249,12 +249,12 @@ pub fn trans_method_callee(bcx: block, None => fail!(~"trans_method_callee: missing param_substs") } } - typeck::method_trait(_, off, vstore) => { + typeck::method_trait(_, off, store) => { trans_trait_callee(bcx, callee_id, off, self, - vstore, + store, mentry.explicit_self) } typeck::method_self(*) | typeck::method_super(*) => { @@ -570,7 +570,7 @@ pub fn trans_trait_callee(bcx: block, callee_id: ast::node_id, n_method: uint, self_expr: @ast::expr, - vstore: ty::vstore, + store: ty::TraitStore, explicit_self: ast::self_ty_) -> Callee { //! @@ -599,7 +599,7 @@ pub fn trans_trait_callee(bcx: block, callee_ty, n_method, llpair, - vstore, + store, explicit_self) } @@ -607,7 +607,7 @@ pub fn trans_trait_callee_from_llval(bcx: block, callee_ty: ty::t, n_method: uint, llpair: ValueRef, - vstore: ty::vstore, + store: ty::TraitStore, explicit_self: ast::self_ty_) -> Callee { //! @@ -641,16 +641,15 @@ pub fn trans_trait_callee_from_llval(bcx: block, } ast::sty_by_ref => { // We need to pass a pointer to a pointer to the payload. - match vstore { - ty::vstore_box | ty::vstore_uniq => { + match store { + ty::BoxTraitStore | + ty::BareTraitStore | + ty::UniqTraitStore => { llself = GEPi(bcx, llbox, [0u, abi::box_field_body]); } - ty::vstore_slice(_) => { + ty::RegionTraitStore(_) => { llself = llbox; } - ty::vstore_fixed(*) => { - bcx.tcx().sess.bug(~"vstore_fixed trait"); - } } self_mode = ast::by_ref; @@ -662,16 +661,15 @@ pub fn trans_trait_callee_from_llval(bcx: block, ast::sty_region(_) => { // As before, we need to pass a pointer to a pointer to the // payload. - match vstore { - ty::vstore_box | ty::vstore_uniq => { + match store { + ty::BoxTraitStore | + ty::BareTraitStore | + ty::UniqTraitStore => { llself = GEPi(bcx, llbox, [0u, abi::box_field_body]); } - ty::vstore_slice(_) => { + ty::RegionTraitStore(_) => { llself = llbox; } - ty::vstore_fixed(*) => { - bcx.tcx().sess.bug(~"vstore_fixed trait"); - } } let llscratch = alloca(bcx, val_ty(llself)); @@ -687,8 +685,8 @@ pub fn trans_trait_callee_from_llval(bcx: block, bcx = glue::take_ty(bcx, llbox, callee_ty); // Pass a pointer to the box. - match vstore { - ty::vstore_box => llself = llbox, + match store { + ty::BoxTraitStore | ty::BareTraitStore => llself = llbox, _ => bcx.tcx().sess.bug(~"@self receiver with non-@Trait") } @@ -700,8 +698,8 @@ pub fn trans_trait_callee_from_llval(bcx: block, } ast::sty_uniq(_) => { // Pass the unique pointer. - match vstore { - ty::vstore_uniq => llself = llbox, + match store { + ty::UniqTraitStore => llself = llbox, _ => bcx.tcx().sess.bug(~"~self receiver with non-~Trait") } @@ -796,7 +794,9 @@ pub fn make_impl_vtable(ccx: @CrateContext, // XXX: This should support multiple traits. let trt_id = driver::session::expect( tcx.sess, - ty::ty_to_def_id(ty::impl_traits(tcx, impl_id, ty::vstore_box)[0]), + ty::ty_to_def_id(ty::impl_traits(tcx, + impl_id, + ty::BoxTraitStore)[0]), || ~"make_impl_vtable: non-trait-type implemented"); let has_tps = (*ty::lookup_item_type(ccx.tcx, impl_id).bounds).len() > 0u; @@ -834,7 +834,7 @@ pub fn trans_trait_cast(bcx: block, val: @ast::expr, id: ast::node_id, dest: expr::Dest, - vstore: ty::vstore) + store: ty::TraitStore) -> block { let mut bcx = bcx; let _icx = bcx.insn_ctxt("impl::trans_cast"); @@ -849,8 +849,8 @@ pub fn trans_trait_cast(bcx: block, let ccx = bcx.ccx(); let v_ty = expr_ty(bcx, val); - match vstore { - ty::vstore_slice(*) | ty::vstore_box => { + match store { + ty::RegionTraitStore(_) | ty::BoxTraitStore | ty::BareTraitStore => { let mut llboxdest = GEPi(bcx, lldest, [0u, 1u]); // Just store the pointer into the pair. llboxdest = PointerCast(bcx, @@ -858,7 +858,7 @@ pub fn trans_trait_cast(bcx: block, T_ptr(type_of(bcx.ccx(), v_ty))); bcx = expr::trans_into(bcx, val, SaveIn(llboxdest)); } - ty::vstore_uniq => { + ty::UniqTraitStore => { // Translate the uniquely-owned value into the second element of // the triple. (The first element is the vtable.) let mut llvaldest = GEPi(bcx, lldest, [0, 1]); @@ -874,10 +874,6 @@ pub fn trans_trait_cast(bcx: block, let lltydescdest = GEPi(bcx, lldest, [0, 2]); Store(bcx, tydesc.tydesc, lltydescdest); } - _ => { - bcx.tcx().sess.span_bug(val.span, ~"unexpected vstore in \ - trans_trait_cast"); - } } // Store the vtable into the pair or triple. diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index f970d8f26b3..320fc3ed77a 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -286,14 +286,11 @@ pub fn normalize_for_monomorphization(tcx: ty::ctxt, ty::ty_closure(ref fty) => { Some(normalized_closure_ty(tcx, fty.sigil)) } - ty::ty_trait(_, _, ref vstore) => { - let sigil = match *vstore { - ty::vstore_uniq => ast::OwnedSigil, - ty::vstore_box => ast::ManagedSigil, - ty::vstore_slice(_) => ast::BorrowedSigil, - ty::vstore_fixed(*) => { - tcx.sess.bug(fmt!("ty_trait with vstore_fixed")); - } + ty::ty_trait(_, _, ref store) => { + let sigil = match *store { + ty::UniqTraitStore => ast::OwnedSigil, + ty::BoxTraitStore | ty::BareTraitStore => ast::ManagedSigil, + ty::RegionTraitStore(_) => ast::BorrowedSigil, }; // Traits have the same runtime representation as closures. diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index 85c0bc80292..a4a7d958e69 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -96,14 +96,14 @@ pub impl Reflector { } let bool_ty = ty::mk_bool(tcx); let scratch = scratch_datum(bcx, bool_ty, false); - // XXX: Should not be vstore_box! + // XXX: Should not be BoxTraitStore! let bcx = callee::trans_call_inner( self.bcx, None, mth_ty, bool_ty, |bcx| meth::trans_trait_callee_from_llval(bcx, mth_ty, mth_idx, v, - ty::vstore_box, + ty::BoxTraitStore, ast::sty_region( ast::m_imm)), ArgVals(args), SaveIn(scratch.val), DontAutorefArg); @@ -313,7 +313,6 @@ pub impl Reflector { ast::infer(_) => 0u, ast::expl(e) => match e { ast::by_ref => 1u, - ast::by_val => 2u, ast::by_copy => 5u } }; diff --git a/src/librustc/middle/trans/tvec.rs b/src/librustc/middle/trans/tvec.rs index 3e4486476c0..9f66bb5b468 100644 --- a/src/librustc/middle/trans/tvec.rs +++ b/src/librustc/middle/trans/tvec.rs @@ -520,7 +520,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 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/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index 68eb0852445..0c3e93885f9 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -21,24 +21,21 @@ use util::ppaux; use core::option::None; use syntax::ast; -pub fn type_of_explicit_arg(ccx: @CrateContext, arg: ty::arg) -> TypeRef { - let llty = type_of(ccx, arg.ty); +pub fn arg_is_indirect(ccx: @CrateContext, arg: &ty::arg) -> bool { match ty::resolved_mode(ccx.tcx, arg.mode) { - ast::by_val => llty, - ast::by_copy => { - if ty::type_is_immediate(arg.ty) { - llty - } else { - T_ptr(llty) - } - } - _ => T_ptr(llty) + ast::by_copy => !ty::type_is_immediate(arg.ty), + ast::by_ref => true } } +pub fn type_of_explicit_arg(ccx: @CrateContext, arg: &ty::arg) -> TypeRef { + let llty = type_of(ccx, arg.ty); + if arg_is_indirect(ccx, arg) {T_ptr(llty)} else {llty} +} + pub fn type_of_explicit_args(ccx: @CrateContext, inputs: &[ty::arg]) -> ~[TypeRef] { - inputs.map(|arg| type_of_explicit_arg(ccx, *arg)) + inputs.map(|arg| type_of_explicit_arg(ccx, arg)) } pub fn type_of_fn(cx: @CrateContext, inputs: &[ty::arg], @@ -133,7 +130,7 @@ pub fn sizing_type_of(cx: @CrateContext, t: ty::t) -> TypeRef { ty::ty_bare_fn(*) => T_ptr(T_i8()), ty::ty_closure(*) => T_struct(~[T_ptr(T_i8()), T_ptr(T_i8())]), - ty::ty_trait(_, _, vstore) => T_opaque_trait(cx, vstore), + ty::ty_trait(_, _, store) => T_opaque_trait(cx, store), ty::ty_estr(ty::vstore_fixed(size)) => T_array(T_i8(), size), ty::ty_evec(mt, ty::vstore_fixed(size)) => { @@ -237,7 +234,7 @@ pub fn type_of(cx: @CrateContext, t: ty::t) -> TypeRef { ty::ty_bare_fn(_) => T_ptr(type_of_fn_from_ty(cx, t)), ty::ty_closure(_) => T_fn_pair(cx, type_of_fn_from_ty(cx, t)), - ty::ty_trait(_, _, vstore) => T_opaque_trait(cx, vstore), + ty::ty_trait(_, _, store) => T_opaque_trait(cx, store), ty::ty_type => T_ptr(cx.tydesc_type), ty::ty_tup(*) => { let repr = adt::represent_type(cx, t); diff --git a/src/librustc/middle/trans/type_use.rs b/src/librustc/middle/trans/type_use.rs index 9a0c330d2d1..593919d108b 100644 --- a/src/librustc/middle/trans/type_use.rs +++ b/src/librustc/middle/trans/type_use.rs @@ -81,7 +81,7 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint) ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) => { for vec::each(sig.inputs) |arg| { match ty::resolved_mode(ccx.tcx, arg.mode) { - by_val | by_copy => { + by_copy => { type_needs(cx, use_repr, arg.ty); } by_ref => {} @@ -185,7 +185,11 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint) pub fn type_needs(cx: Context, use_: uint, ty: ty::t) { // Optimization -- don't descend type if all params already have this use - for uint::range(0, cx.uses.len()) |i| { + let len = { + let uses = &*cx.uses; + uses.len() + }; + for uint::range(0, len) |i| { if cx.uses[i] & use_ != use_ { type_needs_inner(cx, use_, ty, @Nil); return; @@ -326,7 +330,7 @@ pub fn mark_for_expr(cx: Context, e: @expr) { ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, f.id)) ) |a| { match a.mode { - expl(by_copy) | expl(by_val) => { + expl(by_copy) => { type_needs(cx, use_repr, a.ty); } _ => () @@ -340,7 +344,7 @@ pub fn mark_for_expr(cx: Context, e: @expr) { for ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, e.callee_id)).each |a| { match a.mode { - expl(by_copy) | expl(by_val) => { + expl(by_copy) => { type_needs(cx, use_repr, a.ty); } _ => () @@ -348,12 +352,22 @@ pub fn mark_for_expr(cx: Context, e: @expr) { } mark_for_method_call(cx, e.id, e.callee_id); } + + expr_inline_asm(_, ref ins, ref outs, _, _, _) => { + for ins.each |&(_, in)| { + node_type_needs(cx, use_repr, in.id); + } + for outs.each |&(_, out)| { + node_type_needs(cx, use_repr, out.id); + } + } + expr_paren(e) => mark_for_expr(cx, e), expr_match(*) | expr_block(_) | expr_if(*) | expr_while(*) | expr_break(_) | expr_again(_) | expr_unary(_, _) | expr_lit(_) | expr_mac(_) | expr_addr_of(_, _) | expr_ret(_) | expr_loop(_, _) | - expr_loop_body(_) | expr_do_body(_) | expr_inline_asm(*) => () + expr_loop_body(_) | expr_do_body(_) => () } } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 6e21439fc35..599fa28e242 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -24,7 +24,7 @@ use middle::typeck; use middle; use util::ppaux::{note_and_explain_region, bound_region_to_str}; use util::ppaux::{region_to_str, explain_region, vstore_to_str}; -use util::ppaux::{ty_to_str, tys_to_str}; +use util::ppaux::{trait_store_to_str, ty_to_str, tys_to_str}; use util::common::{indenter}; use core::cast; @@ -84,6 +84,7 @@ pub struct mt { #[auto_encode] #[auto_decode] +#[deriving_eq] pub enum vstore { vstore_fixed(uint), vstore_uniq, @@ -91,6 +92,16 @@ pub enum vstore { vstore_slice(Region) } +#[auto_encode] +#[auto_decode] +#[deriving_eq] +pub enum TraitStore { + BareTraitStore, // a plain trait without a sigil + BoxTraitStore, // @Trait + UniqTraitStore, // ~Trait + RegionTraitStore(Region), // &Trait +} + pub struct field_ty { ident: ident, id: def_id, @@ -233,7 +244,7 @@ pub struct InstantiatedTraitRef { pub type ctxt = @ctxt_; struct ctxt_ { - diag: syntax::diagnostic::span_handler, + diag: @syntax::diagnostic::span_handler, interner: HashMap<intern_key, t_box>, next_id: @mut uint, vecs_implicitly_copyable: bool, @@ -437,13 +448,13 @@ pub enum Region { #[auto_encode] #[auto_decode] pub enum bound_region { - /// The self region for structs, impls (&T in a type defn or &self/T) + /// The self region for structs, impls (&T in a type defn or &'self T) br_self, /// An anonymous region parameter for a given fn (&T) br_anon(uint), - /// Named region parameters for functions (a in &a/T) + /// Named region parameters for functions (a in &'a T) br_named(ast::ident), /// Fresh bound identifiers created during GLB computations. @@ -506,7 +517,7 @@ pub enum sty { ty_rptr(Region, mt), ty_bare_fn(BareFnTy), ty_closure(ClosureTy), - ty_trait(def_id, substs, vstore), + ty_trait(def_id, substs, TraitStore), ty_struct(def_id, substs), ty_tup(~[t]), @@ -565,6 +576,7 @@ pub enum type_err { terr_regions_insufficiently_polymorphic(bound_region, Region), terr_regions_overly_polymorphic(bound_region, Region), terr_vstores_differ(terr_vstore_kind, expected_found<vstore>), + terr_trait_stores_differ(terr_vstore_kind, expected_found<TraitStore>), terr_in_field(@type_err, ast::ident), terr_sorts(expected_found<t>), terr_self_substs, @@ -1048,10 +1060,13 @@ pub fn mk_ctor_fn(cx: ctxt, input_tys: &[ty::t], output: ty::t) -> t { } -pub fn mk_trait(cx: ctxt, did: ast::def_id, +substs: substs, vstore: vstore) - -> t { +pub fn mk_trait(cx: ctxt, + did: ast::def_id, + +substs: substs, + store: TraitStore) + -> t { // take a copy of substs so that we own the vectors inside - mk_t(cx, ty_trait(did, substs, vstore)) + mk_t(cx, ty_trait(did, substs, store)) } pub fn mk_struct(cx: ctxt, struct_id: ast::def_id, +substs: substs) -> t { @@ -1110,7 +1125,7 @@ pub fn default_arg_mode_for_ty(tcx: ctxt, ty: ty::t) -> ast::rmode { // forward-compatible with non-legacy, we should use + ast::by_copy } else if ty::type_is_immediate(ty) { - ast::by_val + ast::by_copy } else { ast::by_ref } @@ -1213,8 +1228,8 @@ fn fold_sty(sty: &sty, fldop: &fn(t) -> t) -> sty { ty_enum(tid, ref substs) => { ty_enum(tid, fold_substs(substs, fldop)) } - ty_trait(did, ref substs, vst) => { - ty_trait(did, fold_substs(substs, fldop), vst) + ty_trait(did, ref substs, st) => { + ty_trait(did, fold_substs(substs, fldop), st) } ty_tup(ts) => { let new_ts = vec::map(ts, |tt| fldop(*tt)); @@ -1304,8 +1319,8 @@ pub fn fold_regions_and_ty( ty_struct(def_id, ref substs) => { ty::mk_struct(cx, def_id, fold_substs(substs, fldr, fldt)) } - ty_trait(def_id, ref substs, vst) => { - ty::mk_trait(cx, def_id, fold_substs(substs, fldr, fldt), vst) + ty_trait(def_id, ref substs, st) => { + ty::mk_trait(cx, def_id, fold_substs(substs, fldr, fldt), st) } ty_bare_fn(ref f) => { ty::mk_bare_fn(cx, BareFnTy {sig: fold_sig(&f.sig, fldfnt), @@ -1893,15 +1908,16 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { TC_MANAGED + nonowned(tc_mt(cx, mt, cache)) } - ty_trait(_, _, vstore_uniq) => { + ty_trait(_, _, UniqTraitStore) => { TC_OWNED_CLOSURE } - ty_trait(_, _, vstore_box) => { + ty_trait(_, _, BoxTraitStore) | + ty_trait(_, _, BareTraitStore) => { TC_MANAGED } - ty_trait(_, _, vstore_slice(r)) => { + ty_trait(_, _, RegionTraitStore(r)) => { borrowed_contents(r, m_imm) } @@ -2013,7 +2029,6 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { } ty_type => TC_NONE, - ty_trait(_, _, vstore_fixed(_)) => TC_NONE, ty_err => { cx.sess.bug(~"Asked to compute contents of fictitious type"); @@ -2169,7 +2184,7 @@ pub fn type_moves_by_default(cx: ctxt, ty: t) -> bool { // True if instantiating an instance of `r_ty` requires an instance of `r_ty`. pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool { - fn type_requires(cx: ctxt, seen: @mut ~[def_id], + fn type_requires(cx: ctxt, seen: &mut ~[def_id], r_ty: t, ty: t) -> bool { debug!("type_requires(%s, %s)?", ::util::ppaux::ty_to_str(cx, r_ty), @@ -2187,7 +2202,7 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool { return r; } - fn subtypes_require(cx: ctxt, seen: @mut ~[def_id], + fn subtypes_require(cx: ctxt, seen: &mut ~[def_id], r_ty: t, ty: t) -> bool { debug!("subtypes_require(%s, %s)?", ::util::ppaux::ty_to_str(cx, r_ty), @@ -2557,6 +2572,17 @@ impl to_bytes::IterBytes for vstore { } } +impl to_bytes::IterBytes for TraitStore { + pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { + match *self { + BareTraitStore => 0u8.iter_bytes(lsb0, f), + UniqTraitStore => 1u8.iter_bytes(lsb0, f), + BoxTraitStore => 2u8.iter_bytes(lsb0, f), + RegionTraitStore(ref r) => to_bytes::iter_bytes_2(&3u8, r, lsb0, f), + } + } +} + impl to_bytes::IterBytes for substs { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_3(&self.self_r, @@ -3076,7 +3102,6 @@ pub fn expr_kind(tcx: ctxt, ast::expr_block(*) | ast::expr_copy(*) | ast::expr_repeat(*) | - ast::expr_inline_asm(*) | ast::expr_lit(@codemap::spanned {node: lit_str(_), _}) | ast::expr_vstore(_, ast::expr_vstore_slice) | ast::expr_vstore(_, ast::expr_vstore_mut_slice) | @@ -3119,6 +3144,7 @@ pub fn expr_kind(tcx: ctxt, ast::expr_loop(*) | ast::expr_assign(*) | ast::expr_swap(*) | + ast::expr_inline_asm(*) | ast::expr_assign_op(*) => { RvalueStmtExpr } @@ -3419,6 +3445,11 @@ pub fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str { vstore_to_str(cx, (*values).expected), vstore_to_str(cx, (*values).found)) } + terr_trait_stores_differ(_, ref values) => { + fmt!("trait storage differs: expected %s but found %s", + trait_store_to_str(cx, (*values).expected), + trait_store_to_str(cx, (*values).found)) + } terr_in_field(err, fname) => { fmt!("in field `%s`, %s", *cx.sess.str_of(fname), type_err_to_str(cx, err)) @@ -3565,12 +3596,15 @@ pub fn trait_methods(cx: ctxt, id: ast::def_id) -> @~[method] { /* Could this return a list of (def_id, substs) pairs? */ -pub fn impl_traits(cx: ctxt, id: ast::def_id, vstore: vstore) -> ~[t] { - fn vstoreify(cx: ctxt, ty: t, vstore: vstore) -> t { +pub fn impl_traits(cx: ctxt, id: ast::def_id, store: TraitStore) -> ~[t] { + fn storeify(cx: ctxt, ty: t, store: TraitStore) -> t { match ty::get(ty).sty { - ty::ty_trait(_, _, trait_vstore) if vstore == trait_vstore => ty, - ty::ty_trait(did, ref substs, _) => { - mk_trait(cx, did, (/*bad*/copy *substs), vstore) + ty::ty_trait(did, ref substs, trait_store) => { + if store == trait_store { + ty + } else { + mk_trait(cx, did, (/*bad*/copy *substs), store) + } } _ => cx.sess.bug(~"impl_traits: not a trait") } @@ -3585,16 +3619,16 @@ pub fn impl_traits(cx: ctxt, id: ast::def_id, vstore: vstore) -> ~[t] { _)) => { do option::map_default(&opt_trait, ~[]) |trait_ref| { - ~[vstoreify(cx, - node_id_to_type(cx, trait_ref.ref_id), - vstore)] + ~[storeify(cx, + node_id_to_type(cx, trait_ref.ref_id), + store)] } } _ => ~[] } } else { vec::map(csearch::get_impl_traits(cx, id), - |x| vstoreify(cx, *x, vstore)) + |x| storeify(cx, *x, store)) } } @@ -4163,6 +4197,9 @@ pub fn normalize_ty(cx: ctxt, t: t) -> t { t }, + ty_trait(did, ref substs, BareTraitStore) => + mk_trait(cx, did, copy *substs, BoxTraitStore), + _ => t }; @@ -4318,38 +4355,6 @@ impl cmp::Eq for mt { pure fn ne(&self, other: &mt) -> bool { !(*self).eq(other) } } -impl cmp::Eq for vstore { - pure fn eq(&self, other: &vstore) -> bool { - match (*self) { - vstore_fixed(e0a) => { - match (*other) { - vstore_fixed(e0b) => e0a == e0b, - _ => false - } - } - vstore_uniq => { - match (*other) { - vstore_uniq => true, - _ => false - } - } - vstore_box => { - match (*other) { - vstore_box => true, - _ => false - } - } - vstore_slice(e0a) => { - match (*other) { - vstore_slice(e0b) => e0a == e0b, - _ => false - } - } - } - } - pure fn ne(&self, other: &vstore) -> bool { !(*self).eq(other) } -} - impl cmp::Eq for Region { pure fn eq(&self, other: &Region) -> bool { match (*self) { diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 6c27decc283..2a70ba7d4c1 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -43,10 +43,10 @@ * as it does not already appear in scope. * * Case (b) says that if you have a type: - * type foo/& = ...; + * type foo<'self> = ...; * type bar = fn(&foo, &a.foo) * The fully expanded version of type bar is: - * type bar = fn(&foo/&, &a.foo/&a) + * type bar = fn(&'foo &, &a.foo<'a>) * Note that the self region for the `foo` defaulted to `&` in the first * case but `&a` in the second. Basically, defaults that appear inside * an rptr (`&r.T`) use the region `r` that appears in the rptr. @@ -54,6 +54,7 @@ use core::prelude::*; +use middle::const_eval; use middle::ty::{arg, field, substs}; use middle::ty::{ty_param_substs_and_ty}; use middle::ty; @@ -218,7 +219,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + Durable>( // Handle @, ~, and & being able to mean estrs and evecs. // If a_seq_ty is a str or a vec, make it an estr/evec. - // Also handle function sigils and first-class trait types. + // Also handle first-class trait types. fn mk_pointer<AC:AstConv,RS:region_scope + Copy + Durable>( self: &AC, rscope: &RS, @@ -249,20 +250,26 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + Durable>( type_def_id, path); match ty::get(result.ty).sty { ty::ty_trait(trait_def_id, ref substs, _) => { - match vst { - ty::vstore_box | ty::vstore_slice(*) | - ty::vstore_uniq => {} - _ => { + let trait_store = match vst { + ty::vstore_box => ty::BoxTraitStore, + ty::vstore_uniq => ty::UniqTraitStore, + ty::vstore_slice(r) => { + ty::RegionTraitStore(r) + } + ty::vstore_fixed(*) => { tcx.sess.span_err( path.span, ~"@trait, ~trait or &trait \ are the only supported \ forms of casting-to-\ trait"); + ty::BoxTraitStore } - } - return ty::mk_trait(tcx, trait_def_id, - /*bad*/copy *substs, vst); + }; + return ty::mk_trait(tcx, + trait_def_id, + /*bad*/copy *substs, + trait_store); } _ => {} @@ -406,9 +413,29 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + Durable>( } } } - ast::ty_fixed_length_vec(a_mt, u) => { - ty::mk_evec(tcx, ast_mt_to_mt(self, rscope, a_mt), - ty::vstore_fixed(u)) + ast::ty_fixed_length_vec(a_mt, e) => { + match const_eval::eval_const_expr_partial(tcx, e) { + Ok(ref r) => { + match *r { + const_eval::const_int(i) => + ty::mk_evec(tcx, ast_mt_to_mt(self, rscope, a_mt), + ty::vstore_fixed(i as uint)), + const_eval::const_uint(i) => + ty::mk_evec(tcx, ast_mt_to_mt(self, rscope, a_mt), + ty::vstore_fixed(i as uint)), + _ => { + tcx.sess.span_fatal( + ast_ty.span, ~"expected constant expr for vector length"); + } + } + } + Err(ref r) => { + tcx.sess.span_fatal( + ast_ty.span, + fmt!("expected constant expr for vector length: %s", + *r)); + } + } } ast::ty_infer => { // ty_infer should only appear as the type of arguments or return diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index d6060c1ae31..929555e3148 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -111,20 +111,26 @@ pub enum CheckTraitsFlag { CheckTraitsAndInherentMethods, } -pub fn lookup( - fcx: @mut FnCtxt, +#[deriving_eq] +pub enum AutoderefReceiverFlag { + AutoderefReceiver, + DontAutoderefReceiver, +} - // In a call `a.b::<X, Y, ...>(...)`: - expr: @ast::expr, // The expression `a.b`. - self_expr: @ast::expr, // The expression `a`. - callee_id: node_id, // Where to store the type of `a.b` - m_name: ast::ident, // The ident `b`. - self_ty: ty::t, // The type of `a`. - supplied_tps: &[ty::t], // The list of types X, Y, ... . - deref_args: check::DerefArgs, // Whether we autopointer first. - check_traits: CheckTraitsFlag) // Whether we check traits only. - -> Option<method_map_entry> -{ +pub fn lookup( + fcx: @mut FnCtxt, + + // In a call `a.b::<X, Y, ...>(...)`: + expr: @ast::expr, // The expression `a.b`. + self_expr: @ast::expr, // The expression `a`. + callee_id: node_id, // Where to store `a.b`'s type + m_name: ast::ident, // The ident `b`. + self_ty: ty::t, // The type of `a`. + supplied_tps: &[ty::t], // The list of types X, Y, ... . + deref_args: check::DerefArgs, // Whether we autopointer first. + check_traits: CheckTraitsFlag, // Whether we check traits only. + autoderef_receiver: AutoderefReceiverFlag) + -> Option<method_map_entry> { let lcx = LookupContext { fcx: fcx, expr: expr, @@ -137,6 +143,7 @@ pub fn lookup( extension_candidates: @mut ~[], deref_args: deref_args, check_traits: check_traits, + autoderef_receiver: autoderef_receiver, }; let mme = lcx.do_lookup(self_ty); debug!("method lookup for %s yielded %?", @@ -150,12 +157,13 @@ pub struct LookupContext { self_expr: @ast::expr, callee_id: node_id, m_name: ast::ident, - supplied_tps: &self/[ty::t], + supplied_tps: &'self [ty::t], impl_dups: HashMap<def_id, ()>, inherent_candidates: @mut ~[Candidate], extension_candidates: @mut ~[Candidate], deref_args: check::DerefArgs, check_traits: CheckTraitsFlag, + autoderef_receiver: AutoderefReceiverFlag, } /** @@ -232,6 +240,12 @@ pub impl LookupContext/&self { } } + // Don't autoderef if we aren't supposed to. + if self.autoderef_receiver == DontAutoderefReceiver { + break; + } + + // Otherwise, perform autoderef. match self.deref(self_ty, &mut enum_dids) { None => { break; } Some(ty) => { @@ -288,9 +302,9 @@ pub impl LookupContext/&self { ty_param(p) => { self.push_inherent_candidates_from_param(self_ty, p); } - ty_trait(did, ref substs, vstore) => { + ty_trait(did, ref substs, store) => { self.push_inherent_candidates_from_trait( - self_ty, did, substs, vstore); + self_ty, did, substs, store); self.push_inherent_impl_candidates_for_type(did); } ty_self => { @@ -490,7 +504,7 @@ pub impl LookupContext/&self { self_ty: ty::t, did: def_id, substs: &ty::substs, - vstore: ty::vstore) { + store: ty::TraitStore) { debug!("push_inherent_candidates_from_trait(did=%s, substs=%s)", self.did_to_str(did), substs_to_str(self.tcx(), substs)); @@ -539,7 +553,7 @@ pub impl LookupContext/&self { explicit_self: method.self_ty, num_method_tps: method.tps.len(), self_mode: get_mode_from_self_type(method.self_ty), - origin: method_trait(did, index, vstore) + origin: method_trait(did, index, store) }); } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 445cab4ba95..7a1beeca513 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -89,8 +89,11 @@ use middle::typeck::astconv::{AstConv, ast_path_to_ty}; use middle::typeck::astconv::{ast_region_to_region, ast_ty_to_ty}; use middle::typeck::astconv; use middle::typeck::check::_match::pat_ctxt; +use middle::typeck::check::method::{AutoderefReceiver}; +use middle::typeck::check::method::{AutoderefReceiverFlag}; use middle::typeck::check::method::{CheckTraitsAndInherentMethods}; -use middle::typeck::check::method::{CheckTraitsOnly, TransformTypeNormally}; +use middle::typeck::check::method::{CheckTraitsOnly, DontAutoderefReceiver}; +use middle::typeck::check::method::{TransformTypeNormally}; use middle::typeck::check::regionmanip::replace_bound_regions_in_fn_sig; use middle::typeck::check::vtable::{LocationInfo, VtableContext}; use middle::typeck::CrateCtxt; @@ -1373,7 +1376,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, expr_t, tps, DontDerefArgs, - CheckTraitsAndInherentMethods) { + CheckTraitsAndInherentMethods, + AutoderefReceiver) { Some(ref entry) => { let method_map = fcx.ccx.method_map; method_map.insert(expr.id, (*entry)); @@ -1453,7 +1457,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, self_t: ty::t, opname: ast::ident, +args: ~[@ast::expr], - +deref_args: DerefArgs) + +deref_args: DerefArgs, + +autoderef_receiver: AutoderefReceiverFlag) -> Option<(ty::t, bool)> { match method::lookup(fcx, op_ex, @@ -1463,7 +1468,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, self_t, ~[], deref_args, - CheckTraitsOnly) { + CheckTraitsOnly, + autoderef_receiver) { Some(ref origin) => { let method_ty = fcx.node_ty(op_ex.callee_id); let method_map = fcx.ccx.method_map; @@ -1548,9 +1554,14 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, let tcx = fcx.ccx.tcx; match ast_util::binop_to_method_name(op) { Some(ref name) => { - match lookup_op_method(fcx, ex, lhs_expr, lhs_resolved_t, + match lookup_op_method(fcx, + ex, + lhs_expr, + lhs_resolved_t, fcx.tcx().sess.ident_of(copy *name), - ~[rhs], DoDerefArgs) { + ~[rhs], + DoDerefArgs, + DontAutoderefReceiver) { Some(pair) => return pair, _ => () } @@ -1588,11 +1599,14 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, rhs_expr: @ast::expr, rhs_t: ty::t) -> ty::t { - match lookup_op_method( - fcx, ex, rhs_expr, rhs_t, - fcx.tcx().sess.ident_of(/*bad*/ copy mname), ~[], - DontDerefArgs) - { + match lookup_op_method(fcx, + ex, + rhs_expr, + rhs_t, + fcx.tcx().sess.ident_of(/*bad*/ copy mname), + ~[], + DontDerefArgs, + DontAutoderefReceiver) { Some((ret_ty, _)) => ret_ty, _ => { fcx.type_error_message(ex.span, |actual| { @@ -1682,7 +1696,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, fcx.write_ty(expr.id, fty); let inherited_purity = - ty::determine_inherited_purity(fcx.purity, purity, + ty::determine_inherited_purity(copy fcx.purity, purity, fn_ty.sigil); // We inherit the same self info as the enclosing scope, @@ -1706,7 +1720,6 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, let expr_t = structurally_resolved_type(fcx, expr.span, fcx.expr_ty(base)); let (base_t, derefs) = do_autoderef(fcx, expr.span, expr_t); - let n_tys = tys.len(); match structure_of(fcx, expr.span, base_t) { ty::ty_struct(base_id, ref substs) => { @@ -1741,7 +1754,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, expr_t, tps, DontDerefArgs, - CheckTraitsAndInherentMethods) { + CheckTraitsAndInherentMethods, + AutoderefReceiver) { Some(ref entry) => { let method_map = fcx.ccx.method_map; method_map.insert(expr.id, (*entry)); @@ -2155,7 +2169,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, } ast::expr_repeat(element, count_expr, mutbl) => { let count = ty::eval_repeat_count(tcx, count_expr); - fcx.write_ty(count_expr.id, ty::mk_uint(tcx)); + check_expr_with_hint(fcx, count_expr, ty::mk_uint(tcx)); let tt = ast_expr_vstore_to_vstore(fcx, ev, count, vst); let t: ty::t = fcx.infcx().next_ty_var(); bot |= check_expr_has_type(fcx, element, t); @@ -2303,8 +2317,15 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, let region_lb = ty::re_scope(expr.id); instantiate_path(fcx, pth, tpt, expr.span, expr.id, region_lb); } - ast::expr_inline_asm(*) => { + ast::expr_inline_asm(_, ins, outs, _, _, _) => { fcx.require_unsafe(expr.span, ~"use of inline assembly"); + + for ins.each |&(_, in)| { + check_expr(fcx, in); + } + for outs.each |&(_, out)| { + check_expr(fcx, out); + } fcx.write_nil(id); } ast::expr_mac(_) => tcx.sess.bug(~"unexpanded macro"), @@ -2516,7 +2537,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, } ast::expr_repeat(element, count_expr, mutbl) => { let count = ty::eval_repeat_count(tcx, count_expr); - fcx.write_ty(count_expr.id, ty::mk_uint(tcx)); + check_expr_with_hint(fcx, count_expr, ty::mk_uint(tcx)); let t: ty::t = fcx.infcx().next_ty_var(); bot |= check_expr_has_type(fcx, element, t); let t = ty::mk_evec(tcx, ty::mt {ty: t, mutbl: mutbl}, @@ -2570,9 +2591,14 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, None => { let resolved = structurally_resolved_type(fcx, expr.span, raw_base_t); - match lookup_op_method(fcx, expr, base, resolved, + match lookup_op_method(fcx, + expr, + base, + resolved, tcx.sess.ident_of(~"index"), - ~[idx], DontDerefArgs) { + ~[idx], + DontDerefArgs, + AutoderefReceiver) { Some((ret_ty, _)) => fcx.write_ty(id, ret_ty), _ => { fcx.type_error_message(expr.span, |actual| @@ -3205,9 +3231,22 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { fail_unless!(ccx.tcx.intrinsic_defs.contains_key(&ty_visitor_name)); let (_, tydesc_ty) = tcx.intrinsic_defs.get(&tydesc_name); let (_, visitor_trait) = tcx.intrinsic_defs.get(&ty_visitor_name); + + let visitor_trait = match ty::get(visitor_trait).sty { + ty::ty_trait(trait_def_id, ref trait_substs, _) => { + ty::mk_trait(tcx, + trait_def_id, + copy *trait_substs, + ty::BoxTraitStore) + } + _ => { + tcx.sess.span_bug(it.span, ~"TyVisitor wasn't a trait?!") + } + }; + let td_ptr = ty::mk_ptr(ccx.tcx, ty::mt {ty: tydesc_ty, mutbl: ast::m_imm}); - (0u, ~[arg(ast::by_val, td_ptr), + (0u, ~[arg(ast::by_copy, td_ptr), arg(ast::by_ref, visitor_trait)], ty::mk_nil(tcx)) } ~"frame_address" => { @@ -3217,7 +3256,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { onceness: ast::Once, region: ty::re_bound(ty::br_anon(0)), sig: ty::FnSig { - inputs: ~[arg {mode: ast::expl(ast::by_val), + inputs: ~[arg {mode: ast::expl(ast::by_copy), ty: ty::mk_imm_ptr( ccx.tcx, ty::mk_mach_uint(ccx.tcx, ast::ty_u8))}], diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index 1dd88e6408b..6871496a805 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -18,7 +18,7 @@ know whether a given type will be a region pointer or not until this phase. In particular, we ensure that, if the type of an expression or -variable is `&r/T`, then the expression or variable must occur within +variable is `&'r T`, then the expression or variable must occur within the region scope `r`. Note that in some cases `r` may still be a region variable, so this gives us a chance to influence the value for `r` that we infer to ensure we choose a value large enough to enclose @@ -263,7 +263,7 @@ pub fn visit_expr(expr: @ast::expr, &&rcx: @mut Rcx, v: rvt) { // explaining how it goes about doing that. let target_ty = rcx.resolve_node_type(expr.id); match ty::get(target_ty).sty { - ty::ty_trait(_, _, vstore_slice(trait_region)) => { + ty::ty_trait(_, _, ty::RegionTraitStore(trait_region)) => { let source_ty = rcx.fcx.expr_ty(source); constrain_regions_in_type(rcx, trait_region, expr.span, source_ty); @@ -500,7 +500,7 @@ pub mod guarantor { * * struct Foo { i: int } * struct Bar { foo: Foo } - * fn get_i(x: &a/Bar) -> &a/int { + * fn get_i(x: &'a Bar) -> &'a int { * let foo = &x.foo; // Lifetime L1 * &foo.i // Lifetime L2 * } diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 7c9ca4ba85a..6e86bbca0d1 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -10,6 +10,7 @@ use core::prelude::*; +use middle::resolve::Impl; use middle::ty::{param_ty, substs}; use middle::ty; use middle::typeck::check::{FnCtxt, impl_self_ty}; @@ -140,7 +141,9 @@ pub fn fixup_substs(vcx: &VtableContext, location_info: &LocationInfo, is_early: bool) -> Option<ty::substs> { let tcx = vcx.tcx(); // use a dummy type just to package up the substs that need fixing up - let t = ty::mk_trait(tcx, id, substs, ty::vstore_slice(ty::re_static)); + let t = ty::mk_trait(tcx, + id, substs, + ty::RegionTraitStore(ty::re_static)); do fixup_ty(vcx, location_info, t, is_early).map |t_f| { match ty::get(*t_f).sty { ty::ty_trait(_, ref substs_f, _) => (/*bad*/copy *substs_f), @@ -167,9 +170,9 @@ pub fn lookup_vtable(vcx: &VtableContext, let _i = indenter(); let tcx = vcx.tcx(); - let (trait_id, trait_substs, trait_vstore) = match ty::get(trait_ty).sty { - ty::ty_trait(did, ref substs, vstore) => - (did, (/*bad*/copy *substs), vstore), + let (trait_id, trait_substs, trait_store) = match ty::get(trait_ty).sty { + ty::ty_trait(did, ref substs, store) => + (did, (/*bad*/copy *substs), store), _ => tcx.sess.impossible_case(location_info.span, "lookup_vtable: \ don't know how to handle a non-trait") @@ -196,12 +199,19 @@ pub fn lookup_vtable(vcx: &VtableContext, vcx.infcx.ty_to_str(ity)); match ty::get(ity).sty { - ty::ty_trait(idid, _, _) => { + ty::ty_trait(idid, ref isubsts, _) => { if trait_id == idid { debug!("(checking vtable) @0 \ relating ty to trait \ ty with did %?", idid); + + // Convert `ity` so that it has the right vstore. + let ity = ty::mk_trait(vcx.tcx(), + idid, + copy *isubsts, + trait_store); + relate_trait_tys(vcx, location_info, trait_ty, ity); let vtable = vtable_param(n, n_bound); @@ -231,6 +241,7 @@ pub fn lookup_vtable(vcx: &VtableContext, // Nothing found. Continue. } Some(implementations) => { + let implementations: &mut ~[@Impl] = implementations; // implementations is the list of all impls in scope for // trait_ty. (Usually, there's just one.) for uint::range(0, implementations.len()) |i| { @@ -261,8 +272,9 @@ pub fn lookup_vtable(vcx: &VtableContext, // it's the same trait as trait_ty, we need to // unify it with trait_ty in order to get all // the ty vars sorted out. - for vec::each(ty::impl_traits(tcx, im.did, - trait_vstore)) |of_ty| { + for vec::each(ty::impl_traits(tcx, + im.did, + trait_store)) |of_ty| { match ty::get(*of_ty).sty { ty::ty_trait(id, _, _) => { // Not the trait we're looking for @@ -381,7 +393,7 @@ pub fn lookup_vtable(vcx: &VtableContext, /*bad*/copy substs_f.tps, trait_tps, im.did, - trait_vstore); + trait_store); let subres = lookup_vtables( vcx, location_info, im_bs, &substs_f, is_early); @@ -455,11 +467,11 @@ pub fn connect_trait_tps(vcx: &VtableContext, impl_tys: ~[ty::t], trait_tys: ~[ty::t], impl_did: ast::def_id, - vstore: ty::vstore) { + store: ty::TraitStore) { let tcx = vcx.tcx(); // XXX: This should work for multiple traits. - let ity = ty::impl_traits(tcx, impl_did, vstore)[0]; + let ity = ty::impl_traits(tcx, impl_did, store)[0]; let trait_ty = ty::subst_tps(tcx, impl_tys, None, ity); debug!("(connect trait tps) trait type is %?, impl did is %?", ty::get(trait_ty).sty, impl_did); @@ -557,17 +569,18 @@ pub fn early_resolve_expr(ex: @ast::expr, ast::expr_cast(src, _) => { let target_ty = fcx.expr_ty(ex); match ty::get(target_ty).sty { - ty::ty_trait(_, _, vstore) => { + ty::ty_trait(_, _, store) => { // Look up vtables for the type we're casting to, // passing in the source and target type. The source // must be a pointer type suitable to the object sigil, // e.g.: `@x as @Trait`, `&x as &Trait` or `~x as ~Trait` let ty = structurally_resolved_type(fcx, ex.span, fcx.expr_ty(src)); - match (&ty::get(ty).sty, vstore) { - (&ty::ty_box(mt), ty::vstore_box) | - (&ty::ty_uniq(mt), ty::vstore_uniq) | - (&ty::ty_rptr(_, mt), ty::vstore_slice(*)) => { + match (&ty::get(ty).sty, store) { + (&ty::ty_box(mt), ty::BoxTraitStore) | + // XXX: Bare trait store is deprecated. + (&ty::ty_uniq(mt), ty::UniqTraitStore) | + (&ty::ty_rptr(_, mt), ty::RegionTraitStore(*)) => { let location_info = &location_info_for_expr(ex); let vcx = VtableContext { @@ -604,9 +617,9 @@ pub fn early_resolve_expr(ex: @ast::expr, // Now, if this is &trait, we need to link the // regions. - match (&ty::get(ty).sty, vstore) { + match (&ty::get(ty).sty, store) { (&ty::ty_rptr(ra, _), - ty::vstore_slice(rb)) => { + ty::RegionTraitStore(rb)) => { infer::mk_subr(fcx.infcx(), false, ex.span, @@ -617,7 +630,14 @@ pub fn early_resolve_expr(ex: @ast::expr, } } - (_, ty::vstore_box(*)) => { + (_, ty::BareTraitStore) => { + fcx.ccx.tcx.sess.span_err( + ex.span, + ~"a sigil (`@`, `~`, or `&`) must be specified \ + when casting to a trait"); + } + + (_, ty::BoxTraitStore) => { fcx.ccx.tcx.sess.span_err( ex.span, fmt!("can only cast an @-pointer \ @@ -625,7 +645,7 @@ pub fn early_resolve_expr(ex: @ast::expr, ty::ty_sort_str(fcx.tcx(), ty))); } - (_, ty::vstore_uniq(*)) => { + (_, ty::UniqTraitStore) => { fcx.ccx.tcx.sess.span_err( ex.span, fmt!("can only cast an ~-pointer \ @@ -633,19 +653,13 @@ pub fn early_resolve_expr(ex: @ast::expr, ty::ty_sort_str(fcx.tcx(), ty))); } - (_, ty::vstore_slice(*)) => { + (_, ty::RegionTraitStore(_)) => { fcx.ccx.tcx.sess.span_err( ex.span, fmt!("can only cast an &-pointer \ to an &-object, not a %s", ty::ty_sort_str(fcx.tcx(), ty))); } - - (_, ty::vstore_fixed(*)) => { - fcx.tcx().sess.span_bug( - ex.span, - fmt!("trait with fixed vstore")); - } } } _ => { /* not a cast to a trait; ignore */ } diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 00352ba2958..699b8ad74e4 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -72,8 +72,8 @@ pub fn get_base_type(inference_context: @mut InferCtxt, -> Option<t> { let resolved_type; match resolve_type(inference_context, - original_type, - resolve_ivar) { + original_type, + resolve_ivar) { Ok(resulting_type) if !type_is_ty_var(resulting_type) => { resolved_type = resulting_type; } @@ -87,15 +87,6 @@ pub fn get_base_type(inference_context: @mut InferCtxt, } match get(resolved_type).sty { - ty_box(base_mutability_and_type) | - ty_uniq(base_mutability_and_type) | - ty_ptr(base_mutability_and_type) | - ty_rptr(_, base_mutability_and_type) => { - debug!("(getting base type) recurring"); - get_base_type(inference_context, span, - base_mutability_and_type.ty) - } - ty_enum(*) | ty_trait(*) | ty_struct(*) => { debug!("(getting base type) found base type"); Some(resolved_type) @@ -104,7 +95,8 @@ pub fn get_base_type(inference_context: @mut InferCtxt, ty_nil | ty_bot | ty_bool | ty_int(*) | ty_uint(*) | ty_float(*) | ty_estr(*) | ty_evec(*) | ty_bare_fn(*) | ty_closure(*) | ty_tup(*) | ty_infer(*) | ty_param(*) | ty_self | ty_type | ty_opaque_box | - ty_opaque_closure_ptr(*) | ty_unboxed_vec(*) | ty_err => { + ty_opaque_closure_ptr(*) | ty_unboxed_vec(*) | ty_err | ty_box(_) | + ty_uniq(_) | ty_ptr(_) | ty_rptr(_, _) => { debug!("(getting base type) no base type; found %?", get(original_type).sty); None @@ -474,14 +466,13 @@ pub impl CoherenceChecker { } } - fn iter_impls_of_trait(&self, trait_def_id: def_id, - f: &fn(@Impl)) { - + fn iter_impls_of_trait(&self, trait_def_id: def_id, f: &fn(@Impl)) { let coherence_info = &mut self.crate_context.coherence_info; let extension_methods = &coherence_info.extension_methods; match extension_methods.find(&trait_def_id) { Some(impls) => { + let impls: &mut ~[@Impl] = impls; for uint::range(0, impls.len()) |i| { f(impls[i]); } @@ -558,8 +549,8 @@ pub impl CoherenceChecker { } fn can_unify_universally_quantified(&self, - a: &a/UniversalQuantificationResult, - b: &a/UniversalQuantificationResult) + a: &'a UniversalQuantificationResult, + b: &'a UniversalQuantificationResult) -> bool { let mut might_unify = true; let _ = do self.inference_context.probe { diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 6c8bfdb041d..b9aac4b19ed 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -81,8 +81,10 @@ pub fn collect_item_types(ccx: @mut CrateCtxt, crate: @ast::crate) { match intrinsic_item.node { ast::item_trait(*) => { - let ty = ty::mk_trait(ccx.tcx, def_id, substs, - ty::vstore_box); + let ty = ty::mk_trait(ccx.tcx, + def_id, + substs, + ty::BareTraitStore); ccx.tcx.intrinsic_defs.insert (intrinsic_item.ident, (def_id, ty)); } @@ -436,7 +438,7 @@ pub fn compare_impl_method(tcx: ty::ctxt, // Replace any references to the self region in the self type with // a free region. So, for example, if the impl type is - // "&self/str", then this would replace the self type with a free + // "&'self str", then this would replace the self type with a free // region `self`. let dummy_self_r = ty::re_free(cm.body_id, ty::br_self); let self_ty = replace_bound_self(tcx, self_ty, dummy_self_r); @@ -599,7 +601,7 @@ pub fn convert_methods(ccx: &CrateCtxt, pub fn ensure_no_ty_param_bounds(ccx: &CrateCtxt, span: span, generics: &ast::Generics, - thing: &static/str) { + thing: &'static str) { for generics.ty_params.each |ty_param| { if ty_param.bounds.len() > 0 { ccx.tcx.sess.span_err( @@ -893,7 +895,10 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: @ast::item) } ast::item_trait(ref generics, _, _) => { let (bounds, substs) = mk_substs(ccx, generics, rp); - let t = ty::mk_trait(tcx, local_def(it.id), substs, ty::vstore_box); + let t = ty::mk_trait(tcx, + local_def(it.id), + substs, + ty::BareTraitStore); let tpt = ty_param_bounds_and_ty { bounds: bounds, region_param: rp, diff --git a/src/librustc/middle/typeck/infer/combine.rs b/src/librustc/middle/typeck/infer/combine.rs index 1f5e9707e2d..3ec4fcb6d2e 100644 --- a/src/librustc/middle/typeck/infer/combine.rs +++ b/src/librustc/middle/typeck/infer/combine.rs @@ -102,10 +102,16 @@ pub trait Combine { fn purities(&self, a: purity, b: purity) -> cres<purity>; fn abis(&self, a: ast::Abi, b: ast::Abi) -> cres<ast::Abi>; fn oncenesses(&self, a: Onceness, b: Onceness) -> cres<Onceness>; - fn contraregions(&self, a: ty::Region, b: ty::Region) -> cres<ty::Region>; + fn contraregions(&self, a: ty::Region, b: ty::Region) + -> cres<ty::Region>; fn regions(&self, a: ty::Region, b: ty::Region) -> cres<ty::Region>; fn vstores(&self, vk: ty::terr_vstore_kind, a: ty::vstore, b: ty::vstore) -> cres<ty::vstore>; + fn trait_stores(&self, + vk: ty::terr_vstore_kind, + a: ty::TraitStore, + b: ty::TraitStore) + -> cres<ty::TraitStore>; } pub struct CombineFields { @@ -349,6 +355,30 @@ pub fn super_vstores<C:Combine>( } } +pub fn super_trait_stores<C:Combine>(self: &C, + vk: ty::terr_vstore_kind, + a: ty::TraitStore, + b: ty::TraitStore) + -> cres<ty::TraitStore> { + debug!("%s.super_vstores(a=%?, b=%?)", self.tag(), a, b); + + match (a, b) { + (ty::RegionTraitStore(a_r), ty::RegionTraitStore(b_r)) => { + do self.contraregions(a_r, b_r).chain |r| { + Ok(ty::RegionTraitStore(r)) + } + } + + _ if a == b => { + Ok(a) + } + + _ => { + Err(ty::terr_trait_stores_differ(vk, expected_found(self, a, b))) + } + } +} + pub fn super_closure_tys<C:Combine>( self: &C, a_f: &ty::ClosureTy, b_f: &ty::ClosureTy) -> cres<ty::ClosureTy> { @@ -491,12 +521,12 @@ pub fn super_tys<C:Combine>( } } - (ty::ty_trait(a_id, ref a_substs, a_vstore), - ty::ty_trait(b_id, ref b_substs, b_vstore)) + (ty::ty_trait(a_id, ref a_substs, a_store), + ty::ty_trait(b_id, ref b_substs, b_store)) if a_id == b_id => { do self.substs(a_id, a_substs, b_substs).chain |substs| { - do self.vstores(ty::terr_trait, a_vstore, b_vstore).chain |vs| { - Ok(ty::mk_trait(tcx, a_id, /*bad*/copy substs, vs)) + do self.trait_stores(ty::terr_trait, a_store, b_store).chain |s| { + Ok(ty::mk_trait(tcx, a_id, /*bad*/copy substs, s)) } } } diff --git a/src/librustc/middle/typeck/infer/glb.rs b/src/librustc/middle/typeck/infer/glb.rs index bba35f02b0c..ff13f7ee576 100644 --- a/src/librustc/middle/typeck/infer/glb.rs +++ b/src/librustc/middle/typeck/infer/glb.rs @@ -145,6 +145,14 @@ impl Combine for Glb { super_vstores(self, vk, a, b) } + fn trait_stores(&self, + vk: ty::terr_vstore_kind, + a: ty::TraitStore, + b: ty::TraitStore) + -> cres<ty::TraitStore> { + super_trait_stores(self, vk, a, b) + } + fn modes(&self, a: ast::mode, b: ast::mode) -> cres<ast::mode> { super_modes(self, a, b) } diff --git a/src/librustc/middle/typeck/infer/lattice.rs b/src/librustc/middle/typeck/infer/lattice.rs index 5c59f1215e4..1ce59064765 100644 --- a/src/librustc/middle/typeck/infer/lattice.rs +++ b/src/librustc/middle/typeck/infer/lattice.rs @@ -58,7 +58,7 @@ pub trait LatticeValue { -> cres<Self>; } -pub type LatticeOp<T> = &self/fn(cf: &CombineFields, a: &T, b: &T) -> cres<T>; +pub type LatticeOp<T> = &'self fn(cf: &CombineFields, a: &T, b: &T) -> cres<T>; impl LatticeValue for ty::t { static fn sub(&self, cf: &CombineFields, a: &ty::t, b: &ty::t) -> ures { @@ -378,7 +378,7 @@ pub fn super_lattice_tys<L:LatticeDir + TyLatticeDir + Combine>( } } -pub type LatticeDirOp<T> = &self/fn(a: &T, b: &T) -> cres<T>; +pub type LatticeDirOp<T> = &'self fn(a: &T, b: &T) -> cres<T>; pub enum LatticeVarResult<V,T> { VarResult(V), diff --git a/src/librustc/middle/typeck/infer/lub.rs b/src/librustc/middle/typeck/infer/lub.rs index 3a12fb31a1a..933ad44a79e 100644 --- a/src/librustc/middle/typeck/infer/lub.rs +++ b/src/librustc/middle/typeck/infer/lub.rs @@ -227,6 +227,14 @@ impl Combine for Lub { super_vstores(self, vk, a, b) } + fn trait_stores(&self, + vk: ty::terr_vstore_kind, + a: ty::TraitStore, + b: ty::TraitStore) + -> cres<ty::TraitStore> { + super_trait_stores(self, vk, a, b) + } + fn modes(&self, a: ast::mode, b: ast::mode) -> cres<ast::mode> { super_modes(self, a, b) } diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index f68a0db6387..11da6b60328 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -542,36 +542,37 @@ struct Snapshot { region_vars_snapshot: uint, } -pub impl @mut InferCtxt { - fn combine_fields(&self, a_is_expected: bool, +pub impl InferCtxt { + fn combine_fields(@mut self, a_is_expected: bool, span: span) -> CombineFields { - CombineFields {infcx: *self, + CombineFields {infcx: self, a_is_expected: a_is_expected, span: span} } - fn sub(&self, a_is_expected: bool, span: span) -> Sub { + fn sub(@mut self, a_is_expected: bool, span: span) -> Sub { Sub(self.combine_fields(a_is_expected, span)) } - fn in_snapshot(&self) -> bool { + fn in_snapshot(@mut self) -> bool { self.region_vars.in_snapshot() } - fn start_snapshot(&self) -> Snapshot { + fn start_snapshot(@mut self) -> Snapshot { + let this = &mut *self; Snapshot { ty_var_bindings_len: - self.ty_var_bindings.bindings.len(), + this.ty_var_bindings.bindings.len(), int_var_bindings_len: - self.int_var_bindings.bindings.len(), + this.int_var_bindings.bindings.len(), float_var_bindings_len: - self.float_var_bindings.bindings.len(), + this.float_var_bindings.bindings.len(), region_vars_snapshot: - self.region_vars.start_snapshot(), + this.region_vars.start_snapshot(), } } - fn rollback_to(&self, snapshot: &Snapshot) { + fn rollback_to(@mut self, snapshot: &Snapshot) { debug!("rollback!"); rollback_to(&mut self.ty_var_bindings, snapshot.ty_var_bindings_len); @@ -584,7 +585,7 @@ pub impl @mut InferCtxt { } /// Execute `f` and commit the bindings if successful - fn commit<T,E>(&self, f: &fn() -> Result<T,E>) -> Result<T,E> { + fn commit<T,E>(@mut self, f: &fn() -> Result<T,E>) -> Result<T,E> { fail_unless!(!self.in_snapshot()); debug!("commit()"); @@ -599,7 +600,7 @@ pub impl @mut InferCtxt { } /// Execute `f`, unroll bindings on failure - fn try<T,E>(&self, f: &fn() -> Result<T,E>) -> Result<T,E> { + fn try<T,E>(@mut self, f: &fn() -> Result<T,E>) -> Result<T,E> { debug!("try()"); do indent { let snapshot = self.start_snapshot(); @@ -613,7 +614,7 @@ pub impl @mut InferCtxt { } /// Execute `f` then unroll any bindings it creates - fn probe<T,E>(&self, f: &fn() -> Result<T,E>) -> Result<T,E> { + fn probe<T,E>(@mut self, f: &fn() -> Result<T,E>) -> Result<T,E> { debug!("probe()"); do indent { let snapshot = self.start_snapshot(); @@ -634,8 +635,8 @@ fn next_simple_var<V:Copy,T:Copy>( return id; } -pub impl @mut InferCtxt { - fn next_ty_var_id(&self) -> TyVid { +pub impl InferCtxt { + fn next_ty_var_id(@mut self) -> TyVid { let id = self.ty_var_counter; self.ty_var_counter += 1; let vals = self.ty_var_bindings.vals; @@ -643,37 +644,37 @@ pub impl @mut InferCtxt { return TyVid(id); } - fn next_ty_var(&self) -> ty::t { + fn next_ty_var(@mut self) -> ty::t { ty::mk_var(self.tcx, self.next_ty_var_id()) } - fn next_ty_vars(&self, n: uint) -> ~[ty::t] { + fn next_ty_vars(@mut self, n: uint) -> ~[ty::t] { vec::from_fn(n, |_i| self.next_ty_var()) } - fn next_int_var_id(&self) -> IntVid { + fn next_int_var_id(@mut self) -> IntVid { IntVid(next_simple_var(&mut self.int_var_counter, &mut self.int_var_bindings)) } - fn next_int_var(&self) -> ty::t { + fn next_int_var(@mut self) -> ty::t { ty::mk_int_var(self.tcx, self.next_int_var_id()) } - fn next_float_var_id(&self) -> FloatVid { + fn next_float_var_id(@mut self) -> FloatVid { FloatVid(next_simple_var(&mut self.float_var_counter, &mut self.float_var_bindings)) } - fn next_float_var(&self) -> ty::t { + fn next_float_var(@mut self) -> ty::t { ty::mk_float_var(self.tcx, self.next_float_var_id()) } - fn next_region_var_nb(&self, span: span) -> ty::Region { + fn next_region_var_nb(@mut self, span: span) -> ty::Region { ty::re_infer(ty::ReVar(self.region_vars.new_region_var(span))) } - fn next_region_var_with_lb(&self, span: span, + fn next_region_var_with_lb(@mut self, span: span, lb_region: ty::Region) -> ty::Region { let region_var = self.next_region_var_nb(span); @@ -685,28 +686,28 @@ pub impl @mut InferCtxt { return region_var; } - fn next_region_var(&self, span: span, scope_id: ast::node_id) + fn next_region_var(@mut self, span: span, scope_id: ast::node_id) -> ty::Region { self.next_region_var_with_lb(span, ty::re_scope(scope_id)) } - fn resolve_regions(&self) { + fn resolve_regions(@mut self) { self.region_vars.resolve_regions(); } - fn ty_to_str(&self, t: ty::t) -> ~str { + fn ty_to_str(@mut self, t: ty::t) -> ~str { ty_to_str(self.tcx, self.resolve_type_vars_if_possible(t)) } - fn resolve_type_vars_if_possible(&self, typ: ty::t) -> ty::t { - match resolve_type(*self, typ, resolve_nested_tvar | resolve_ivar) { + fn resolve_type_vars_if_possible(@mut self, typ: ty::t) -> ty::t { + match resolve_type(self, typ, resolve_nested_tvar | resolve_ivar) { result::Ok(new_type) => new_type, result::Err(_) => typ } } - fn type_error_message(&self, sp: span, mk_msg: &fn(~str) -> ~str, + fn type_error_message(@mut self, sp: span, mk_msg: &fn(~str) -> ~str, actual_ty: ty::t, err: Option<&ty::type_err>) { let actual_ty = self.resolve_type_vars_if_possible(actual_ty); @@ -725,7 +726,7 @@ pub impl @mut InferCtxt { } } - fn report_mismatched_types(&self, sp: span, e: ty::t, a: ty::t, + fn report_mismatched_types(@mut self, sp: span, e: ty::t, a: ty::t, err: &ty::type_err) { let resolved_expected = self.resolve_type_vars_if_possible(e); @@ -743,7 +744,7 @@ pub impl @mut InferCtxt { self.type_error_message(sp, mk_msg, a, Some(err)); } - fn replace_bound_regions_with_fresh_regions(&self, + fn replace_bound_regions_with_fresh_regions(@mut self, span: span, fsig: &ty::FnSig) -> (ty::FnSig, isr_alist) { @@ -763,7 +764,7 @@ pub impl @mut InferCtxt { } fn fold_regions_in_sig( - &self, + @mut self, fn_sig: &ty::FnSig, fldr: &fn(r: ty::Region, in_fn: bool) -> ty::Region) -> ty::FnSig { diff --git a/src/librustc/middle/typeck/infer/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index 33e953b6218..534e50e115f 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -153,7 +153,7 @@ The problem we are addressing is that there is a kind of subtyping between functions with bound region parameters. Consider, for example, whether the following relation holds: - fn(&a/int) <: &fn(&b/int)? (Yes, a => b) + fn(&'a int) <: &fn(&'b int)? (Yes, a => b) The answer is that of course it does. These two types are basically the same, except that in one we used the name `a` and one we used @@ -163,14 +163,14 @@ In the examples that follow, it becomes very important to know whether a lifetime is bound in a function type (that is, is a lifetime parameter) or appears free (is defined in some outer scope). Therefore, from now on I will write the bindings explicitly, using a -notation like `fn<a>(&a/int)` to indicate that `a` is a lifetime +notation like `fn<a>(&'a int)` to indicate that `a` is a lifetime parameter. Now let's consider two more function types. Here, we assume that the `self` lifetime is defined somewhere outside and hence is not a lifetime parameter bound by the function type (it "appears free"): - fn<a>(&a/int) <: &fn(&self/int)? (Yes, a => self) + fn<a>(&'a int) <: &fn(&'self int)? (Yes, a => self) This subtyping relation does in fact hold. To see why, you have to consider what subtyping means. One way to look at `T1 <: T2` is to @@ -187,7 +187,7 @@ to the same thing: a function that accepts pointers with any lifetime So, what if we reverse the order of the two function types, like this: - fn(&self/int) <: &fn<a>(&a/int)? (No) + fn(&'self int) <: &fn<a>(&'a int)? (No) Does the subtyping relationship still hold? The answer of course is no. In this case, the function accepts *only the lifetime `&self`*, @@ -196,8 +196,8 @@ accepted any lifetime. What about these two examples: - fn<a,b>(&a/int, &b/int) <: &fn<a>(&a/int, &a/int)? (Yes) - fn<a>(&a/int, &a/int) <: &fn<a,b>(&a/int, &b/int)? (No) + fn<a,b>(&'a int, &'b int) <: &fn<a>(&'a int, &'a int)? (Yes) + fn<a>(&'a int, &'a int) <: &fn<a,b>(&'a int, &'b int)? (No) Here, it is true that functions which take two pointers with any two lifetimes can be treated as if they only accepted two pointers with @@ -221,12 +221,12 @@ Let's walk through some examples and see how this algorithm plays out. We'll start with the first example, which was: - 1. fn<a>(&a/T) <: &fn<b>(&b/T)? Yes: a -> b + 1. fn<a>(&'a T) <: &fn<b>(&'b T)? Yes: a -> b After steps 1 and 2 of the algorithm we will have replaced the types like so: - 1. fn(&A/T) <: &fn(&x/T)? + 1. fn(&'A T) <: &fn(&'x T)? Here the upper case `&A` indicates a *region variable*, that is, a region whose value is being inferred by the system. I also replaced @@ -238,7 +238,7 @@ region names anymore (as indicated by the absence of `<` and `>`). The next step is to check that the parameter types match. Because parameters are contravariant, this means that we check whether: - &x/T <: &A/T + &'x T <: &'A T Region pointers are contravariant so this implies that @@ -255,12 +255,12 @@ So far we have encountered no error, so the subtype check succeeds. Now let's look first at the third example, which was: - 3. fn(&self/T) <: &fn<b>(&b/T)? No! + 3. fn(&'self T) <: &fn<b>(&'b T)? No! After steps 1 and 2 of the algorithm we will have replaced the types like so: - 3. fn(&self/T) <: &fn(&x/T)? + 3. fn(&'self T) <: &fn(&'x T)? This looks pretty much the same as before, except that on the LHS `&self` was not bound, and hence was left as-is and not replaced with @@ -275,33 +275,33 @@ You may be wondering about that mysterious last step in the algorithm. So far it has not been relevant. The purpose of that last step is to catch something like *this*: - fn<a>() -> fn(&a/T) <: &fn() -> fn<b>(&b/T)? No. + fn<a>() -> fn(&'a T) <: &fn() -> fn<b>(&'b T)? No. Here the function types are the same but for where the binding occurs. The subtype returns a function that expects a value in precisely one region. The supertype returns a function that expects a value in any region. If we allow an instance of the subtype to be used where the supertype is expected, then, someone could call the fn and think that -the return value has type `fn<b>(&b/T)` when it really has type -`fn(&a/T)` (this is case #3, above). Bad. +the return value has type `fn<b>(&'b T)` when it really has type +`fn(&'a T)` (this is case #3, above). Bad. So let's step through what happens when we perform this subtype check. We first replace the bound regions in the subtype (the supertype has no bound regions). This gives us: - fn() -> fn(&A/T) <: &fn() -> fn<b>(&b/T)? + fn() -> fn(&'A T) <: &fn() -> fn<b>(&'b T)? Now we compare the return types, which are covariant, and hence we have: - fn(&A/T) <: &fn<b>(&b/T)? + fn(&'A T) <: &fn<b>(&'b T)? Here we skolemize the bound region in the supertype to yield: - fn(&A/T) <: &fn(&x/T)? + fn(&'A T) <: &fn(&'x T)? And then proceed to compare the argument types: - &x/T <: &A/T + &'x T <: &'A T &A <= &x Finally, this is where it gets interesting! This is where an error @@ -314,7 +314,7 @@ The difference between this example and the first one is that the variable `A` already existed at the point where the skolemization occurred. In the first example, you had two functions: - fn<a>(&a/T) <: &fn<b>(&b/T) + fn<a>(&'a T) <: &fn<b>(&'b T) and hence `&A` and `&x` were created "together". In general, the intention of the skolemized names is that they are supposed to be diff --git a/src/librustc/middle/typeck/infer/sub.rs b/src/librustc/middle/typeck/infer/sub.rs index b4d8905a936..580aefe5b1a 100644 --- a/src/librustc/middle/typeck/infer/sub.rs +++ b/src/librustc/middle/typeck/infer/sub.rs @@ -239,6 +239,14 @@ impl Combine for Sub { super_vstores(self, vk, a, b) } + fn trait_stores(&self, + vk: ty::terr_vstore_kind, + a: ty::TraitStore, + b: ty::TraitStore) + -> cres<ty::TraitStore> { + super_trait_stores(self, vk, a, b) + } + fn modes(&self, a: ast::mode, b: ast::mode) -> cres<ast::mode> { super_modes(self, a, b) } diff --git a/src/librustc/middle/typeck/infer/unify.rs b/src/librustc/middle/typeck/infer/unify.rs index d692a66f699..fe77b62de43 100644 --- a/src/librustc/middle/typeck/infer/unify.rs +++ b/src/librustc/middle/typeck/infer/unify.rs @@ -35,8 +35,8 @@ pub struct Node<V, T> { } pub trait UnifyVid<T> { - static fn appropriate_vals_and_bindings(&self, infcx: &v/mut InferCtxt) - -> &v/mut ValsAndBindings<Self, T>; + static fn appropriate_vals_and_bindings(&self, infcx: &'v mut InferCtxt) + -> &'v mut ValsAndBindings<Self, T>; } pub impl InferCtxt { @@ -235,15 +235,15 @@ pub impl InferCtxt { // ______________________________________________________________________ impl UnifyVid<Bounds<ty::t>> for ty::TyVid { - static fn appropriate_vals_and_bindings(&self, infcx: &v/mut InferCtxt) - -> &v/mut ValsAndBindings<ty::TyVid, Bounds<ty::t>> { + static fn appropriate_vals_and_bindings(&self, infcx: &'v mut InferCtxt) + -> &'v mut ValsAndBindings<ty::TyVid, Bounds<ty::t>> { return &mut infcx.ty_var_bindings; } } impl UnifyVid<Option<IntVarValue>> for ty::IntVid { - static fn appropriate_vals_and_bindings(&self, infcx: &v/mut InferCtxt) - -> &v/mut ValsAndBindings<ty::IntVid, Option<IntVarValue>> { + static fn appropriate_vals_and_bindings(&self, infcx: &'v mut InferCtxt) + -> &'v mut ValsAndBindings<ty::IntVid, Option<IntVarValue>> { return &mut infcx.int_var_bindings; } } @@ -256,8 +256,8 @@ impl SimplyUnifiable for IntVarValue { } impl UnifyVid<Option<ast::float_ty>> for ty::FloatVid { - static fn appropriate_vals_and_bindings(&self, infcx: &v/mut InferCtxt) - -> &v/mut ValsAndBindings<ty::FloatVid, Option<ast::float_ty>> { + static fn appropriate_vals_and_bindings(&self, infcx: &'v mut InferCtxt) + -> &'v mut ValsAndBindings<ty::FloatVid, Option<ast::float_ty>> { return &mut infcx.float_var_bindings; } } diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index abaf658a1a4..ed1a3d33f4c 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -90,7 +90,7 @@ pub enum method_origin { method_param(method_param), // method invoked on a trait instance - method_trait(ast::def_id, uint, ty::vstore), + method_trait(ast::def_id, uint, ty::TraitStore), // method invoked on "self" inside a default method method_self(ast::def_id, uint) @@ -273,26 +273,6 @@ impl get_and_find_region for isr_alist { } } -fn arg_is_argv_ty(tcx: ty::ctxt, a: ty::arg) -> bool { - match ty::resolved_mode(tcx, a.mode) { - ast::by_val => { /*ok*/ } - _ => { - return false; - } - } - - match ty::get(a.ty).sty { - ty::ty_evec(mt, vstore_uniq) => { - if mt.mutbl != ast::m_imm { return false; } - match ty::get(mt.ty).sty { - ty::ty_estr(vstore_uniq) => return true, - _ => return false - } - } - _ => return false - } -} - fn check_main_fn_ty(ccx: @mut CrateCtxt, main_id: ast::node_id, main_span: span) { diff --git a/src/librustc/middle/typeck/rscope.rs b/src/librustc/middle/typeck/rscope.rs index f74a0960f66..e29e63c41ec 100644 --- a/src/librustc/middle/typeck/rscope.rs +++ b/src/librustc/middle/typeck/rscope.rs @@ -125,7 +125,8 @@ pub struct binding_rscope { pub fn in_binding_rscope<RS:region_scope + Copy + Durable>(self: &RS) -> binding_rscope { - let base = @(copy *self) as @region_scope; + let base = @copy *self; + let base = base as @region_scope; binding_rscope { base: base, anon_bindings: @mut 0 } } impl region_scope for binding_rscope { diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 7add8dd2dbe..77258d0b329 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -132,21 +132,21 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region) } pub fn bound_region_to_str(cx: ctxt, br: bound_region) -> ~str { - bound_region_to_str_adorned(cx, "&", br, "") + bound_region_to_str_space(cx, "&", br) } -pub fn bound_region_to_str_adorned(cx: ctxt, prefix: &str, - br: bound_region, sep: &str) -> ~str { - if cx.sess.verbose() { return fmt!("%s%?%s", prefix, br, sep); } +pub fn bound_region_to_str_space(cx: ctxt, + prefix: &str, + br: bound_region) + -> ~str { + if cx.sess.verbose() { return fmt!("%s%? ", prefix, br); } match br { - br_named(id) => fmt!("%s%s%s", prefix, *cx.sess.str_of(id), - sep), - br_self => fmt!("%sself%s", prefix, sep), + br_named(id) => fmt!("%s'%s ", prefix, *cx.sess.str_of(id)), + br_self => fmt!("%s'self ", prefix), br_anon(_) => prefix.to_str(), br_fresh(_) => prefix.to_str(), - br_cap_avoid(_, br) => bound_region_to_str_adorned(cx, prefix, - *br, sep) + br_cap_avoid(_, br) => bound_region_to_str_space(cx, prefix, *br) } } @@ -194,13 +194,12 @@ pub fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str { // you should use `explain_region()` or, better yet, // `note_and_explain_region()` pub fn region_to_str(cx: ctxt, region: Region) -> ~str { - region_to_str_adorned(cx, "&", region, "") + region_to_str_space(cx, "&", region) } -pub fn region_to_str_adorned(cx: ctxt, prefix: &str, - region: Region, sep: &str) -> ~str { +pub fn region_to_str_space(cx: ctxt, prefix: &str, region: Region) -> ~str { if cx.sess.verbose() { - return fmt!("%s%?%s", prefix, region, sep); + return fmt!("%s%? ", prefix, region); } // These printouts are concise. They do not contain all the information @@ -209,13 +208,13 @@ pub fn region_to_str_adorned(cx: ctxt, prefix: &str, // `explain_region()` or `note_and_explain_region()`. match region { re_scope(_) => prefix.to_str(), - re_bound(br) => bound_region_to_str_adorned(cx, prefix, br, sep), - re_free(_, br) => bound_region_to_str_adorned(cx, prefix, br, sep), + re_bound(br) => bound_region_to_str_space(cx, prefix, br), + re_free(_, br) => bound_region_to_str_space(cx, prefix, br), re_infer(ReSkolemized(_, br)) => { - bound_region_to_str_adorned(cx, prefix, br, sep) + bound_region_to_str_space(cx, prefix, br) } re_infer(ReVar(_)) => prefix.to_str(), - re_static => fmt!("%sstatic%s", prefix, sep) + re_static => fmt!("%s'static ", prefix) } } @@ -233,7 +232,16 @@ pub fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str { ty::vstore_fixed(n) => fmt!("%u", n), ty::vstore_uniq => ~"~", ty::vstore_box => ~"@", - ty::vstore_slice(r) => region_to_str_adorned(cx, "&", r, "/") + ty::vstore_slice(r) => region_to_str_space(cx, "&", r) + } +} + +pub fn trait_store_to_str(cx: ctxt, s: ty::TraitStore) -> ~str { + match s { + ty::BareTraitStore => ~"", + ty::UniqTraitStore => ~"~", + ty::BoxTraitStore => ~"@", + ty::RegionTraitStore(r) => region_to_str_space(cx, "&", r) } } @@ -243,7 +251,7 @@ pub fn vstore_ty_to_str(cx: ctxt, ty: ~str, vs: ty::vstore) -> ~str { fmt!("[%s * %s]", ty, vstore_to_str(cx, vs)) } ty::vstore_slice(_) => { - fmt!("%s/%s", vstore_to_str(cx, vs), ty) + fmt!("%s %s", vstore_to_str(cx, vs), ty) } _ => fmt!("%s[%s]", vstore_to_str(cx, vs), ty) } @@ -335,7 +343,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str { (ast::OwnedSigil, ty::re_static) => {} (_, region) => { - s.push_str(region_to_str_adorned(cx, "", region, "/")); + s.push_str(region_to_str_space(cx, "", region)); } } @@ -409,7 +417,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str { ty_uniq(tm) => ~"~" + mt_to_str(cx, tm), ty_ptr(tm) => ~"*" + mt_to_str(cx, tm), ty_rptr(r, tm) => { - region_to_str_adorned(cx, ~"&", r, ~"/") + mt_to_str(cx, tm) + region_to_str_space(cx, ~"&", r) + mt_to_str(cx, tm) } ty_unboxed_vec(tm) => { ~"unboxed_vec<" + mt_to_str(cx, tm) + ~">" } ty_type => ~"type", @@ -441,11 +449,11 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str { let base = ast_map::path_to_str(path, cx.sess.intr()); parameterized(cx, base, substs.self_r, substs.tps) } - ty_trait(did, ref substs, vs) => { + ty_trait(did, ref substs, s) => { let path = ty::item_path(cx, did); let base = ast_map::path_to_str(path, cx.sess.intr()); let ty = parameterized(cx, base, substs.self_r, substs.tps); - fmt!("%s%s", vstore_to_str(cx, vs), ty) + fmt!("%s%s", trait_store_to_str(cx, s), ty) } ty_evec(mt, vs) => { vstore_ty_to_str(cx, fmt!("%s", mt_to_str(cx, mt)), vs) diff --git a/src/librustdoc/demo.rs b/src/librustdoc/demo.rs index 6a3a509ded4..ad57af8942d 100644 --- a/src/librustdoc/demo.rs +++ b/src/librustdoc/demo.rs @@ -128,7 +128,7 @@ struct Bored { } impl Drop for Bored { - fn finalize(&self) { log(error, self.bored); } + fn finalize(&self) { } } /** diff --git a/src/librustdoc/markdown_pass.rs b/src/librustdoc/markdown_pass.rs index d7dd288ed89..70d5c730569 100644 --- a/src/librustdoc/markdown_pass.rs +++ b/src/librustdoc/markdown_pass.rs @@ -734,8 +734,8 @@ fn should_write_trait_method_header() { #[test] fn should_write_trait_method_signature() { let markdown = test::render( - ~"trait i { fn a(); }"); - fail_unless!(str::contains(markdown, ~"\n fn a()")); + ~"trait i { fn a(&self); }"); + fail_unless!(str::contains(markdown, ~"\n fn a(&self)")); } fn write_impl(ctxt: &Ctxt, doc: doc::ImplDoc) { @@ -773,8 +773,8 @@ fn should_write_impl_method_header() { #[test] fn should_write_impl_method_signature() { let markdown = test::render( - ~"impl int { fn a() { } }"); - fail_unless!(str::contains(markdown, ~"\n fn a()")); + ~"impl int { fn a(&mut self) { } }"); + fail_unless!(str::contains(markdown, ~"\n fn a(&mut self)")); } fn write_type( diff --git a/src/librustdoc/pass.rs b/src/librustdoc/pass.rs index 7b80b0b4ae8..e71b145d7df 100644 --- a/src/librustdoc/pass.rs +++ b/src/librustdoc/pass.rs @@ -31,7 +31,7 @@ pub fn run_passes( ) -> doc::Doc { let mut passno = 0; do vec::foldl(doc, passes) |doc, pass| { - log(debug, fmt!("pass #%d", passno)); + debug!("pass #%d", passno); passno += 1; do time(copy pass.name) { (pass.f)(srv.clone(), copy doc) diff --git a/src/librustdoc/prune_private_pass.rs b/src/librustdoc/prune_private_pass.rs index 17f11de8aeb..67dbc659f9e 100644 --- a/src/librustdoc/prune_private_pass.rs +++ b/src/librustdoc/prune_private_pass.rs @@ -59,7 +59,19 @@ fn is_visible(srv: astsrv::Srv, doc: doc::ItemDoc) -> bool { do astsrv::exec(srv) |ctxt| { match ctxt.ast_map.get(&id) { ast_map::node_item(item, _) => { - item.vis == ast::public + match item.node { + ast::item_impl(_, Some(_), _, _) => { + // This is a trait implementation, make it visible + // NOTE: This is not quite right since this could be an impl + // of a private trait. We can't know that without running + // resolve though. + true + } + _ => { + // Otherwise just look at the visibility + item.vis == ast::public + } + } } _ => util::unreachable() } @@ -72,6 +84,16 @@ fn should_prune_items_without_pub_modifier() { fail_unless!(vec::is_empty(doc.cratemod().mods())); } +#[test] +fn unless_they_are_trait_impls() { + let doc = test::mk_doc( + ~" \ + trait Foo { } \ + impl Foo for int { } \ + "); + fail_unless!(!doc.cratemod().impls().is_empty()); +} + #[cfg(test)] pub mod test { use astsrv; diff --git a/src/librustdoc/rustdoc.rc b/src/librustdoc/rustdoc.rc index f5cf98759b3..5cae8e31657 100644 --- a/src/librustdoc/rustdoc.rc +++ b/src/librustdoc/rustdoc.rc @@ -116,8 +116,7 @@ fn run(config: Config) { // Remove things marked doc(hidden) prune_hidden_pass::mk_pass(), // Remove things that are private - // XXX enable this after 'export' is removed in favor of 'pub' - // prune_private_pass::mk_pass(), + prune_private_pass::mk_pass(), // Extract brief documentation from the full descriptions desc_to_brief_pass::mk_pass(), // Massage the text to remove extra indentation diff --git a/src/librustdoc/tystr_pass.rs b/src/librustdoc/tystr_pass.rs index e5f304ee8ac..54197e316da 100644 --- a/src/librustdoc/tystr_pass.rs +++ b/src/librustdoc/tystr_pass.rs @@ -75,7 +75,7 @@ fn get_fn_sig(srv: astsrv::Srv, fn_id: doc::AstId) -> Option<~str> { ident: ident, node: ast::foreign_item_fn(ref decl, _, ref tys), _ }, _, _) => { - Some(pprust::fun_to_str(decl, ident, tys, + Some(pprust::fun_to_str(decl, ident, None, tys, extract::interner())) } _ => fail!(~"get_fn_sig: fn_id not bound to a fn item") @@ -215,6 +215,7 @@ fn get_method_sig( Some(pprust::fun_to_str( &ty_m.decl, ty_m.ident, + Some(ty_m.self_ty.node), &ty_m.generics, extract::interner() )) @@ -223,6 +224,7 @@ fn get_method_sig( Some(pprust::fun_to_str( &m.decl, m.ident, + Some(m.self_ty.node), &m.generics, extract::interner() )) @@ -242,6 +244,7 @@ fn get_method_sig( Some(pprust::fun_to_str( &method.decl, method.ident, + Some(method.self_ty.node), &method.generics, extract::interner() )) @@ -256,9 +259,9 @@ fn get_method_sig( #[test] fn should_add_trait_method_sigs() { - let doc = test::mk_doc(~"trait i { fn a<T>() -> int; }"); + let doc = test::mk_doc(~"trait i { fn a<T>(&mut self) -> int; }"); fail_unless!(doc.cratemod().traits()[0].methods[0].sig - == Some(~"fn a<T>() -> int")); + == Some(~"fn a<T>(&mut self) -> int")); } fn fold_impl( @@ -315,9 +318,9 @@ fn should_add_impl_self_ty() { #[test] fn should_add_impl_method_sigs() { - let doc = test::mk_doc(~"impl int { fn a<T>() -> int { fail!() } }"); + let doc = test::mk_doc(~"impl int { fn a<T>(&self) -> int { fail!() } }"); fail_unless!(doc.cratemod().impls()[0].methods[0].sig - == Some(~"fn a<T>() -> int")); + == Some(~"fn a<T>(&self) -> int")); } fn fold_type( diff --git a/src/librusti/rusti.rc b/src/librusti/rusti.rc index 0367a771ffb..182cfc43ade 100644 --- a/src/librusti/rusti.rc +++ b/src/librusti/rusti.rc @@ -59,7 +59,7 @@ enum CmdAction { /// A utility function that hands off a pretty printer to a callback. fn with_pp(intr: @token::ident_interner, - cb: &fn(@pprust::ps, io::Writer)) -> ~str { + cb: &fn(@pprust::ps, @io::Writer)) -> ~str { do io::with_str_writer |writer| { let pp = pprust::rust_printer(writer, intr); @@ -257,7 +257,7 @@ fn get_line(prompt: ~str) -> Option<~str> { } /// Run a command, e.g. :clear, :exit, etc. -fn run_cmd(repl: &mut Repl, _in: io::Reader, _out: io::Writer, +fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer, cmd: ~str, args: ~[~str]) -> CmdAction { let mut action = action_none; match cmd { @@ -334,7 +334,7 @@ fn run_cmd(repl: &mut Repl, _in: io::Reader, _out: io::Writer, /// Executes a line of input, which may either be rust code or a /// :command. Returns a new Repl if it has changed. -fn run_line(repl: &mut Repl, in: io::Reader, out: io::Writer, line: ~str) +fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str) -> Option<Repl> { if line.starts_with(~":") { let full = line.substr(1, line.len() - 1); diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index 7d2b8eccd6c..0572cf771db 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -70,13 +70,14 @@ struct ListenerFn { struct ReadyCtx { sess: session::Session, crate: @ast::crate, - ext_cx: ext_ctxt, + ext_cx: @ext_ctxt, path: ~[ast::ident], fns: ~[ListenerFn] } -fn fold_mod(_ctx: @mut ReadyCtx, m: &ast::_mod, - fold: fold::ast_fold) -> ast::_mod { +fn fold_mod(_ctx: @mut ReadyCtx, + m: &ast::_mod, + fold: @fold::ast_fold) -> ast::_mod { fn strip_main(item: @ast::item) -> @ast::item { @ast::item { attrs: do item.attrs.filtered |attr| { @@ -94,9 +95,9 @@ fn fold_mod(_ctx: @mut ReadyCtx, m: &ast::_mod, }, fold) } -fn fold_item(ctx: @mut ReadyCtx, item: @ast::item, - fold: fold::ast_fold) -> Option<@ast::item> { - +fn fold_item(ctx: @mut ReadyCtx, + item: @ast::item, + fold: @fold::ast_fold) -> Option<@ast::item> { ctx.path.push(item.ident); let attrs = attr::find_attrs_by_name(item.attrs, ~"pkg_do"); diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs index d7d878fa192..5a08884777c 100644 --- a/src/libstd/arc.rs +++ b/src/libstd/arc.rs @@ -27,8 +27,8 @@ use core::task; /// As sync::condvar, a mechanism for unlock-and-descheduling and signalling. pub struct Condvar { is_mutex: bool, - failed: &self/mut bool, - cond: &self/sync::Condvar/&self + failed: &'self mut bool, + cond: &'self sync::Condvar/&self } pub impl Condvar/&self { @@ -95,7 +95,7 @@ pub fn ARC<T:Const + Owned>(data: T) -> ARC<T> { * Access the underlying data in an atomically reference counted * wrapper. */ -pub fn get<T:Const + Owned>(rc: &a/ARC<T>) -> &a/T { +pub fn get<T:Const + Owned>(rc: &'a ARC<T>) -> &'a T { unsafe { get_shared_immutable_state(&rc.x) } } @@ -193,7 +193,7 @@ pub impl<T:Owned> MutexARC<T> { #[inline(always)] unsafe fn access_cond<U>( &self, - blk: &fn(x: &x/mut T, c: &c/Condvar) -> U) -> U + blk: &fn(x: &'x mut T, c: &'c Condvar) -> U) -> U { unsafe { let state = get_shared_mutable_state(&self.x); @@ -239,7 +239,7 @@ impl Drop for PoisonOnFail { } } -fn PoisonOnFail(failed: &r/mut bool) -> PoisonOnFail { +fn PoisonOnFail(failed: &'r mut bool) -> PoisonOnFail { PoisonOnFail { failed: ptr::to_mut_unsafe_ptr(failed) } @@ -313,7 +313,7 @@ pub impl<T:Const + Owned> RWARC<T> { } /// As write(), but with a condvar, as sync::rwlock.write_cond(). #[inline(always)] - fn write_cond<U>(&self, blk: &fn(x: &x/mut T, c: &c/Condvar) -> U) -> U { + fn write_cond<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| { @@ -436,7 +436,7 @@ pub impl<T:Const + Owned> RWWriteMode/&self<T> { } } /// Access the pre-downgrade RWARC in write mode with a condvar. - fn write_cond<U>(&self, blk: &fn(x: &x/mut T, c: &c/Condvar) -> U) -> U { + fn write_cond<U>(&self, blk: &fn(x: &'x mut T, c: &'c Condvar) -> U) -> U { match *self { RWWriteMode { data: ref data, @@ -509,7 +509,7 @@ mod tests { fail_unless!((*arc::get(&arc_v))[2] == 3); - log(info, arc_v); + info!(arc_v); } #[test] @@ -572,7 +572,7 @@ mod tests { #[test] #[should_fail] #[ignore(cfg(windows))] pub fn test_rw_arc_poison_wr() { let arc = ~RWARC(1); - let arc2 = ~arc.clone(); + let arc2 = (*arc).clone(); do task::try || { do arc2.write |one| { fail_unless!(*one == 2); @@ -585,7 +585,7 @@ mod tests { #[test] #[should_fail] #[ignore(cfg(windows))] pub fn test_rw_arc_poison_ww() { let arc = ~RWARC(1); - let arc2 = ~arc.clone(); + let arc2 = (*arc).clone(); do task::try || { do arc2.write |one| { fail_unless!(*one == 2); @@ -598,7 +598,7 @@ mod tests { #[test] #[should_fail] #[ignore(cfg(windows))] pub fn test_rw_arc_poison_dw() { let arc = ~RWARC(1); - let arc2 = ~arc.clone(); + let arc2 = (*arc).clone(); do task::try || { do arc2.write_downgrade |write_mode| { do (&write_mode).write |one| { @@ -613,7 +613,7 @@ mod tests { #[test] #[ignore(cfg(windows))] pub fn test_rw_arc_no_poison_rr() { let arc = ~RWARC(1); - let arc2 = ~arc.clone(); + let arc2 = (*arc).clone(); do task::try || { do arc2.read |one| { fail_unless!(*one == 2); @@ -626,7 +626,7 @@ mod tests { #[test] #[ignore(cfg(windows))] pub fn test_rw_arc_no_poison_rw() { let arc = ~RWARC(1); - let arc2 = ~arc.clone(); + let arc2 = (*arc).clone(); do task::try || { do arc2.read |one| { fail_unless!(*one == 2); @@ -639,7 +639,7 @@ mod tests { #[test] #[ignore(cfg(windows))] pub fn test_rw_arc_no_poison_dr() { let arc = ~RWARC(1); - let arc2 = ~arc.clone(); + let arc2 = (*arc).clone(); do task::try || { do arc2.write_downgrade |write_mode| { let read_mode = arc2.downgrade(write_mode); @@ -655,7 +655,7 @@ mod tests { #[test] pub fn test_rw_arc() { let arc = ~RWARC(0); - let arc2 = ~arc.clone(); + let arc2 = (*arc).clone(); let (p,c) = comm::stream(); do task::spawn || { @@ -673,7 +673,7 @@ mod tests { // Readers try to catch the writer in the act let mut children = ~[]; for 5.times { - let arc3 = ~arc.clone(); + let arc3 = (*arc).clone(); do task::task().future_result(|+r| children.push(r)).spawn || { do arc3.read |num| { @@ -704,7 +704,7 @@ mod tests { for 10.times { let ((rp1,rc1),(rp2,rc2)) = (comm::stream(),comm::stream()); reader_convos.push((rc1, rp2)); - let arcn = ~arc.clone(); + let arcn = (*arc).clone(); do task::spawn || { rp1.recv(); // wait for downgrader to give go-ahead do arcn.read |state| { @@ -715,7 +715,7 @@ mod tests { } // Writer task - let arc2 = ~arc.clone(); + let arc2 = (*arc).clone(); let ((wp1,wc1),(wp2,wc2)) = (comm::stream(),comm::stream()); do task::spawn || { wp1.recv(); diff --git a/src/libstd/arena.rs b/src/libstd/arena.rs index 695b3d01376..68132a1c08d 100644 --- a/src/libstd/arena.rs +++ b/src/libstd/arena.rs @@ -49,7 +49,7 @@ use core::vec; pub mod rusti { #[abi = "rust-intrinsic"] pub extern { - fn move_val_init<T>(dst: &mut T, -src: T); + fn move_val_init<T>(dst: &mut T, +src: T); fn needs_drop<T>() -> bool; } } @@ -201,7 +201,7 @@ pub impl Arena { } #[inline(always)] - fn alloc_pod<T>(&self, op: &fn() -> T) -> &self/T { + fn alloc_pod<T>(&self, op: &fn() -> T) -> &'self T { unsafe { let tydesc = sys::get_type_desc::<T>(); let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align); @@ -246,7 +246,7 @@ pub impl Arena { } #[inline(always)] - fn alloc_nonpod<T>(&self, op: &fn() -> T) -> &self/T { + fn alloc_nonpod<T>(&self, op: &fn() -> T) -> &'self T { unsafe { let tydesc = sys::get_type_desc::<T>(); let (ty_ptr, ptr) = @@ -268,7 +268,7 @@ pub impl Arena { // The external interface #[inline(always)] - fn alloc<T>(&self, op: &fn() -> T) -> &self/T { + fn alloc<T>(&self, op: &fn() -> T) -> &'self T { unsafe { if !rusti::needs_drop::<T>() { self.alloc_pod(op) diff --git a/src/libstd/base64.rs b/src/libstd/base64.rs index 0bd9e1eac51..56ce54be44e 100644 --- a/src/libstd/base64.rs +++ b/src/libstd/base64.rs @@ -16,7 +16,7 @@ pub trait ToBase64 { pure fn to_base64(&self) -> ~str; } -impl ToBase64 for &self/[u8] { +impl ToBase64 for &'self [u8] { pure fn to_base64(&self) -> ~str { let chars = str::chars( ~"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" @@ -69,7 +69,7 @@ impl ToBase64 for &self/[u8] { } } -impl ToBase64 for &self/str { +impl ToBase64 for &'self str { pure fn to_base64(&self) -> ~str { str::to_bytes(*self).to_base64() } diff --git a/src/libstd/bigint.rs b/src/libstd/bigint.rs index 5c3f37faca7..e128859bb7d 100644 --- a/src/libstd/bigint.rs +++ b/src/libstd/bigint.rs @@ -1045,9 +1045,9 @@ mod biguint_tests { fail_unless!(BigUint::new(~[0, 0, -1]).to_uint() == uint::max_value); } - const sum_triples: &static/[(&static/[BigDigit], - &static/[BigDigit], - &static/[BigDigit])] = &[ + const sum_triples: &'static [(&'static [BigDigit], + &'static [BigDigit], + &'static [BigDigit])] = &[ (&[], &[], &[]), (&[], &[ 1], &[ 1]), (&[ 1], &[ 1], &[ 2]), @@ -1085,9 +1085,9 @@ mod biguint_tests { } } - const mul_triples: &static/[(&static/[BigDigit], - &static/[BigDigit], - &static/[BigDigit])] = &[ + const mul_triples: &'static [(&'static [BigDigit], + &'static [BigDigit], + &'static [BigDigit])] = &[ (&[], &[], &[]), (&[], &[ 1], &[]), (&[ 2], &[], &[]), @@ -1111,10 +1111,10 @@ mod biguint_tests { (&[ 0, 0, 1], &[ 0, 0, 0, 1], &[0, 0, 0, 0, 0, 1]) ]; - const divmod_quadruples: &static/[(&static/[BigDigit], - &static/[BigDigit], - &static/[BigDigit], - &static/[BigDigit])] + const divmod_quadruples: &'static [(&'static [BigDigit], + &'static [BigDigit], + &'static [BigDigit], + &'static [BigDigit])] = &[ (&[ 1], &[ 2], &[], &[1]), (&[ 1, 1], &[ 2], &[-1/2+1], &[1]), @@ -1399,9 +1399,9 @@ mod bigint_tests { ).to_uint() == 0); } - const sum_triples: &static/[(&static/[BigDigit], - &static/[BigDigit], - &static/[BigDigit])] = &[ + const sum_triples: &'static [(&'static [BigDigit], + &'static [BigDigit], + &'static [BigDigit])] = &[ (&[], &[], &[]), (&[], &[ 1], &[ 1]), (&[ 1], &[ 1], &[ 2]), @@ -1451,9 +1451,9 @@ mod bigint_tests { } } - const mul_triples: &static/[(&static/[BigDigit], - &static/[BigDigit], - &static/[BigDigit])] = &[ + const mul_triples: &'static [(&'static [BigDigit], + &'static [BigDigit], + &'static [BigDigit])] = &[ (&[], &[], &[]), (&[], &[ 1], &[]), (&[ 2], &[], &[]), @@ -1477,10 +1477,10 @@ mod bigint_tests { (&[ 0, 0, 1], &[ 0, 0, 0, 1], &[0, 0, 0, 0, 0, 1]) ]; - const divmod_quadruples: &static/[(&static/[BigDigit], - &static/[BigDigit], - &static/[BigDigit], - &static/[BigDigit])] + const divmod_quadruples: &'static [(&'static [BigDigit], + &'static [BigDigit], + &'static [BigDigit], + &'static [BigDigit])] = &[ (&[ 1], &[ 2], &[], &[1]), (&[ 1, 1], &[ 2], &[-1/2+1], &[1]), diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index 8dbdb83698c..430a5eab64e 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -700,8 +700,8 @@ impl cmp::Eq for BitvSet { } impl Container for BitvSet { - pure fn len(&self) -> uint { self.size } - pure fn is_empty(&self) -> bool { self.size == 0 } + pure fn len(&const self) -> uint { self.size } + pure fn is_empty(&const self) -> bool { self.size == 0 } } impl Mutable for BitvSet { @@ -1424,7 +1424,7 @@ mod tests { fail_unless!(a.capacity() == uint::bits); } - fn rng() -> rand::Rng { + fn rng() -> @rand::Rng { let seed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; rand::seeded_rng(seed) } diff --git a/src/libstd/deque.rs b/src/libstd/deque.rs index 33b0fd4eb68..86304f48e79 100644 --- a/src/libstd/deque.rs +++ b/src/libstd/deque.rs @@ -22,13 +22,17 @@ pub struct Deque<T> { } impl<T> Container for Deque<T> { - pure fn len(&self) -> uint { self.nelts } - pure fn is_empty(&self) -> bool { self.len() == 0 } + /// Return the number of elements in the deque + pure fn len(&const self) -> uint { self.nelts } + + /// Return true if the deque contains no elements + pure fn is_empty(&const self) -> bool { self.len() == 0 } } impl<T> Mutable for Deque<T> { + /// Clear the deque, removing all values. fn clear(&mut self) { - for vec::each_mut(self.elts) |x| { *x = None } + for self.elts.each_mut |x| { *x = None } self.nelts = 0; self.lo = 0; self.hi = 0; @@ -36,19 +40,33 @@ impl<T> Mutable for Deque<T> { } pub impl<T> Deque<T> { + /// Create an empty Deque static pure fn new() -> Deque<T> { Deque{nelts: 0, lo: 0, hi: 0, elts: vec::from_fn(initial_capacity, |_| None)} } - fn peek_front(&self) -> &self/T { get(self.elts, self.lo) } - fn peek_back(&self) -> &self/T { get(self.elts, self.hi - 1u) } + /// Return a reference to the first element in the deque + /// + /// Fails if the deque is empty + fn peek_front(&self) -> &'self T { get(self.elts, self.lo) } + + /// Return a reference to the last element in the deque + /// + /// Fails if the deque is empty + fn peek_back(&self) -> &'self T { get(self.elts, self.hi - 1u) } - fn get(&self, i: int) -> &self/T { + /// Retrieve an element in the deque by index + /// + /// Fails if there is no element with the given index + fn get(&self, i: int) -> &'self T { let idx = (self.lo + (i as uint)) % self.elts.len(); get(self.elts, idx) } + /// Remove and return the first element in the deque + /// + /// Fails if the deque is empty fn pop_front(&mut self) -> T { let mut result = self.elts[self.lo].swap_unwrap(); self.lo = (self.lo + 1u) % self.elts.len(); @@ -56,6 +74,9 @@ pub impl<T> Deque<T> { result } + /// Remove and return the last element in the deque + /// + /// Fails if the deque is empty fn pop_back(&mut self) -> T { if self.hi == 0u { self.hi = self.elts.len() - 1u; @@ -66,6 +87,7 @@ pub impl<T> Deque<T> { result } + /// Prepend an element to the deque fn add_front(&mut self, t: T) { let oldlo = self.lo; if self.lo == 0u { @@ -80,6 +102,7 @@ pub impl<T> Deque<T> { self.nelts += 1u; } + /// Append an element to the deque fn add_back(&mut self, t: T) { if self.lo == self.hi && self.nelts != 0u { self.elts = grow(self.nelts, self.lo, self.elts); @@ -107,7 +130,7 @@ fn grow<T>(nelts: uint, lo: uint, elts: &mut [Option<T>]) -> ~[Option<T>] { rv } -fn get<T>(elts: &r/[Option<T>], i: uint) -> &r/T { +fn get<T>(elts: &'r [Option<T>], i: uint) -> &'r T { match elts[i] { Some(ref t) => t, _ => fail!() } } @@ -116,7 +139,6 @@ mod tests { use super::*; use core::cmp::Eq; use core::kinds::{Durable, Copy}; - use core::prelude::debug; #[test] fn test_simple() { @@ -128,21 +150,21 @@ mod tests { fail_unless!(d.len() == 3u); d.add_back(137); fail_unless!(d.len() == 4u); - log(debug, d.peek_front()); + debug!(d.peek_front()); fail_unless!(*d.peek_front() == 42); - log(debug, d.peek_back()); + debug!(d.peek_back()); fail_unless!(*d.peek_back() == 137); let mut i: int = d.pop_front(); - log(debug, i); + debug!(i); fail_unless!(i == 42); i = d.pop_back(); - log(debug, i); + debug!(i); fail_unless!(i == 137); i = d.pop_back(); - log(debug, i); + debug!(i); fail_unless!(i == 137); i = d.pop_back(); - log(debug, i); + debug!(i); fail_unless!(i == 17); fail_unless!(d.len() == 0u); d.add_back(3); @@ -153,10 +175,10 @@ mod tests { fail_unless!(d.len() == 3u); d.add_front(1); fail_unless!(d.len() == 4u); - log(debug, d.get(0)); - log(debug, d.get(1)); - log(debug, d.get(2)); - log(debug, d.get(3)); + debug!(d.get(0)); + debug!(d.get(1)); + debug!(d.get(2)); + debug!(d.get(3)); fail_unless!(*d.get(0) == 1); fail_unless!(*d.get(1) == 2); fail_unless!(*d.get(2) == 3); diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index a55d4bc97ec..4ab119abf1c 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -415,11 +415,11 @@ pub mod writer { // ebml writing pub struct Encoder { - writer: io::Writer, + writer: @io::Writer, priv mut size_positions: ~[uint], } - fn write_sized_vuint(w: io::Writer, n: uint, size: uint) { + fn write_sized_vuint(w: @io::Writer, n: uint, size: uint) { match size { 1u => w.write(&[0x80u8 | (n as u8)]), 2u => w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]), @@ -431,7 +431,7 @@ pub mod writer { }; } - fn write_vuint(w: io::Writer, n: uint) { + fn write_vuint(w: @io::Writer, n: uint) { if n < 0x7f_u { write_sized_vuint(w, n, 1u); return; } if n < 0x4000_u { write_sized_vuint(w, n, 2u); return; } if n < 0x200000_u { write_sized_vuint(w, n, 3u); return; } @@ -439,7 +439,7 @@ pub mod writer { fail!(fmt!("vint to write too big: %?", n)); } - pub fn Encoder(w: io::Writer) -> Encoder { + pub fn Encoder(w: @io::Writer) -> Encoder { let size_positions: ~[uint] = ~[]; Encoder { writer: w, mut size_positions: size_positions } } diff --git a/src/libstd/flatpipes.rs b/src/libstd/flatpipes.rs index 897cb4c2034..c5515c63b29 100644 --- a/src/libstd/flatpipes.rs +++ b/src/libstd/flatpipes.rs @@ -459,15 +459,15 @@ pub mod flatteners { } pub trait FromReader { - static fn from_reader(r: Reader) -> Self; + static fn from_reader(r: @Reader) -> Self; } pub trait FromWriter { - static fn from_writer(w: Writer) -> Self; + static fn from_writer(w: @Writer) -> Self; } impl FromReader for json::Decoder/&self { - static fn from_reader(r: Reader) -> json::Decoder/&self { + static fn from_reader(r: @Reader) -> json::Decoder/&self { match json::from_reader(r) { Ok(json) => { json::Decoder(json) @@ -478,13 +478,13 @@ pub mod flatteners { } impl FromWriter for json::Encoder { - static fn from_writer(w: Writer) -> json::Encoder { + static fn from_writer(w: @Writer) -> json::Encoder { json::Encoder(w) } } impl FromReader for ebml::reader::Decoder { - static fn from_reader(r: Reader) -> ebml::reader::Decoder { + static fn from_reader(r: @Reader) -> ebml::reader::Decoder { let buf = @r.read_whole_stream(); let doc = ebml::reader::Doc(buf); ebml::reader::Decoder(doc) @@ -492,7 +492,7 @@ pub mod flatteners { } impl FromWriter for ebml::writer::Encoder { - static fn from_writer(w: Writer) -> ebml::writer::Encoder { + static fn from_writer(w: @Writer) -> ebml::writer::Encoder { ebml::writer::Encoder(w) } } @@ -569,12 +569,12 @@ pub mod bytepipes { impl BytePort for PipeBytePort { fn try_recv(&self, count: uint) -> Option<~[u8]> { - if self.buf.len() >= count { + if vec::uniq_len(&const self.buf) >= count { let mut bytes = ::core::util::replace(&mut self.buf, ~[]); self.buf = bytes.slice(count, bytes.len()); bytes.truncate(count); return Some(bytes); - } else if self.buf.len() > 0 { + } else if vec::uniq_len(&const self.buf) > 0 { let mut bytes = ::core::util::replace(&mut self.buf, ~[]); fail_unless!(count > bytes.len()); match self.try_recv(count - bytes.len()) { @@ -584,7 +584,7 @@ pub mod bytepipes { } None => return None } - } else if self.buf.is_empty() { + } else if vec::uniq_len(&const self.buf) == 0 { match self.port.try_recv() { Some(buf) => { fail_unless!(!buf.is_empty()); diff --git a/src/libstd/future.rs b/src/libstd/future.rs index 5dc264cb878..4867204ea39 100644 --- a/src/libstd/future.rs +++ b/src/libstd/future.rs @@ -55,7 +55,7 @@ pub impl<A:Copy> Future<A> { pub impl<A> Future<A> { - pure fn get_ref(&self) -> &self/A { + pure fn get_ref(&self) -> &'self A { /*! * Executes the future's closure and then returns a borrowed * pointer to the result. The borrowed pointer lasts as long as diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index 54271dadb54..0b615e0c0da 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -881,7 +881,7 @@ mod tests { let rs = getopts(args, opts); match rs { Err(copy f) => { - log(error, fail_str(f)); + error!(fail_str(f)); check_fail_type(f, UnexpectedArgument_); } _ => fail!() diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 8c6a870b98c..f2f37604fb5 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -74,10 +74,10 @@ fn spaces(n: uint) -> ~str { } pub struct Encoder { - priv wr: io::Writer, + priv wr: @io::Writer, } -pub fn Encoder(wr: io::Writer) -> Encoder { +pub fn Encoder(wr: @io::Writer) -> Encoder { Encoder { wr: wr } } @@ -208,11 +208,11 @@ impl serialize::Encoder for Encoder { } pub struct PrettyEncoder { - priv wr: io::Writer, + priv wr: @io::Writer, priv mut indent: uint, } -pub fn PrettyEncoder(wr: io::Writer) -> PrettyEncoder { +pub fn PrettyEncoder(wr: @io::Writer) -> PrettyEncoder { PrettyEncoder { wr: wr, indent: 0 } } @@ -346,7 +346,7 @@ impl<S:serialize::Encoder> serialize::Encodable<S> for Json { } /// Encodes a json value into a io::writer -pub fn to_writer(wr: io::Writer, json: &Json) { +pub fn to_writer(wr: @io::Writer, json: &Json) { json.encode(&Encoder(wr)) } @@ -359,7 +359,7 @@ pub pure fn to_str(json: &Json) -> ~str { } /// Encodes a json value into a io::writer -pub fn to_pretty_writer(wr: io::Writer, json: &Json) { +pub fn to_pretty_writer(wr: @io::Writer, json: &Json) { json.encode(&PrettyEncoder(wr)) } @@ -369,14 +369,14 @@ pub fn to_pretty_str(json: &Json) -> ~str { } pub struct Parser { - priv rdr: io::Reader, + priv rdr: @io::Reader, priv mut ch: char, priv mut line: uint, priv mut col: uint, } /// Decode a json value from an io::reader -pub fn Parser(rdr: io::Reader) -> Parser { +pub fn Parser(rdr: @io::Reader) -> Parser { Parser { rdr: rdr, ch: rdr.read_char(), @@ -734,8 +734,8 @@ priv impl Parser { } } -/// Decodes a json value from an io::reader -pub fn from_reader(rdr: io::Reader) -> Result<Json, Error> { +/// Decodes a json value from an @io::Reader +pub fn from_reader(rdr: @io::Reader) -> Result<Json, Error> { Parser(rdr).parse() } @@ -748,7 +748,7 @@ pub fn from_str(s: &str) -> Result<Json, Error> { pub struct Decoder { priv json: Json, - priv mut stack: ~[&self/Json], + priv mut stack: ~[&'self Json], } pub fn Decoder(json: Json) -> Decoder { @@ -756,13 +756,17 @@ pub fn Decoder(json: Json) -> Decoder { } priv impl Decoder/&self { - fn peek(&self) -> &self/Json { - if self.stack.len() == 0 { self.stack.push(&self.json); } - self.stack[self.stack.len() - 1] + fn peek(&self) -> &'self Json { + if vec::uniq_len(&const self.stack) == 0 { + self.stack.push(&self.json); + } + self.stack[vec::uniq_len(&const self.stack) - 1] } - fn pop(&self) -> &self/Json { - if self.stack.len() == 0 { self.stack.push(&self.json); } + fn pop(&self) -> &'self Json { + if vec::uniq_len(&const self.stack) == 0 { + self.stack.push(&self.json); + } self.stack.pop() } } diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index a5e68907773..04283674d88 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -117,7 +117,7 @@ pub fn get_addr(node: &str, iotask: &iotask) do str::as_buf(node) |node_ptr, len| { let output_ch = output_ch.swap_unwrap(); unsafe { - log(debug, fmt!("slice len %?", len)); + debug!("slice len %?", len); let handle = create_uv_getaddrinfo_t(); let handle_ptr = ptr::addr_of(&handle); let handle_data = GetAddrData { @@ -228,8 +228,8 @@ pub mod v4 { let new_addr = uv_ip4_addr(str::from_slice(ip), 22); let reformatted_name = uv_ip4_name(&new_addr); - log(debug, fmt!("try_parse_addr: input ip: %s reparsed ip: %s", - ip, reformatted_name)); + debug!("try_parse_addr: input ip: %s reparsed ip: %s", + ip, reformatted_name); let ref_ip_rep_result = parse_to_ipv4_rep(reformatted_name); if result::is_err(&ref_ip_rep_result) { let err_str = result::get_err(&ref_ip_rep_result); @@ -282,8 +282,8 @@ pub mod v6 { // need to figure out how to establish a parse failure.. let new_addr = uv_ip6_addr(str::from_slice(ip), 22); let reparsed_name = uv_ip6_name(&new_addr); - log(debug, fmt!("v6::try_parse_addr ip: '%s' reparsed '%s'", - ip, reparsed_name)); + debug!("v6::try_parse_addr ip: '%s' reparsed '%s'", + ip, reparsed_name); // '::' appears to be uv_ip6_name() returns for bogus // parses.. if ip != &"::" && reparsed_name == ~"::" { @@ -303,14 +303,14 @@ struct GetAddrData { extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int, res: *addrinfo) { unsafe { - log(debug, ~"in get_addr_cb"); + debug!("in get_addr_cb"); let handle_data = get_data_for_req(handle) as *GetAddrData; let output_ch = (*handle_data).output_ch.clone(); if status == 0i32 { if res != (ptr::null::<addrinfo>()) { let mut out_vec = ~[]; - log(debug, fmt!("initial addrinfo: %?", res)); + debug!("initial addrinfo: %?", res); let mut curr_addr = res; loop { let new_ip_addr = if ll::is_ipv4_addrinfo(curr_addr) { @@ -322,8 +322,8 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int, *ll::addrinfo_as_sockaddr_in6(curr_addr)))) } else { - log(debug, ~"curr_addr is not of family AF_INET or "+ - ~"AF_INET6. Error."); + debug!("curr_addr is not of family AF_INET or \ + AF_INET6. Error."); output_ch.send( result::Err(GetAddrUnknownError)); break; @@ -332,33 +332,33 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int, let next_addr = ll::get_next_addrinfo(curr_addr); if next_addr == ptr::null::<addrinfo>() as *addrinfo { - log(debug, ~"null next_addr encountered. no mas"); + debug!("null next_addr encountered. no mas"); break; } else { curr_addr = next_addr; - log(debug, fmt!("next_addr addrinfo: %?", curr_addr)); + debug!("next_addr addrinfo: %?", curr_addr); } } - log(debug, fmt!("successful process addrinfo result, len: %?", - vec::len(out_vec))); + debug!("successful process addrinfo result, len: %?", + vec::len(out_vec)); output_ch.send(result::Ok(out_vec)); } else { - log(debug, ~"addrinfo pointer is NULL"); + debug!("addrinfo pointer is NULL"); output_ch.send( result::Err(GetAddrUnknownError)); } } else { - log(debug, ~"status != 0 error in get_addr_cb"); + debug!("status != 0 error in get_addr_cb"); output_ch.send( result::Err(GetAddrUnknownError)); } if res != (ptr::null::<addrinfo>()) { uv_freeaddrinfo(res); } - log(debug, ~"leaving get_addr_cb"); + debug!("leaving get_addr_cb"); } } @@ -384,15 +384,15 @@ mod test { fn test_ip_ipv6_parse_and_format_ip() { let localhost_str = ~"::1"; let format_result = format_addr(&v6::parse_addr(localhost_str)); - log(debug, fmt!("results: expected: '%s' actual: '%s'", - localhost_str, format_result)); + debug!("results: expected: '%s' actual: '%s'", + localhost_str, format_result); fail_unless!(format_result == localhost_str); } #[test] fn test_ip_ipv4_bad_parse() { match v4::try_parse_addr(~"b4df00d") { result::Err(ref err_info) => { - log(debug, fmt!("got error as expected %?", err_info)); + debug!("got error as expected %?", err_info); fail_unless!(true); } result::Ok(ref addr) => { @@ -405,7 +405,7 @@ mod test { fn test_ip_ipv6_bad_parse() { match v6::try_parse_addr(~"::,~2234k;") { result::Err(ref err_info) => { - log(debug, fmt!("got error as expected %?", err_info)); + debug!("got error as expected %?", err_info); fail_unless!(true); } result::Ok(ref addr) => { @@ -425,15 +425,15 @@ mod test { // note really sure how to realiably test/assert // this.. mostly just wanting to see it work, atm. let results = result::unwrap(ga_result); - log(debug, fmt!("test_get_addr: Number of results for %s: %?", - localhost_name, vec::len(results))); + debug!("test_get_addr: Number of results for %s: %?", + localhost_name, vec::len(results)); for vec::each(results) |r| { let ipv_prefix = match *r { Ipv4(_) => ~"IPv4", Ipv6(_) => ~"IPv6" }; - log(debug, fmt!("test_get_addr: result %s: '%s'", - ipv_prefix, format_addr(r))); + debug!("test_get_addr: result %s: '%s'", + ipv_prefix, format_addr(r)); } // at least one result.. this is going to vary from system // to system, based on stuff like the contents of /etc/hosts diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index 5328975f82a..a93e94e0d04 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -559,14 +559,14 @@ pub fn accept(new_conn: TcpNewConnection) server_handle_ptr); match uv::ll::tcp_init(loop_ptr, client_stream_handle_ptr) { 0i32 => { - log(debug, ~"uv_tcp_init successful for \ + debug!("uv_tcp_init successful for \ client stream"); match uv::ll::accept( server_handle_ptr as *libc::c_void, client_stream_handle_ptr as *libc::c_void) { 0i32 => { - log(debug, - ~"successfully accepted client \ + debug!( + "successfully accepted client \ connection"); uv::ll::set_data_for_uv_handle( client_stream_handle_ptr, @@ -575,7 +575,7 @@ pub fn accept(new_conn: TcpNewConnection) result_ch.send(None); } _ => { - log(debug, ~"failed to accept client conn"); + debug!("failed to accept client conn"); result_ch.send(Some( uv::ll::get_last_err_data( loop_ptr).to_tcp_err())); @@ -583,7 +583,7 @@ pub fn accept(new_conn: TcpNewConnection) } } _ => { - log(debug, ~"failed to accept client stream"); + debug!("failed to accept client stream"); result_ch.send(Some( uv::ll::get_last_err_data( loop_ptr).to_tcp_err())); @@ -694,7 +694,7 @@ fn listen_common(host_ip: ip::IpAddr, let addr_str = ip::format_addr(&loc_ip); let bind_result = match loc_ip { ip::Ipv4(ref addr) => { - log(debug, fmt!("addr: %?", addr)); + debug!("addr: %?", addr); let in_addr = uv::ll::ip4_addr( addr_str, port as int); @@ -702,7 +702,7 @@ fn listen_common(host_ip: ip::IpAddr, ptr::addr_of(&in_addr)) } ip::Ipv6(ref addr) => { - log(debug, fmt!("addr: %?", addr)); + debug!("addr: %?", addr); let in_addr = uv::ll::ip6_addr( addr_str, port as int); @@ -718,8 +718,8 @@ fn listen_common(host_ip: ip::IpAddr, tcp_lfc_on_connection_cb) { 0i32 => setup_ch.send(None), _ => { - log(debug, - ~"failure to uv_tcp_init"); + debug!( + "failure to uv_tcp_init"); let err_data = uv::ll::get_last_err_data( loop_ptr); @@ -728,7 +728,7 @@ fn listen_common(host_ip: ip::IpAddr, } } _ => { - log(debug, ~"failure to uv_tcp_bind"); + debug!("failure to uv_tcp_bind"); let err_data = uv::ll::get_last_err_data( loop_ptr); setup_ch.send(Some(err_data)); @@ -736,7 +736,7 @@ fn listen_common(host_ip: ip::IpAddr, } } _ => { - log(debug, ~"failure to uv_tcp_bind"); + debug!("failure to uv_tcp_bind"); let err_data = uv::ll::get_last_err_data( loop_ptr); setup_ch.send(Some(err_data)); @@ -751,9 +751,9 @@ fn listen_common(host_ip: ip::IpAddr, Some(ref err_data) => { do iotask::interact(iotask) |loop_ptr| { unsafe { - log(debug, - fmt!("tcp::listen post-kill recv hl interact %?", - loop_ptr)); + debug!( + "tcp::listen post-kill recv hl interact %?", + loop_ptr); (*server_data_ptr).active = false; uv::ll::close(server_stream_ptr, tcp_lfc_close_cb); } @@ -761,16 +761,16 @@ fn listen_common(host_ip: ip::IpAddr, stream_closed_po.recv(); match err_data.err_name { ~"EACCES" => { - log(debug, ~"Got EACCES error"); + debug!("Got EACCES error"); result::Err(AccessDenied) } ~"EADDRINUSE" => { - log(debug, ~"Got EADDRINUSE error"); + debug!("Got EADDRINUSE error"); result::Err(AddressInUse) } _ => { - log(debug, fmt!("Got '%s' '%s' libuv error", - err_data.err_name, err_data.err_msg)); + debug!("Got '%s' '%s' libuv error", + err_data.err_name, err_data.err_msg); result::Err( GenericListenErr(err_data.err_name, err_data.err_msg)) @@ -782,9 +782,9 @@ fn listen_common(host_ip: ip::IpAddr, let kill_result = kill_po.recv(); do iotask::interact(iotask) |loop_ptr| { unsafe { - log(debug, - fmt!("tcp::listen post-kill recv hl interact %?", - loop_ptr)); + debug!( + "tcp::listen post-kill recv hl interact %?", + loop_ptr); (*server_data_ptr).active = false; uv::ll::close(server_stream_ptr, tcp_lfc_close_cb); } @@ -879,7 +879,8 @@ impl io::Reader for TcpSocketBuf { // If possible, copy up to `len` bytes from the internal // `data.buf` into `buf` - let nbuffered = self.data.buf.len() - self.data.buf_off; + let nbuffered = vec::uniq_len(&const self.data.buf) - + self.data.buf_off; let needed = len - count; if nbuffered > 0 { unsafe { @@ -931,7 +932,7 @@ impl io::Reader for TcpSocketBuf { } fn read_byte(&self) -> int { loop { - if self.data.buf.len() > self.data.buf_off { + if vec::uniq_len(&const self.data.buf) > self.data.buf_off { let c = self.data.buf[self.data.buf_off]; self.data.buf_off += 1; return c as int @@ -981,9 +982,9 @@ impl io::Writer for TcpSocketBuf { ).to_vec()); if w_result.is_err() { let err_data = w_result.get_err(); - log(debug, - fmt!("ERROR sock_buf as io::writer.writer err: %? %?", - err_data.err_name, err_data.err_msg)); + debug!( + "ERROR sock_buf as io::writer.writer err: %? %?", + err_data.err_name, err_data.err_msg); } } } @@ -1015,9 +1016,9 @@ fn tear_down_socket_data(socket_data: @TcpSocketData) { let stream_handle_ptr = (*socket_data).stream_handle_ptr; do iotask::interact(&(*socket_data).iotask) |loop_ptr| { unsafe { - log(debug, - fmt!("interact dtor for tcp_socket stream %? loop %?", - stream_handle_ptr, loop_ptr)); + debug!( + "interact dtor for tcp_socket stream %? loop %?", + stream_handle_ptr, loop_ptr); uv::ll::set_data_for_uv_handle(stream_handle_ptr, close_data_ptr); uv::ll::close(stream_handle_ptr, tcp_socket_dtor_close_cb); @@ -1028,7 +1029,7 @@ fn tear_down_socket_data(socket_data: @TcpSocketData) { //log(debug, fmt!("about to free socket_data at %?", socket_data)); rustrt::rust_uv_current_kernel_free(stream_handle_ptr as *libc::c_void); - log(debug, ~"exiting dtor for tcp_socket"); + debug!("exiting dtor for tcp_socket"); } } @@ -1038,7 +1039,7 @@ fn read_common_impl(socket_data: *TcpSocketData, timeout_msecs: uint) unsafe { use timer; - log(debug, ~"starting tcp::read"); + debug!("starting tcp::read"); let iotask = &(*socket_data).iotask; let rs_result = read_start_common_impl(socket_data); if result::is_err(&rs_result) { @@ -1046,17 +1047,17 @@ fn read_common_impl(socket_data: *TcpSocketData, timeout_msecs: uint) result::Err(err_data) } else { - log(debug, ~"tcp::read before recv_timeout"); + debug!("tcp::read before recv_timeout"); let read_result = if timeout_msecs > 0u { timer::recv_timeout( iotask, timeout_msecs, result::unwrap(rs_result)) } else { Some(result::get(&rs_result).recv()) }; - log(debug, ~"tcp::read after recv_timeout"); + debug!("tcp::read after recv_timeout"); match read_result { None => { - log(debug, ~"tcp::read: timed out.."); + debug!("tcp::read: timed out.."); let err_data = TcpErrData { err_name: ~"TIMEOUT", err_msg: ~"req timed out" @@ -1065,7 +1066,7 @@ fn read_common_impl(socket_data: *TcpSocketData, timeout_msecs: uint) result::Err(err_data) } Some(data_result) => { - log(debug, ~"tcp::read got data"); + debug!("tcp::read got data"); read_stop_common_impl(socket_data); data_result } @@ -1082,15 +1083,15 @@ fn read_stop_common_impl(socket_data: *TcpSocketData) -> let (stop_po, stop_ch) = stream::<Option<TcpErrData>>(); do iotask::interact(&(*socket_data).iotask) |loop_ptr| { unsafe { - log(debug, ~"in interact cb for tcp::read_stop"); + debug!("in interact cb for tcp::read_stop"); match uv::ll::read_stop(stream_handle_ptr as *uv::ll::uv_stream_t) { 0i32 => { - log(debug, ~"successfully called uv_read_stop"); + debug!("successfully called uv_read_stop"); stop_ch.send(None); } _ => { - log(debug, ~"failure in calling uv_read_stop"); + debug!("failure in calling uv_read_stop"); let err_data = uv::ll::get_last_err_data(loop_ptr); stop_ch.send(Some(err_data.to_tcp_err())); } @@ -1111,21 +1112,21 @@ fn read_start_common_impl(socket_data: *TcpSocketData) unsafe { let stream_handle_ptr = (*socket_data).stream_handle_ptr; let (start_po, start_ch) = stream::<Option<uv::ll::uv_err_data>>(); - log(debug, ~"in tcp::read_start before interact loop"); + debug!("in tcp::read_start before interact loop"); do iotask::interact(&(*socket_data).iotask) |loop_ptr| { unsafe { - log(debug, fmt!("in tcp::read_start interact cb %?", - loop_ptr)); + debug!("in tcp::read_start interact cb %?", + loop_ptr); match uv::ll::read_start(stream_handle_ptr as *uv::ll::uv_stream_t, on_alloc_cb, on_tcp_read_cb) { 0i32 => { - log(debug, ~"success doing uv_read_start"); + debug!("success doing uv_read_start"); start_ch.send(None); } _ => { - log(debug, ~"error attempting uv_read_start"); + debug!("error attempting uv_read_start"); let err_data = uv::ll::get_last_err_data(loop_ptr); start_ch.send(Some(err_data)); } @@ -1164,19 +1165,19 @@ fn write_common_impl(socket_data_ptr: *TcpSocketData, let write_data_ptr = ptr::addr_of(&write_data); do iotask::interact(&(*socket_data_ptr).iotask) |loop_ptr| { unsafe { - log(debug, fmt!("in interact cb for tcp::write %?", - loop_ptr)); + debug!("in interact cb for tcp::write %?", + loop_ptr); match uv::ll::write(write_req_ptr, stream_handle_ptr, write_buf_vec_ptr, tcp_write_complete_cb) { 0i32 => { - log(debug, ~"uv_write() invoked successfully"); + debug!("uv_write() invoked successfully"); uv::ll::set_data_for_req(write_req_ptr, write_data_ptr); } _ => { - log(debug, ~"error invoking uv_write()"); + debug!("error invoking uv_write()"); let err_data = uv::ll::get_last_err_data(loop_ptr); let result_ch = (*write_data_ptr).result_ch.clone(); result_ch.send(TcpWriteError(err_data.to_tcp_err())); @@ -1281,8 +1282,8 @@ extern fn on_tcp_read_cb(stream: *uv::ll::uv_stream_t, nread: libc::ssize_t, ++buf: uv::ll::uv_buf_t) { unsafe { - log(debug, fmt!("entering on_tcp_read_cb stream: %? nread: %?", - stream, nread)); + debug!("entering on_tcp_read_cb stream: %? nread: %?", + stream, nread); let loop_ptr = uv::ll::get_loop_for_uv_handle(stream); let socket_data_ptr = uv::ll::get_data_for_uv_handle(stream) as *TcpSocketData; @@ -1290,8 +1291,8 @@ extern fn on_tcp_read_cb(stream: *uv::ll::uv_stream_t, // incoming err.. probably eof -1 => { let err_data = uv::ll::get_last_err_data(loop_ptr).to_tcp_err(); - log(debug, fmt!("on_tcp_read_cb: incoming err.. name %? msg %?", - err_data.err_name, err_data.err_msg)); + debug!("on_tcp_read_cb: incoming err.. name %? msg %?", + err_data.err_name, err_data.err_msg); let reader_ch = &(*socket_data_ptr).reader_ch; reader_ch.send(result::Err(err_data)); } @@ -1300,7 +1301,7 @@ extern fn on_tcp_read_cb(stream: *uv::ll::uv_stream_t, // have data _ => { // we have data - log(debug, fmt!("tcp on_read_cb nread: %d", nread as int)); + debug!("tcp on_read_cb nread: %d", nread as int); let reader_ch = &(*socket_data_ptr).reader_ch; let buf_base = uv::ll::get_base_from_buf(buf); let new_bytes = vec::from_buf(buf_base, nread as uint); @@ -1308,7 +1309,7 @@ extern fn on_tcp_read_cb(stream: *uv::ll::uv_stream_t, } } uv::ll::free_base_of_buf(buf); - log(debug, ~"exiting on_tcp_read_cb"); + debug!("exiting on_tcp_read_cb"); } } @@ -1316,12 +1317,12 @@ extern fn on_alloc_cb(handle: *libc::c_void, suggested_size: size_t) -> uv::ll::uv_buf_t { unsafe { - log(debug, ~"tcp read on_alloc_cb!"); + debug!("tcp read on_alloc_cb!"); let char_ptr = uv::ll::malloc_buf_base_of(suggested_size); - log(debug, fmt!("tcp read on_alloc_cb h: %? char_ptr: %u sugsize: %u", + debug!("tcp read on_alloc_cb h: %? char_ptr: %u sugsize: %u", handle, char_ptr as uint, - suggested_size as uint)); + suggested_size as uint); uv::ll::buf_init(char_ptr, suggested_size as uint) } } @@ -1336,7 +1337,7 @@ extern fn tcp_socket_dtor_close_cb(handle: *uv::ll::uv_tcp_t) { as *TcpSocketCloseData; let closed_ch = (*data).closed_ch.clone(); closed_ch.send(()); - log(debug, ~"tcp_socket_dtor_close_cb exiting.."); + debug!("tcp_socket_dtor_close_cb exiting.."); } } @@ -1346,7 +1347,7 @@ extern fn tcp_write_complete_cb(write_req: *uv::ll::uv_write_t, let write_data_ptr = uv::ll::get_data_for_req(write_req) as *WriteReqData; if status == 0i32 { - log(debug, ~"successful write complete"); + debug!("successful write complete"); let result_ch = (*write_data_ptr).result_ch.clone(); result_ch.send(TcpWriteSuccess); } else { @@ -1354,7 +1355,7 @@ extern fn tcp_write_complete_cb(write_req: *uv::ll::uv_write_t, write_req); let loop_ptr = uv::ll::get_loop_for_uv_handle(stream_handle_ptr); let err_data = uv::ll::get_last_err_data(loop_ptr); - log(debug, ~"failure to write"); + debug!("failure to write"); let result_ch = (*write_data_ptr).result_ch.clone(); result_ch.send(TcpWriteError(err_data.to_tcp_err())); } @@ -1376,13 +1377,13 @@ extern fn stream_error_close_cb(handle: *uv::ll::uv_tcp_t) { *ConnectReqData; let closed_signal_ch = (*data).closed_signal_ch.clone(); closed_signal_ch.send(()); - log(debug, fmt!("exiting steam_error_close_cb for %?", handle)); + debug!("exiting steam_error_close_cb for %?", handle); } } extern fn tcp_connect_close_cb(handle: *uv::ll::uv_tcp_t) { unsafe { - log(debug, fmt!("closed client tcp handle %?", handle)); + debug!("closed client tcp handle %?", handle); } } @@ -1392,27 +1393,27 @@ extern fn tcp_connect_on_connect_cb(connect_req_ptr: *uv::ll::uv_connect_t, let conn_data_ptr = (uv::ll::get_data_for_req(connect_req_ptr) as *ConnectReqData); let result_ch = (*conn_data_ptr).result_ch.clone(); - log(debug, fmt!("tcp_connect result_ch %?", result_ch)); + debug!("tcp_connect result_ch %?", result_ch); let tcp_stream_ptr = uv::ll::get_stream_handle_from_connect_req(connect_req_ptr); match status { 0i32 => { - log(debug, ~"successful tcp connection!"); + debug!("successful tcp connection!"); result_ch.send(ConnSuccess); } _ => { - log(debug, ~"error in tcp_connect_on_connect_cb"); + debug!("error in tcp_connect_on_connect_cb"); let loop_ptr = uv::ll::get_loop_for_uv_handle(tcp_stream_ptr); let err_data = uv::ll::get_last_err_data(loop_ptr); - log(debug, fmt!("err_data %? %?", err_data.err_name, - err_data.err_msg)); + debug!("err_data %? %?", err_data.err_name, + err_data.err_msg); result_ch.send(ConnFailure(err_data)); uv::ll::set_data_for_uv_handle(tcp_stream_ptr, conn_data_ptr); uv::ll::close(tcp_stream_ptr, stream_error_close_cb); } } - log(debug, ~"leaving tcp_connect_on_connect_cb"); + debug!("leaving tcp_connect_on_connect_cb"); } } @@ -1758,10 +1759,10 @@ pub mod test { }; let actual_req = server_result_po.recv(); - log(debug, fmt!("REQ: expected: '%s' actual: '%s'", - expected_req, actual_req)); - log(debug, fmt!("RESP: expected: '%s' actual: '%s'", - expected_resp, actual_resp)); + debug!("REQ: expected: '%s' actual: '%s'", + expected_req, actual_req); + debug!("RESP: expected: '%s' actual: '%s'", + expected_resp, actual_resp); fail_unless!(str::contains(actual_req, expected_req)); fail_unless!(str::contains(actual_resp, expected_resp)); } @@ -1799,7 +1800,7 @@ pub mod test { let sock_buf = @socket_buf(result::unwrap(conn_result)); buf_write(sock_buf, expected_req); - let buf_reader = sock_buf as Reader; + let buf_reader = sock_buf as @Reader; let actual_response = str::from_bytes(buf_reader.read_whole_stream()); debug!("Actual response: %s", actual_response); fail_unless!(expected_resp == actual_response); diff --git a/src/libstd/oldmap.rs b/src/libstd/oldmap.rs index 18527cfece1..0a07a24e8ee 100644 --- a/src/libstd/oldmap.rs +++ b/src/libstd/oldmap.rs @@ -73,7 +73,7 @@ pub mod chained { FoundAfter(@Entry<K,V>, @Entry<K,V>) } - priv impl<K:Eq + IterBytes + Hash,V> T<K, V> { + priv impl<K:Eq + IterBytes + Hash,V> HashMap_<K, V> { pure fn search_rem(&self, k: &K, h: uint, idx: uint, e_root: @Entry<K,V>) -> SearchResult<K,V> { let mut e0 = e_root; @@ -101,7 +101,7 @@ pub mod chained { } pure fn search_tbl(&self, k: &K, h: uint) -> SearchResult<K,V> { - let idx = h % vec::len(self.chains); + let idx = h % vec::uniq_len(&const self.chains); match copy self.chains[idx] { None => { debug!("search_tbl: none, comp %u, hash %u, idx %u", @@ -120,8 +120,8 @@ pub mod chained { } } - fn rehash(&self) { - let n_old_chains = self.chains.len(); + fn rehash(@self) { + let n_old_chains = vec::uniq_len(&const self.chains); let n_new_chains: uint = uint::next_power_of_two(n_old_chains+1u); let mut new_chains = chains(n_new_chains); for self.each_entry |entry| { @@ -133,11 +133,11 @@ pub mod chained { } } - pub impl<K:Eq + IterBytes + Hash,V> T<K, V> { + pub impl<K:Eq + IterBytes + Hash,V> HashMap_<K, V> { pure fn each_entry(&self, blk: &fn(@Entry<K,V>) -> bool) { // n.b. we can't use vec::iter() here because self.chains // is stored in a mutable location. - let mut i = 0u, n = self.chains.len(); + let mut i = 0u, n = vec::uniq_len(&const self.chains); while i < n { let mut chain = self.chains[i]; loop { @@ -153,22 +153,20 @@ pub mod chained { i += 1u; } } - } - - impl<K:Eq + IterBytes + Hash,V> Container for T<K, V> { - pure fn len(&self) -> uint { self.count } - pure fn is_empty(&self) -> bool { self.count == 0 } - } - impl<K:Eq + IterBytes + Hash,V> Mutable for T<K, V> { - fn clear(&mut self) { + fn clear(@self) { self.count = 0u; self.chains = chains(initial_capacity); } } - pub impl<K:Eq + IterBytes + Hash,V> T<K, V> { - pure fn contains_key(&self, k: &K) -> bool { + impl<K:Eq + IterBytes + Hash,V> Container for HashMap_<K, V> { + pure fn len(&const self) -> uint { self.count } + pure fn is_empty(&const self) -> bool { self.count == 0 } + } + + pub impl<K:Eq + IterBytes + Hash,V> HashMap_<K, V> { + pure fn contains_key(@self, k: &K) -> bool { let hash = k.hash_keyed(0,0) as uint; match self.search_tbl(k, hash) { NotFound => false, @@ -176,12 +174,12 @@ pub mod chained { } } - fn insert(&self, k: K, v: V) -> bool { + fn insert(@self, k: K, v: V) -> bool { let hash = k.hash_keyed(0,0) as uint; match self.search_tbl(&k, hash) { NotFound => { self.count += 1u; - let idx = hash % vec::len(self.chains); + let idx = hash % vec::uniq_len(&const self.chains); let old_chain = self.chains[idx]; self.chains[idx] = Some(@Entry { hash: hash, @@ -190,7 +188,7 @@ pub mod chained { next: old_chain}); // consider rehashing if more 3/4 full - let nchains = vec::len(self.chains); + let nchains = vec::uniq_len(&const self.chains); let load = util::Rational { num: (self.count + 1u) as int, den: nchains as int, @@ -220,7 +218,7 @@ pub mod chained { } } - fn remove(&self, k: &K) -> bool { + fn remove(@self, k: &K) -> bool { match self.search_tbl(k, k.hash_keyed(0,0) as uint) { NotFound => false, FoundFirst(idx, entry) => { @@ -236,22 +234,22 @@ pub mod chained { } } - pure fn each(&self, blk: &fn(key: &K, value: &V) -> bool) { + pure fn each(@self, blk: &fn(key: &K, value: &V) -> bool) { for self.each_entry |entry| { if !blk(&entry.key, &entry.value) { break; } } } - pure fn each_key(&self, blk: &fn(key: &K) -> bool) { + pure fn each_key(@self, blk: &fn(key: &K) -> bool) { self.each(|k, _v| blk(k)) } - pure fn each_value(&self, blk: &fn(value: &V) -> bool) { + pure fn each_value(@self, blk: &fn(value: &V) -> bool) { self.each(|_k, v| blk(v)) } } - pub impl<K:Eq + IterBytes + Hash + Copy,V:Copy> T<K, V> { + pub impl<K:Eq + IterBytes + Hash + Copy,V:Copy> HashMap_<K, V> { pure fn find(&self, k: &K) -> Option<V> { match self.search_tbl(k, k.hash_keyed(0,0) as uint) { NotFound => None, @@ -260,7 +258,7 @@ pub mod chained { } } - fn update_with_key(&self, key: K, newval: V, ff: &fn(K, V, V) -> V) + fn update_with_key(@self, key: K, newval: V, ff: &fn(K, V, V) -> V) -> bool { /* match self.find(key) { @@ -273,7 +271,7 @@ pub mod chained { match self.search_tbl(&key, hash) { NotFound => { self.count += 1u; - let idx = hash % vec::len(self.chains); + let idx = hash % vec::uniq_len(&const self.chains); let old_chain = self.chains[idx]; self.chains[idx] = Some(@Entry { hash: hash, @@ -282,7 +280,7 @@ pub mod chained { next: old_chain}); // consider rehashing if more 3/4 full - let nchains = vec::len(self.chains); + let nchains = vec::uniq_len(&const self.chains); let load = util::Rational { num: (self.count + 1u) as int, den: nchains as int, @@ -312,7 +310,7 @@ pub mod chained { } } - fn update(&self, key: K, newval: V, ff: &fn(V, V) -> V) -> bool { + fn update(@self, key: K, newval: V, ff: &fn(V, V) -> V) -> bool { return self.update_with_key(key, newval, |_k, v, v1| ff(v,v1)); } @@ -325,8 +323,9 @@ pub mod chained { } } - pub impl<K:Eq + IterBytes + Hash + Copy + ToStr,V:ToStr + Copy> T<K, V> { - fn to_writer(&self, wr: io::Writer) { + pub impl<K:Eq + IterBytes + Hash + Copy + ToStr,V:ToStr + Copy> + HashMap_<K, V> { + fn to_writer(&self, wr: @io::Writer) { if self.count == 0u { wr.write_str(~"{}"); return; @@ -348,7 +347,7 @@ pub mod chained { } impl<K:Eq + IterBytes + Hash + Copy + ToStr,V:ToStr + Copy> ToStr - for T<K, V> { + for HashMap_<K, V> { pure fn to_str(&self) -> ~str { unsafe { // Meh -- this should be safe @@ -357,7 +356,8 @@ pub mod chained { } } - impl<K:Eq + IterBytes + Hash + Copy,V:Copy> ops::Index<K, V> for T<K, V> { + impl<K:Eq + IterBytes + Hash + Copy,V:Copy> ops::Index<K, V> + for HashMap_<K, V> { pure fn index(&self, k: K) -> V { self.get(&k) } diff --git a/src/libstd/par.rs b/src/libstd/par.rs index a33effba8e0..17ae48e03b9 100644 --- a/src/libstd/par.rs +++ b/src/libstd/par.rs @@ -41,7 +41,7 @@ fn map_slices<A:Copy + Owned,B:Copy + Owned>( let len = xs.len(); if len < min_granularity { - log(info, ~"small slice"); + info!("small slice"); // This is a small vector, fall back on the normal map. ~[f()(0u, xs)] } @@ -52,7 +52,7 @@ fn map_slices<A:Copy + Owned,B:Copy + Owned>( let mut futures = ~[]; let mut base = 0u; - log(info, ~"spawning tasks"); + info!("spawning tasks"); while base < len { let end = uint::min(len, base + items_per_task); do vec::as_imm_buf(xs) |p, _len| { @@ -63,11 +63,11 @@ fn map_slices<A:Copy + Owned,B:Copy + Owned>( let len = end - base; let slice = (ptr::offset(p, base), len * sys::size_of::<A>()); - log(info, fmt!("pre-slice: %?", (base, slice))); + info!("pre-slice: %?", (base, slice)); let slice : &[A] = cast::reinterpret_cast(&slice); - log(info, fmt!("slice: %?", - (base, vec::len(slice), end - base))); + info!("slice: %?", + (base, vec::len(slice), end - base)); fail_unless!((vec::len(slice) == end - base)); f(base, slice) } @@ -76,9 +76,9 @@ fn map_slices<A:Copy + Owned,B:Copy + Owned>( }; base += items_per_task; } - log(info, ~"tasks spawned"); + info!("tasks spawned"); - log(info, fmt!("num_tasks: %?", (num_tasks, futures.len()))); + info!("num_tasks: %?", (num_tasks, futures.len())); fail_unless!((num_tasks == futures.len())); let r = do futures.map() |ys| { @@ -114,7 +114,7 @@ pub fn mapi<A:Copy + Owned,B:Copy + Owned>( result }); let r = vec::concat(slices); - log(info, (r.len(), xs.len())); + info!("%?", (r.len(), xs.len())); fail_unless!((r.len() == xs.len())); r } diff --git a/src/libstd/prettyprint.rs b/src/libstd/prettyprint.rs index d2d80eb7da8..f823d73cf0b 100644 --- a/src/libstd/prettyprint.rs +++ b/src/libstd/prettyprint.rs @@ -14,10 +14,10 @@ use core::io::WriterUtil; use core::io; pub struct Serializer { - wr: io::Writer, + wr: @io::Writer, } -pub fn Serializer(wr: io::Writer) -> Serializer { +pub fn Serializer(wr: @io::Writer) -> Serializer { Serializer { wr: wr } } diff --git a/src/libstd/priority_queue.rs b/src/libstd/priority_queue.rs index 31f29ce23f2..a5a291c5b18 100644 --- a/src/libstd/priority_queue.rs +++ b/src/libstd/priority_queue.rs @@ -19,7 +19,7 @@ use core::vec; #[abi = "rust-intrinsic"] extern "C" mod rusti { - fn move_val_init<T>(dst: &mut T, -src: T); + fn move_val_init<T>(dst: &mut T, +src: T); fn init<T>() -> T; } @@ -37,10 +37,10 @@ impl<T:Ord> BaseIter<T> for PriorityQueue<T> { impl<T:Ord> Container for PriorityQueue<T> { /// Returns the length of the queue - pure fn len(&self) -> uint { self.data.len() } + pure fn len(&const self) -> uint { vec::uniq_len(&const self.data) } /// Returns true if a queue contains no elements - pure fn is_empty(&self) -> bool { self.data.is_empty() } + pure fn is_empty(&const self) -> bool { self.len() == 0 } } impl<T:Ord> Mutable for PriorityQueue<T> { @@ -50,10 +50,10 @@ impl<T:Ord> Mutable for PriorityQueue<T> { pub impl <T:Ord> PriorityQueue<T> { /// Returns the greatest item in the queue - fails if empty - pure fn top(&self) -> &self/T { &self.data[0] } + pure fn top(&self) -> &'self T { &self.data[0] } /// Returns the greatest item in the queue - None if empty - pure fn maybe_top(&self) -> Option<&self/T> { + pure fn maybe_top(&self) -> Option<&'self T> { if self.is_empty() { None } else { Some(self.top()) } } diff --git a/src/libstd/semver.rs b/src/libstd/semver.rs index 7b8a06f1b93..85996c8ac4a 100644 --- a/src/libstd/semver.rs +++ b/src/libstd/semver.rs @@ -138,7 +138,7 @@ condition! { bad_parse: () -> (); } -fn take_nonempty_prefix(rdr: io::Reader, +fn take_nonempty_prefix(rdr: @io::Reader, ch: char, pred: &fn(char) -> bool) -> (~str, char) { let mut buf = ~""; @@ -154,7 +154,7 @@ fn take_nonempty_prefix(rdr: io::Reader, (buf, ch) } -fn take_num(rdr: io::Reader, ch: char) -> (uint, char) { +fn take_num(rdr: @io::Reader, ch: char) -> (uint, char) { let (s, ch) = take_nonempty_prefix(rdr, ch, char::is_digit); match uint::from_str(s) { None => { bad_parse::cond.raise(()); (0, ch) }, @@ -162,7 +162,7 @@ fn take_num(rdr: io::Reader, ch: char) -> (uint, char) { } } -fn take_ident(rdr: io::Reader, ch: char) -> (Identifier, char) { +fn take_ident(rdr: @io::Reader, ch: char) -> (Identifier, char) { let (s,ch) = take_nonempty_prefix(rdr, ch, char::is_alphanumeric); if s.all(char::is_digit) { match uint::from_str(s) { @@ -180,8 +180,7 @@ fn expect(ch: char, c: char) { } } -fn parse_reader(rdr: io::Reader) -> Version { - +fn parse_reader(rdr: @io::Reader) -> Version { let (major, ch) = take_num(rdr, rdr.read_char()); expect(ch, '.'); let (minor, ch) = take_num(rdr, rdr.read_char()); diff --git a/src/libstd/serialize.rs b/src/libstd/serialize.rs index 0288155d29e..2c927b5db16 100644 --- a/src/libstd/serialize.rs +++ b/src/libstd/serialize.rs @@ -213,7 +213,7 @@ impl<D:Decoder> Decodable<D> for i64 { } } -impl<S:Encoder> Encodable<S> for &self/str { +impl<S:Encoder> Encodable<S> for &'self str { fn encode(&self, s: &S) { s.emit_borrowed_str(*self) } } @@ -286,7 +286,7 @@ impl<D:Decoder> Decodable<D> for () { } } -impl<S:Encoder,T:Encodable<S>> Encodable<S> for &self/T { +impl<S:Encoder,T:Encodable<S>> Encodable<S> for &'self T { fn encode(&self, s: &S) { s.emit_borrowed(|| (**self).encode(s)) } @@ -316,7 +316,7 @@ impl<D:Decoder,T:Decodable<D>> Decodable<D> for @T { } } -impl<S:Encoder,T:Encodable<S>> Encodable<S> for &self/[T] { +impl<S:Encoder,T:Encodable<S>> Encodable<S> for &'self [T] { fn encode(&self, s: &S) { do s.emit_borrowed_vec(self.len()) { for self.eachi |i, e| { diff --git a/src/libstd/sha1.rs b/src/libstd/sha1.rs index b1ef0233d97..f7e31bc7df7 100644 --- a/src/libstd/sha1.rs +++ b/src/libstd/sha1.rs @@ -91,7 +91,7 @@ pub fn sha1() -> @Sha1 { } fn process_msg_block(st: &mut Sha1State) { fail_unless!((vec::len(st.h) == digest_buf_len)); - fail_unless!((vec::len(*st.work_buf) == work_buf_len)); + fail_unless!((vec::uniq_len(st.work_buf) == work_buf_len)); let mut t: int; // Loop counter let mut w = st.work_buf; diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index 726e7c36abd..dc2688a20e7 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -22,9 +22,9 @@ pub struct SmallIntMap<T> { priv v: ~[Option<T>], } -impl<V> BaseIter<(uint, &self/V)> for SmallIntMap<V> { +impl<V> BaseIter<(uint, &'self V)> for SmallIntMap<V> { /// Visit all key-value pairs in order - pure fn each(&self, it: &fn(&(uint, &self/V)) -> bool) { + pure fn each(&self, it: &fn(&(uint, &'self V)) -> bool) { for uint::range(0, self.v.len()) |i| { match self.v[i] { Some(ref elt) => if !it(&(i, elt)) { break }, @@ -36,9 +36,9 @@ impl<V> BaseIter<(uint, &self/V)> for SmallIntMap<V> { pure fn size_hint(&self) -> Option<uint> { Some(self.len()) } } -impl<V> ReverseIter<(uint, &self/V)> for SmallIntMap<V> { +impl<V> ReverseIter<(uint, &'self V)> for SmallIntMap<V> { /// Visit all key-value pairs in reverse order - pure fn each_reverse(&self, it: &fn(&(uint, &self/V)) -> bool) { + pure fn each_reverse(&self, it: &fn(&(uint, &'self V)) -> bool) { for uint::range_rev(self.v.len(), 0) |i| { match self.v[i - 1] { Some(ref elt) => if !it(&(i - 1, elt)) { break }, @@ -50,18 +50,19 @@ impl<V> ReverseIter<(uint, &self/V)> for SmallIntMap<V> { impl<V> Container for SmallIntMap<V> { /// Return the number of elements in the map - pure fn len(&self) -> uint { + pure fn len(&const self) -> uint { let mut sz = 0; - for self.v.each |item| { - if item.is_some() { - sz += 1; + for uint::range(0, vec::uniq_len(&const self.v)) |i| { + match self.v[i] { + Some(_) => sz += 1, + None => {} } } sz } /// Return true if the map contains no elements - pure fn is_empty(&self) -> bool { self.len() == 0 } + pure fn is_empty(&const self) -> bool { self.len() == 0 } } impl<V> Mutable for SmallIntMap<V> { @@ -85,8 +86,18 @@ impl<V> Map<uint, V> for SmallIntMap<V> { self.each(|&(_, v)| blk(v)) } - /// Return the value corresponding to the key in the map - pure fn find(&self, key: &uint) -> Option<&self/V> { + /// Visit all key-value pairs in order + fn mutate_values(&mut self, it: &fn(&uint, &'self mut V) -> bool) { + for uint::range(0, self.v.len()) |i| { + match self.v[i] { + Some(ref mut elt) => if !it(&i, elt) { break }, + None => () + } + } + } + + /// Iterate over the map and mutate the contained values + pure fn find(&self, key: &uint) -> Option<&'self V> { if *key < self.v.len() { match self.v[*key] { Some(ref value) => Some(value), @@ -126,7 +137,7 @@ pub impl<V> SmallIntMap<V> { /// Create an empty SmallIntMap static pure fn new() -> SmallIntMap<V> { SmallIntMap{v: ~[]} } - pure fn get(&self, key: &uint) -> &self/V { + pure fn get(&self, key: &uint) -> &'self V { self.find(key).expect("key not present") } } diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs index 50de528762f..40be303a147 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<T> = &self/pure fn(v1: &T, v2: &T) -> bool; +type Le<T> = &'self pure fn(v1: &T, v2: &T) -> bool; /** * Merge sort. Returns a new vector containing the sorted list. @@ -68,9 +68,14 @@ fn part<T>(arr: &mut [T], left: uint, let mut storage_index: uint = left; let mut i: uint = left; while i < right { - if compare_func(&arr[i], &arr[right]) { - arr[i] <-> arr[storage_index]; - storage_index += 1; + // XXX: Unsafe because borrow check doesn't handle this right + unsafe { + let a: &T = cast::transmute(&mut arr[i]); + let b: &T = cast::transmute(&mut arr[right]); + if compare_func(a, b) { + arr[i] <-> arr[storage_index]; + storage_index += 1; + } } i += 1; } @@ -168,7 +173,7 @@ pub trait Sort { fn qsort(self); } -impl<T:Copy + Ord + Eq> Sort for &self/mut [T] { +impl<T:Copy + Ord + Eq> Sort for &'self mut [T] { fn qsort(self) { quick_sort3(self); } } @@ -451,7 +456,10 @@ impl<T:Copy + Ord> MergeState<T> { base2: uint, len2: uint) { fail_unless!(len1 != 0 && len2 != 0 && base1+len1 == base2); - let mut tmp = vec::slice(array, base1, base1+len1).to_vec(); + let mut tmp = ~[]; + for uint::range(base1, base1+len1) |i| { + tmp.push(array[i]); + } let mut c1 = 0; let mut c2 = base2; @@ -554,7 +562,10 @@ impl<T:Copy + Ord> MergeState<T> { base2: uint, len2: uint) { fail_unless!(len1 != 1 && len2 != 0 && base1 + len1 == base2); - let mut tmp = vec::slice(array, base2, base2+len2).to_vec(); + let mut tmp = ~[]; + for uint::range(base2, base2+len2) |i| { + tmp.push(array[i]); + } let mut c1 = base1 + len1 - 1; let mut c2 = len2 - 1; @@ -702,7 +713,11 @@ fn copy_vec<T:Copy>(dest: &mut [T], s1: uint, from: &[const T], s2: uint, len: uint) { fail_unless!(s1+len <= dest.len() && s2+len <= from.len()); - let slice = vec::slice(from, s2, s2+len).to_vec(); + let mut slice = ~[]; + for uint::range(s2, s2+len) |i| { + slice.push(from[i]); + } + for slice.eachi |i, v| { dest[s1+i] = *v; } @@ -721,7 +736,7 @@ mod test_qsort3 { quick_sort3::<int>(v1); let mut i = 0; while i < len { - log(debug, v2[i]); + // debug!(v2[i]); fail_unless!((v2[i] == v1[i])); i += 1; } @@ -768,7 +783,7 @@ mod test_qsort { quick_sort::<int>(v1, leual); let mut i = 0u; while i < len { - log(debug, v2[i]); + // debug!(v2[i]); fail_unless!((v2[i] == v1[i])); i += 1; } @@ -834,7 +849,7 @@ mod tests { let v3 = merge_sort::<int>(v1, f); let mut i = 0u; while i < len { - log(debug, v3[i]); + debug!(v3[i]); fail_unless!((v3[i] == v2[i])); i += 1; } @@ -868,7 +883,7 @@ mod tests { #[test] pub fn test_merge_sort_stability() { // tjc: funny that we have to use parens - pure fn ile(x: &(&static/str), y: &(&static/str)) -> bool + pure fn ile(x: &(&'static str), y: &(&'static str)) -> bool { unsafe // to_lower is not pure... { @@ -893,6 +908,7 @@ mod test_tim_sort { use sort::tim_sort; + use core::rand::RngUtil; use core::rand; use core::vec; @@ -918,7 +934,7 @@ mod test_tim_sort { tim_sort::<int>(v1); let mut i = 0u; while i < len { - log(debug, v2[i]); + // debug!(v2[i]); fail_unless!((v2[i] == v1[i])); i += 1u; } @@ -990,6 +1006,7 @@ mod big_tests { use sort::*; + use core::rand::RngUtil; use core::rand; use core::task; use core::uint; @@ -1170,7 +1187,7 @@ mod big_tests { struct LVal { val: uint, - key: &self/fn(@uint), + key: &'self fn(@uint), } impl Drop for LVal/&self { @@ -1188,16 +1205,16 @@ mod big_tests { } impl Ord for LVal/&self { - pure fn lt(&self, other: &a/LVal/&self) -> bool { + pure fn lt(&self, other: &'a LVal/&self) -> bool { (*self).val < other.val } - pure fn le(&self, other: &a/LVal/&self) -> bool { + pure fn le(&self, other: &'a LVal/&self) -> bool { (*self).val <= other.val } - pure fn gt(&self, other: &a/LVal/&self) -> bool { + pure fn gt(&self, other: &'a LVal/&self) -> bool { (*self).val > other.val } - pure fn ge(&self, other: &a/LVal/&self) -> bool { + pure fn ge(&self, other: &'a LVal/&self) -> bool { (*self).val >= other.val } } diff --git a/src/libstd/stats.rs b/src/libstd/stats.rs index 2a62ebadd2b..cecf9686327 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 Stats for &'self [f64] { fn sum(self) -> f64 { vec::foldl(0.0, self, |p,q| p + *q) } diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index 2190475d943..d47232cc535 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -99,7 +99,7 @@ fn new_sem_and_signal(count: int, num_condvars: uint) } #[doc(hidden)] -pub impl<Q:Owned> &self/Sem<Q> { +pub impl<Q:Owned> Sem<Q> { fn acquire(&self) { let mut waiter_nobe = None; unsafe { @@ -135,26 +135,26 @@ pub impl<Q:Owned> &self/Sem<Q> { } // FIXME(#3154) move both copies of this into Sem<Q>, and unify the 2 structs #[doc(hidden)] -pub impl &self/Sem<()> { +pub impl Sem<()> { fn access<U>(&self, blk: &fn() -> U) -> U { let mut release = None; unsafe { do task::unkillable { self.acquire(); - release = Some(SemRelease(*self)); + release = Some(SemRelease(self)); } } blk() } } #[doc(hidden)] -pub impl &self/Sem<~[Waitqueue]> { +pub impl Sem<~[Waitqueue]> { fn access<U>(&self, blk: &fn() -> U) -> U { let mut release = None; unsafe { do task::unkillable { self.acquire(); - release = Some(SemAndSignalRelease(*self)); + release = Some(SemAndSignalRelease(self)); } } blk() @@ -163,9 +163,9 @@ pub impl &self/Sem<~[Waitqueue]> { // FIXME(#3588) should go inside of access() #[doc(hidden)] -type SemRelease = SemReleaseGeneric/&self<()>; -type SemAndSignalRelease = SemReleaseGeneric/&self<~[Waitqueue]>; -struct SemReleaseGeneric<Q> { sem: &self/Sem<Q> } +type SemRelease = SemReleaseGeneric<'self, ()>; +type SemAndSignalRelease = SemReleaseGeneric<'self, ~[Waitqueue]>; +struct SemReleaseGeneric<Q> { sem: &'self Sem<Q> } impl<Q:Owned> Drop for SemReleaseGeneric/&self<Q> { fn finalize(&self) { @@ -173,13 +173,13 @@ impl<Q:Owned> Drop for SemReleaseGeneric/&self<Q> { } } -fn SemRelease(sem: &r/Sem<()>) -> SemRelease/&r { +fn SemRelease(sem: &'r Sem<()>) -> SemRelease/&r { SemReleaseGeneric { sem: sem } } -fn SemAndSignalRelease(sem: &r/Sem<~[Waitqueue]>) +fn SemAndSignalRelease(sem: &'r Sem<~[Waitqueue]>) -> SemAndSignalRelease/&r { SemReleaseGeneric { sem: sem @@ -187,7 +187,7 @@ fn SemAndSignalRelease(sem: &r/Sem<~[Waitqueue]>) } /// A mechanism for atomic-unlock-and-deschedule blocking and signalling. -pub struct Condvar { priv sem: &self/Sem<~[Waitqueue]> } +pub struct Condvar { priv sem: &'self Sem<~[Waitqueue]> } impl Drop for Condvar/&self { fn finalize(&self) {} } @@ -258,7 +258,7 @@ pub impl Condvar/&self { // mutex during unwinding. As long as the wrapper (mutex, etc) is // bounded in when it gets released, this shouldn't hang forever. struct SemAndSignalReacquire { - sem: &self/Sem<~[Waitqueue]>, + sem: &'self Sem<~[Waitqueue]>, } impl Drop for SemAndSignalReacquire/&self { @@ -272,7 +272,7 @@ pub impl Condvar/&self { } } - fn SemAndSignalReacquire(sem: &r/Sem<~[Waitqueue]>) + fn SemAndSignalReacquire(sem: &'r Sem<~[Waitqueue]>) -> SemAndSignalReacquire/&r { SemAndSignalReacquire { sem: sem @@ -610,7 +610,7 @@ pub impl RWlock { // FIXME(#3588) should go inside of read() #[doc(hidden)] struct RWlockReleaseRead { - lock: &self/RWlock, + lock: &'self RWlock, } impl Drop for RWlockReleaseRead/&self { @@ -635,7 +635,7 @@ impl Drop for RWlockReleaseRead/&self { } } -fn RWlockReleaseRead(lock: &r/RWlock) -> RWlockReleaseRead/&r { +fn RWlockReleaseRead(lock: &'r RWlock) -> RWlockReleaseRead/&r { RWlockReleaseRead { lock: lock } @@ -644,7 +644,7 @@ fn RWlockReleaseRead(lock: &r/RWlock) -> RWlockReleaseRead/&r { // FIXME(#3588) should go inside of downgrade() #[doc(hidden)] struct RWlockReleaseDowngrade { - lock: &self/RWlock, + lock: &'self RWlock, } impl Drop for RWlockReleaseDowngrade/&self { @@ -677,18 +677,18 @@ impl Drop for RWlockReleaseDowngrade/&self { } } -fn RWlockReleaseDowngrade(lock: &r/RWlock) -> RWlockReleaseDowngrade/&r { +fn RWlockReleaseDowngrade(lock: &'r RWlock) -> RWlockReleaseDowngrade/&r { RWlockReleaseDowngrade { lock: lock } } /// The "write permission" token used for rwlock.write_downgrade(). -pub struct RWlockWriteMode { priv lock: &self/RWlock } +pub struct RWlockWriteMode { priv lock: &'self RWlock } impl 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 { priv lock: &'self RWlock } impl Drop for RWlockReadMode/&self { fn finalize(&self) {} } pub impl RWlockWriteMode/&self { @@ -827,7 +827,7 @@ mod tests { // "load tmp = move ptr; inc tmp; store ptr <- tmp" dance. let (p,c) = comm::stream(); let m = ~Mutex(); - let m2 = ~m.clone(); + let m2 = m.clone(); let mut sharedstate = ~0; let ptr = ptr::addr_of(&(*sharedstate)); do task::spawn || { @@ -1105,13 +1105,13 @@ mod tests { // Test mutual exclusion between readers and writers. Just like the // mutex mutual exclusion test, a ways above. let (p,c) = comm::stream(); - let x2 = ~x.clone(); + let x2 = (*x).clone(); let mut sharedstate = ~0; let ptr = ptr::addr_of(&(*sharedstate)); do task::spawn || { let sharedstate: &mut int = unsafe { cast::reinterpret_cast(&ptr) }; - access_shared(sharedstate, x2, mode1, 10); + access_shared(sharedstate, &x2, mode1, 10); c.send(()); } access_shared(sharedstate, x, mode2, 10); @@ -1150,14 +1150,14 @@ mod tests { mode2: RWlockMode, make_mode2_go_first: bool) { // Much like sem_multi_resource. - let x2 = ~x.clone(); + let x2 = (*x).clone(); let (p1,c1) = comm::stream(); let (p2,c2) = comm::stream(); do task::spawn || { if !make_mode2_go_first { let _ = p2.recv(); // parent sends to us once it locks, or ... } - do lock_rwlock_in_mode(x2, mode2) { + do lock_rwlock_in_mode(&x2, mode2) { if make_mode2_go_first { c1.send(()); // ... we send to it once we lock } @@ -1207,7 +1207,7 @@ mod tests { // Child wakes up parent do x.write_cond |cond| { - let x2 = ~x.clone(); + let x2 = (*x).clone(); do task::spawn || { do x2.write_cond |cond| { let woken = cond.signal(); @@ -1218,7 +1218,7 @@ mod tests { } // Parent wakes up child let (port,chan) = comm::stream(); - let x3 = ~x.clone(); + let x3 = (*x).clone(); do task::spawn || { do x3.write_cond |cond| { chan.send(()); @@ -1253,11 +1253,11 @@ mod tests { let mut ports = ~[]; for num_waiters.times { - let xi = ~x.clone(); + let xi = (*x).clone(); let (port, chan) = comm::stream(); ports.push(port); do task::spawn || { - do lock_cond(xi, dg1) |cond| { + do lock_cond(&xi, dg1) |cond| { chan.send(()); cond.wait(); chan.send(()); @@ -1289,10 +1289,10 @@ mod tests { pub fn rwlock_kill_helper(mode1: RWlockMode, mode2: RWlockMode) { // Mutex must get automatically unlocked if failed/killed within. let x = ~RWlock(); - let x2 = ~x.clone(); + let x2 = (*x).clone(); let result: result::Result<(),()> = do task::try || { - do lock_rwlock_in_mode(x2, mode1) { + do lock_rwlock_in_mode(&x2, mode1) { fail!(); } }; diff --git a/src/libstd/tempfile.rs b/src/libstd/tempfile.rs index cd023962c88..7704ec158e5 100644 --- a/src/libstd/tempfile.rs +++ b/src/libstd/tempfile.rs @@ -12,6 +12,7 @@ use core::os; use core::prelude::*; +use core::rand::RngUtil; use core::rand; pub fn mkdtemp(tmpdir: &Path, suffix: &str) -> Option<Path> { diff --git a/src/libstd/term.rs b/src/libstd/term.rs index fb63755a572..2a8c8b3b06b 100644 --- a/src/libstd/term.rs +++ b/src/libstd/term.rs @@ -36,10 +36,10 @@ pub const color_bright_magenta: u8 = 13u8; pub const color_bright_cyan: u8 = 14u8; pub const color_bright_white: u8 = 15u8; -pub fn esc(writer: io::Writer) { writer.write(~[0x1bu8, '[' as u8]); } +pub fn esc(writer: @io::Writer) { writer.write(~[0x1bu8, '[' as u8]); } /// Reset the foreground and background colors to default -pub fn reset(writer: io::Writer) { +pub fn reset(writer: @io::Writer) { esc(writer); writer.write(~['0' as u8, 'm' as u8]); } @@ -59,7 +59,7 @@ pub fn color_supported() -> bool { }; } -pub fn set_color(writer: io::Writer, first_char: u8, color: u8) { +pub fn set_color(writer: @io::Writer, first_char: u8, color: u8) { fail_unless!((color < 16u8)); esc(writer); let mut color = color; @@ -68,12 +68,12 @@ pub fn set_color(writer: io::Writer, first_char: u8, color: u8) { } /// Set the foreground color -pub fn fg(writer: io::Writer, color: u8) { +pub fn fg(writer: @io::Writer, color: u8) { return set_color(writer, '3' as u8, color); } /// Set the background color -pub fn bg(writer: io::Writer, color: u8) { +pub fn bg(writer: @io::Writer, color: u8) { return set_color(writer, '4' as u8, color); } diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 7286ce5e2bd..fcc60c8d978 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -26,7 +26,6 @@ use core::either::Either; use core::either; use core::io::WriterUtil; use core::io; -use core::libc::size_t; use core::comm::{stream, Chan, Port, SharedChan}; use core::option; use core::prelude::*; @@ -50,7 +49,7 @@ pub mod rustrt { // hierarchically it may. pub enum TestName { - StaticTestName(&static/str), + StaticTestName(&'static str), DynTestName(~str) } impl ToStr for TestName { @@ -199,8 +198,8 @@ pub struct BenchSamples { pub enum TestResult { TrOk, TrFailed, TrIgnored, TrBench(BenchSamples) } struct ConsoleTestState { - out: io::Writer, - log_out: Option<io::Writer>, + out: @io::Writer, + log_out: Option<@io::Writer>, use_color: bool, mut total: uint, mut passed: uint, @@ -317,7 +316,7 @@ pub fn run_tests_console(opts: &TestOpts, } } - fn write_log(out: io::Writer, result: TestResult, test: &TestDesc) { + fn write_log(out: @io::Writer, result: TestResult, test: &TestDesc) { out.write_line(fmt!("%s %s", match result { TrOk => ~"ok", @@ -327,23 +326,26 @@ pub fn run_tests_console(opts: &TestOpts, }, test.name.to_str())); } - fn write_ok(out: io::Writer, use_color: bool) { + fn write_ok(out: @io::Writer, use_color: bool) { write_pretty(out, ~"ok", term::color_green, use_color); } - fn write_failed(out: io::Writer, use_color: bool) { + fn write_failed(out: @io::Writer, use_color: bool) { write_pretty(out, ~"FAILED", term::color_red, use_color); } - fn write_ignored(out: io::Writer, use_color: bool) { + fn write_ignored(out: @io::Writer, use_color: bool) { write_pretty(out, ~"ignored", term::color_yellow, use_color); } - fn write_bench(out: io::Writer, use_color: bool) { + fn write_bench(out: @io::Writer, use_color: bool) { write_pretty(out, ~"bench", term::color_cyan, use_color); } - fn write_pretty(out: io::Writer, word: &str, color: u8, use_color: bool) { + fn write_pretty(out: @io::Writer, + word: &str, + color: u8, + use_color: bool) { if use_color && term::color_supported() { term::fg(out, color); } @@ -356,7 +358,11 @@ pub fn run_tests_console(opts: &TestOpts, fn print_failures(st: @ConsoleTestState) { st.out.write_line(~"\nfailures:"); - let mut failures = st.failures.map(|t| t.name.to_str()); + let mut failures = ~[]; + for uint::range(0, vec::uniq_len(&const st.failures)) |i| { + let name = copy st.failures[i].name; + failures.push(name.to_str()); + } sort::tim_sort(failures); for vec::each(failures) |name| { st.out.write_line(fmt!(" %s", name.to_str())); @@ -602,6 +608,7 @@ pub mod bench { use stats::Stats; use core::num; + use core::rand::RngUtil; use core::rand; use core::u64; use core::vec; @@ -701,7 +708,6 @@ pub mod bench { let mut prev_madp = 0.0; loop { - let n_samples = rng.gen_uint_range(50, 60); let n_iter = rng.gen_uint_range(magnitude, magnitude * 2); diff --git a/src/libstd/time.rs b/src/libstd/time.rs index d6e19515ba6..d768eef9a8c 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -30,10 +30,10 @@ pub mod rustrt { pub unsafe fn rust_tzset(); // FIXME: The i64 values can be passed by-val when #2064 is fixed. - pub unsafe fn rust_gmtime(&&sec: i64, &&nsec: i32, &&result: Tm); - pub unsafe fn rust_localtime(&&sec: i64, &&nsec: i32, &&result: Tm); - pub unsafe fn rust_timegm(&&tm: Tm, sec: &mut i64); - pub unsafe fn rust_mktime(&&tm: Tm, sec: &mut i64); + pub unsafe fn rust_gmtime(sec: i64, nsec: i32, result: &mut Tm); + pub unsafe fn rust_localtime(sec: i64, nsec: i32, result: &mut Tm); + pub unsafe fn rust_timegm(tm: &Tm, sec: &mut i64); + pub unsafe fn rust_mktime(tm: &Tm, sec: &mut i64); } } @@ -172,7 +172,7 @@ pub fn at_utc(clock: Timespec) -> Tm { unsafe { let mut Timespec { sec, nsec } = clock; let mut tm = empty_tm(); - rustrt::rust_gmtime(sec, nsec, tm); + rustrt::rust_gmtime(sec, nsec, &mut tm); tm } } @@ -187,7 +187,7 @@ pub fn at(clock: Timespec) -> Tm { unsafe { let mut Timespec { sec, nsec } = clock; let mut tm = empty_tm(); - rustrt::rust_localtime(sec, nsec, tm); + rustrt::rust_localtime(sec, nsec, &mut tm); tm } } @@ -217,9 +217,9 @@ pub impl Tm { unsafe { let mut sec = 0i64; if self.tm_gmtoff == 0_i32 { - rustrt::rust_timegm(*self, &mut sec); + rustrt::rust_timegm(self, &mut sec); } else { - rustrt::rust_mktime(*self, &mut sec); + rustrt::rust_mktime(self, &mut sec); } Timespec::new(sec, self.tm_nsec) } diff --git a/src/libstd/timer.rs b/src/libstd/timer.rs index 60469d0b0f2..d72bfe73dd6 100644 --- a/src/libstd/timer.rs +++ b/src/libstd/timer.rs @@ -142,8 +142,8 @@ pub fn recv_timeout<T:Copy + Owned>(iotask: &IoTask, extern fn delayed_send_cb(handle: *uv::ll::uv_timer_t, status: libc::c_int) { unsafe { - log(debug, - fmt!("delayed_send_cb handle %? status %?", handle, status)); + debug!( + "delayed_send_cb handle %? status %?", handle, status); // Faking a borrowed pointer to our ~SharedChan let timer_done_ch_ptr: &*c_void = &uv::ll::get_data_for_uv_handle( handle); @@ -163,7 +163,7 @@ extern fn delayed_send_cb(handle: *uv::ll::uv_timer_t, extern fn delayed_send_close_cb(handle: *uv::ll::uv_timer_t) { unsafe { - log(debug, fmt!("delayed_send_close_cb handle %?", handle)); + debug!("delayed_send_close_cb handle %?", handle); let timer_done_ch_ptr = uv::ll::get_data_for_uv_handle(handle); let timer_done_ch = transmute::<*c_void, ~SharedChan<()>>( timer_done_ch_ptr); @@ -179,6 +179,7 @@ mod test { use uv; use core::iter; + use core::rand::RngUtil; use core::rand; use core::task; use core::pipes::{stream, SharedChan}; diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index 42a84da43d2..f4d58568ae7 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -72,7 +72,7 @@ pure fn lt<K: Ord + TotalOrd, V>(a: &TreeMap<K, V>, } }; - return a_len < b_len; + a_len < b_len } impl<K: Ord + TotalOrd, V> Ord for TreeMap<K, V> { @@ -88,7 +88,7 @@ impl<K: Ord + TotalOrd, V> Ord for TreeMap<K, V> { impl<'self, K: TotalOrd, V> BaseIter<(&'self K, &'self V)> for TreeMap<K, V> { /// Visit all key-value pairs in order - pure fn each(&self, f: &fn(&(&self/K, &self/V)) -> bool) { + pure fn each(&self, f: &fn(&(&'self K, &'self V)) -> bool) { each(&self.root, f) } pure fn size_hint(&self) -> Option<uint> { Some(self.len()) } @@ -99,17 +99,17 @@ impl<'self, K: TotalOrd, V> for TreeMap<K, V> { /// Visit all key-value pairs in reverse order - pure fn each_reverse(&self, f: &fn(&(&self/K, &self/V)) -> bool) { + pure fn each_reverse(&self, f: &fn(&(&'self K, &'self V)) -> bool) { each_reverse(&self.root, f); } } impl<K: TotalOrd, V> Container for TreeMap<K, V> { /// Return the number of elements in the map - pure fn len(&self) -> uint { self.length } + pure fn len(&const self) -> uint { self.length } /// Return true if the map contains no elements - pure fn is_empty(&self) -> bool { self.root.is_none() } + pure fn is_empty(&const self) -> bool { self.root.is_none() } } impl<K: TotalOrd, V> Mutable for TreeMap<K, V> { @@ -134,9 +134,14 @@ impl<K: TotalOrd, V> Map<K, V> for TreeMap<K, V> { self.each(|&(_, v)| f(v)) } + /// Iterate over the map and mutate the contained values + fn mutate_values(&mut self, f: &fn(&'self K, &'self mut V) -> bool) { + mutate_values(&mut self.root, f); + } + /// Return the value corresponding to the key in the map - pure fn find(&self, key: &K) -> Option<&self/V> { - let mut current: &self/Option<~TreeNode<K, V>> = &self.root; + pure fn find(&self, key: &K) -> Option<&'self V> { + let mut current: &'self Option<~TreeNode<K, V>> = &self.root; loop { match *current { Some(ref r) => { @@ -192,15 +197,15 @@ pub impl<K: TotalOrd, V> TreeMap<K, V> { /// Lazy forward iterator over a map pub struct TreeMapIterator<K, V> { - priv stack: ~[&self/~TreeNode<K, V>], - priv node: &self/Option<~TreeNode<K, V>> + priv stack: ~[&'self ~TreeNode<K, V>], + priv node: &'self Option<~TreeNode<K, V>> } /// Advance the iterator to the next node (in order) and return a /// tuple with a reference to the key and value. If there are no /// more nodes, return `None`. pub fn map_next<K, V>(iter: &mut TreeMapIterator/&r<K, V>) - -> Option<(&r/K, &r/V)> { + -> Option<(&'r K, &'r V)> { while !iter.stack.is_empty() || iter.node.is_some() { match *iter.node { Some(ref x) => { @@ -219,7 +224,7 @@ pub fn map_next<K, V>(iter: &mut TreeMapIterator/&r<K, V>) /// Advance the iterator through the map pub fn map_advance<K, V>(iter: &mut TreeMapIterator/&r<K, V>, - f: &fn((&r/K, &r/V)) -> bool) { + f: &fn((&'r K, &'r V)) -> bool) { loop { match map_next(iter) { Some(x) => { @@ -271,11 +276,11 @@ impl<T: Ord + TotalOrd> Ord for TreeSet<T> { impl<T: TotalOrd> Container for TreeSet<T> { /// Return the number of elements in the set #[inline(always)] - pure fn len(&self) -> uint { self.map.len() } + pure fn len(&const self) -> uint { self.map.len() } /// Return true if the set contains no elements #[inline(always)] - pure fn is_empty(&self) -> bool { self.map.is_empty() } + pure fn is_empty(&const self) -> bool { self.map.is_empty() } } impl<T: TotalOrd> Mutable for TreeSet<T> { @@ -514,14 +519,14 @@ pub struct TreeSetIterator<T> { /// Advance the iterator to the next node (in order). If this iterator is /// finished, does nothing. #[inline(always)] -pub fn set_next<T>(iter: &mut TreeSetIterator/&r<T>) -> Option<&r/T> { +pub fn set_next<T>(iter: &mut TreeSetIterator/&r<T>) -> Option<&'r T> { do map_next(&mut iter.iter).map |&(value, _)| { value } } /// Advance the iterator through the set #[inline(always)] pub fn set_advance<T>(iter: &mut TreeSetIterator/&r<T>, - f: &fn(&r/T) -> bool) { + f: &fn(&'r T) -> bool) { do map_advance(&mut iter.iter) |(k, _)| { f(k) } } @@ -542,22 +547,36 @@ pub impl<K: TotalOrd, V> TreeNode<K, V> { } } -pure fn each<K: TotalOrd, V>(node: &r/Option<~TreeNode<K, V>>, - f: &fn(&(&r/K, &r/V)) -> bool) { +pure fn each<K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>, + f: &fn(&(&'r K, &'r V)) -> bool) { for node.each |x| { each(&x.left, f); if f(&(&x.key, &x.value)) { each(&x.right, f) } } } -pure fn each_reverse<K: TotalOrd, V>(node: &r/Option<~TreeNode<K, V>>, - f: &fn(&(&r/K, &r/V)) -> bool) { +pure fn each_reverse<K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>, + f: &fn(&(&'r K, &'r V)) -> bool) { for node.each |x| { each_reverse(&x.right, f); if f(&(&x.key, &x.value)) { each_reverse(&x.left, f) } } } +fn mutate_values<K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>, + f: &fn(&'r K, &'r mut V) -> bool) -> bool { + match *node { + Some(~TreeNode{key: ref key, value: ref mut value, left: ref mut left, + right: ref mut right, _}) => { + if !mutate_values(left, f) { return false } + if !f(key, value) { return false } + if !mutate_values(right, f) { return false } + } + None => return false + } + true +} + // Remove left horizontal link by rotating right fn skew<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) { if node.left.map_default(false, |x| x.level == node.level) { @@ -617,14 +636,13 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>, fn heir_swap<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>, child: &mut Option<~TreeNode<K, V>>) { // *could* be done without recursion, but it won't borrow check - do child.mutate |mut child| { - if child.right.is_some() { - heir_swap(node, &mut child.right); + for child.each_mut |x| { + if x.right.is_some() { + heir_swap(node, &mut x.right); } else { - node.key <-> child.key; - node.value <-> child.value; + node.key <-> x.key; + node.value <-> x.value; } - child } } @@ -670,27 +688,18 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>, save.level -= 1; if right_level > save.level { - do save.right.mutate |mut x| { x.level = save.level; x } + for save.right.each_mut |x| { x.level = save.level } } skew(save); - match save.right { - Some(ref mut right) => { + for save.right.each_mut |right| { skew(right); - match right.right { - Some(ref mut x) => { skew(x) }, - None => () - } - } - None => () + for right.right.each_mut |x| { skew(x) } } split(save); - match save.right { - Some(ref mut x) => { split(x) }, - None => () - } + for save.right.each_mut |x| { split(x) } } return removed; @@ -699,13 +708,14 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>, } *node = None; - return true; + true } #[cfg(test)] mod test_treemap { use core::prelude::*; use super::*; + use core::rand::RngUtil; use core::rand; #[test] @@ -977,8 +987,6 @@ mod test_treemap { let m = m; let mut a = m.iter(); - // FIXME: #4492 (ICE): iter.get() == Some((&x1, &y1)) - fail_unless!(map_next(&mut a).unwrap() == (&x1, &y1)); fail_unless!(map_next(&mut a).unwrap() == (&x2, &y2)); fail_unless!(map_next(&mut a).unwrap() == (&x3, &y3)); diff --git a/src/libstd/uv_global_loop.rs b/src/libstd/uv_global_loop.rs index db3570941e8..1f3dc2f01de 100644 --- a/src/libstd/uv_global_loop.rs +++ b/src/libstd/uv_global_loop.rs @@ -136,26 +136,25 @@ mod test { timer_ptr as *libc::c_void); let exit_ch = transmute::<*c_void, ~Chan<bool>>(exit_ch_ptr); exit_ch.send(true); - log(debug, - fmt!("EXIT_CH_PTR simple_timer_close_cb exit_ch_ptr: %?", - exit_ch_ptr)); + debug!("EXIT_CH_PTR simple_timer_close_cb exit_ch_ptr: %?", + exit_ch_ptr); } } extern fn simple_timer_cb(timer_ptr: *ll::uv_timer_t, _status: libc::c_int) { unsafe { - log(debug, ~"in simple timer cb"); + debug!(~"in simple timer cb"); ll::timer_stop(timer_ptr); let hl_loop = &get_gl(); do iotask::interact(hl_loop) |_loop_ptr| { - log(debug, ~"closing timer"); + debug!(~"closing timer"); unsafe { ll::close(timer_ptr, simple_timer_close_cb); } - log(debug, ~"about to deref exit_ch_ptr"); - log(debug, ~"after msg sent on deref'd exit_ch"); + debug!(~"about to deref exit_ch_ptr"); + debug!(~"after msg sent on deref'd exit_ch"); }; - log(debug, ~"exiting simple timer cb"); + debug!(~"exiting simple timer cb"); } } @@ -163,13 +162,13 @@ mod test { unsafe { let (exit_po, exit_ch) = stream::<bool>(); let exit_ch_ptr: *libc::c_void = transmute(~exit_ch); - log(debug, fmt!("EXIT_CH_PTR newly created exit_ch_ptr: %?", - exit_ch_ptr)); + debug!("EXIT_CH_PTR newly created exit_ch_ptr: %?", + exit_ch_ptr); let timer_handle = ll::timer_t(); let timer_ptr = ptr::addr_of(&timer_handle); do iotask::interact(iotask) |loop_ptr| { unsafe { - log(debug, ~"user code inside interact loop!!!"); + debug!(~"user code inside interact loop!!!"); let init_status = ll::timer_init(loop_ptr, timer_ptr); if(init_status == 0i32) { ll::set_data_for_uv_handle( @@ -188,7 +187,7 @@ mod test { } }; exit_po.recv(); - log(debug, + debug!( ~"global_loop timer test: msg recv on exit_po, done.."); } } @@ -225,7 +224,7 @@ mod test { for iter::repeat(cycles) { exit_po.recv(); }; - log(debug, ~"test_stress_gl_uv_global_loop_high_level_global_timer"+ + debug!(~"test_stress_gl_uv_global_loop_high_level_global_timer"+ ~" exiting sucessfully!"); } } diff --git a/src/libstd/uv_iotask.rs b/src/libstd/uv_iotask.rs index 522a613f02d..1c7a7c22a9d 100644 --- a/src/libstd/uv_iotask.rs +++ b/src/libstd/uv_iotask.rs @@ -132,10 +132,10 @@ fn run_loop(iotask_ch: &Chan<IoTask>) { }; iotask_ch.send(iotask); - log(debug, ~"about to run uv loop"); + debug!("about to run uv loop"); // enter the loop... this blocks until the loop is done.. ll::run(loop_ptr); - log(debug, ~"uv loop ended"); + debug!("uv loop ended"); ll::loop_delete(loop_ptr); } } @@ -158,8 +158,8 @@ fn send_msg(iotask: &IoTask, extern fn wake_up_cb(async_handle: *ll::uv_async_t, status: int) { - log(debug, fmt!("wake_up_cb extern.. handle: %? status: %?", - async_handle, status)); + debug!("wake_up_cb extern.. handle: %? status: %?", + async_handle, status); unsafe { let loop_ptr = ll::get_loop_for_uv_handle(async_handle); @@ -178,13 +178,13 @@ extern fn wake_up_cb(async_handle: *ll::uv_async_t, fn begin_teardown(data: *IoTaskLoopData) { unsafe { - log(debug, ~"iotask begin_teardown() called, close async_handle"); + debug!("iotask begin_teardown() called, close async_handle"); let async_handle = (*data).async_handle; ll::close(async_handle as *c_void, tear_down_close_cb); } } extern fn tear_down_walk_cb(handle: *libc::c_void, arg: *libc::c_void) { - log(debug, ~"IN TEARDOWN WALK CB"); + debug!("IN TEARDOWN WALK CB"); // pretty much, if we still have an active handle and it is *not* // the async handle that facilities global loop communication, we // want to barf out and fail @@ -194,7 +194,7 @@ extern fn tear_down_walk_cb(handle: *libc::c_void, arg: *libc::c_void) { extern fn tear_down_close_cb(handle: *ll::uv_async_t) { unsafe { let loop_ptr = ll::get_loop_for_uv_handle(handle); - log(debug, ~"in tear_down_close_cb"); + debug!("in tear_down_close_cb"); ll::walk(loop_ptr, tear_down_walk_cb, handle as *libc::c_void); } } @@ -202,7 +202,7 @@ extern fn tear_down_close_cb(handle: *ll::uv_async_t) { #[cfg(test)] extern fn async_close_cb(handle: *ll::uv_async_t) { unsafe { - log(debug, fmt!("async_close_cb handle %?", handle)); + debug!("async_close_cb handle %?", handle); let exit_ch = &(*(ll::get_data_for_uv_handle(handle) as *AhData)).exit_ch; let exit_ch = exit_ch.clone(); @@ -213,8 +213,7 @@ extern fn async_close_cb(handle: *ll::uv_async_t) { #[cfg(test)] extern fn async_handle_cb(handle: *ll::uv_async_t, status: libc::c_int) { unsafe { - log(debug, - fmt!("async_handle_cb handle %? status %?",handle,status)); + debug!("async_handle_cb handle %? status %?",handle,status); ll::close(handle, async_close_cb); } } @@ -269,15 +268,15 @@ unsafe fn spawn_test_loop(exit_ch: ~Chan<()>) -> IoTask { #[cfg(test)] extern fn lifetime_handle_close(handle: *libc::c_void) { unsafe { - log(debug, fmt!("lifetime_handle_close ptr %?", handle)); + debug!("lifetime_handle_close ptr %?", handle); } } #[cfg(test)] extern fn lifetime_async_callback(handle: *libc::c_void, status: libc::c_int) { - log(debug, fmt!("lifetime_handle_close ptr %? status %?", - handle, status)); + debug!("lifetime_handle_close ptr %? status %?", + handle, status); } #[test] @@ -311,9 +310,9 @@ fn test_uv_iotask_async() { debug!("waiting"); work_exit_po.recv(); }; - log(debug, ~"sending teardown_loop msg.."); + debug!(~"sending teardown_loop msg.."); exit(iotask); exit_po.recv(); - log(debug, ~"after recv on exit_po.. exiting.."); + debug!(~"after recv on exit_po.. exiting.."); } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b22018c4c76..65eeff5bbab 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -386,7 +386,6 @@ pub enum vstore { #[auto_decode] #[deriving_eq] pub enum expr_vstore { - // FIXME (#3469): Change uint to @expr (actually only constant exprs) expr_vstore_fixed(Option<uint>), // [1,2,3,4] expr_vstore_uniq, // ~[1,2,3,4] expr_vstore_box, // @[1,2,3,4] @@ -456,7 +455,7 @@ impl<T:to_bytes::IterBytes> to_bytes::IterBytes for inferable<T> { #[auto_encode] #[auto_decode] #[deriving_eq] -pub enum rmode { by_ref, by_val, by_copy } +pub enum rmode { by_ref, by_copy } impl to_bytes::IterBytes for rmode { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { @@ -601,8 +600,10 @@ pub enum expr_ { expr_ret(Option<@expr>), expr_log(log_level, @expr, @expr), - /* asm, clobbers + constraints, volatile, align stack */ - expr_inline_asm(@~str, @~str, bool, bool), + expr_inline_asm(@~str, // asm + ~[(@~str, @expr)], // inputs + ~[(@~str, @expr)], // outputs + @~str, bool, bool), // clobbers, volatile, align stack expr_mac(mac), @@ -914,7 +915,7 @@ pub enum ty_ { ty_box(mt), ty_uniq(mt), ty_vec(mt), - ty_fixed_length_vec(mt, uint), + ty_fixed_length_vec(mt, @expr), ty_ptr(mt), ty_rptr(Option<@Lifetime>, mt), ty_closure(@TyClosure), diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index a7d5c0ce75f..5266d1b049a 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -110,7 +110,7 @@ pub struct Ctx { map: @map, path: path, local_id: uint, - diag: span_handler, + diag: @span_handler, } pub type vt = visit::vt<@mut Ctx>; @@ -132,7 +132,7 @@ pub fn mk_ast_map_visitor() -> vt { }); } -pub fn map_crate(diag: span_handler, c: crate) -> map { +pub fn map_crate(diag: @span_handler, c: crate) -> map { let cx = @mut Ctx { map: @std::oldmap::HashMap(), path: ~[], @@ -146,9 +146,9 @@ pub fn map_crate(diag: span_handler, c: crate) -> map { // Used for items loaded from external crate that are being inlined into this // crate. The `path` should be the path to the item but should not include // the item itself. -pub fn map_decoded_item(diag: span_handler, +pub fn map_decoded_item(diag: @span_handler, map: map, - path: path, + +path: path, ii: inlined_item) { // I believe it is ok for the local IDs of inlined items from other crates // to overlap with the local ids from this crate, so just generate the ids @@ -171,10 +171,10 @@ pub fn map_decoded_item(diag: span_handler, ii_item(*) | ii_dtor(*) => { /* fallthrough */ } ii_foreign(i) => { cx.map.insert(i.id, node_foreign_item(i, foreign_abi_rust_intrinsic, - @/*bad*/ copy path)); + @path)); } ii_method(impl_did, m) => { - map_method(impl_did, @/*bad*/ copy path, m, cx); + map_method(impl_did, @path, m, cx); } } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index fb7143f7c14..a410d6cf8e3 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -72,7 +72,7 @@ pub fn attr_meta(attr: ast::attribute) -> @ast::meta_item { } // Get the meta_items from inside a vector of attributes -pub fn attr_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] { +pub fn attr_metas(attrs: &[ast::attribute]) -> ~[@ast::meta_item] { do attrs.map |a| { attr_meta(*a) } } @@ -214,7 +214,7 @@ pub fn attrs_contains_name(attrs: &[ast::attribute], name: &str) -> bool { !find_attrs_by_name(attrs, name).is_empty() } -pub fn first_attr_value_str_by_name(attrs: ~[ast::attribute], name: &str) +pub fn first_attr_value_str_by_name(attrs: &[ast::attribute], name: &str) -> Option<@~str> { let mattrs = find_attrs_by_name(attrs, name); @@ -304,7 +304,7 @@ pub fn find_linkage_metas(attrs: &[ast::attribute]) -> ~[@ast::meta_item] { } } -pub fn foreign_abi(attrs: ~[ast::attribute]) +pub fn foreign_abi(attrs: &[ast::attribute]) -> Either<~str, ast::foreign_abi> { return match attr::first_attr_value_str_by_name(attrs, ~"abi") { None => { @@ -360,7 +360,7 @@ pub fn find_inline_attr(attrs: &[ast::attribute]) -> inline_attr { } -pub fn require_unique_names(diagnostic: span_handler, +pub fn require_unique_names(diagnostic: @span_handler, metas: &[@ast::meta_item]) { let mut set = LinearSet::new(); for metas.each |meta| { diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 0d6ece8ad92..538f0de8c84 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -140,7 +140,7 @@ impl cmp::Eq for span { impl<S:Encoder> Encodable<S> for span { /* Note #1972 -- spans are encoded but not decoded */ - fn encode(&self, _s: &S) { } + fn encode(&self, _s: &S) { _s.emit_nil() } } impl<D:Decoder> Decodable<D> for span { @@ -252,8 +252,8 @@ pub impl FileMap { // about what ends a line between this file and parse.rs fn next_line(&self, +pos: BytePos) { // the new charpos must be > the last one (or it's the first one). - fail_unless!((self.lines.len() == 0) - || (self.lines[self.lines.len() - 1] < pos)); + let lines = &mut *self.lines; + fail_unless!((lines.len() == 0) || (lines[lines.len() - 1] < pos)); self.lines.push(pos); } @@ -302,11 +302,12 @@ pub impl CodeMap { +substr: FileSubstr, src: @~str ) -> @FileMap { - let start_pos = if self.files.len() == 0 { + let files = &mut *self.files; + let start_pos = if files.len() == 0 { 0 } else { - let last_start = self.files.last().start_pos.to_uint(); - let last_len = self.files.last().src.len(); + let last_start = files.last().start_pos.to_uint(); + let last_len = files.last().src.len(); last_start + last_len }; @@ -364,7 +365,8 @@ pub impl CodeMap { } pub fn span_to_str(&self, sp: span) -> ~str { - if self.files.len() == 0 && sp == dummy_sp() { + let files = &mut *self.files; + if files.len() == 0 && sp == dummy_sp() { return ~"no-location"; } @@ -409,7 +411,8 @@ pub impl CodeMap { priv impl CodeMap { fn lookup_filemap_idx(&self, +pos: BytePos) -> uint { - let len = self.files.len(); + let files = &*self.files; + let len = files.len(); let mut a = 0u; let mut b = len; while b - a > 1u { @@ -433,10 +436,11 @@ priv impl CodeMap { let idx = self.lookup_filemap_idx(pos); let f = self.files[idx]; let mut a = 0u; - let mut b = f.lines.len(); + let lines = &*f.lines; + let mut b = lines.len(); while b - a > 1u { let m = (a + b) / 2u; - if f.lines[m] > pos { b = m; } else { a = m; } + if lines[m] > pos { b = m; } else { a = m; } } return FileMapAndLine {fm: f, line: a}; } diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 4e177fecec9..93d28f31c8d 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -55,7 +55,7 @@ pub trait span_handler { fn span_note(@mut self, sp: span, msg: &str); fn span_bug(@mut self, sp: span, msg: &str) -> !; fn span_unimpl(@mut self, sp: span, msg: &str) -> !; - fn handler(@mut self) -> handler; + fn handler(@mut self) -> @handler; } struct HandlerT { @@ -64,7 +64,7 @@ struct HandlerT { } struct CodemapT { - handler: handler, + handler: @handler, cm: @codemap::CodeMap, } @@ -89,7 +89,7 @@ impl span_handler for CodemapT { fn span_unimpl(@mut self, sp: span, msg: &str) -> ! { self.span_bug(sp, ~"unimplemented " + msg); } - fn handler(@mut self) -> handler { + fn handler(@mut self) -> @handler { self.handler } } @@ -143,8 +143,8 @@ pub fn ice_msg(msg: &str) -> ~str { fmt!("internal compiler error: %s", msg) } -pub fn mk_span_handler(handler: handler, cm: @codemap::CodeMap) - -> span_handler { +pub fn mk_span_handler(handler: @handler, cm: @codemap::CodeMap) + -> @span_handler { @mut CodemapT { handler: handler, cm: cm } as @span_handler } @@ -304,7 +304,7 @@ fn print_macro_backtrace(cm: @codemap::CodeMap, sp: span) { } } -pub fn expect<T:Copy>(diag: span_handler, +pub fn expect<T:Copy>(diag: @span_handler, opt: Option<T>, msg: &fn() -> ~str) -> T { match opt { diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index 8051a67d8fd..a014d8ccb8b 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -41,10 +41,10 @@ fn next_state(s: State) -> Option<State> { } } -pub fn expand_asm(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) - -> base::MacResult { - - let p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), +pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) + -> base::MacResult { + let p = parse::new_parser_from_tts(cx.parse_sess(), + cx.cfg(), vec::from_slice(tts)); let mut asm = ~""; @@ -75,6 +75,13 @@ pub fn expand_asm(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) let out = p.parse_expr(); p.expect(&token::RPAREN); + let out = @ast::expr { + id: cx.next_id(), + callee_id: cx.next_id(), + span: out.span, + node: ast::expr_addr_of(ast::m_mutbl, out) + }; + outputs.push((constraint, out)); } } @@ -156,7 +163,8 @@ pub fn expand_asm(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) MRExpr(@ast::expr { id: cx.next_id(), callee_id: cx.next_id(), - node: ast::expr_inline_asm(@asm, @cons, volatile, alignstack), + node: ast::expr_inline_asm(@asm, inputs, outputs, + @cons, volatile, alignstack), span: sp }) } diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index c99d8977643..8c02b432371 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -110,7 +110,7 @@ mod syntax { } pub fn expand_auto_encode( - cx: ext_ctxt, + cx: @ext_ctxt, span: span, _mitem: @ast::meta_item, in_items: ~[@ast::item] @@ -165,7 +165,7 @@ pub fn expand_auto_encode( } pub fn expand_auto_decode( - cx: ext_ctxt, + cx: @ext_ctxt, span: span, _mitem: @ast::meta_item, in_items: ~[@ast::item] @@ -219,7 +219,7 @@ pub fn expand_auto_decode( } } -priv impl ext_ctxt { +priv impl @ext_ctxt { fn bind_path( &self, span: span, @@ -426,7 +426,7 @@ priv impl ext_ctxt { } fn mk_impl( - cx: ext_ctxt, + cx: @ext_ctxt, span: span, ident: ast::ident, ty_param: ast::TyParam, @@ -499,7 +499,7 @@ fn mk_impl( } fn mk_ser_impl( - cx: ext_ctxt, + cx: @ext_ctxt, span: span, ident: ast::ident, generics: &ast::Generics, @@ -543,7 +543,7 @@ fn mk_ser_impl( } fn mk_deser_impl( - cx: ext_ctxt, + cx: @ext_ctxt, span: span, ident: ast::ident, generics: &ast::Generics, @@ -587,7 +587,7 @@ fn mk_deser_impl( } fn mk_ser_method( - cx: ext_ctxt, + cx: @ext_ctxt, span: span, +ser_body: ast::blk ) -> @ast::method { @@ -647,7 +647,7 @@ fn mk_ser_method( } fn mk_deser_method( - cx: ext_ctxt, + cx: @ext_ctxt, span: span, ty: @ast::Ty, +deser_body: ast::blk @@ -701,7 +701,7 @@ fn mk_deser_method( } fn mk_struct_ser_impl( - cx: ext_ctxt, + cx: @ext_ctxt, span: span, ident: ast::ident, fields: &[@ast::struct_field], @@ -762,7 +762,7 @@ fn mk_struct_ser_impl( } fn mk_struct_deser_impl( - cx: ext_ctxt, + cx: @ext_ctxt, span: span, ident: ast::ident, fields: ~[@ast::struct_field], @@ -866,7 +866,7 @@ fn mk_struct_fields(fields: &[@ast::struct_field]) -> ~[field] { } fn mk_enum_ser_impl( - cx: ext_ctxt, + cx: @ext_ctxt, span: span, ident: ast::ident, +enum_def: ast::enum_def, @@ -883,7 +883,7 @@ fn mk_enum_ser_impl( } fn mk_enum_deser_impl( - cx: ext_ctxt, + cx: @ext_ctxt, span: span, ident: ast::ident, +enum_def: ast::enum_def, @@ -900,7 +900,7 @@ fn mk_enum_deser_impl( } fn ser_variant( - cx: ext_ctxt, + cx: @ext_ctxt, span: span, v_name: ast::ident, v_idx: uint, @@ -982,7 +982,7 @@ fn ser_variant( } fn mk_enum_ser_body( - cx: ext_ctxt, + cx: @ext_ctxt, span: span, name: ast::ident, +variants: ~[ast::variant] @@ -1032,7 +1032,7 @@ fn mk_enum_ser_body( } fn mk_enum_deser_variant_nary( - cx: ext_ctxt, + cx: @ext_ctxt, span: span, name: ast::ident, args: ~[ast::variant_arg] @@ -1069,7 +1069,7 @@ fn mk_enum_deser_variant_nary( } fn mk_enum_deser_body( - ext_cx: ext_ctxt, + ext_cx: @ext_ctxt, span: span, name: ast::ident, variants: ~[ast::variant] diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index c8363e3daa8..652bc541a1f 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -36,7 +36,7 @@ pub struct MacroDef { ext: SyntaxExtension } -pub type ItemDecorator = @fn(ext_ctxt, +pub type ItemDecorator = @fn(@ext_ctxt, span, @ast::meta_item, ~[@ast::item]) @@ -47,7 +47,7 @@ pub struct SyntaxExpanderTT { span: Option<span> } -pub type SyntaxExpanderTTFun = @fn(ext_ctxt, +pub type SyntaxExpanderTTFun = @fn(@ext_ctxt, span, &[ast::token_tree]) -> MacResult; @@ -57,7 +57,7 @@ pub struct SyntaxExpanderTTItem { span: Option<span> } -pub type SyntaxExpanderTTItemFun = @fn(ext_ctxt, +pub type SyntaxExpanderTTItemFun = @fn(@ext_ctxt, span, ast::ident, ~[ast::token_tree]) @@ -238,8 +238,8 @@ pub trait ext_ctxt { fn ident_of(@mut self, st: ~str) -> ast::ident; } -pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, - +cfg: ast::crate_cfg) -> ext_ctxt { +pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, +cfg: ast::crate_cfg) + -> @ext_ctxt { struct CtxtRepr { parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg, @@ -333,7 +333,7 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, ((imp) as @ext_ctxt) } -pub fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, err_msg: ~str) -> ~str { +pub fn expr_to_str(cx: @ext_ctxt, expr: @ast::expr, err_msg: ~str) -> ~str { match expr.node { ast::expr_lit(l) => match l.node { ast::lit_str(s) => copy *s, @@ -343,7 +343,7 @@ pub fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, err_msg: ~str) -> ~str { } } -pub fn expr_to_ident(cx: ext_ctxt, +pub fn expr_to_ident(cx: @ext_ctxt, expr: @ast::expr, err_msg: ~str) -> ast::ident { match expr.node { @@ -357,14 +357,14 @@ pub fn expr_to_ident(cx: ext_ctxt, } } -pub fn check_zero_tts(cx: ext_ctxt, sp: span, tts: &[ast::token_tree], +pub fn check_zero_tts(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree], name: &str) { if tts.len() != 0 { cx.span_fatal(sp, fmt!("%s takes no arguments", name)); } } -pub fn get_single_str_from_tts(cx: ext_ctxt, +pub fn get_single_str_from_tts(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree], name: &str) -> ~str { @@ -379,7 +379,7 @@ pub fn get_single_str_from_tts(cx: ext_ctxt, } } -pub fn get_exprs_from_tts(cx: ext_ctxt, tts: &[ast::token_tree]) +pub fn get_exprs_from_tts(cx: @ext_ctxt, tts: &[ast::token_tree]) -> ~[@ast::expr] { let p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), @@ -421,7 +421,7 @@ pub fn get_exprs_from_tts(cx: ext_ctxt, tts: &[ast::token_tree]) // use a top-level managed pointer by some difficulties // with pushing and popping functionally, and the ownership // issues. As a result, the values returned by the table -// also need to be managed; the &self/... type that Maps +// also need to be managed; the &'self ... type that Maps // return won't work for things that need to get outside // of that managed pointer. The easiest way to do this // is just to insist that the values in the tables are @@ -454,7 +454,7 @@ impl <K: Eq + Hash + IterBytes ,V: Copy> MapChain<K,V>{ // ugh: can't get this to compile with mut because of the // lack of flow sensitivity. - fn get_map(&self) -> &self/LinearMap<K,@V> { + fn get_map(&self) -> &'self LinearMap<K,@V> { match *self { BaseMapChain (~ref map) => map, ConsMapChain (~ref map,_) => map diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 5d071b8d517..18c7cd3f861 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -25,7 +25,7 @@ pub struct Field { ex: @ast::expr } -pub fn mk_expr(cx: ext_ctxt, +pub fn mk_expr(cx: @ext_ctxt, sp: codemap::span, +expr: ast::expr_) -> @ast::expr { @@ -37,28 +37,28 @@ pub fn mk_expr(cx: ext_ctxt, } } -pub fn mk_lit(cx: ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr { +pub fn mk_lit(cx: @ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr { let sp_lit = @codemap::spanned { node: lit, span: sp }; mk_expr(cx, sp, ast::expr_lit(sp_lit)) } -pub fn mk_int(cx: ext_ctxt, sp: span, i: int) -> @ast::expr { +pub fn mk_int(cx: @ext_ctxt, sp: span, i: int) -> @ast::expr { let lit = ast::lit_int(i as i64, ast::ty_i); return mk_lit(cx, sp, lit); } -pub fn mk_uint(cx: ext_ctxt, sp: span, u: uint) -> @ast::expr { +pub fn mk_uint(cx: @ext_ctxt, sp: span, u: uint) -> @ast::expr { let lit = ast::lit_uint(u as u64, ast::ty_u); return mk_lit(cx, sp, lit); } -pub fn mk_u8(cx: ext_ctxt, sp: span, u: u8) -> @ast::expr { +pub fn mk_u8(cx: @ext_ctxt, sp: span, u: u8) -> @ast::expr { let lit = ast::lit_uint(u as u64, ast::ty_u8); return mk_lit(cx, sp, lit); } -pub fn mk_binary(cx: ext_ctxt, sp: span, op: ast::binop, +pub fn mk_binary(cx: @ext_ctxt, sp: span, op: ast::binop, lhs: @ast::expr, rhs: @ast::expr) -> @ast::expr { cx.next_id(); // see ast_util::op_expr_callee_id mk_expr(cx, sp, ast::expr_binary(op, lhs, rhs)) } -pub fn mk_unary(cx: ext_ctxt, sp: span, op: ast::unop, e: @ast::expr) +pub fn mk_unary(cx: @ext_ctxt, sp: span, op: ast::unop, e: @ast::expr) -> @ast::expr { cx.next_id(); // see ast_util::op_expr_callee_id mk_expr(cx, sp, ast::expr_unary(op, e)) @@ -88,69 +88,70 @@ pub fn mk_raw_path_global(sp: span, +idents: ~[ast::ident]) -> @ast::path { rp: None, types: ~[] } } -pub fn mk_path(cx: ext_ctxt, sp: span, +idents: ~[ast::ident]) -> @ast::expr { +pub fn mk_path(cx: @ext_ctxt, sp: span, +idents: ~[ast::ident]) + -> @ast::expr { mk_expr(cx, sp, ast::expr_path(mk_raw_path(sp, idents))) } -pub fn mk_path_global(cx: ext_ctxt, sp: span, +idents: ~[ast::ident]) +pub fn mk_path_global(cx: @ext_ctxt, sp: span, +idents: ~[ast::ident]) -> @ast::expr { mk_expr(cx, sp, ast::expr_path(mk_raw_path_global(sp, idents))) } -pub fn mk_access_(cx: ext_ctxt, sp: span, p: @ast::expr, m: ast::ident) +pub fn mk_access_(cx: @ext_ctxt, sp: span, p: @ast::expr, m: ast::ident) -> @ast::expr { mk_expr(cx, sp, ast::expr_field(p, m, ~[])) } -pub fn mk_access(cx: ext_ctxt, sp: span, +p: ~[ast::ident], m: ast::ident) +pub fn mk_access(cx: @ext_ctxt, sp: span, +p: ~[ast::ident], m: ast::ident) -> @ast::expr { let pathexpr = mk_path(cx, sp, p); return mk_access_(cx, sp, pathexpr, m); } -pub fn mk_addr_of(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr { +pub fn mk_addr_of(cx: @ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr { return mk_expr(cx, sp, ast::expr_addr_of(ast::m_imm, e)); } -pub fn mk_call_(cx: ext_ctxt, sp: span, fn_expr: @ast::expr, +pub fn mk_call_(cx: @ext_ctxt, sp: span, fn_expr: @ast::expr, +args: ~[@ast::expr]) -> @ast::expr { mk_expr(cx, sp, ast::expr_call(fn_expr, args, ast::NoSugar)) } -pub fn mk_call(cx: ext_ctxt, sp: span, +fn_path: ~[ast::ident], +pub fn mk_call(cx: @ext_ctxt, sp: span, +fn_path: ~[ast::ident], +args: ~[@ast::expr]) -> @ast::expr { let pathexpr = mk_path(cx, sp, fn_path); return mk_call_(cx, sp, pathexpr, args); } -pub fn mk_call_global(cx: ext_ctxt, sp: span, +fn_path: ~[ast::ident], +pub fn mk_call_global(cx: @ext_ctxt, sp: span, +fn_path: ~[ast::ident], +args: ~[@ast::expr]) -> @ast::expr { let pathexpr = mk_path_global(cx, sp, fn_path); return mk_call_(cx, sp, pathexpr, args); } // e = expr, t = type -pub fn mk_base_vec_e(cx: ext_ctxt, sp: span, +exprs: ~[@ast::expr]) +pub fn mk_base_vec_e(cx: @ext_ctxt, sp: span, +exprs: ~[@ast::expr]) -> @ast::expr { let vecexpr = ast::expr_vec(exprs, ast::m_imm); mk_expr(cx, sp, vecexpr) } -pub fn mk_vstore_e(cx: ext_ctxt, sp: span, expr: @ast::expr, +pub fn mk_vstore_e(cx: @ext_ctxt, sp: span, expr: @ast::expr, vst: ast::expr_vstore) -> @ast::expr { mk_expr(cx, sp, ast::expr_vstore(expr, vst)) } -pub fn mk_uniq_vec_e(cx: ext_ctxt, sp: span, +exprs: ~[@ast::expr]) +pub fn mk_uniq_vec_e(cx: @ext_ctxt, sp: span, +exprs: ~[@ast::expr]) -> @ast::expr { mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::expr_vstore_uniq) } -pub fn mk_slice_vec_e(cx: ext_ctxt, sp: span, +exprs: ~[@ast::expr]) +pub fn mk_slice_vec_e(cx: @ext_ctxt, sp: span, +exprs: ~[@ast::expr]) -> @ast::expr { mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::expr_vstore_slice) } -pub fn mk_fixed_vec_e(cx: ext_ctxt, sp: span, +exprs: ~[@ast::expr]) +pub fn mk_fixed_vec_e(cx: @ext_ctxt, sp: span, +exprs: ~[@ast::expr]) -> @ast::expr { mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::expr_vstore_fixed(None)) } -pub fn mk_base_str(cx: ext_ctxt, sp: span, +s: ~str) -> @ast::expr { +pub fn mk_base_str(cx: @ext_ctxt, sp: span, +s: ~str) -> @ast::expr { let lit = ast::lit_str(@s); return mk_lit(cx, sp, lit); } -pub fn mk_uniq_str(cx: ext_ctxt, sp: span, +s: ~str) -> @ast::expr { +pub fn mk_uniq_str(cx: @ext_ctxt, sp: span, +s: ~str) -> @ast::expr { mk_vstore_e(cx, sp, mk_base_str(cx, sp, s), ast::expr_vstore_uniq) } pub fn mk_field(sp: span, f: &Field) -> ast::field { @@ -162,7 +163,7 @@ pub fn mk_field(sp: span, f: &Field) -> ast::field { pub fn mk_fields(sp: span, fields: ~[Field]) -> ~[ast::field] { fields.map(|f| mk_field(sp, f)) } -pub fn mk_struct_e(cx: ext_ctxt, +pub fn mk_struct_e(cx: @ext_ctxt, sp: span, +ctor_path: ~[ast::ident], +fields: ~[Field]) @@ -172,7 +173,7 @@ pub fn mk_struct_e(cx: ext_ctxt, mk_fields(sp, fields), option::None::<@ast::expr>)) } -pub fn mk_global_struct_e(cx: ext_ctxt, +pub fn mk_global_struct_e(cx: @ext_ctxt, sp: span, +ctor_path: ~[ast::ident], +fields: ~[Field]) @@ -182,7 +183,7 @@ pub fn mk_global_struct_e(cx: ext_ctxt, mk_fields(sp, fields), option::None::<@ast::expr>)) } -pub fn mk_glob_use(cx: ext_ctxt, +pub fn mk_glob_use(cx: @ext_ctxt, sp: span, +path: ~[ast::ident]) -> @ast::view_item { let glob = @codemap::spanned { @@ -194,7 +195,7 @@ pub fn mk_glob_use(cx: ext_ctxt, vis: ast::private, span: sp } } -pub fn mk_local(cx: ext_ctxt, sp: span, mutbl: bool, +pub fn mk_local(cx: @ext_ctxt, sp: span, mutbl: bool, ident: ast::ident, ex: @ast::expr) -> @ast::stmt { let pat = @ast::pat { @@ -219,7 +220,7 @@ pub fn mk_local(cx: ext_ctxt, sp: span, mutbl: bool, let decl = codemap::spanned {node: ast::decl_local(~[local]), span: sp}; @codemap::spanned { node: ast::stmt_decl(@decl, cx.next_id()), span: sp } } -pub fn mk_block(cx: ext_ctxt, span: span, +pub fn mk_block(cx: @ext_ctxt, span: span, +view_items: ~[@ast::view_item], +stmts: ~[@ast::stmt], expr: Option<@ast::expr>) -> @ast::expr { @@ -235,7 +236,7 @@ pub fn mk_block(cx: ext_ctxt, span: span, }; mk_expr(cx, span, ast::expr_block(blk)) } -pub fn mk_block_(cx: ext_ctxt, +pub fn mk_block_(cx: @ext_ctxt, span: span, +stmts: ~[@ast::stmt]) -> ast::blk { @@ -250,7 +251,7 @@ pub fn mk_block_(cx: ext_ctxt, span: span, } } -pub fn mk_simple_block(cx: ext_ctxt, +pub fn mk_simple_block(cx: @ext_ctxt, span: span, expr: @ast::expr) -> ast::blk { @@ -265,21 +266,21 @@ pub fn mk_simple_block(cx: ext_ctxt, span: span, } } -pub fn mk_copy(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr { +pub fn mk_copy(cx: @ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr { mk_expr(cx, sp, ast::expr_copy(e)) } -pub fn mk_managed(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr { +pub fn mk_managed(cx: @ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr { mk_expr(cx, sp, ast::expr_unary(ast::box(ast::m_imm), e)) } -pub fn mk_pat(cx: ext_ctxt, span: span, +pat: ast::pat_) -> @ast::pat { +pub fn mk_pat(cx: @ext_ctxt, span: span, +pat: ast::pat_) -> @ast::pat { @ast::pat { id: cx.next_id(), node: pat, span: span } } -pub fn mk_pat_ident(cx: ext_ctxt, +pub fn mk_pat_ident(cx: @ext_ctxt, span: span, ident: ast::ident) -> @ast::pat { mk_pat_ident_with_binding_mode(cx, span, ident, ast::bind_by_copy) } -pub fn mk_pat_ident_with_binding_mode(cx: ext_ctxt, +pub fn mk_pat_ident_with_binding_mode(cx: @ext_ctxt, span: span, ident: ast::ident, bm: ast::binding_mode) -> @ast::pat { @@ -287,7 +288,7 @@ pub fn mk_pat_ident_with_binding_mode(cx: ext_ctxt, let pat = ast::pat_ident(bm, path, None); mk_pat(cx, span, pat) } -pub fn mk_pat_enum(cx: ext_ctxt, +pub fn mk_pat_enum(cx: @ext_ctxt, span: span, path: @ast::path, +subpats: ~[@ast::pat]) @@ -295,7 +296,7 @@ pub fn mk_pat_enum(cx: ext_ctxt, let pat = ast::pat_enum(path, Some(subpats)); mk_pat(cx, span, pat) } -pub fn mk_pat_struct(cx: ext_ctxt, +pub fn mk_pat_struct(cx: @ext_ctxt, span: span, path: @ast::path, +field_pats: ~[ast::field_pat]) @@ -303,17 +304,17 @@ pub fn mk_pat_struct(cx: ext_ctxt, let pat = ast::pat_struct(path, field_pats, false); mk_pat(cx, span, pat) } -pub fn mk_bool(cx: ext_ctxt, span: span, value: bool) -> @ast::expr { +pub fn mk_bool(cx: @ext_ctxt, span: span, value: bool) -> @ast::expr { let lit_expr = ast::expr_lit(@codemap::spanned { node: ast::lit_bool(value), span: span }); build::mk_expr(cx, span, lit_expr) } -pub fn mk_stmt(cx: ext_ctxt, span: span, expr: @ast::expr) -> @ast::stmt { +pub fn mk_stmt(cx: @ext_ctxt, span: span, expr: @ast::expr) -> @ast::stmt { let stmt_ = ast::stmt_semi(expr, cx.next_id()); @codemap::spanned { node: stmt_, span: span } } -pub fn mk_ty_path(cx: ext_ctxt, +pub fn mk_ty_path(cx: @ext_ctxt, span: span, +idents: ~[ ast::ident ]) -> @ast::Ty { @@ -322,7 +323,7 @@ pub fn mk_ty_path(cx: ext_ctxt, let ty = @ast::Ty { id: cx.next_id(), node: ty, span: span }; ty } -pub fn mk_ty_path_global(cx: ext_ctxt, +pub fn mk_ty_path_global(cx: @ext_ctxt, span: span, +idents: ~[ ast::ident ]) -> @ast::Ty { @@ -331,13 +332,13 @@ pub fn mk_ty_path_global(cx: ext_ctxt, let ty = @ast::Ty { id: cx.next_id(), node: ty, span: span }; ty } -pub fn mk_simple_ty_path(cx: ext_ctxt, +pub fn mk_simple_ty_path(cx: @ext_ctxt, span: span, ident: ast::ident) -> @ast::Ty { mk_ty_path(cx, span, ~[ ident ]) } -pub fn mk_arg(cx: ext_ctxt, +pub fn mk_arg(cx: @ext_ctxt, span: span, ident: ast::ident, ty: @ast::Ty) @@ -354,13 +355,13 @@ pub fn mk_arg(cx: ext_ctxt, pub fn mk_fn_decl(+inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl { ast::fn_decl { inputs: inputs, output: output, cf: ast::return_val } } -pub fn mk_ty_param(cx: ext_ctxt, +pub fn mk_ty_param(cx: @ext_ctxt, ident: ast::ident, bounds: @OptVec<ast::TyParamBound>) -> ast::TyParam { ast::TyParam { ident: ident, id: cx.next_id(), bounds: bounds } } -pub fn mk_lifetime(cx: ext_ctxt, +pub fn mk_lifetime(cx: @ext_ctxt, span: span, ident: ast::ident) -> ast::Lifetime { diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index 4f53bf62efb..0c3bef56459 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -16,7 +16,7 @@ use ext::base::*; use ext::base; use parse::token; -pub fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_syntax_ext(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let mut res_str = ~""; for tts.eachi |i, e| { diff --git a/src/libsyntax/ext/deriving.rs b/src/libsyntax/ext/deriving.rs index 093327ec32e..76ab21f403b 100644 --- a/src/libsyntax/ext/deriving.rs +++ b/src/libsyntax/ext/deriving.rs @@ -45,18 +45,18 @@ pub impl Junction { } } -type ExpandDerivingStructDefFn = &self/fn(ext_ctxt, +type ExpandDerivingStructDefFn = &'self fn(@ext_ctxt, span, x: &struct_def, ident, y: &Generics) -> @item; -type ExpandDerivingEnumDefFn = &self/fn(ext_ctxt, +type ExpandDerivingEnumDefFn = &'self fn(@ext_ctxt, span, x: &enum_def, ident, y: &Generics) -> @item; -pub fn expand_meta_deriving(cx: ext_ctxt, +pub fn expand_meta_deriving(cx: @ext_ctxt, _span: span, mitem: @meta_item, in_items: ~[@item]) @@ -98,7 +98,7 @@ pub fn expand_meta_deriving(cx: ext_ctxt, } } -pub fn expand_deriving_eq(cx: ext_ctxt, +pub fn expand_deriving_eq(cx: @ext_ctxt, span: span, _mitem: @meta_item, in_items: ~[@item]) @@ -110,7 +110,7 @@ pub fn expand_deriving_eq(cx: ext_ctxt, expand_deriving_eq_enum_def) } -pub fn expand_deriving_iter_bytes(cx: ext_ctxt, +pub fn expand_deriving_iter_bytes(cx: @ext_ctxt, span: span, _mitem: @meta_item, in_items: ~[@item]) @@ -122,7 +122,7 @@ pub fn expand_deriving_iter_bytes(cx: ext_ctxt, expand_deriving_iter_bytes_enum_def) } -pub fn expand_deriving_clone(cx: ext_ctxt, +pub fn expand_deriving_clone(cx: @ext_ctxt, span: span, _: @meta_item, in_items: ~[@item]) @@ -134,7 +134,7 @@ pub fn expand_deriving_clone(cx: ext_ctxt, expand_deriving_clone_enum_def) } -fn expand_deriving(cx: ext_ctxt, +fn expand_deriving(cx: @ext_ctxt, span: span, in_items: ~[@item], expand_deriving_struct_def: ExpandDerivingStructDefFn, @@ -164,7 +164,7 @@ fn expand_deriving(cx: ext_ctxt, result } -fn create_impl_item(cx: ext_ctxt, span: span, +item: item_) -> @item { +fn create_impl_item(cx: @ext_ctxt, span: span, +item: item_) -> @item { @ast::item { ident: clownshoes_extensions, attrs: ~[], @@ -177,7 +177,7 @@ fn create_impl_item(cx: ext_ctxt, span: span, +item: item_) -> @item { /// Creates a method from the given expression, the signature of which /// conforms to the `eq` or `ne` method. -fn create_eq_method(cx: ext_ctxt, +fn create_eq_method(cx: @ext_ctxt, span: span, method_ident: ident, type_ident: ident, @@ -226,7 +226,7 @@ fn create_eq_method(cx: ext_ctxt, attrs: ~[], generics: ast_util::empty_generics(), self_ty: self_ty, - purity: pure_fn, + purity: impure_fn, decl: fn_decl, body: body_block, id: cx.next_id(), @@ -236,7 +236,7 @@ fn create_eq_method(cx: ext_ctxt, } } -fn create_self_type_with_params(cx: ext_ctxt, +fn create_self_type_with_params(cx: @ext_ctxt, span: span, type_ident: ident, generics: &Generics) @@ -258,7 +258,7 @@ fn create_self_type_with_params(cx: ext_ctxt, @ast::Ty { id: cx.next_id(), node: self_type, span: span } } -fn create_derived_impl(cx: ext_ctxt, +fn create_derived_impl(cx: @ext_ctxt, span: span, type_ident: ident, generics: &Generics, @@ -320,7 +320,7 @@ fn create_derived_impl(cx: ext_ctxt, return create_impl_item(cx, span, impl_item); } -fn create_derived_eq_impl(cx: ext_ctxt, +fn create_derived_eq_impl(cx: @ext_ctxt, span: span, type_ident: ident, generics: &Generics, @@ -336,7 +336,7 @@ fn create_derived_eq_impl(cx: ext_ctxt, create_derived_impl(cx, span, type_ident, generics, methods, trait_path) } -fn create_derived_iter_bytes_impl(cx: ext_ctxt, +fn create_derived_iter_bytes_impl(cx: @ext_ctxt, span: span, type_ident: ident, generics: &Generics, @@ -351,7 +351,7 @@ fn create_derived_iter_bytes_impl(cx: ext_ctxt, create_derived_impl(cx, span, type_ident, generics, methods, trait_path) } -fn create_derived_clone_impl(cx: ext_ctxt, +fn create_derived_clone_impl(cx: @ext_ctxt, span: span, type_ident: ident, generics: &Generics, @@ -368,7 +368,7 @@ fn create_derived_clone_impl(cx: ext_ctxt, // Creates a method from the given set of statements conforming to the // signature of the `iter_bytes` method. -fn create_iter_bytes_method(cx: ext_ctxt, +fn create_iter_bytes_method(cx: @ext_ctxt, span: span, +statements: ~[@stmt]) -> @method { @@ -405,7 +405,7 @@ fn create_iter_bytes_method(cx: ext_ctxt, attrs: ~[], generics: ast_util::empty_generics(), self_ty: self_ty, - purity: pure_fn, + purity: impure_fn, decl: fn_decl, body: body_block, id: cx.next_id(), @@ -417,7 +417,7 @@ fn create_iter_bytes_method(cx: ext_ctxt, // Creates a method from the given expression conforming to the signature of // the `clone` method. -fn create_clone_method(cx: ext_ctxt, +fn create_clone_method(cx: @ext_ctxt, span: span, +type_ident: ast::ident, generics: &Generics, @@ -467,7 +467,7 @@ fn create_clone_method(cx: ext_ctxt, } } -fn create_subpatterns(cx: ext_ctxt, +fn create_subpatterns(cx: @ext_ctxt, span: span, prefix: ~str, n: uint) @@ -496,7 +496,7 @@ fn is_struct_tuple(struct_def: &struct_def) -> bool { }) } -fn create_enum_variant_pattern(cx: ext_ctxt, +fn create_enum_variant_pattern(cx: @ext_ctxt, span: span, variant: &variant, prefix: ~str) @@ -542,7 +542,7 @@ fn create_enum_variant_pattern(cx: ext_ctxt, } } -fn call_substructure_eq_method(cx: ext_ctxt, +fn call_substructure_eq_method(cx: @ext_ctxt, span: span, self_field: @expr, other_field_ref: @expr, @@ -571,7 +571,7 @@ fn call_substructure_eq_method(cx: ext_ctxt, }; } -fn finish_eq_chain_expr(cx: ext_ctxt, +fn finish_eq_chain_expr(cx: @ext_ctxt, span: span, chain_expr: Option<@expr>, junction: Junction) @@ -587,7 +587,7 @@ fn finish_eq_chain_expr(cx: ext_ctxt, } } -fn call_substructure_iter_bytes_method(cx: ext_ctxt, +fn call_substructure_iter_bytes_method(cx: @ext_ctxt, span: span, self_field: @expr) -> @stmt { @@ -612,7 +612,7 @@ fn call_substructure_iter_bytes_method(cx: ext_ctxt, build::mk_stmt(cx, span, self_call) } -fn call_substructure_clone_method(cx: ext_ctxt, +fn call_substructure_clone_method(cx: @ext_ctxt, span: span, self_field: @expr) -> @expr { @@ -622,7 +622,7 @@ fn call_substructure_clone_method(cx: ext_ctxt, build::mk_call_(cx, span, self_method, ~[]) } -fn variant_arg_count(cx: ext_ctxt, span: span, variant: &variant) -> uint { +fn variant_arg_count(cx: @ext_ctxt, span: span, variant: &variant) -> uint { match variant.node.kind { tuple_variant_kind(ref args) => args.len(), struct_variant_kind(ref struct_def) => struct_def.fields.len(), @@ -632,7 +632,7 @@ fn variant_arg_count(cx: ext_ctxt, span: span, variant: &variant) -> uint { } } -fn expand_deriving_eq_struct_def(cx: ext_ctxt, +fn expand_deriving_eq_struct_def(cx: @ext_ctxt, span: span, struct_def: &struct_def, type_ident: ident, @@ -672,7 +672,7 @@ fn expand_deriving_eq_struct_def(cx: ext_ctxt, ne_method); } -fn expand_deriving_eq_enum_def(cx: ext_ctxt, +fn expand_deriving_eq_enum_def(cx: @ext_ctxt, span: span, enum_definition: &enum_def, type_ident: ident, @@ -705,7 +705,7 @@ fn expand_deriving_eq_enum_def(cx: ext_ctxt, ne_method); } -fn expand_deriving_iter_bytes_struct_def(cx: ext_ctxt, +fn expand_deriving_iter_bytes_struct_def(cx: @ext_ctxt, span: span, struct_def: &struct_def, type_ident: ident, @@ -724,7 +724,7 @@ fn expand_deriving_iter_bytes_struct_def(cx: ext_ctxt, method); } -fn expand_deriving_iter_bytes_enum_def(cx: ext_ctxt, +fn expand_deriving_iter_bytes_enum_def(cx: @ext_ctxt, span: span, enum_definition: &enum_def, type_ident: ident, @@ -743,7 +743,7 @@ fn expand_deriving_iter_bytes_enum_def(cx: ext_ctxt, method); } -fn expand_deriving_clone_struct_def(cx: ext_ctxt, +fn expand_deriving_clone_struct_def(cx: @ext_ctxt, span: span, struct_def: &struct_def, type_ident: ident, @@ -768,7 +768,7 @@ fn expand_deriving_clone_struct_def(cx: ext_ctxt, create_derived_clone_impl(cx, span, type_ident, generics, method) } -fn expand_deriving_clone_enum_def(cx: ext_ctxt, +fn expand_deriving_clone_enum_def(cx: @ext_ctxt, span: span, enum_definition: &enum_def, type_ident: ident, @@ -785,7 +785,7 @@ fn expand_deriving_clone_enum_def(cx: ext_ctxt, create_derived_clone_impl(cx, span, type_ident, generics, method) } -fn expand_deriving_eq_struct_method(cx: ext_ctxt, +fn expand_deriving_eq_struct_method(cx: @ext_ctxt, span: span, struct_def: &struct_def, method_ident: ident, @@ -841,7 +841,7 @@ fn expand_deriving_eq_struct_method(cx: ext_ctxt, body); } -fn expand_deriving_iter_bytes_struct_method(cx: ext_ctxt, +fn expand_deriving_iter_bytes_struct_method(cx: @ext_ctxt, span: span, struct_def: &struct_def) -> @method { @@ -875,7 +875,7 @@ fn expand_deriving_iter_bytes_struct_method(cx: ext_ctxt, return create_iter_bytes_method(cx, span, statements); } -fn expand_deriving_clone_struct_method(cx: ext_ctxt, +fn expand_deriving_clone_struct_method(cx: @ext_ctxt, span: span, struct_def: &struct_def, type_ident: ident, @@ -918,7 +918,7 @@ fn expand_deriving_clone_struct_method(cx: ext_ctxt, create_clone_method(cx, span, type_ident, generics, struct_literal) } -fn expand_deriving_clone_tuple_struct_method(cx: ext_ctxt, +fn expand_deriving_clone_tuple_struct_method(cx: @ext_ctxt, span: span, struct_def: &struct_def, type_ident: ident, @@ -962,7 +962,7 @@ fn expand_deriving_clone_tuple_struct_method(cx: ext_ctxt, create_clone_method(cx, span, type_ident, generics, self_match_expr) } -fn expand_deriving_eq_enum_method(cx: ext_ctxt, +fn expand_deriving_eq_enum_method(cx: @ext_ctxt, span: span, enum_definition: &enum_def, method_ident: ident, @@ -1096,7 +1096,7 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt, self_match_expr); } -fn expand_deriving_eq_struct_tuple_method(cx: ext_ctxt, +fn expand_deriving_eq_struct_tuple_method(cx: @ext_ctxt, span: span, struct_def: &struct_def, method_ident: ident, @@ -1155,7 +1155,7 @@ fn expand_deriving_eq_struct_tuple_method(cx: ext_ctxt, type_ident, generics, self_match_expr) } -fn expand_enum_or_struct_match(cx: ext_ctxt, +fn expand_enum_or_struct_match(cx: @ext_ctxt, span: span, arms: ~[ ast::arm ]) -> @expr { @@ -1166,7 +1166,7 @@ fn expand_enum_or_struct_match(cx: ext_ctxt, build::mk_expr(cx, span, self_match_expr) } -fn expand_deriving_iter_bytes_enum_method(cx: ext_ctxt, +fn expand_deriving_iter_bytes_enum_method(cx: @ext_ctxt, span: span, enum_definition: &enum_def) -> @method { @@ -1221,7 +1221,7 @@ fn expand_deriving_iter_bytes_enum_method(cx: ext_ctxt, create_iter_bytes_method(cx, span, ~[ self_match_stmt ]) } -fn expand_deriving_clone_enum_method(cx: ext_ctxt, +fn expand_deriving_clone_enum_method(cx: @ext_ctxt, span: span, enum_definition: &enum_def, type_ident: ident, diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index c8fb83224ac..c21a9fa8739 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -23,7 +23,7 @@ use ext::base::*; use ext::base; use ext::build::mk_uniq_str; -pub fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_syntax_ext(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let var = get_single_str_from_tts(cx, sp, tts, "env!"); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index e61e8a1a594..ec693fa1f08 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -26,11 +26,11 @@ use core::option; use core::vec; pub fn expand_expr(extsbox: @mut SyntaxEnv, - cx: ext_ctxt, + cx: @ext_ctxt, e: &expr_, s: span, - fld: ast_fold, - orig: @fn(&expr_, span, ast_fold) -> (expr_, span)) + fld: @ast_fold, + orig: @fn(&expr_, span, @ast_fold) -> (expr_, span)) -> (expr_, span) { match *e { // expr_mac should really be expr_ext or something; it's the @@ -112,10 +112,10 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv, // NB: there is some redundancy between this and expand_item, below, and // they might benefit from some amount of semantic and language-UI merger. pub fn expand_mod_items(extsbox: @mut SyntaxEnv, - cx: ext_ctxt, + cx: @ext_ctxt, module_: &ast::_mod, - fld: ast_fold, - orig: @fn(&ast::_mod, ast_fold) -> ast::_mod) + fld: @ast_fold, + orig: @fn(&ast::_mod, @ast_fold) -> ast::_mod) -> ast::_mod { // Fold the contents first: let module_ = orig(module_, fld); @@ -163,10 +163,10 @@ macro_rules! with_exts_frame ( // When we enter a module, record it, for the sake of `module!` pub fn expand_item(extsbox: @mut SyntaxEnv, - cx: ext_ctxt, + cx: @ext_ctxt, it: @ast::item, - fld: ast_fold, - orig: @fn(@ast::item, ast_fold) -> Option<@ast::item>) + fld: @ast_fold, + orig: @fn(@ast::item, @ast_fold) -> Option<@ast::item>) -> Option<@ast::item> { // need to do expansion first... it might turn out to be a module. let maybe_it = match it.node { @@ -239,9 +239,9 @@ macro_rules! without_macro_scoping( // Support for item-position macro invocations, exactly the same // logic as for expression-position macro invocations. pub fn expand_item_mac(+extsbox: @mut SyntaxEnv, - cx: ext_ctxt, &&it: @ast::item, - fld: ast_fold) -> Option<@ast::item> { - + cx: @ext_ctxt, &&it: @ast::item, + fld: @ast_fold) + -> Option<@ast::item> { let (pth, tts) = match it.node { item_mac(codemap::spanned { node: mac_invoc_tt(pth, ref tts), _}) => { (pth, copy *tts) @@ -307,11 +307,11 @@ pub fn expand_item_mac(+extsbox: @mut SyntaxEnv, // expand a stmt pub fn expand_stmt(extsbox: @mut SyntaxEnv, - cx: ext_ctxt, + cx: @ext_ctxt, s: &stmt_, sp: span, - fld: ast_fold, - orig: @fn(&stmt_, span, ast_fold) -> (stmt_, span)) + fld: @ast_fold, + orig: @fn(&stmt_, span, @ast_fold) -> (stmt_, span)) -> (stmt_, span) { let (mac, pth, tts, semi) = match *s { stmt_mac(ref mac, semi) => { @@ -373,11 +373,11 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv, pub fn expand_block(extsbox: @mut SyntaxEnv, - cx: ext_ctxt, + cx: @ext_ctxt, blk: &blk_, sp: span, - fld: ast_fold, - orig: @fn(&blk_, span, ast_fold) -> (blk_, span)) + fld: @ast_fold, + orig: @fn(&blk_, span, @ast_fold) -> (blk_, span)) -> (blk_, span) { match (*extsbox).find(&@~" block") { // no scope limit on macros in this block, no need @@ -395,7 +395,7 @@ pub fn expand_block(extsbox: @mut SyntaxEnv, } } -pub fn new_span(cx: ext_ctxt, sp: span) -> span { +pub fn new_span(cx: @ext_ctxt, sp: span) -> span { /* this discards information in the case of macro-defining macros */ return span {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()}; } @@ -411,34 +411,34 @@ pub fn core_macros() -> ~str { macro_rules! error ( ($arg:expr) => ( - log(::core::error, fmt!( \"%?\", $arg )) + __log(1u32, fmt!( \"%?\", $arg )) ); ($( $arg:expr ),+) => ( - log(::core::error, fmt!( $($arg),+ )) + __log(1u32, fmt!( $($arg),+ )) ) ) macro_rules! warn ( ($arg:expr) => ( - log(::core::warn, fmt!( \"%?\", $arg )) + __log(2u32, fmt!( \"%?\", $arg )) ); ($( $arg:expr ),+) => ( - log(::core::warn, fmt!( $($arg),+ )) + __log(2u32, fmt!( $($arg),+ )) ) ) macro_rules! info ( ($arg:expr) => ( - log(::core::info, fmt!( \"%?\", $arg )) + __log(3u32, fmt!( \"%?\", $arg )) ); ($( $arg:expr ),+) => ( - log(::core::info, fmt!( $($arg),+ )) + __log(3u32, fmt!( $($arg),+ )) ) ) macro_rules! debug ( ($arg:expr) => ( - log(::core::debug, fmt!( \"%?\", $arg )) + __log(4u32, fmt!( \"%?\", $arg )) ); ($( $arg:expr ),+) => ( - log(::core::debug, fmt!( $($arg),+ )) + __log(4u32, fmt!( $($arg),+ )) ) ) @@ -488,7 +488,7 @@ pub fn expand_crate(parse_sess: @mut parse::ParseSess, // every method/element of AstFoldFns in fold.rs. let extsbox = @mut syntax_expander_table(); let afp = default_ast_fold(); - let cx: ext_ctxt = mk_ctxt(parse_sess, copy cfg); + let cx: @ext_ctxt = mk_ctxt(parse_sess, copy cfg); let f_pre = @AstFoldFns { fold_expr: |expr,span,recur| expand_expr(extsbox, cx, expr, span, recur, afp.fold_expr), diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index af558e6b330..f6a6ddefb7e 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -27,7 +27,7 @@ use ext::build::*; use core::unstable::extfmt::ct::*; -pub fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_syntax_ext(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let args = get_exprs_from_tts(cx, tts); if args.len() == 0 { @@ -37,9 +37,8 @@ pub fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) expr_to_str(cx, args[0], ~"first argument to fmt! must be a string literal."); let fmtspan = args[0].span; - debug!("Format string:"); - log(debug, fmt); - fn parse_fmt_err_(cx: ext_ctxt, sp: span, msg: &str) -> ! { + debug!("Format string: %s", fmt); + fn parse_fmt_err_(cx: @ext_ctxt, sp: span, msg: &str) -> ! { cx.span_fatal(sp, msg); } let parse_fmt_err: @fn(&str) -> ! = |s| parse_fmt_err_(cx, fmtspan, s); @@ -51,23 +50,23 @@ pub fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) // probably be factored out in common with other code that builds // expressions. Also: Cleanup the naming of these functions. // Note: Moved many of the common ones to build.rs --kevina -fn pieces_to_expr(cx: ext_ctxt, sp: span, +fn pieces_to_expr(cx: @ext_ctxt, sp: span, pieces: ~[Piece], args: ~[@ast::expr]) -> @ast::expr { - fn make_path_vec(cx: ext_ctxt, ident: @~str) -> ~[ast::ident] { + fn make_path_vec(cx: @ext_ctxt, ident: @~str) -> ~[ast::ident] { let intr = cx.parse_sess().interner; return ~[intr.intern(@~"unstable"), intr.intern(@~"extfmt"), intr.intern(@~"rt"), intr.intern(ident)]; } - fn make_rt_path_expr(cx: ext_ctxt, sp: span, nm: @~str) -> @ast::expr { + fn make_rt_path_expr(cx: @ext_ctxt, sp: span, nm: @~str) -> @ast::expr { let path = make_path_vec(cx, nm); return mk_path_global(cx, sp, path); } // Produces an AST expression that represents a RT::conv record, // which tells the RT::conv* functions how to perform the conversion - fn make_rt_conv_expr(cx: ext_ctxt, sp: span, cnv: Conv) -> @ast::expr { - fn make_flags(cx: ext_ctxt, sp: span, flags: ~[Flag]) -> @ast::expr { + fn make_rt_conv_expr(cx: @ext_ctxt, sp: span, cnv: Conv) -> @ast::expr { + fn make_flags(cx: @ext_ctxt, sp: span, flags: ~[Flag]) -> @ast::expr { let mut tmp_expr = make_rt_path_expr(cx, sp, @~"flag_none"); for flags.each |f| { let fstr = match *f { @@ -82,7 +81,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, } return tmp_expr; } - fn make_count(cx: ext_ctxt, sp: span, cnt: Count) -> @ast::expr { + fn make_count(cx: @ext_ctxt, sp: span, cnt: Count) -> @ast::expr { match cnt { CountImplied => { return make_rt_path_expr(cx, sp, @~"CountImplied"); @@ -96,7 +95,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, _ => cx.span_unimpl(sp, ~"unimplemented fmt! conversion") } } - fn make_ty(cx: ext_ctxt, sp: span, t: Ty) -> @ast::expr { + fn make_ty(cx: @ext_ctxt, sp: span, t: Ty) -> @ast::expr { let mut rt_type; match t { TyHex(c) => match c { @@ -109,7 +108,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, } return make_rt_path_expr(cx, sp, @rt_type); } - fn make_conv_struct(cx: ext_ctxt, sp: span, flags_expr: @ast::expr, + fn make_conv_struct(cx: @ext_ctxt, sp: span, flags_expr: @ast::expr, width_expr: @ast::expr, precision_expr: @ast::expr, ty_expr: @ast::expr) -> @ast::expr { let intr = cx.parse_sess().interner; @@ -140,7 +139,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, make_conv_struct(cx, sp, rt_conv_flags, rt_conv_width, rt_conv_precision, rt_conv_ty) } - fn make_conv_call(cx: ext_ctxt, sp: span, conv_type: ~str, cnv: Conv, + fn make_conv_call(cx: @ext_ctxt, sp: span, conv_type: ~str, cnv: Conv, arg: @ast::expr) -> @ast::expr { let fname = ~"conv_" + conv_type; let path = make_path_vec(cx, @fname); @@ -149,7 +148,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, return mk_call_global(cx, arg.span, path, args); } - fn make_new_conv(cx: ext_ctxt, sp: span, cnv: Conv, arg: @ast::expr) -> + fn make_new_conv(cx: @ext_ctxt, sp: span, cnv: Conv, arg: @ast::expr) -> @ast::expr { // FIXME: Move validation code into core::extfmt (Issue #2249) @@ -223,7 +222,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, } fn log_conv(c: Conv) { match c.param { - Some(p) => { log(debug, ~"param: " + p.to_str()); } + Some(p) => { debug!("param: %s", p.to_str()); } _ => debug!("param: none") } for c.flags.each |f| { @@ -236,18 +235,18 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, } } match c.width { - CountIs(i) => log( - debug, ~"width: count is " + i.to_str()), - CountIsParam(i) => log( - debug, ~"width: count is param " + i.to_str()), + CountIs(i) => + debug!("width: count is %s", i.to_str()), + CountIsParam(i) => + debug!("width: count is param %s", i.to_str()), CountIsNextParam => debug!("width: count is next param"), CountImplied => debug!("width: count is implied") } match c.precision { - CountIs(i) => log( - debug, ~"prec: count is " + i.to_str()), - CountIsParam(i) => log( - debug, ~"prec: count is param " + i.to_str()), + CountIs(i) => + debug!("prec: count is %s", i.to_str()), + CountIsParam(i) => + debug!("prec: count is param %s", i.to_str()), CountIsNextParam => debug!("prec: count is next param"), CountImplied => debug!("prec: count is implied") } diff --git a/src/libsyntax/ext/log_syntax.rs b/src/libsyntax/ext/log_syntax.rs index 8a8583420f8..bf4a997bc17 100644 --- a/src/libsyntax/ext/log_syntax.rs +++ b/src/libsyntax/ext/log_syntax.rs @@ -17,7 +17,7 @@ use ext::base::*; use ext::base; use print; -pub fn expand_syntax_ext(cx: ext_ctxt, +pub fn expand_syntax_ext(cx: @ext_ctxt, sp: codemap::span, tt: &[ast::token_tree]) -> base::MacResult { diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index e6f0cdde8c1..76b70225c6c 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -138,7 +138,7 @@ pub trait ext_ctxt_ast_builder { fn strip_bounds(&self, bounds: &Generics) -> Generics; } -impl ext_ctxt_ast_builder for ext_ctxt { +impl ext_ctxt_ast_builder for @ext_ctxt { fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty { self.ty_path_ast_builder(path_global(~[ self.ident_of(~"core"), diff --git a/src/libsyntax/ext/pipes/check.rs b/src/libsyntax/ext/pipes/check.rs index b543ef5fdae..29c9e86ec62 100644 --- a/src/libsyntax/ext/pipes/check.rs +++ b/src/libsyntax/ext/pipes/check.rs @@ -37,12 +37,12 @@ use ext::base::ext_ctxt; use ext::pipes::proto::{state, protocol, next_state}; use ext::pipes::proto; -impl proto::visitor<(), (), ()> for ext_ctxt { - fn visit_proto(&self, _proto: protocol, - _states: &[()]) { } +impl proto::visitor<(), (), ()> for @ext_ctxt { + fn visit_proto(&self, _proto: protocol, _states: &[()]) { } fn visit_state(&self, state: state, _m: &[()]) { - if state.messages.len() == 0 { + let messages = &*state.messages; + if messages.len() == 0 { self.span_warn( state.span, // use a real span! fmt!("state %s contains no messages, \ diff --git a/src/libsyntax/ext/pipes/liveness.rs b/src/libsyntax/ext/pipes/liveness.rs index c5bed32a24f..c6fdf4d9c1b 100644 --- a/src/libsyntax/ext/pipes/liveness.rs +++ b/src/libsyntax/ext/pipes/liveness.rs @@ -45,7 +45,7 @@ use ext::pipes::proto::protocol; use core::str; use std::bitv::Bitv; -pub fn analyze(proto: protocol, _cx: ext_ctxt) { +pub fn analyze(proto: protocol, _cx: @ext_ctxt) { debug!("initializing colive analysis"); let num_states = proto.num_states(); let mut colive = do (copy proto.states).map_to_vec |state| { @@ -63,7 +63,7 @@ pub fn analyze(proto: protocol, _cx: ext_ctxt) { debug!("colive iteration %?", i); let mut new_colive = ~[]; for colive.eachi |i, this_colive| { - let mut result = ~this_colive.clone(); + let mut result = this_colive.clone(); let this = proto.get_state_by_id(i); for this_colive.ones |j| { let next = proto.get_state_by_id(j); @@ -91,7 +91,7 @@ pub fn analyze(proto: protocol, _cx: ext_ctxt) { let states = str::connect(self_live.map(|s| copy s.name), ~" "); debug!("protocol %s is unbounded due to loops involving: %s", - proto.name, states); + copy proto.name, states); // Someday this will be configurable with a warning //cx.span_warn(empty_span(), @@ -103,7 +103,7 @@ pub fn analyze(proto: protocol, _cx: ext_ctxt) { proto.bounded = Some(false); } else { - debug!("protocol %s is bounded. yay!", proto.name); + debug!("protocol %s is bounded. yay!", copy proto.name); proto.bounded = Some(true); } } diff --git a/src/libsyntax/ext/pipes/mod.rs b/src/libsyntax/ext/pipes/mod.rs index df17c960ba2..327cb0ae517 100644 --- a/src/libsyntax/ext/pipes/mod.rs +++ b/src/libsyntax/ext/pipes/mod.rs @@ -63,13 +63,15 @@ pub mod check; pub mod liveness; -pub fn expand_proto(cx: ext_ctxt, _sp: span, id: ast::ident, +pub fn expand_proto(cx: @ext_ctxt, _sp: span, id: ast::ident, tt: ~[ast::token_tree]) -> base::MacResult { let sess = cx.parse_sess(); let cfg = cx.cfg(); let tt_rdr = new_tt_reader(copy cx.parse_sess().span_diagnostic, - cx.parse_sess().interner, None, copy tt); - let rdr = tt_rdr as reader; + cx.parse_sess().interner, + None, + copy tt); + let rdr = tt_rdr as @reader; let rust_parser = Parser(sess, cfg, rdr.dup()); let mut proto = rust_parser.parse_proto(cx.str_of(id)); diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index fd8b2dbf72f..a7725eab695 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -26,27 +26,27 @@ use core::to_str::ToStr; use core::vec; pub trait gen_send { - fn gen_send(&mut self, cx: ext_ctxt, try: bool) -> @ast::item; - fn to_ty(&mut self, cx: ext_ctxt) -> @ast::Ty; + fn gen_send(&mut self, cx: @ext_ctxt, try: bool) -> @ast::item; + fn to_ty(&mut self, cx: @ext_ctxt) -> @ast::Ty; } pub trait to_type_decls { - fn to_type_decls(&self, cx: ext_ctxt) -> ~[@ast::item]; - fn to_endpoint_decls(&self, cx: ext_ctxt, + fn to_type_decls(&self, cx: @ext_ctxt) -> ~[@ast::item]; + fn to_endpoint_decls(&self, cx: @ext_ctxt, dir: direction) -> ~[@ast::item]; } pub trait gen_init { - fn gen_init(&self, cx: ext_ctxt) -> @ast::item; - fn compile(&self, cx: ext_ctxt) -> @ast::item; - fn buffer_ty_path(&self, cx: ext_ctxt) -> @ast::Ty; - fn gen_buffer_type(&self, cx: ext_ctxt) -> @ast::item; - fn gen_buffer_init(&self, ext_cx: ext_ctxt) -> @ast::expr; - fn gen_init_bounded(&self, ext_cx: ext_ctxt) -> @ast::expr; + fn gen_init(&self, cx: @ext_ctxt) -> @ast::item; + fn compile(&self, cx: @ext_ctxt) -> @ast::item; + fn buffer_ty_path(&self, cx: @ext_ctxt) -> @ast::Ty; + fn gen_buffer_type(&self, cx: @ext_ctxt) -> @ast::item; + fn gen_buffer_init(&self, ext_cx: @ext_ctxt) -> @ast::expr; + fn gen_init_bounded(&self, ext_cx: @ext_ctxt) -> @ast::expr; } impl gen_send for message { - fn gen_send(&mut self, cx: ext_ctxt, try: bool) -> @ast::item { + fn gen_send(&mut self, cx: @ext_ctxt, try: bool) -> @ast::item { debug!("pipec: gen_send"); let name = self.name(); @@ -188,14 +188,14 @@ impl gen_send for message { } } - fn to_ty(&mut self, cx: ext_ctxt) -> @ast::Ty { + fn to_ty(&mut self, cx: @ext_ctxt) -> @ast::Ty { cx.ty_path_ast_builder(path(~[cx.ident_of(self.name())], self.span()) .add_tys(cx.ty_vars_global(&self.get_generics().ty_params))) } } impl to_type_decls for state { - fn to_type_decls(&self, cx: ext_ctxt) -> ~[@ast::item] { + fn to_type_decls(&self, cx: @ext_ctxt) -> ~[@ast::item] { debug!("pipec: to_type_decls"); // This compiles into two different type declarations. Say the // state is called ping. This will generate both `ping` and @@ -244,7 +244,7 @@ impl to_type_decls for state { ] } - fn to_endpoint_decls(&self, cx: ext_ctxt, + fn to_endpoint_decls(&self, cx: @ext_ctxt, dir: direction) -> ~[@ast::item] { debug!("pipec: to_endpoint_decls"); let dir = match dir { @@ -306,7 +306,7 @@ impl to_type_decls for state { } impl gen_init for protocol { - fn gen_init(&self, cx: ext_ctxt) -> @ast::item { + fn gen_init(&self, cx: @ext_ctxt) -> @ast::item { let ext_cx = cx; debug!("gen_init"); @@ -344,7 +344,7 @@ impl gen_init for protocol { body.to_source(cx))) } - fn gen_buffer_init(&self, ext_cx: ext_ctxt) -> @ast::expr { + fn gen_buffer_init(&self, ext_cx: @ext_ctxt) -> @ast::expr { ext_cx.struct_expr(path(~[ext_cx.ident_of(~"__Buffer")], dummy_sp()), self.states.map_to_vec(|s| { @@ -356,7 +356,7 @@ impl gen_init for protocol { })) } - fn gen_init_bounded(&self, ext_cx: ext_ctxt) -> @ast::expr { + fn gen_init_bounded(&self, ext_cx: @ext_ctxt) -> @ast::expr { debug!("gen_init_bounded"); let buffer_fields = self.gen_buffer_init(ext_cx); let buffer = quote_expr!(~::core::pipes::Buffer { @@ -382,7 +382,7 @@ impl gen_init for protocol { }) } - fn buffer_ty_path(&self, cx: ext_ctxt) -> @ast::Ty { + fn buffer_ty_path(&self, cx: @ext_ctxt) -> @ast::Ty { let mut params: OptVec<ast::TyParam> = opt_vec::Empty; for (copy self.states).each |s| { for s.generics.ty_params.each |tp| { @@ -399,7 +399,7 @@ impl gen_init for protocol { .add_tys(cx.ty_vars_global(¶ms))) } - fn gen_buffer_type(&self, cx: ext_ctxt) -> @ast::item { + fn gen_buffer_type(&self, cx: @ext_ctxt) -> @ast::item { let ext_cx = cx; let mut params: OptVec<ast::TyParam> = opt_vec::Empty; let fields = do (copy self.states).map_to_vec |s| { @@ -442,7 +442,7 @@ impl gen_init for protocol { cx.strip_bounds(&generics)) } - fn compile(&self, cx: ext_ctxt) -> @ast::item { + fn compile(&self, cx: @ext_ctxt) -> @ast::item { let mut items = ~[self.gen_init(cx)]; let mut client_states = ~[]; let mut server_states = ~[]; diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index dc9abd536d1..a47b39a45c8 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -96,7 +96,7 @@ pub impl state_ { } /// Returns the type that is used for the messages. - fn to_ty(&self, cx: ext_ctxt) -> @ast::Ty { + fn to_ty(&self, cx: @ext_ctxt) -> @ast::Ty { cx.ty_path_ast_builder (path(~[cx.ident_of(self.name)],self.span).add_tys( cx.ty_vars(&self.generics.ty_params))) @@ -156,7 +156,10 @@ pub impl protocol_ { ~"proto://" + self.name } - fn num_states(&mut self) -> uint { self.states.len() } + fn num_states(&mut self) -> uint { + let states = &mut *self.states; + states.len() + } fn has_ty_params(&mut self) -> bool { for self.states.each |s| { @@ -172,20 +175,25 @@ pub impl protocol_ { } } -pub impl protocol { - fn add_state_poly(&self, +name: ~str, ident: ast::ident, dir: direction, - +generics: ast::Generics) -> state { +pub impl protocol_ { + fn add_state_poly(@mut self, + +name: ~str, + ident: ast::ident, + dir: direction, + +generics: ast::Generics) + -> state { let messages = @mut ~[]; + let states = &*self.states; let state = @state_ { - id: self.states.len(), + id: states.len(), name: name, ident: ident, span: self.span, dir: dir, generics: generics, messages: messages, - proto: *self + proto: self }; self.states.push(state); diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 49d5ed1d0cc..2cf52c47959 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -49,11 +49,11 @@ pub mod rt { use print::pprust::{item_to_str, ty_to_str}; pub trait ToTokens { - pub fn to_tokens(&self, _cx: ext_ctxt) -> ~[token_tree]; + pub fn to_tokens(&self, _cx: @ext_ctxt) -> ~[token_tree]; } impl ToTokens for ~[token_tree] { - pub fn to_tokens(&self, _cx: ext_ctxt) -> ~[token_tree] { + pub fn to_tokens(&self, _cx: @ext_ctxt) -> ~[token_tree] { copy *self } } @@ -62,10 +62,10 @@ pub mod rt { trait ToSource : ToTokens { // Takes a thing and generates a string containing rust code for it. - pub fn to_source(cx: ext_ctxt) -> ~str; + pub fn to_source(cx: @ext_ctxt) -> ~str; // If you can make source, you can definitely make tokens. - pub fn to_tokens(cx: ext_ctxt) -> ~[token_tree] { + pub fn to_tokens(cx: @ext_ctxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } @@ -74,47 +74,47 @@ pub mod rt { pub trait ToSource { // Takes a thing and generates a string containing rust code for it. - pub fn to_source(&self, cx: ext_ctxt) -> ~str; + pub fn to_source(&self, cx: @ext_ctxt) -> ~str; } impl ToSource for ast::ident { - fn to_source(&self, cx: ext_ctxt) -> ~str { + fn to_source(&self, cx: @ext_ctxt) -> ~str { copy *cx.parse_sess().interner.get(*self) } } impl ToSource for @ast::item { - fn to_source(&self, cx: ext_ctxt) -> ~str { + fn to_source(&self, cx: @ext_ctxt) -> ~str { item_to_str(*self, cx.parse_sess().interner) } } impl ToSource for ~[@ast::item] { - fn to_source(&self, cx: ext_ctxt) -> ~str { + fn to_source(&self, cx: @ext_ctxt) -> ~str { str::connect(self.map(|i| i.to_source(cx)), ~"\n\n") } } impl ToSource for @ast::Ty { - fn to_source(&self, cx: ext_ctxt) -> ~str { + fn to_source(&self, cx: @ext_ctxt) -> ~str { ty_to_str(*self, cx.parse_sess().interner) } } impl ToSource for ~[@ast::Ty] { - fn to_source(&self, cx: ext_ctxt) -> ~str { + fn to_source(&self, cx: @ext_ctxt) -> ~str { str::connect(self.map(|i| i.to_source(cx)), ~", ") } } impl ToSource for Generics { - fn to_source(&self, cx: ext_ctxt) -> ~str { + fn to_source(&self, cx: @ext_ctxt) -> ~str { pprust::generics_to_str(self, cx.parse_sess().interner) } } impl ToSource for @ast::expr { - fn to_source(&self, cx: ext_ctxt) -> ~str { + fn to_source(&self, cx: @ext_ctxt) -> ~str { pprust::expr_to_str(*self, cx.parse_sess().interner) } } @@ -122,43 +122,43 @@ pub mod rt { // Alas ... we write these out instead. All redundant. impl ToTokens for ast::ident { - fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for @ast::item { - fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for ~[@ast::item] { - fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for @ast::Ty { - fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for ~[@ast::Ty] { - fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for Generics { - fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for @ast::expr { - fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: @ext_ctxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } @@ -170,7 +170,7 @@ pub mod rt { fn parse_tts(&self, s: ~str) -> ~[ast::token_tree]; } - impl ExtParseUtils for ext_ctxt { + impl ExtParseUtils for @ext_ctxt { fn parse_item(&self, s: ~str) -> @ast::item { let res = parse::parse_item_from_source_str( @@ -216,19 +216,19 @@ pub mod rt { } -pub fn expand_quote_tokens(cx: ext_ctxt, +pub fn expand_quote_tokens(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::MRExpr(expand_tts(cx, sp, tts)) } -pub fn expand_quote_expr(cx: ext_ctxt, +pub fn expand_quote_expr(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::MRExpr(expand_parse_call(cx, sp, ~"parse_expr", ~[], tts)) } -pub fn expand_quote_item(cx: ext_ctxt, +pub fn expand_quote_item(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let e_attrs = build::mk_uniq_vec_e(cx, sp, ~[]); @@ -236,7 +236,7 @@ pub fn expand_quote_item(cx: ext_ctxt, ~[e_attrs], tts)) } -pub fn expand_quote_pat(cx: ext_ctxt, +pub fn expand_quote_pat(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let e_refutable = build::mk_lit(cx, sp, ast::lit_bool(true)); @@ -244,7 +244,7 @@ pub fn expand_quote_pat(cx: ext_ctxt, ~[e_refutable], tts)) } -pub fn expand_quote_ty(cx: ext_ctxt, +pub fn expand_quote_ty(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let e_param_colons = build::mk_lit(cx, sp, ast::lit_bool(false)); @@ -252,7 +252,7 @@ pub fn expand_quote_ty(cx: ext_ctxt, ~[e_param_colons], tts)) } -pub fn expand_quote_stmt(cx: ext_ctxt, +pub fn expand_quote_stmt(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let e_attrs = build::mk_uniq_vec_e(cx, sp, ~[]); @@ -260,16 +260,16 @@ pub fn expand_quote_stmt(cx: ext_ctxt, ~[e_attrs], tts)) } -fn ids_ext(cx: ext_ctxt, strs: ~[~str]) -> ~[ast::ident] { +fn ids_ext(cx: @ext_ctxt, strs: ~[~str]) -> ~[ast::ident] { strs.map(|str| cx.parse_sess().interner.intern(@copy *str)) } -fn id_ext(cx: ext_ctxt, +str: ~str) -> ast::ident { +fn id_ext(cx: @ext_ctxt, +str: ~str) -> ast::ident { cx.parse_sess().interner.intern(@str) } // Lift an ident to the expr that evaluates to that ident. -fn mk_ident(cx: ext_ctxt, sp: span, ident: ast::ident) -> @ast::expr { +fn mk_ident(cx: @ext_ctxt, sp: span, ident: ast::ident) -> @ast::expr { let e_meth = build::mk_access(cx, sp, ids_ext(cx, ~[~"ext_cx"]), id_ext(cx, ~"ident_of")); @@ -277,13 +277,13 @@ fn mk_ident(cx: ext_ctxt, sp: span, ident: ast::ident) -> @ast::expr { build::mk_call_(cx, sp, e_meth, ~[e_str]) } -fn mk_bytepos(cx: ext_ctxt, sp: span, bpos: BytePos) -> @ast::expr { +fn mk_bytepos(cx: @ext_ctxt, sp: span, bpos: BytePos) -> @ast::expr { let path = ids_ext(cx, ~[~"BytePos"]); let arg = build::mk_uint(cx, sp, bpos.to_uint()); build::mk_call(cx, sp, path, ~[arg]) } -fn mk_binop(cx: ext_ctxt, sp: span, bop: token::binop) -> @ast::expr { +fn mk_binop(cx: @ext_ctxt, sp: span, bop: token::binop) -> @ast::expr { let name = match bop { PLUS => "PLUS", MINUS => "MINUS", @@ -300,7 +300,7 @@ fn mk_binop(cx: ext_ctxt, sp: span, bop: token::binop) -> @ast::expr { ids_ext(cx, ~[name.to_owned()])) } -fn mk_token(cx: ext_ctxt, sp: span, tok: token::Token) -> @ast::expr { +fn mk_token(cx: @ext_ctxt, sp: span, tok: token::Token) -> @ast::expr { match tok { BINOP(binop) => { @@ -392,6 +392,12 @@ fn mk_token(cx: ext_ctxt, sp: span, tok: token::Token) -> @ast::expr { build::mk_lit(cx, sp, ast::lit_bool(b))]); } + LIFETIME(ident) => { + return build::mk_call(cx, sp, + ids_ext(cx, ~[~"LIFETIME"]), + ~[mk_ident(cx, sp, ident)]); + } + DOC_COMMENT(ident) => { return build::mk_call(cx, sp, ids_ext(cx, ~[~"DOC_COMMENT"]), @@ -443,7 +449,7 @@ fn mk_token(cx: ext_ctxt, sp: span, tok: token::Token) -> @ast::expr { } -fn mk_tt(cx: ext_ctxt, sp: span, tt: &ast::token_tree) +fn mk_tt(cx: @ext_ctxt, sp: span, tt: &ast::token_tree) -> ~[@ast::stmt] { match *tt { @@ -494,7 +500,7 @@ fn mk_tt(cx: ext_ctxt, sp: span, tt: &ast::token_tree) } } -fn mk_tts(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) +fn mk_tts(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> ~[@ast::stmt] { let mut ss = ~[]; for tts.each |tt| { @@ -503,7 +509,7 @@ fn mk_tts(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) ss } -fn expand_tts(cx: ext_ctxt, +fn expand_tts(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> @ast::expr { @@ -577,7 +583,7 @@ fn expand_tts(cx: ext_ctxt, ids_ext(cx, ~[~"tt"])))) } -fn expand_parse_call(cx: ext_ctxt, +fn expand_parse_call(cx: @ext_ctxt, sp: span, +parse_method: ~str, +arg_exprs: ~[@ast::expr], diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 296305bb62e..b2de322be55 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -29,7 +29,7 @@ use core::vec; // a given file into the current one. /* line!(): expands to the current line number */ -pub fn expand_line(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_line(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "line!"); @@ -40,7 +40,7 @@ pub fn expand_line(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) } /* col!(): expands to the current column number */ -pub fn expand_col(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_col(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "col!"); @@ -52,7 +52,7 @@ pub fn expand_col(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) /* file!(): expands to the current filename */ /* The filemap (`loc.file`) contains a bunch more information we could spit * out if we wanted. */ -pub fn expand_file(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_file(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "file!"); @@ -62,13 +62,13 @@ pub fn expand_file(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) base::MRExpr(mk_base_str(cx, topmost.call_site, filename)) } -pub fn expand_stringify(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_stringify(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let s = pprust::tts_to_str(tts, cx.parse_sess().interner); base::MRExpr(mk_base_str(cx, sp, s)) } -pub fn expand_mod(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_mod(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "module_path!"); base::MRExpr(mk_base_str(cx, sp, @@ -79,7 +79,7 @@ pub fn expand_mod(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) // include! : parse the given file as an expr // This is generally a bad idea because it's going to behave // unhygienically. -pub fn expand_include(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_include(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include!"); let p = parse::new_sub_parser_from_file( @@ -89,7 +89,7 @@ pub fn expand_include(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) } // include_str! : read the given file, insert it as a literal string expr -pub fn expand_include_str(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_include_str(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include_str!"); let res = io::read_whole_file_str(&res_rel_file(cx, sp, &Path(file))); @@ -103,7 +103,7 @@ pub fn expand_include_str(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) base::MRExpr(mk_base_str(cx, sp, result::unwrap(res))) } -pub fn expand_include_bin(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) +pub fn expand_include_bin(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include_bin!"); match io::read_whole_file(&res_rel_file(cx, sp, &Path(file))) { @@ -147,7 +147,7 @@ fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo { // resolve a file-system path to an absolute file-system path (if it // isn't already) -fn res_rel_file(cx: ext_ctxt, sp: codemap::span, arg: &Path) -> Path { +fn res_rel_file(cx: @ext_ctxt, sp: codemap::span, arg: &Path) -> Path { // NB: relative paths are resolved relative to the compilation unit if !arg.is_absolute { let cu = Path(cx.codemap().span_to_filename(sp)); diff --git a/src/libsyntax/ext/trace_macros.rs b/src/libsyntax/ext/trace_macros.rs index b53523f78a4..29a959013f2 100644 --- a/src/libsyntax/ext/trace_macros.rs +++ b/src/libsyntax/ext/trace_macros.rs @@ -17,8 +17,10 @@ use ext::base; use parse::lexer::{new_tt_reader, reader}; use parse::parser::Parser; -pub fn expand_trace_macros(cx: ext_ctxt, sp: span, - tt: &[ast::token_tree]) -> base::MacResult { +pub fn expand_trace_macros(cx: @ext_ctxt, + sp: span, + tt: &[ast::token_tree]) + -> base::MacResult { let sess = cx.parse_sess(); let cfg = cx.cfg(); let tt_rdr = new_tt_reader( @@ -27,7 +29,7 @@ pub fn expand_trace_macros(cx: ext_ctxt, sp: span, None, vec::from_slice(tt) ); - let rdr = tt_rdr as reader; + let rdr = tt_rdr as @reader; let rust_parser = Parser( sess, copy cfg, diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 88797a15206..b0628437bb0 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -224,7 +224,7 @@ pub enum parse_result { pub fn parse_or_else( sess: @mut ParseSess, +cfg: ast::crate_cfg, - rdr: reader, + rdr: @reader, ms: ~[matcher] ) -> HashMap<ident, @named_match> { match parse(sess, cfg, rdr, ms) { @@ -237,7 +237,7 @@ pub fn parse_or_else( pub fn parse( sess: @mut ParseSess, cfg: ast::crate_cfg, - rdr: reader, + rdr: @reader, ms: ~[matcher] ) -> parse_result { let mut cur_eis = ~[]; diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index e5b7152bea2..dcc84ce46fe 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -27,8 +27,11 @@ use print; use core::io; -pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, - arg: ~[ast::token_tree]) -> base::MacResult { +pub fn add_new_extension(cx: @ext_ctxt, + sp: span, + name: ident, + arg: ~[ast::token_tree]) + -> base::MacResult { // these spans won't matter, anyways fn ms(m: matcher_) -> matcher { spanned { node: copy m, span: dummy_sp() } @@ -54,8 +57,10 @@ pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, // Parse the macro_rules! invocation (`none` is for no interpolations): let arg_reader = new_tt_reader(copy cx.parse_sess().span_diagnostic, cx.parse_sess().interner, None, copy arg); - let argument_map = parse_or_else(cx.parse_sess(), cx.cfg(), - arg_reader as reader, argument_gram); + let argument_map = parse_or_else(cx.parse_sess(), + cx.cfg(), + arg_reader as @reader, + argument_gram); // Extract the arguments: let lhses = match argument_map.get(&lhs_nm) { @@ -69,7 +74,7 @@ pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, }; // Given `lhses` and `rhses`, this is the new macro we create - fn generic_extension(cx: ext_ctxt, sp: span, name: ident, + fn generic_extension(cx: @ext_ctxt, sp: span, name: ident, arg: &[ast::token_tree], lhses: ~[@named_match], rhses: ~[@named_match]) -> MacResult { @@ -98,7 +103,7 @@ pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, itr, None, vec::from_slice(arg) - ) as reader; + ) as @reader; match parse(cx.parse_sess(), cx.cfg(), arg_rdr, (*mtcs)) { success(named_matches) => { let rhs = match rhses[i] { @@ -118,8 +123,9 @@ pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, // rhs has holes ( `$id` and `$(...)` that need filled) let trncbr = new_tt_reader(s_d, itr, Some(named_matches), rhs); - let p = @Parser(cx.parse_sess(), cx.cfg(), - trncbr as reader); + let p = @Parser(cx.parse_sess(), + cx.cfg(), + trncbr as @reader); // Let the context choose how to interpret the result. // Weird, but useful for X-macros. @@ -140,7 +146,7 @@ pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, cx.span_fatal(best_fail_spot, best_fail_msg); } - let exp: @fn(ext_ctxt, span, &[ast::token_tree]) -> MacResult = + let exp: @fn(@ext_ctxt, span, &[ast::token_tree]) -> MacResult = |cx, sp, arg| generic_extension(cx, sp, name, arg, lhses, rhses); return MRDef(MacroDef{ diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 589b7693f9e..0196ee6d184 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -34,7 +34,7 @@ struct TtFrame { } pub struct TtReader { - sp_diag: span_handler, + sp_diag: @span_handler, interner: @ident_interner, // the unzipped tree: cur: @mut TtFrame, @@ -50,7 +50,7 @@ pub struct TtReader { /** This can do Macro-By-Example transcription. On the other hand, if * `src` contains no `tt_seq`s and `tt_nonterminal`s, `interp` can (and * should) be none. */ -pub fn new_tt_reader(sp_diag: span_handler, +pub fn new_tt_reader(sp_diag: @span_handler, itr: @ident_interner, interp: Option<std::oldmap::HashMap<ident,@named_match>>, +src: ~[ast::token_tree]) @@ -106,8 +106,9 @@ pub pure fn dup_tt_reader(r: @mut TtReader) -> @mut TtReader { } -pure fn lookup_cur_matched_by_matched(r: @mut TtReader, - start: @named_match) -> @named_match { +pure fn lookup_cur_matched_by_matched(r: &mut TtReader, + start: @named_match) + -> @named_match { pure fn red(+ad: @named_match, idx: &uint) -> @named_match { match *ad { matched_nonterminal(_) => { @@ -117,18 +118,20 @@ pure fn lookup_cur_matched_by_matched(r: @mut TtReader, matched_seq(ref ads, _) => ads[*idx] } } - vec::foldl(start, r.repeat_idx, red) + let r = &mut *r; + let repeat_idx = &r.repeat_idx; + vec::foldl(start, *repeat_idx, red) } -fn lookup_cur_matched(r: @mut TtReader, name: ident) -> @named_match { +fn lookup_cur_matched(r: &mut TtReader, name: ident) -> @named_match { lookup_cur_matched_by_matched(r, r.interpolations.get(&name)) } enum lis { lis_unconstrained, lis_constraint(uint, ident), lis_contradiction(~str) } -fn lockstep_iter_size(t: token_tree, r: @mut TtReader) -> lis { - fn lis_merge(lhs: lis, rhs: lis, r: @mut TtReader) -> lis { +fn lockstep_iter_size(t: token_tree, r: &mut TtReader) -> lis { + fn lis_merge(lhs: lis, rhs: lis, r: &mut TtReader) -> lis { match lhs { lis_unconstrained => copy rhs, lis_contradiction(_) => copy lhs, @@ -148,8 +151,10 @@ fn lockstep_iter_size(t: token_tree, r: @mut TtReader) -> lis { } match t { tt_delim(ref tts) | tt_seq(_, ref tts, _, _) => { - vec::foldl(lis_unconstrained, (*tts), |lis, tt| - lis_merge(lis, lockstep_iter_size(*tt, r), r)) + vec::foldl(lis_unconstrained, (*tts), |lis, tt| { + let lis2 = lockstep_iter_size(*tt, r); + lis_merge(lis, lis2, r) + }) } tt_tok(*) => lis_unconstrained, tt_nonterminal(_, name) => match *lookup_cur_matched(r, name) { @@ -160,12 +165,20 @@ fn lockstep_iter_size(t: token_tree, r: @mut TtReader) -> lis { } -pub fn tt_next_token(r: @mut TtReader) -> TokenAndSpan { +pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { let ret_val = TokenAndSpan { tok: copy r.cur_tok, sp: r.cur_span, }; - while r.cur.idx >= r.cur.readme.len() { + loop { + { + let cur = &mut *r.cur; + let readme = &mut *cur.readme; + if cur.idx < readme.len() { + break; + } + } + /* done with this set; pop or repeat? */ if ! r.cur.dotdotdoted || { *r.repeat_idx.last() == *r.repeat_len.last() - 1 } { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 15097f57b02..159b23f4f99 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -48,26 +48,26 @@ pub trait ast_fold { pub struct AstFoldFns { //unlike the others, item_ is non-trivial - fold_crate: @fn(&crate_, span, ast_fold) -> (crate_, span), - fold_view_item: @fn(view_item_, ast_fold) -> view_item_, - fold_foreign_item: @fn(@foreign_item, ast_fold) -> @foreign_item, - fold_item: @fn(@item, ast_fold) -> Option<@item>, - fold_struct_field: @fn(@struct_field, ast_fold) -> @struct_field, - fold_item_underscore: @fn(&item_, ast_fold) -> item_, - fold_method: @fn(@method, ast_fold) -> @method, - fold_block: @fn(&blk_, span, ast_fold) -> (blk_, span), - fold_stmt: @fn(&stmt_, span, ast_fold) -> (stmt_, span), - fold_arm: @fn(&arm, ast_fold) -> arm, - fold_pat: @fn(&pat_, span, ast_fold) -> (pat_, span), - fold_decl: @fn(&decl_, span, ast_fold) -> (decl_, span), - fold_expr: @fn(&expr_, span, ast_fold) -> (expr_, span), - fold_ty: @fn(&ty_, span, ast_fold) -> (ty_, span), - fold_mod: @fn(&_mod, ast_fold) -> _mod, - fold_foreign_mod: @fn(&foreign_mod, ast_fold) -> foreign_mod, - fold_variant: @fn(&variant_, span, ast_fold) -> (variant_, span), - fold_ident: @fn(ident, ast_fold) -> ident, - fold_path: @fn(@path, ast_fold) -> path, - fold_local: @fn(&local_, span, ast_fold) -> (local_, span), + fold_crate: @fn(&crate_, span, @ast_fold) -> (crate_, span), + fold_view_item: @fn(view_item_, @ast_fold) -> view_item_, + fold_foreign_item: @fn(@foreign_item, @ast_fold) -> @foreign_item, + fold_item: @fn(@item, @ast_fold) -> Option<@item>, + fold_struct_field: @fn(@struct_field, @ast_fold) -> @struct_field, + fold_item_underscore: @fn(&item_, @ast_fold) -> item_, + fold_method: @fn(@method, @ast_fold) -> @method, + fold_block: @fn(&blk_, span, @ast_fold) -> (blk_, span), + fold_stmt: @fn(&stmt_, span, @ast_fold) -> (stmt_, span), + fold_arm: @fn(&arm, @ast_fold) -> arm, + fold_pat: @fn(&pat_, span, @ast_fold) -> (pat_, span), + fold_decl: @fn(&decl_, span, @ast_fold) -> (decl_, span), + fold_expr: @fn(&expr_, span, @ast_fold) -> (expr_, span), + fold_ty: @fn(&ty_, span, @ast_fold) -> (ty_, span), + fold_mod: @fn(&_mod, @ast_fold) -> _mod, + fold_foreign_mod: @fn(&foreign_mod, @ast_fold) -> foreign_mod, + fold_variant: @fn(&variant_, span, @ast_fold) -> (variant_, span), + fold_ident: @fn(ident, @ast_fold) -> ident, + fold_path: @fn(@path, @ast_fold) -> path, + fold_local: @fn(&local_, span, @ast_fold) -> (local_, span), map_exprs: @fn(@fn(@expr) -> @expr, &[@expr]) -> ~[@expr], new_id: @fn(node_id) -> node_id, new_span: @fn(span) -> span @@ -436,8 +436,8 @@ fn noop_fold_decl(d: &decl_, fld: @ast_fold) -> decl_ { } } -pub fn wrap<T>(f: @fn(&T, ast_fold) -> T) - -> @fn(&T, span, ast_fold) -> (T, span) { +pub fn wrap<T>(f: @fn(&T, @ast_fold) -> T) + -> @fn(&T, span, @ast_fold) -> (T, span) { let result: @fn(&T, span, @ast_fold) -> (T, span) = |x, s, fld| { (f(x, fld), s) }; @@ -560,7 +560,14 @@ pub fn noop_fold_expr(e: &expr_, fld: @ast_fold) -> expr_ { fld.fold_expr(e) ) } - expr_inline_asm(*) => copy *e, + expr_inline_asm(asm, ins, outs, c, v, a) => { + expr_inline_asm( + asm, + ins.map(|&(c, in)| (c, fld.fold_expr(in))), + outs.map(|&(c, out)| (c, fld.fold_expr(out))), + c, v, a + ) + } expr_mac(ref mac) => expr_mac(fold_mac((*mac))), expr_struct(path, ref fields, maybe_expr) => { expr_struct( @@ -615,10 +622,10 @@ pub fn noop_fold_ty(t: &ty_, fld: @ast_fold) -> ty_ { } ty_tup(ref tys) => ty_tup(tys.map(|ty| fld.fold_ty(*ty))), ty_path(path, id) => ty_path(fld.fold_path(path), fld.new_id(id)), - ty_fixed_length_vec(ref mt, vs) => { + ty_fixed_length_vec(ref mt, e) => { ty_fixed_length_vec( fold_mt(mt, fld), - vs + fld.fold_expr(e) ) } ty_mac(ref mac) => ty_mac(fold_mac(*mac)) @@ -879,13 +886,13 @@ impl ast_fold for AstFoldFns { } } -pub impl ast_fold { +pub impl @ast_fold { fn fold_attributes(&self, attrs: ~[attribute]) -> ~[attribute] { attrs.map(|x| fold_attribute_(*x, *self)) } } -pub fn make_fold(afp: ast_fold_fns) -> ast_fold { +pub fn make_fold(afp: ast_fold_fns) -> @ast_fold { afp as @ast_fold } diff --git a/src/libsyntax/opt_vec.rs b/src/libsyntax/opt_vec.rs index ba0c7a71b7c..dbabca55a11 100644 --- a/src/libsyntax/opt_vec.rs +++ b/src/libsyntax/opt_vec.rs @@ -61,7 +61,7 @@ impl<T> OptVec<T> { } } - pure fn get(&self, i: uint) -> &self/T { + pure fn get(&self, i: uint) -> &'self T { match *self { Empty => fail!(fmt!("Invalid index %u", i)), Vec(ref v) => &v[i] diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index 494ef3a81a0..b6ec3aff44d 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -183,7 +183,7 @@ fn read_line_comments(rdr: @mut StringReader, code_to_the_left: bool, let mut lines: ~[~str] = ~[]; while rdr.curr == '/' && nextch(rdr) == '/' { let line = read_one_line_comment(rdr); - log(debug, line); + debug!("%s", line); if is_doc_comment(line) { // doc-comments are not put in comments break; } @@ -221,7 +221,7 @@ fn trim_whitespace_prefix_and_push_line(lines: &mut ~[~str], s1 = str::slice(s, col, len); } else { s1 = ~""; } } else { s1 = /*bad*/ copy s; } - log(debug, ~"pushing line: " + s1); + debug!("pushing line: %s", s1); lines.push(s1); } @@ -256,7 +256,7 @@ fn read_block_comment(rdr: @mut StringReader, while level > 0 { debug!("=== block comment level %d", level); if is_eof(rdr) { - (rdr as reader).fatal(~"unterminated block comment"); + (rdr as @reader).fatal(~"unterminated block comment"); } if rdr.curr == '\n' { trim_whitespace_prefix_and_push_line(&mut lines, curr_line, @@ -319,9 +319,11 @@ pub struct lit { pos: BytePos } -pub fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler, +pub fn gather_comments_and_literals(span_diagnostic: + @diagnostic::span_handler, +path: ~str, - srdr: io::Reader) -> (~[cmnt], ~[lit]) { + srdr: @io::Reader) + -> (~[cmnt], ~[lit]) { let src = @str::from_bytes(srdr.read_whole_stream()); let itr = parse::token::mk_fake_ident_interner(); let cm = CodeMap::new(); diff --git a/src/libsyntax/parse/common.rs b/src/libsyntax/parse/common.rs index c7b9a769293..1b64a9a6275 100644 --- a/src/libsyntax/parse/common.rs +++ b/src/libsyntax/parse/common.rs @@ -47,7 +47,7 @@ pub fn seq_sep_none() -> SeqSep { } } -pub fn token_to_str(reader: reader, token: &token::Token) -> ~str { +pub fn token_to_str(reader: @reader, token: &token::Token) -> ~str { token::to_str(reader.interner(), token) } diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index ab57d177112..90f51fe9b65 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -31,17 +31,17 @@ pub trait reader { fn is_eof(@mut self) -> bool; fn next_token(@mut self) -> TokenAndSpan; fn fatal(@mut self, ~str) -> !; - fn span_diag(@mut self) -> span_handler; + fn span_diag(@mut self) -> @span_handler; pure fn interner(@mut self) -> @token::ident_interner; fn peek(@mut self) -> TokenAndSpan; - fn dup(@mut self) -> reader; + fn dup(@mut self) -> @reader; } #[deriving_eq] pub struct TokenAndSpan {tok: token::Token, sp: span} pub struct StringReader { - span_diagnostic: span_handler, + span_diagnostic: @span_handler, src: @~str, // The absolute offset within the codemap of the next character to read pos: BytePos, @@ -58,7 +58,7 @@ pub struct StringReader { peek_span: span } -pub fn new_string_reader(span_diagnostic: span_handler, +pub fn new_string_reader(span_diagnostic: @span_handler, filemap: @codemap::FileMap, itr: @token::ident_interner) -> @mut StringReader { @@ -68,7 +68,7 @@ pub fn new_string_reader(span_diagnostic: span_handler, } /* For comments.rs, which hackily pokes into 'pos' and 'curr' */ -pub fn new_low_level_string_reader(span_diagnostic: span_handler, +pub fn new_low_level_string_reader(span_diagnostic: @span_handler, filemap: @codemap::FileMap, itr: @token::ident_interner) -> @mut StringReader { @@ -121,7 +121,7 @@ impl reader for StringReader { fn fatal(@mut self, m: ~str) -> ! { self.span_diagnostic.span_fatal(copy self.peek_span, m) } - fn span_diag(@mut self) -> span_handler { self.span_diagnostic } + fn span_diag(@mut self) -> @span_handler { self.span_diagnostic } pure fn interner(@mut self) -> @token::ident_interner { self.interner } fn peek(@mut self) -> TokenAndSpan { TokenAndSpan { @@ -129,7 +129,7 @@ impl reader for StringReader { sp: copy self.peek_span, } } - fn dup(@mut self) -> reader { dup_string_reader(self) as reader } + fn dup(@mut self) -> @reader { dup_string_reader(self) as @reader } } impl reader for TtReader { @@ -138,7 +138,7 @@ impl reader for TtReader { fn fatal(@mut self, m: ~str) -> ! { self.sp_diag.span_fatal(copy self.cur_span, m); } - fn span_diag(@mut self) -> span_handler { self.sp_diag } + fn span_diag(@mut self) -> @span_handler { self.sp_diag } pure fn interner(@mut self) -> @token::ident_interner { self.interner } fn peek(@mut self) -> TokenAndSpan { TokenAndSpan { @@ -146,7 +146,7 @@ impl reader for TtReader { sp: copy self.cur_span, } } - fn dup(@mut self) -> reader { dup_tt_reader(self) as reader } + fn dup(@mut self) -> @reader { dup_tt_reader(self) as @reader } } // EFFECT: advance peek_tok and peek_span to refer to the next token. @@ -811,7 +811,7 @@ pub mod test { sp:span {lo:BytePos(21),hi:BytePos(23),expn_info: None}}; check_equal (tok1,tok2); // the 'main' id is already read: - check_equal (string_reader.last_pos,BytePos(28)); + check_equal (copy string_reader.last_pos,BytePos(28)); // read another token: let tok3 = string_reader.next_token(); let tok4 = TokenAndSpan{ @@ -819,7 +819,7 @@ pub mod test { sp:span {lo:BytePos(24),hi:BytePos(28),expn_info: None}}; check_equal (tok3,tok4); // the lparen is already read: - check_equal (string_reader.last_pos,BytePos(29)) + check_equal (copy string_reader.last_pos,BytePos(29)) } // check that the given reader produces the desired stream diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index fd84f867068..a133befb046 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -48,7 +48,7 @@ pub mod obsolete; pub struct ParseSess { cm: @codemap::CodeMap, next_id: node_id, - span_diagnostic: span_handler, + span_diagnostic: @span_handler, interner: @ident_interner, } @@ -62,8 +62,9 @@ pub fn new_parse_sess(demitter: Option<Emitter>) -> @mut ParseSess { } } -pub fn new_parse_sess_special_handler(sh: span_handler, cm: @codemap::CodeMap) - -> @mut ParseSess { +pub fn new_parse_sess_special_handler(sh: @span_handler, + cm: @codemap::CodeMap) + -> @mut ParseSess { @mut ParseSess { cm: cm, next_id: 1, @@ -138,6 +139,22 @@ pub fn parse_item_from_source_str( maybe_aborted(p.parse_item(attrs),p) } +pub fn parse_meta_from_source_str( + name: ~str, + source: @~str, + +cfg: ast::crate_cfg, + sess: @mut ParseSess +) -> @ast::meta_item { + let p = new_parser_from_source_str( + sess, + cfg, + /*bad*/ copy name, + codemap::FssNone, + source + ); + maybe_aborted(p.parse_meta_item(),p) +} + pub fn parse_stmt_from_source_str( name: ~str, source: @~str, @@ -201,20 +218,19 @@ pub fn next_node_id(sess: @mut ParseSess) -> node_id { return rv; } -pub fn new_parser_from_source_str( - sess: @mut ParseSess, - +cfg: ast::crate_cfg, - +name: ~str, - +ss: codemap::FileSubstr, - source: @~str -) -> Parser { +pub fn new_parser_from_source_str(sess: @mut ParseSess, + +cfg: ast::crate_cfg, + +name: ~str, + +ss: codemap::FileSubstr, + source: @~str) + -> Parser { let filemap = sess.cm.new_filemap_w_substr(name, ss, source); let srdr = lexer::new_string_reader( copy sess.span_diagnostic, filemap, sess.interner ); - Parser(sess, cfg, srdr as reader) + Parser(sess, cfg, srdr as @reader) } /// Read the entire source file, return a parser @@ -227,12 +243,10 @@ pub fn new_parser_result_from_file( match io::read_whole_file_str(path) { Ok(src) => { let filemap = sess.cm.new_filemap(path.to_str(), @src); - let srdr = lexer::new_string_reader( - copy sess.span_diagnostic, - filemap, - sess.interner - ); - Ok(Parser(sess, cfg, srdr as reader)) + let srdr = lexer::new_string_reader(copy sess.span_diagnostic, + filemap, + sess.interner); + Ok(Parser(sess, cfg, srdr as @reader)) } Err(e) => Err(e) @@ -281,7 +295,7 @@ pub fn new_parser_from_tts( None, tts ); - Parser(sess, cfg, trdr as reader) + Parser(sess, cfg, trdr as @reader) } // abort if necessary @@ -299,10 +313,9 @@ mod test { use std; use core::io; use core::option::None; - use core::str; use util::testing::*; - #[test] fn to_json_str (val: Encodable<std::json::Encoder>) -> ~str { + #[test] fn to_json_str<E : Encodable<std::json::Encoder>>(val: @E) -> ~str { do io::with_str_writer |writer| { val.encode(~std::json::Encoder(writer)); } @@ -314,18 +327,18 @@ mod test { @~"fn foo (x : int) { x; }", ~[], new_parse_sess(None)); - check_equal(to_json_str(@tts as Encodable::<std::json::Encoder>), - ~"[[\"tt_tok\",[,[\"IDENT\",[\"fn\",false]]]],\ - [\"tt_tok\",[,[\"IDENT\",[\"foo\",false]]]],\ - [\"tt_delim\",[[[\"tt_tok\",[,[\"LPAREN\",[]]]],\ - [\"tt_tok\",[,[\"IDENT\",[\"x\",false]]]],\ - [\"tt_tok\",[,[\"COLON\",[]]]],\ - [\"tt_tok\",[,[\"IDENT\",[\"int\",false]]]],\ - [\"tt_tok\",[,[\"RPAREN\",[]]]]]]],\ - [\"tt_delim\",[[[\"tt_tok\",[,[\"LBRACE\",[]]]],\ - [\"tt_tok\",[,[\"IDENT\",[\"x\",false]]]],\ - [\"tt_tok\",[,[\"SEMI\",[]]]],\ - [\"tt_tok\",[,[\"RBRACE\",[]]]]]]]]" + check_equal(to_json_str(@tts), + ~"[[\"tt_tok\",[null,[\"IDENT\",[\"fn\",false]]]],\ + [\"tt_tok\",[null,[\"IDENT\",[\"foo\",false]]]],\ + [\"tt_delim\",[[[\"tt_tok\",[null,[\"LPAREN\",[]]]],\ + [\"tt_tok\",[null,[\"IDENT\",[\"x\",false]]]],\ + [\"tt_tok\",[null,[\"COLON\",[]]]],\ + [\"tt_tok\",[null,[\"IDENT\",[\"int\",false]]]],\ + [\"tt_tok\",[null,[\"RPAREN\",[]]]]]]],\ + [\"tt_delim\",[[[\"tt_tok\",[null,[\"LBRACE\",[]]]],\ + [\"tt_tok\",[null,[\"IDENT\",[\"x\",false]]]],\ + [\"tt_tok\",[null,[\"SEMI\",[]]]],\ + [\"tt_tok\",[null,[\"RBRACE\",[]]]]]]]]" ); let ast1 = new_parser_from_tts(new_parse_sess(None),~[],tts) .parse_item(~[]); diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index ef858a2d5eb..f5e83a1beae 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -55,6 +55,9 @@ pub enum ObsoleteSyntax { ObsoletePostFnTySigil, ObsoleteBareFnType, ObsoleteNewtypeEnum, + ObsoleteMode, + ObsoleteImplicitSelf, + ObsoleteLifetimeNotation, } impl to_bytes::IterBytes for ObsoleteSyntax { @@ -176,6 +179,20 @@ pub impl Parser { "newtype enum", "instead of `enum Foo = int`, write `struct Foo(int)`" ), + ObsoleteMode => ( + "obsolete argument mode", + "replace `-` or `++` mode with `+`" + ), + ObsoleteImplicitSelf => ( + "implicit self", + "use an explicit `self` declaration or declare the method as \ + static" + ), + ObsoleteLifetimeNotation => ( + "`/` lifetime notation", + "instead of `&foo/bar`, write `&'foo bar`; instead of \ + `bar/&foo`, write `&bar<'foo>" + ), }; self.report(sp, kind, kind_str, desc); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 51e36d9ec02..c7e93635d4c 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -17,7 +17,7 @@ use ast::{RegionTyParamBound, TraitTyParamBound}; use ast::{provided, public, pure_fn, purity}; use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_infer}; use ast::{bind_by_copy, bitand, bitor, bitxor, blk}; -use ast::{blk_check_mode, box, by_copy, by_ref, by_val}; +use ast::{blk_check_mode, box, by_copy, by_ref}; use ast::{crate, crate_cfg, decl, decl_item}; use ast::{decl_local, default_blk, deref, div, enum_def, enum_variant_kind}; use ast::{expl, expr, expr_, expr_addr_of, expr_match, expr_again}; @@ -78,6 +78,8 @@ use parse::obsolete::{ObsoleteMutVector, ObsoleteTraitImplVisibility}; use parse::obsolete::{ObsoleteRecordType, ObsoleteRecordPattern}; use parse::obsolete::{ObsoleteAssertion, ObsoletePostFnTySigil}; use parse::obsolete::{ObsoleteBareFnType, ObsoleteNewtypeEnum}; +use parse::obsolete::{ObsoleteMode, ObsoleteImplicitSelf}; +use parse::obsolete::{ObsoleteLifetimeNotation}; 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}; @@ -214,8 +216,8 @@ struct ParsedItemsAndViewItems { pub fn Parser(sess: @mut ParseSess, +cfg: ast::crate_cfg, - +rdr: reader) -> Parser { - + +rdr: @reader) + -> Parser { let tok0 = copy rdr.next_token(); let interner = rdr.interner(); @@ -253,7 +255,7 @@ pub struct Parser { tokens_consumed: @mut uint, restriction: @mut restriction, quote_depth: @mut uint, // not (yet) related to the quasiquoter - reader: reader, + reader: @reader, interner: @token::ident_interner, keywords: HashMap<~str, ()>, strict_keywords: HashMap<~str, ()>, @@ -410,7 +412,8 @@ pub impl Parser { fn parse_purity(&self) -> purity { if self.eat_keyword(&~"pure") { - return pure_fn; + // NB: We parse this as impure for bootstrapping purposes. + return impure_fn; } else if self.eat_keyword(&~"unsafe") { return unsafe_fn; } else { @@ -468,7 +471,11 @@ pub impl Parser { either::Left(p.parse_arg_general(false)) }; // XXX: Wrong. Shouldn't allow both static and self_ty - let self_ty = if is_static { static_sty } else { self_ty }; + let self_ty = if is_static || self_ty.node == sty_by_ref { + static_sty + } else { + self_ty + }; let hi = p.last_span.hi; debug!("parse_trait_methods(): trait method signature ends in \ @@ -635,7 +642,8 @@ pub impl Parser { self.obsolete(*self.last_span, ObsoleteMutVector); } - // Parse the `* 3` in `[ int * 3 ]` + // Parse the `* e` in `[ int * e ]` + // where `e` is a const expression let t = match self.maybe_parse_fixed_vstore_with_star() { None => ty_vec(mt), Some(suffix) => ty_fixed_length_vec(mt, suffix) @@ -681,6 +689,7 @@ pub impl Parser { self.token_is_closure_keyword(&self.look_ahead(2u)) { let lifetime = @self.parse_lifetime(); + self.obsolete(*self.last_span, ObsoleteLifetimeNotation); return self.parse_ty_closure(sigil, Some(lifetime)); } else if self.token_is_closure_keyword(© *self.token) { return self.parse_ty_closure(sigil, None); @@ -703,7 +712,7 @@ pub impl Parser { } fn parse_borrowed_pointee(&self) -> ty_ { - // look for `&'lt` or `&foo/` and interpret `foo` as the region name: + // look for `&'lt` or `&'foo ` and interpret `foo` as the region name: let opt_lifetime = self.parse_opt_lifetime(); if self.token_is_closure_keyword(© *self.token) { @@ -716,12 +725,15 @@ pub impl Parser { fn parse_arg_mode(&self) -> mode { if self.eat(&token::BINOP(token::MINUS)) { - expl(by_copy) // NDM outdated syntax + self.obsolete(*self.span, ObsoleteMode); + expl(by_copy) } else if self.eat(&token::ANDAND) { expl(by_ref) } else if self.eat(&token::BINOP(token::PLUS)) { if self.eat(&token::BINOP(token::PLUS)) { - expl(by_val) + // ++ mode is obsolete, but we need a snapshot + // to stop parsing it. + expl(by_copy) } else { expl(by_copy) } @@ -803,23 +815,9 @@ pub impl Parser { }) } - fn maybe_parse_fixed_vstore_with_star(&self) -> Option<uint> { + fn maybe_parse_fixed_vstore_with_star(&self) -> Option<@ast::expr> { if self.eat(&token::BINOP(token::STAR)) { - match *self.token { - token::LIT_INT_UNSUFFIXED(i) if i >= 0i64 => { - self.bump(); - Some(i as uint) - } - _ => { - self.fatal( - fmt!( - "expected integral vector length \ - but found `%s`", - token_to_str(self.reader, © *self.token) - ) - ); - } - } + Some(self.parse_expr()) } else { None } @@ -955,6 +953,7 @@ pub impl Parser { // Also accept the (obsolete) syntax `foo/` token::IDENT(*) => { if self.look_ahead(1u) == token::BINOP(token::SLASH) { + self.obsolete(*self.last_span, ObsoleteLifetimeNotation); Some(@self.parse_lifetime()) } else { None @@ -989,6 +988,7 @@ pub impl Parser { let span = copy self.span; self.bump(); self.expect(&token::BINOP(token::SLASH)); + self.obsolete(*self.last_span, ObsoleteLifetimeNotation); return ast::Lifetime { id: self.get_id(), span: *span, @@ -1184,7 +1184,7 @@ pub impl Parser { } } hi = self.span.hi; - } else if self.eat_keyword(&~"log") { + } else if self.eat_keyword(&~"__log") { self.expect(&token::LPAREN); let lvl = self.parse_expr(); self.expect(&token::COMMA); @@ -2656,7 +2656,8 @@ pub impl Parser { fn parse_optional_purity(&self) -> ast::purity { if self.eat_keyword(&~"pure") { - ast::pure_fn + // NB: We parse this as impure for bootstrapping purposes. + ast::impure_fn } else if self.eat_keyword(&~"unsafe") { ast::unsafe_fn } else { @@ -2975,7 +2976,11 @@ pub impl Parser { p.parse_arg() }; // XXX: interaction between staticness, self_ty is broken now - let self_ty = if is_static { static_sty} else { self_ty }; + let self_ty = if is_static || self_ty.node == sty_by_ref { + static_sty + } else { + self_ty + }; let (inner_attrs, body) = self.parse_inner_attrs_and_block(true); let hi = body.span.hi; @@ -3402,8 +3407,9 @@ pub impl Parser { let prefix = Path(self.sess.cm.span_to_filename(*self.span)); let prefix = prefix.dir_path(); - let mod_path = Path(".").push_many(*self.mod_path_stack); - let default_path = self.sess.interner.get(id) + ~".rs"; + let mod_path_stack = &*self.mod_path_stack; + let mod_path = Path(".").push_many(*mod_path_stack); + let default_path = *self.sess.interner.get(id) + ~".rs"; let file_path = match ::attr::first_attr_value_str_by_name( outer_attrs, ~"path") { Some(d) => { @@ -3489,7 +3495,8 @@ pub impl Parser { if self.eat_keyword(&~"fn") { impure_fn } else if self.eat_keyword(&~"pure") { self.expect_keyword(&~"fn"); - pure_fn + // NB: We parse this as impure for bootstrapping purposes. + impure_fn } else if self.eat_keyword(&~"unsafe") { self.expect_keyword(&~"fn"); unsafe_fn @@ -3641,6 +3648,7 @@ pub impl Parser { fn parse_region_param(&self) { if self.eat(&token::BINOP(token::SLASH)) { + self.obsolete(*self.last_span, ObsoleteLifetimeNotation); self.expect(&token::BINOP(token::AND)); } } @@ -3877,8 +3885,9 @@ pub impl Parser { maybe_append(attrs, extra_attrs))); } else if items_allowed && self.eat_keyword(&~"pure") { // PURE FUNCTION ITEM + // NB: We parse this as impure for bootstrapping purposes. self.expect_keyword(&~"fn"); - let (ident, item_, extra_attrs) = self.parse_item_fn(pure_fn); + let (ident, item_, extra_attrs) = self.parse_item_fn(impure_fn); return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_, visibility, maybe_append(attrs, extra_attrs))); diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 81aacbf173d..c41b3aec09b 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -495,7 +495,7 @@ pub fn strict_keyword_table() -> HashMap<~str, ()> { ~"else", ~"enum", ~"extern", ~"false", ~"fn", ~"for", ~"if", ~"impl", - ~"let", ~"log", ~"loop", + ~"let", ~"__log", ~"loop", ~"match", ~"mod", ~"mut", ~"once", ~"priv", ~"pub", ~"pure", diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 8557ef22fc6..492ecdb3f4d 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -452,9 +452,10 @@ pub impl Printer { self.pending_indentation += amount; } fn get_top(&mut self) -> print_stack_elt { - let n = self.print_stack.len(); + let print_stack = &mut *self.print_stack; + let n = print_stack.len(); if n != 0u { - self.print_stack[n - 1u] + print_stack[n - 1u] } else { print_stack_elt { offset: 0, @@ -472,7 +473,7 @@ pub impl Printer { fn print(&mut self, x: token, L: int) { debug!("print %s %d (remaining line space=%d)", tok_str(x), L, self.space); - log(debug, buf_str(copy self.token, + debug!("%s", buf_str(copy self.token, copy self.size, self.left, self.right, @@ -496,7 +497,8 @@ pub impl Printer { } END => { debug!("print END -> pop END"); - fail_unless!((self.print_stack.len() != 0u)); + let print_stack = &*self.print_stack; + fail_unless!((print_stack.len() != 0u)); self.print_stack.pop(); } BREAK(b) => { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 92883123782..93583a1487a 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -76,7 +76,7 @@ pub fn end(s: @ps) { pp::end(s.s); } -pub fn rust_printer(writer: io::Writer, intr: @ident_interner) -> @ps { +pub fn rust_printer(writer: @io::Writer, intr: @ident_interner) -> @ps { return @ps { s: pp::mk_printer(writer, default_columns), cm: None::<@CodeMap>, @@ -100,10 +100,15 @@ pub const default_columns: uint = 78u; // Requires you to pass an input filename and reader so that // it can scan the input text for comments and literals to // copy forward. -pub fn print_crate(cm: @CodeMap, intr: @ident_interner, - span_diagnostic: diagnostic::span_handler, - crate: @ast::crate, filename: ~str, in: io::Reader, - out: io::Writer, ann: pp_ann, is_expanded: bool) { +pub fn print_crate(cm: @CodeMap, + intr: @ident_interner, + span_diagnostic: @diagnostic::span_handler, + crate: @ast::crate, + filename: ~str, + in: @io::Reader, + out: @io::Writer, + ann: pp_ann, + is_expanded: bool) { let (cmnts, lits) = comments::gather_comments_and_literals( span_diagnostic, copy filename, @@ -176,10 +181,11 @@ pub fn path_to_str(&&p: @ast::path, intr: @ident_interner) -> ~str { } pub fn fun_to_str(decl: &ast::fn_decl, name: ast::ident, + opt_self_ty: Option<ast::self_ty_>, generics: &ast::Generics, intr: @ident_interner) -> ~str { do io::with_str_writer |wr| { let s = rust_printer(wr, intr); - print_fn(s, decl, None, name, generics, None, ast::inherited); + print_fn(s, decl, None, name, generics, opt_self_ty, ast::inherited); end(s); // Close the head box end(s); // Close the outer box eof(s.s); @@ -273,9 +279,10 @@ pub fn is_bol(s: @ps) -> bool { } pub fn in_cbox(s: @ps) -> bool { - let len = s.boxes.len(); + let boxes = &*s.boxes; + let len = boxes.len(); if len == 0u { return false; } - return s.boxes[len - 1u] == pp::consistent; + return boxes[len - 1u] == pp::consistent; } pub fn hardbreak_if_not_bol(s: @ps) { if !is_bol(s) { hardbreak(s.s); } } @@ -418,7 +425,7 @@ pub fn print_type_ex(s: @ps, &&ty: @ast::Ty, print_colons: bool) { } print_type(s, mt.ty); word(s.s, ~" * "); - word(s.s, fmt!("%u", v)); + print_expr(s, v); word(s.s, ~"]"); } ast::ty_mac(_) => { @@ -1398,7 +1405,7 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) { } } } - ast::expr_inline_asm(a, c, v, _) => { + ast::expr_inline_asm(a, in, out, c, v, _) => { if v { word(s.s, ~"__volatile__ asm!"); } else { @@ -1406,7 +1413,23 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) { } popen(s); print_string(s, *a); - word_space(s, ~","); + word_space(s, ~":"); + for out.each |&(co, o)| { + print_string(s, *co); + popen(s); + print_expr(s, o); + pclose(s); + word_space(s, ~","); + } + word_space(s, ~":"); + for in.each |&(co, o)| { + print_string(s, *co); + popen(s); + print_expr(s, o); + pclose(s); + word_space(s, ~","); + } + word_space(s, ~":"); print_string(s, *c); pclose(s); } @@ -1710,7 +1733,6 @@ pub fn mode_to_str(m: ast::mode) -> ~str { match m { ast::expl(ast::by_ref) => ~"&&", ast::expl(ast::by_copy) => ~"+", - ast::expl(ast::by_val) => ~"++", ast::infer(_) => ~"" } } @@ -2254,7 +2276,7 @@ pub mod test { cf: ast::return_val }; let generics = ast_util::empty_generics(); - check_equal (&fun_to_str(&decl, abba_ident, &generics, mock_interner), + check_equal (&fun_to_str(&decl, abba_ident, None, &generics, mock_interner), &~"fn abba()"); } diff --git a/src/libsyntax/syntax.rc b/src/libsyntax/syntax.rc index e13ef976d97..912846d9f0f 100644 --- a/src/libsyntax/syntax.rc +++ b/src/libsyntax/syntax.rc @@ -22,7 +22,6 @@ #[allow(vecs_implicitly_copyable)]; #[allow(non_camel_case_types)]; #[allow(deprecated_mode)]; -#[deny(deprecated_self)]; #[no_core]; diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 7a5708049e9..47f49ebadaa 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -41,14 +41,18 @@ pub impl<T:Eq + IterBytes + Hash + Const + Copy> Interner<T> { None => (), } - let new_idx = self.vect.len(); + let vect = &*self.vect; + let new_idx = vect.len(); self.map.insert(val, new_idx); self.vect.push(val); new_idx } fn gensym(&self, val: T) -> uint { - let new_idx = self.vect.len(); + let new_idx = { + let vect = &*self.vect; + vect.len() + }; // leave out of .map to avoid colliding self.vect.push(val); new_idx @@ -59,7 +63,7 @@ pub impl<T:Eq + IterBytes + Hash + Const + Copy> Interner<T> { // where we first check a pred and then rely on it, ceasing to fail is ok. pure fn get(&self, idx: uint) -> T { self.vect[idx] } - fn len(&self) -> uint { self.vect.len() } + fn len(&self) -> uint { let vect = &*self.vect; vect.len() } } #[test] diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 95ab603f584..a159c98d21b 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -246,7 +246,10 @@ pub fn visit_ty<E>(t: @Ty, e: E, v: vt<E>) { (v.visit_ty)(f.decl.output, e, v); }, ty_path(p, _) => visit_path(p, e, v), - ty_fixed_length_vec(ref mt, _) => (v.visit_ty)(mt.ty, e, v), + ty_fixed_length_vec(ref mt, ex) => { + (v.visit_ty)(mt.ty, e, v); + (v.visit_expr)(ex, e, v); + }, ty_nil | ty_bot | ty_mac(_) | ty_infer => () } } @@ -562,7 +565,14 @@ pub fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) { } expr_mac(ref mac) => visit_mac((*mac), e, v), expr_paren(x) => (v.visit_expr)(x, e, v), - expr_inline_asm(*) => (), + expr_inline_asm(_, ins, outs, _, _, _) => { + for ins.each |&(_, in)| { + (v.visit_expr)(in, e, v); + } + for outs.each |&(_, out)| { + (v.visit_expr)(out, e, v); + } + } } (v.visit_expr_post)(ex, e, v); } diff --git a/src/libuv b/src/libuv -Subproject 576ab1db8ea03889eb7b2274654afe7c5c86723 +Subproject 218ab86721eefd7b7e97fa6d9f95a80a1fa8686 diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 8d83e2036b9..a2053c115bb 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -321,7 +321,7 @@ get_time(int64_t *sec, int32_t *nsec) { ul.HighPart = fileTime.dwHighDateTime; uint64_t ns_since_1601 = ul.QuadPart / 10; - const uint64_t NANOSECONDS_FROM_1601_TO_1970 = 11644473600000000u; + const uint64_t NANOSECONDS_FROM_1601_TO_1970 = 11644473600000000ull; uint64_t ns_since_1970 = ns_since_1601 - NANOSECONDS_FROM_1601_TO_1970; *sec = ns_since_1970 / 1000000; *nsec = (ns_since_1970 % 1000000) * 1000; @@ -434,18 +434,18 @@ rust_tzset() { } extern "C" CDECL void -rust_gmtime(int64_t *sec, int32_t *nsec, rust_tm *timeptr) { +rust_gmtime(int64_t sec, int32_t nsec, rust_tm *timeptr) { tm tm; - time_t s = *sec; + time_t s = sec; GMTIME(&s, &tm); - tm_to_rust_tm(&tm, timeptr, 0, "UTC", *nsec); + tm_to_rust_tm(&tm, timeptr, 0, "UTC", nsec); } extern "C" CDECL void -rust_localtime(int64_t *sec, int32_t *nsec, rust_tm *timeptr) { +rust_localtime(int64_t sec, int32_t nsec, rust_tm *timeptr) { tm tm; - time_t s = *sec; + time_t s = sec; LOCALTIME(&s, &tm); #if defined(__WIN32__) @@ -457,7 +457,7 @@ rust_localtime(int64_t *sec, int32_t *nsec, rust_tm *timeptr) { const char *zone = tm.tm_zone; #endif - tm_to_rust_tm(&tm, timeptr, gmtoff, zone, *nsec); + tm_to_rust_tm(&tm, timeptr, gmtoff, zone, nsec); } extern "C" CDECL void @@ -844,6 +844,43 @@ rust_readdir() { #endif +// These functions are used in the unit tests for C ABI calls. + +extern "C" CDECL uint32_t +rust_dbg_extern_identity_u32(uint32_t u) { + return u; +} + +extern "C" CDECL uint64_t +rust_dbg_extern_identity_u64(uint64_t u) { + return u; +} + +struct TwoU64s { + uint64_t one; + uint64_t two; +}; + +extern "C" CDECL TwoU64s +rust_dbg_extern_identity_TwoU64s(TwoU64s u) { + return u; +} + +extern "C" CDECL double +rust_dbg_extern_identity_double(double u) { + return u; +} + +extern "C" CDECL char +rust_dbg_extern_identity_u8(char u) { + return u; +} + +extern "C" rust_env* +rust_get_rt_env() { + rust_task *task = rust_get_current_task(); + return task->kernel->env; +} // // Local Variables: diff --git a/src/rt/rust_env.cpp b/src/rt/rust_env.cpp index b2df5f03b23..cade5f1ed2c 100644 --- a/src/rt/rust_env.cpp +++ b/src/rt/rust_env.cpp @@ -23,6 +23,7 @@ #define DETAILED_LEAKS "DETAILED_LEAKS" #define RUST_SEED "RUST_SEED" #define RUST_POISON_ON_FREE "RUST_POISON_ON_FREE" +#define RUST_DEBUG_MEM "RUST_DEBUG_MEM" #if defined(__WIN32__) static int @@ -128,6 +129,7 @@ load_env(int argc, char **argv) { env->poison_on_free = getenv(RUST_POISON_ON_FREE) != NULL; env->argc = argc; env->argv = argv; + env->debug_mem = getenv(RUST_DEBUG_MEM) != NULL; return env; } diff --git a/src/rt/rust_env.h b/src/rt/rust_env.h index c2aba575c44..df27f7674f2 100644 --- a/src/rt/rust_env.h +++ b/src/rt/rust_env.h @@ -14,16 +14,20 @@ #include "rust_globals.h" +// Avoiding 'bool' type here since I'm not sure it has a standard size +typedef uint8_t rust_bool; + struct rust_env { size_t num_sched_threads; size_t min_stack_size; size_t max_stack_size; char* logspec; - bool detailed_leaks; + rust_bool detailed_leaks; char* rust_seed; - bool poison_on_free; + rust_bool poison_on_free; int argc; char **argv; + rust_bool debug_mem; }; rust_env* load_env(int argc, char **argv); diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index 886d945b144..5a8868f33f9 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -195,4 +195,10 @@ rust_get_exchange_count_ptr rust_get_sched_tls_key swap_registers rust_readdir -rust_opendir \ No newline at end of file +rust_opendir +rust_dbg_extern_identity_u32 +rust_dbg_extern_identity_u64 +rust_dbg_extern_identity_TwoU64s +rust_dbg_extern_identity_double +rust_dbg_extern_identity_u8 +rust_get_rt_env diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 7686dcd4ff4..1b3c1f6e581 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -433,10 +433,10 @@ LLVMRustWriteOutputFile(LLVMPassManagerRef PMR, Options.EnableSegmentedStacks = EnableSegmentedStacks; std::string Err; - const Target *TheTarget = TargetRegistry::lookupTarget(triple, Err); + std::string Trip(Triple::normalize(triple)); std::string FeaturesStr; - std::string Trip(triple); std::string CPUStr("generic"); + const Target *TheTarget = TargetRegistry::lookupTarget(Trip, Err); TargetMachine *Target = TheTarget->createTargetMachine(Trip, CPUStr, FeaturesStr, Options, Reloc::PIC_, @@ -546,8 +546,8 @@ extern "C" LLVMValueRef LLVMInlineAsm(LLVMTypeRef Ty, char *Constraints, LLVMBool HasSideEffects, LLVMBool IsAlignStack, - InlineAsm::AsmDialect Dialect) { + unsigned Dialect) { return wrap(InlineAsm::get(unwrap<FunctionType>(Ty), AsmString, Constraints, HasSideEffects, - IsAlignStack, Dialect)); + IsAlignStack, (InlineAsm::AsmDialect) Dialect)); } diff --git a/src/test/auxiliary/ambig_impl_2_lib.rs b/src/test/auxiliary/ambig_impl_2_lib.rs index c6dfe7b79a9..e56df439bc2 100644 --- a/src/test/auxiliary/ambig_impl_2_lib.rs +++ b/src/test/auxiliary/ambig_impl_2_lib.rs @@ -9,6 +9,6 @@ // except according to those terms. trait me { - fn me() -> uint; + fn me(&self) -> uint; } -impl me for uint { fn me() -> uint { self } } +impl me for uint { fn me(&self) -> uint { *self } } diff --git a/src/test/auxiliary/cci_class_2.rs b/src/test/auxiliary/cci_class_2.rs index b955ed9c2a7..9dc27054ef7 100644 --- a/src/test/auxiliary/cci_class_2.rs +++ b/src/test/auxiliary/cci_class_2.rs @@ -17,7 +17,7 @@ pub mod kitties { } pub impl cat { - fn speak() {} + fn speak(&self) {} } pub fn cat(in_x : uint, in_y : int) -> cat { diff --git a/src/test/auxiliary/cci_class_6.rs b/src/test/auxiliary/cci_class_6.rs index ceccea409c4..80990099cda 100644 --- a/src/test/auxiliary/cci_class_6.rs +++ b/src/test/auxiliary/cci_class_6.rs @@ -23,7 +23,7 @@ pub mod kitties { fn meow_count(&mut self) -> uint { self.meows } } - pub fn cat<U>(in_x : uint, in_y : int, -in_info: ~[U]) -> cat<U> { + pub fn cat<U>(in_x : uint, in_y : int, +in_info: ~[U]) -> cat<U> { cat { meows: in_x, how_hungry: in_y, diff --git a/src/test/auxiliary/cci_const.rs b/src/test/auxiliary/cci_const.rs index b2dd0cc8e58..945004ede6d 100644 --- a/src/test/auxiliary/cci_const.rs +++ b/src/test/auxiliary/cci_const.rs @@ -11,6 +11,6 @@ pub extern fn bar() { } -pub const foopy: &static/str = "hi there"; +pub const foopy: &'static str = "hi there"; pub const uint_val: uint = 12; pub const uint_expr: uint = (1 << uint_val) - 1; diff --git a/src/test/auxiliary/cci_impl_lib.rs b/src/test/auxiliary/cci_impl_lib.rs index b7149be00cc..aebe9382f64 100644 --- a/src/test/auxiliary/cci_impl_lib.rs +++ b/src/test/auxiliary/cci_impl_lib.rs @@ -11,13 +11,13 @@ #[link(name="cci_impl_lib", vers="0.0")]; trait uint_helpers { - fn to(v: uint, f: &fn(uint)); + fn to(&self, v: uint, f: &fn(uint)); } impl uint_helpers for uint { #[inline] - fn to(v: uint, f: &fn(uint)) { - let mut i = self; + fn to(&self, v: uint, f: &fn(uint)) { + let mut i = *self; while i < v { f(i); i += 1u; diff --git a/src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs b/src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs index f578ad82d6d..ea42a51ff11 100644 --- a/src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs +++ b/src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs @@ -16,11 +16,11 @@ pub mod name_pool { pub type name_pool = (); pub trait add { - fn add(s: ~str); + fn add(&self, s: ~str); } impl add for name_pool { - fn add(s: ~str) { + fn add(&self, s: ~str) { } } } @@ -31,11 +31,11 @@ pub mod rust { pub type rt = @(); pub trait cx { - fn cx(); + fn cx(&self); } impl cx for rt { - fn cx() { + fn cx(&self) { } } } diff --git a/src/test/auxiliary/issue-2380.rs b/src/test/auxiliary/issue-2380.rs index afe7d4a6e8b..bd1b9d84e07 100644 --- a/src/test/auxiliary/issue-2380.rs +++ b/src/test/auxiliary/issue-2380.rs @@ -13,7 +13,7 @@ pub trait i<T> { } -pub fn f<T>() -> i<T> { +pub fn f<T>() -> @i<T> { impl<T> i<T> for () { } @() as @i<T> diff --git a/src/test/auxiliary/issue-2414-a.rs b/src/test/auxiliary/issue-2414-a.rs index fb97adf51a5..9f4f369b70d 100644 --- a/src/test/auxiliary/issue-2414-a.rs +++ b/src/test/auxiliary/issue-2414-a.rs @@ -14,10 +14,10 @@ type t1 = uint; trait foo { - fn foo(); + fn foo(&self); } impl foo for ~str { - fn foo() {} + fn foo(&self) {} } diff --git a/src/test/auxiliary/issue-2526.rs b/src/test/auxiliary/issue-2526.rs index 958fb75b9d2..c09e64eac8c 100644 --- a/src/test/auxiliary/issue-2526.rs +++ b/src/test/auxiliary/issue-2526.rs @@ -56,5 +56,5 @@ fn context_res() -> context_res { pub type context = arc_destruct<context_res>; pub impl context { - fn socket() { } + fn socket(&self) { } } diff --git a/src/test/auxiliary/issue_2472_b.rs b/src/test/auxiliary/issue_2472_b.rs index 1dd30edcc98..7969128ce52 100644 --- a/src/test/auxiliary/issue_2472_b.rs +++ b/src/test/auxiliary/issue_2472_b.rs @@ -12,13 +12,13 @@ pub struct S(()); pub impl S { - fn foo() { } + fn foo(&self) { } } pub trait T { - fn bar(); + fn bar(&self); } impl T for S { - fn bar() { } + fn bar(&self) { } } diff --git a/src/test/auxiliary/issue_3136_a.rs b/src/test/auxiliary/issue_3136_a.rs index c80457ef1e9..f7c866da9ae 100644 --- a/src/test/auxiliary/issue_3136_a.rs +++ b/src/test/auxiliary/issue_3136_a.rs @@ -9,11 +9,11 @@ // except according to those terms. trait x { - fn use_x<T>(); + fn use_x<T>(&self); } struct y(()); impl x for y { - fn use_x<T>() { + fn use_x<T>(&self) { struct foo { //~ ERROR quux i: () } diff --git a/src/test/auxiliary/trait_inheritance_auto_xc_2_aux.rs b/src/test/auxiliary/trait_inheritance_auto_xc_2_aux.rs index 11d4b28c215..1c7ebd941c3 100644 --- a/src/test/auxiliary/trait_inheritance_auto_xc_2_aux.rs +++ b/src/test/auxiliary/trait_inheritance_auto_xc_2_aux.rs @@ -8,14 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub trait Foo { fn f() -> int; } -pub trait Bar { fn g() -> int; } -pub trait Baz { fn h() -> int; } +pub trait Foo { fn f(&self) -> int; } +pub trait Bar { fn g(&self) -> int; } +pub trait Baz { fn h(&self) -> int; } pub struct A { x: int } -impl Foo for A { fn f() -> int { 10 } } -impl Bar for A { fn g() -> int { 20 } } -impl Baz for A { fn h() -> int { 30 } } +impl Foo for A { fn f(&self) -> int { 10 } } +impl Bar for A { fn g(&self) -> int { 20 } } +impl Baz for A { fn h(&self) -> int { 30 } } diff --git a/src/test/auxiliary/trait_inheritance_auto_xc_aux.rs b/src/test/auxiliary/trait_inheritance_auto_xc_aux.rs index ecd43686b77..d5949d1ce09 100644 --- a/src/test/auxiliary/trait_inheritance_auto_xc_aux.rs +++ b/src/test/auxiliary/trait_inheritance_auto_xc_aux.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait Foo { fn f() -> int; } -trait Bar { fn g() -> int; } -trait Baz { fn h() -> int; } +trait Foo { fn f(&self) -> int; } +trait Bar { fn g(&self) -> int; } +trait Baz { fn h(&self) -> int; } trait Quux: Foo + Bar + Baz { } diff --git a/src/test/auxiliary/trait_inheritance_cross_trait_call_xc_aux.rs b/src/test/auxiliary/trait_inheritance_cross_trait_call_xc_aux.rs index 724860d6855..c9694fec610 100644 --- a/src/test/auxiliary/trait_inheritance_cross_trait_call_xc_aux.rs +++ b/src/test/auxiliary/trait_inheritance_cross_trait_call_xc_aux.rs @@ -10,7 +10,7 @@ pub trait Foo { - fn f() -> int; + fn f(&self) -> int; } pub struct A { @@ -18,5 +18,5 @@ pub struct A { } impl Foo for A { - fn f() -> int { 10 } + fn f(&self) -> int { 10 } } diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index e8fb86fda78..eecf509998b 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -17,6 +17,7 @@ use std::oldmap; use std::oldmap::{Map, HashMap}; use core::io::{Reader, ReaderUtil}; +use core::rand::RngUtil; macro_rules! bench ( ($id:ident) => (maybe_run_test(argv, stringify!($id).to_owned(), $id)) diff --git a/src/test/bench/core-uint-to-str.rs b/src/test/bench/core-uint-to-str.rs index 56f616c6f28..c637fcbaf50 100644 --- a/src/test/bench/core-uint-to-str.rs +++ b/src/test/bench/core-uint-to-str.rs @@ -22,6 +22,6 @@ fn main() { for uint::range(0u, n) |i| { let x = uint::to_str(i); - log(debug, x); + debug!(x); } } diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 9efcc05e996..b99dfa8bacb 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -29,6 +29,7 @@ use std::deque::Deque; use std::par; use core::io::WriterUtil; use core::int::abs; +use core::rand::RngUtil; type node_id = i64; type graph = ~[~[node_id]]; @@ -37,7 +38,7 @@ type bfs_result = ~[node_id]; fn make_edges(scale: uint, edgefactor: uint) -> ~[(node_id, node_id)] { let r = rand::xorshift(); - fn choose_edge(i: node_id, j: node_id, scale: uint, r: rand::Rng) + fn choose_edge(i: node_id, j: node_id, scale: uint, r: @rand::Rng) -> (node_id, node_id) { let A = 0.57; @@ -100,7 +101,7 @@ fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph { } } -fn gen_search_keys(graph: graph, n: uint) -> ~[node_id] { +fn gen_search_keys(graph: &[~[node_id]], n: uint) -> ~[node_id] { let keys = oldmap::HashMap::<node_id, ()>(); let r = rand::Rng(); @@ -181,7 +182,7 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result { let mut i = 0; while vec::any(colors, is_gray) { // Do the BFS. - log(info, fmt!("PBFS iteration %?", i)); + info!("PBFS iteration %?", i); i += 1; colors = do colors.mapi() |i, c| { let c : color = *c; @@ -257,7 +258,7 @@ fn pbfs(&&graph: arc::ARC<graph>, key: node_id) -> bfs_result { let mut i = 0; while par::any(colors, is_gray_factory) { // Do the BFS. - log(info, fmt!("PBFS iteration %?", i)); + info!("PBFS iteration %?", i); i += 1; let old_len = colors.len(); @@ -320,7 +321,7 @@ fn validate(edges: ~[(node_id, node_id)], // parent chains back to the root. While we do this, we also // compute the levels for each node. - log(info, ~"Verifying tree structure..."); + info!(~"Verifying tree structure..."); let mut status = true; let level = do tree.map() |parent| { @@ -352,7 +353,7 @@ fn validate(edges: ~[(node_id, node_id)], // 2. Each tree edge connects vertices whose BFS levels differ by // exactly one. - log(info, ~"Verifying tree edges..."); + info!(~"Verifying tree edges..."); let status = do tree.alli() |k, parent| { if *parent != root && *parent != -1i64 { @@ -368,7 +369,7 @@ fn validate(edges: ~[(node_id, node_id)], // 3. Every edge in the input list has vertices with levels that // differ by at most one or that both are not in the BFS tree. - log(info, ~"Verifying graph edges..."); + info!(~"Verifying graph edges..."); let status = do edges.all() |e| { let (u, v) = *e; @@ -385,7 +386,7 @@ fn validate(edges: ~[(node_id, node_id)], // 5. A node and its parent are joined by an edge of the original // graph. - log(info, ~"Verifying tree and graph edges..."); + info!(~"Verifying tree and graph edges..."); let status = do par::alli(tree) { let edges = copy edges; diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs index 9825671bc8a..7993822afd8 100644 --- a/src/test/bench/noise.rs +++ b/src/test/bench/noise.rs @@ -1,5 +1,7 @@ // Perlin noise benchmark from https://gist.github.com/1170424 +use core::rand::RngUtil; + struct Vec2 { x: f32, y: f32, @@ -8,7 +10,7 @@ struct Vec2 { fn lerp(a: f32, b: f32, v: f32) -> f32 { a * (1.0 - v) + b * v } fn smooth(v: f32) -> f32 { v * v * (3.0 - 2.0 * v) } -fn random_gradient(r: rand::Rng) -> Vec2 { +fn random_gradient(r: @rand::Rng) -> Vec2 { let v = r.gen_float() * float::consts::pi * 2.0; Vec2{ x: float::cos(v) as f32, diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index 2bc89f64a29..8c371150e1e 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -57,7 +57,11 @@ fn select_random(r: u32, genelist: ~[AminoAcids]) -> char { return bisect(copy genelist, 0, vec::len::<AminoAcids>(genelist) - 1, r); } -fn make_random_fasta(wr: io::Writer, id: ~str, desc: ~str, genelist: ~[AminoAcids], n: int) { +fn make_random_fasta(wr: @io::Writer, + id: ~str, + desc: ~str, + genelist: ~[AminoAcids], + n: int) { wr.write_line(~">" + id + ~" " + desc); let rng = @mut MyRandom {last: rand::Rng().next()}; let mut op: ~str = ~""; @@ -72,7 +76,7 @@ fn make_random_fasta(wr: io::Writer, id: ~str, desc: ~str, genelist: ~[AminoAcid if str::len(op) > 0u { wr.write_line(op); } } -fn make_repeat_fasta(wr: io::Writer, id: ~str, desc: ~str, s: ~str, n: int) { +fn make_repeat_fasta(wr: @io::Writer, id: ~str, desc: ~str, s: ~str, n: int) { unsafe { wr.write_line(~">" + id + ~" " + desc); let mut op: ~str = ~""; diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index 146a4b8c869..eeea62d50fb 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -110,7 +110,7 @@ impl io::Writer for Devnull { fn writer(path: ~str, pport: comm::Port<Line>, size: uint) { - let cout: io::Writer = match path { + let cout: @io::Writer = match path { ~"" => { @Devnull as @io::Writer } diff --git a/src/test/bench/shootout-threadring.rs b/src/test/bench/shootout-threadring.rs new file mode 100644 index 00000000000..9eb8a29cec0 --- /dev/null +++ b/src/test/bench/shootout-threadring.rs @@ -0,0 +1,74 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Based on threadring.erlang by Jira Isa + +fn start(n_tasks: int, token: int) { + let mut (p, ch1) = comm::stream(); + ch1.send(token); + // XXX could not get this to work with a range closure + let mut i = 2; + while i <= n_tasks { + let (next_p, ch) = comm::stream(); + let imm_i = i; + let imm_p = p; + do task::spawn { + roundtrip(imm_i, n_tasks, &imm_p, &ch); + }; + p = next_p; + i += 1; + } + let imm_p = p; + let imm_ch = ch1; + do task::spawn { + roundtrip(1, n_tasks, &imm_p, &imm_ch); + } +} + +fn roundtrip(id: int, n_tasks: int, p: &comm::Port<int>, ch: &comm::Chan<int>) { + while (true) { + match p.recv() { + 1 => { + io::println(fmt!("%d\n", id)); + return; + } + token => { + debug!("thread: %d got token: %d", id, token); + ch.send(token - 1); + if token <= n_tasks { + return; + } + } + } + } +} + +fn main() { + let args = if os::getenv(~"RUST_BENCH").is_some() { + ~[~"", ~"2000000", ~"503"] + } + else { + os::args() + }; + let token = if args.len() > 1u { + int::from_str(args[1]).get() + } + else { + 1000 + }; + let n_tasks = if args.len() > 2u { + int::from_str(args[2]).get() + } + else { + 503 + }; + start(n_tasks, token); + +} diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index 78234ca0dfa..92320986ae8 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -12,9 +12,9 @@ extern mod std; -use std::bitv; use core::io::{ReaderUtil, WriterUtil}; use core::io; +use core::unstable::intrinsics::cttz16; // Computes a single solution to a given 9x9 sudoku // @@ -35,146 +35,241 @@ use core::io; // internal type of sudoku grids type grid = ~[~[u8]]; -// exported type of sudoku grids -pub enum grid_t { grid_ctor(grid), } - -// read a sudoku problem from file f -pub fn read_grid(f: io::Reader) -> grid_t { - fail_unless!(f.read_line() == ~"9,9"); /* assert first line is exactly "9,9" */ - - let mut g = vec::from_fn(10u, {|_i| - vec::from_elem(10u, 0 as u8) - }); - while !f.eof() { - let comps = str::split_char(str::trim(f.read_line()), ','); - if vec::len(comps) >= 3u { - let row = uint::from_str(comps[0]).get() as u8; - let col = uint::from_str(comps[1]).get() as u8; - g[row][col] = uint::from_str(comps[2]).get() as u8; +struct Sudoku { + grid: grid +} + +pub impl Sudoku { + static pub fn new(g: grid) -> Sudoku { + return Sudoku { grid: g } + } + + static 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] } + }; + return Sudoku::new(g) + } + + pub fn equal(&self, other: &Sudoku) -> bool { + for u8::range(0u8, 9u8) |row| { + for u8::range(0u8, 9u8) |col| { + if self.grid[row][col] != other.grid[row][col] { + return false; + } + } + } + return true; + } + + static pub fn read(reader: @io::Reader) -> Sudoku { + fail_unless!(reader.read_line() == ~"9,9"); /* assert first line is exactly "9,9" */ + + let mut g = vec::from_fn(10u, { |_i| ~[0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8] }); + while !reader.eof() { + let comps = str::split_char(str::trim(reader.read_line()), ','); + if vec::len(comps) == 3u { + let row = uint::from_str(comps[0]).get() as u8; + let col = uint::from_str(comps[1]).get() as u8; + g[row][col] = uint::from_str(comps[2]).get() as u8; + } + else { + fail!(~"Invalid sudoku file"); + } + } + return Sudoku::new(g) + } + + pub fn write(&self, writer: @io::Writer) { + for u8::range(0u8, 9u8) |row| { + writer.write_str(fmt!("%u", self.grid[row][0] as uint)); + for u8::range(1u8, 9u8) |col| { + writer.write_str(fmt!(" %u", self.grid[row][col] as uint)); + } + writer.write_char('\n'); + } + } + + // solve sudoku grid + pub fn solve(&mut self) { + let mut work: ~[(u8, u8)] = ~[]; /* queue of uncolored fields */ + for u8::range(0u8, 9u8) |row| { + for u8::range(0u8, 9u8) |col| { + let color = self.grid[row][col]; + if color == 0u8 { work += ~[(row, col)]; } + } + } + + let mut ptr = 0u; + let end = vec::len(work); + while (ptr < end) { + let (row, col) = work[ptr]; + // is there another color to try? + if self.next_color(row, col, self.grid[row][col] + (1 as u8)) { + // yes: advance work list + ptr = ptr + 1u; + } else { + // no: redo this field aft recoloring pred; unless there is none + if ptr == 0u { fail!(~"No solution found for this sudoku"); } + ptr = ptr - 1u; + } } } - return grid_ctor(g); -} -// solve sudoku grid -pub fn solve_grid(g: grid_t) { - fn next_color(mut g: grid, row: u8, col: u8, start_color: u8) -> bool { + fn next_color(&mut self, row: u8, col: u8, start_color: u8) -> bool { if start_color < 10u8 { // colors not yet used - let mut avail = bitv::Bitv::new(10u, false); - for u8::range(start_color, 10u8) |color| { - avail.set(color as uint, true); - } + let mut avail = ~Colors::new(start_color); // drop colors already in use in neighbourhood - drop_colors(copy g, copy avail, row, col); + self.drop_colors(avail, row, col); // find first remaining color that is available - for uint::range(1u, 10u) |i| { - if avail.get(i) { - g[row][col] = i as u8; - return true; - } - }; + let next = avail.next(); + self.grid[row][col] = next; + return 0u8 != next; } - g[row][col] = 0u8; + self.grid[row][col] = 0u8; return false; } // find colors available in neighbourhood of (row, col) - fn drop_colors(g: grid, avail: bitv::Bitv, row: u8, col: u8) { - fn drop_color(g: grid, mut colors: bitv::Bitv, row: u8, col: u8) { - let color = g[row][col]; - if color != 0u8 { colors.set(color as uint, false); } - } - - let it = |a,b| drop_color(copy g, copy avail, a, b); - + fn drop_colors(&mut self, avail: &mut Colors, row: u8, col: u8) { for u8::range(0u8, 9u8) |idx| { - it(idx, col); /* check same column fields */ - it(row, idx); /* check same row fields */ + avail.remove(self.grid[idx][col]); /* check same column fields */ + avail.remove(self.grid[row][idx]); /* check same row fields */ } // check same block fields let row0 = (row / 3u8) * 3u8; let col0 = (col / 3u8) * 3u8; for u8::range(row0, row0 + 3u8) |alt_row| { - for u8::range(col0, col0 + 3u8) |alt_col| { it(alt_row, alt_col); } + for u8::range(col0, col0 + 3u8) |alt_col| { avail.remove(self.grid[alt_row][alt_col]); } } } +} + +// Stores available colors as simple bitfield, bit 0 is always unset +struct Colors(u16); + +const heads: u16 = (1u16 << 10) - 1; /* bits 9..0 */ + +impl Colors { + static fn new(start_color: u8) -> Colors { + // Sets bits 9..start_color + let tails = !0u16 << start_color; + return Colors(heads & tails); + } - let mut work: ~[(u8, u8)] = ~[]; /* queue of uncolored fields */ - for u8::range(0u8, 9u8) |row| { - for u8::range(0u8, 9u8) |col| { - let color = (*g)[row][col]; - if color == 0u8 { work += ~[(row, col)]; } + fn next(&self) -> u8 { + let val = **self & heads; + if (0u16 == val) { + return 0u8; + } + else + { + return cttz16(val as i16) as u8; } } - let mut ptr = 0u; - let end = vec::len(work); - while (ptr < end) { - let (row, col) = work[ptr]; - // is there another color to try? - if next_color(copy *g, row, col, (*g)[row][col] + (1 as u8)) { - // yes: advance work list - ptr = ptr + 1u; - } else { - // no: redo this field aft recoloring pred; unless there is none - if ptr == 0u { fail!(~"No solution found for this sudoku"); } - ptr = ptr - 1u; + fn remove(&mut self, color: u8) { + if color != 0u8 { + let val = **self; + let mask = !(1u16 << color); + *self = Colors(val & mask); } } } -pub fn write_grid(f: io::Writer, g: grid_t) { - for u8::range(0u8, 9u8) |row| { - f.write_str(fmt!("%u", (*g)[row][0] as uint)); - for u8::range(1u8, 9u8) |col| { - f.write_str(fmt!(" %u", (*g)[row][col] as uint)); - } - f.write_char('\n'); - } +const 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], + /* 2 */ [7u8, 0u8, 0u8, 8u8, 0u8, 0u8, 0u8, 0u8, 0u8], + /* 3 */ [0u8, 0u8, 0u8, 5u8, 0u8, 0u8, 0u8, 0u8, 0u8], + /* 4 */ [0u8, 5u8, 0u8, 0u8, 0u8, 3u8, 6u8, 0u8, 0u8], + /* 5 */ [6u8, 8u8, 0u8, 0u8, 0u8, 0u8, 0u8, 9u8, 0u8], + /* 6 */ [0u8, 9u8, 5u8, 0u8, 0u8, 6u8, 0u8, 7u8, 0u8], + /* 7 */ [0u8, 0u8, 0u8, 0u8, 4u8, 0u8, 0u8, 6u8, 0u8], + /* 8 */ [4u8, 0u8, 0u8, 0u8, 0u8, 7u8, 2u8, 0u8, 3u8] +]; + +#[cfg(test)] +const 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], + /* 2 */ [7u8, 2u8, 6u8, 8u8, 3u8, 4u8, 1u8, 5u8, 9u8], + /* 3 */ [9u8, 1u8, 4u8, 5u8, 6u8, 8u8, 3u8, 2u8, 7u8], + /* 4 */ [2u8, 5u8, 7u8, 4u8, 9u8, 3u8, 6u8, 1u8, 8u8], + /* 5 */ [6u8, 8u8, 3u8, 7u8, 1u8, 2u8, 5u8, 9u8, 4u8], + /* 6 */ [3u8, 9u8, 5u8, 2u8, 8u8, 6u8, 4u8, 7u8, 1u8], + /* 7 */ [8u8, 7u8, 2u8, 3u8, 4u8, 1u8, 9u8, 6u8, 5u8], + /* 8 */ [4u8, 6u8, 1u8, 9u8, 5u8, 7u8, 2u8, 8u8, 3u8] +]; + +#[test] +fn colors_new_works() { + fail_unless!(*Colors::new(1) == 1022u16); + fail_unless!(*Colors::new(2) == 1020u16); + fail_unless!(*Colors::new(3) == 1016u16); + fail_unless!(*Colors::new(4) == 1008u16); + fail_unless!(*Colors::new(5) == 992u16); + fail_unless!(*Colors::new(6) == 960u16); + fail_unless!(*Colors::new(7) == 896u16); + fail_unless!(*Colors::new(8) == 768u16); + fail_unless!(*Colors::new(9) == 512u16); +} + +#[test] +fn colors_next_works() { + fail_unless!(Colors(0).next() == 0u8); + fail_unless!(Colors(2).next() == 1u8); + fail_unless!(Colors(4).next() == 2u8); + fail_unless!(Colors(8).next() == 3u8); + fail_unless!(Colors(16).next() == 4u8); + fail_unless!(Colors(32).next() == 5u8); + fail_unless!(Colors(64).next() == 6u8); + fail_unless!(Colors(128).next() == 7u8); + fail_unless!(Colors(256).next() == 8u8); + fail_unless!(Colors(512).next() == 9u8); + fail_unless!(Colors(1024).next() == 0u8); +} + +#[test] +fn colors_remove_works() { + // GIVEN + let mut colors = Colors::new(1); + + // WHEN + colors.remove(1); + + // THEN + fail_unless!(colors.next() == 2u8); +} + +#[test] +fn check_default_sudoku_solution() { + // GIVEN + let mut sudoku = Sudoku::from_vec(&default_sudoku); + let solution = Sudoku::from_vec(&default_solution); + + // WHEN + sudoku.solve(); + + // THEN + fail_unless!(sudoku.equal(&solution)); } fn main() { - let args = os::args(); - let grid = if vec::len(args) == 1u { - // FIXME create sudoku inline since nested vec consts dont work yet - // (#3733) - let mut g = vec::from_fn(10u, |_i| { - vec::from_elem(10u, 0 as u8) - }); - g[0][1] = 4u8; - g[0][3] = 6u8; - g[0][7] = 3u8; - g[0][8] = 2u8; - g[1][2] = 8u8; - g[1][4] = 2u8; - g[2][0] = 7u8; - g[2][3] = 8u8; - g[3][3] = 5u8; - g[4][1] = 5u8; - g[4][5] = 3u8; - g[4][6] = 6u8; - g[5][0] = 6u8; - g[5][1] = 8u8; - g[5][7] = 9u8; - g[6][1] = 9u8; - g[6][2] = 5u8; - g[6][5] = 6u8; - g[6][7] = 7u8; - g[7][4] = 4u8; - g[7][7] = 6u8; - g[8][0] = 4u8; - g[8][5] = 7u8; - g[8][6] = 2u8; - g[8][8] = 3u8; - grid_ctor(g) + let args = os::args(); + let use_default = vec::len(args) == 1u; + let mut sudoku = if use_default { + Sudoku::from_vec(&default_sudoku) } else { - read_grid(io::stdin()) + Sudoku::read(io::stdin()) }; - solve_grid(copy grid); - write_grid(io::stdout(), grid); + sudoku.solve(); + sudoku.write(io::stdout()); } diff --git a/src/test/bench/task-perf-jargon-metal-smoke.rs b/src/test/bench/task-perf-jargon-metal-smoke.rs index 9bdc5aae3f2..17b7d1d2948 100644 --- a/src/test/bench/task-perf-jargon-metal-smoke.rs +++ b/src/test/bench/task-perf-jargon-metal-smoke.rs @@ -19,7 +19,7 @@ use core::cell::Cell; -fn child_generation(gens_left: uint, -c: comm::Chan<()>) { +fn child_generation(gens_left: uint, c: comm::Chan<()>) { // This used to be O(n^2) in the number of generations that ever existed. // With this code, only as many generations are alive at a time as tasks // alive at a time, diff --git a/src/test/compile-fail/alt-join.rs b/src/test/compile-fail/alt-join.rs index 94488fbb552..73f2c81302c 100644 --- a/src/test/compile-fail/alt-join.rs +++ b/src/test/compile-fail/alt-join.rs @@ -16,6 +16,6 @@ fn my_fail() -> ! { fail!(); } fn main() { match true { false => { my_fail(); } true => { } } - log(debug, x); //~ ERROR unresolved name: `x`. + debug!(x); //~ ERROR unresolved name: `x`. let x: int; } diff --git a/src/test/compile-fail/ambig_impl_2_exe.rs b/src/test/compile-fail/ambig_impl_2_exe.rs index ed18abe9bf0..1cf08b7f503 100644 --- a/src/test/compile-fail/ambig_impl_2_exe.rs +++ b/src/test/compile-fail/ambig_impl_2_exe.rs @@ -13,8 +13,8 @@ extern mod ambig_impl_2_lib; use ambig_impl_2_lib::me; trait me { - fn me() -> uint; + fn me(&self) -> uint; } -impl me for uint { fn me() -> uint { self } } //~ NOTE is `__extensions__::me` +impl me for uint { fn me(&self) -> uint { *self } } //~ NOTE is `__extensions__::me` fn main() { 1u.me(); } //~ ERROR multiple applicable methods in scope //~^ NOTE is `ambig_impl_2_lib::__extensions__::me` diff --git a/src/test/compile-fail/ambig_impl_bounds.rs b/src/test/compile-fail/ambig_impl_bounds.rs index 92581d756db..9f26e5ae9b3 100644 --- a/src/test/compile-fail/ambig_impl_bounds.rs +++ b/src/test/compile-fail/ambig_impl_bounds.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait A { fn foo(); } -trait B { fn foo(); } +trait A { fn foo(&self); } +trait B { fn foo(&self); } fn foo<T:A + B>(t: T) { t.foo(); //~ ERROR multiple applicable methods in scope diff --git a/src/test/compile-fail/ambig_impl_unify.rs b/src/test/compile-fail/ambig_impl_unify.rs index 7e27a51ccdd..ce8c2a29544 100644 --- a/src/test/compile-fail/ambig_impl_unify.rs +++ b/src/test/compile-fail/ambig_impl_unify.rs @@ -9,15 +9,15 @@ // except according to those terms. trait foo { - fn foo() -> int; + fn foo(&self) -> int; } impl foo for ~[uint] { - fn foo() -> int {1} //~ NOTE candidate #1 is `__extensions__::foo` + fn foo(&self) -> int {1} //~ NOTE candidate #1 is `__extensions__::foo` } impl foo for ~[int] { - fn foo() -> int {2} //~ NOTE candidate #2 is `__extensions__::foo` + fn foo(&self) -> int {2} //~ NOTE candidate #2 is `__extensions__::foo` } fn main() { diff --git a/src/test/compile-fail/assign-to-method.rs b/src/test/compile-fail/assign-to-method.rs index 2436e4da8df..4993846f445 100644 --- a/src/test/compile-fail/assign-to-method.rs +++ b/src/test/compile-fail/assign-to-method.rs @@ -16,7 +16,7 @@ struct cat { pub impl cat { - fn speak() { self.meows += 1u; } + fn speak(&self) { self.meows += 1u; } } fn cat(in_x : uint, in_y : int) -> cat { diff --git a/src/test/compile-fail/attempted-access-non-fatal.rs b/src/test/compile-fail/attempted-access-non-fatal.rs index 06dd154c279..ba15abc3f89 100644 --- a/src/test/compile-fail/attempted-access-non-fatal.rs +++ b/src/test/compile-fail/attempted-access-non-fatal.rs @@ -11,6 +11,6 @@ // Check that bogus field access is non-fatal fn main() { let x = 0; - log(debug, x.foo); //~ ERROR attempted access of field - log(debug, x.bar); //~ ERROR attempted access of field + debug!(x.foo); //~ ERROR attempted access of field + debug!(x.bar); //~ ERROR attempted access of field } diff --git a/src/test/compile-fail/auto-ref-borrowck-failure.rs b/src/test/compile-fail/auto-ref-borrowck-failure.rs index 3cf1c770df7..9fe7ae40dbb 100644 --- a/src/test/compile-fail/auto-ref-borrowck-failure.rs +++ b/src/test/compile-fail/auto-ref-borrowck-failure.rs @@ -15,11 +15,11 @@ struct Foo { } trait Stuff { - fn printme(); + fn printme(self); } impl Stuff for &'self mut Foo { - fn printme() { + fn printme(self) { io::println(fmt!("%d", self.x)); } } diff --git a/src/test/compile-fail/autoderef-full-lval.rs b/src/test/compile-fail/autoderef-full-lval.rs index 25ae0308732..8178b46d1d3 100644 --- a/src/test/compile-fail/autoderef-full-lval.rs +++ b/src/test/compile-fail/autoderef-full-lval.rs @@ -22,11 +22,11 @@ fn main() { let a: clam = clam{x: @1, y: @2}; let b: clam = clam{x: @10, y: @20}; let z: int = a.x + b.y; - log(debug, z); + debug!(z); fail_unless!((z == 21)); let forty: fish = fish{a: @40}; let two: fish = fish{a: @2}; let answer: int = forty.a + two.a; - log(debug, answer); + debug!(answer); fail_unless!((answer == 42)); } diff --git a/src/test/compile-fail/bad-const-type.rs b/src/test/compile-fail/bad-const-type.rs index 3c28472ce79..e35d5e79bde 100644 --- a/src/test/compile-fail/bad-const-type.rs +++ b/src/test/compile-fail/bad-const-type.rs @@ -11,4 +11,4 @@ // error-pattern:expected `~str` but found `int` const i: str = 10i; -fn main() { log(debug, i); } +fn main() { debug!(i); } diff --git a/src/test/compile-fail/bad-method-typaram-kind.rs b/src/test/compile-fail/bad-method-typaram-kind.rs index 7032a3a0b22..d5b8f99ada0 100644 --- a/src/test/compile-fail/bad-method-typaram-kind.rs +++ b/src/test/compile-fail/bad-method-typaram-kind.rs @@ -13,11 +13,11 @@ fn foo<T>() { } trait bar { - fn bar<T:Copy>(); + fn bar<T:Copy>(&self); } impl bar for uint { - fn bar<T:Copy>() { + fn bar<T:Copy>(&self) { } } diff --git a/src/test/compile-fail/block-arg-as-stmt-with-value.rs b/src/test/compile-fail/block-arg-as-stmt-with-value.rs index 1ef5ae16079..b4b10db9398 100644 --- a/src/test/compile-fail/block-arg-as-stmt-with-value.rs +++ b/src/test/compile-fail/block-arg-as-stmt-with-value.rs @@ -18,6 +18,6 @@ fn compute1() -> float { fn main() { let x = compute1(); - log(debug, x); + debug!(x); fail_unless!((x == -4f)); } diff --git a/src/test/compile-fail/block-coerce-no.rs b/src/test/compile-fail/block-coerce-no.rs index 980dc66b4af..bdde5144b04 100644 --- a/src/test/compile-fail/block-coerce-no.rs +++ b/src/test/compile-fail/block-coerce-no.rs @@ -21,6 +21,6 @@ fn coerce(b: &fn()) -> extern fn() { fn main() { let i = 8; - let f = coerce(|| log(error, i) ); + let f = coerce(|| error!(i) ); f(); } diff --git a/src/test/compile-fail/borrowck-addr-of-upvar.rs b/src/test/compile-fail/borrowck-addr-of-upvar.rs index 4e8af4f0421..640bc887731 100644 --- a/src/test/compile-fail/borrowck-addr-of-upvar.rs +++ b/src/test/compile-fail/borrowck-addr-of-upvar.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(x: @int) -> @fn() -> &static/int { - let result: @fn() -> &static/int = || &*x; //~ ERROR illegal borrow +fn foo(x: @int) -> @fn() -> &'static int { + let result: @fn() -> &'static int = || &*x; //~ ERROR illegal borrow result } diff --git a/src/test/compile-fail/borrowck-autoref-3261.rs b/src/test/compile-fail/borrowck-autoref-3261.rs index b874eac34b1..c95b93445ad 100644 --- a/src/test/compile-fail/borrowck-autoref-3261.rs +++ b/src/test/compile-fail/borrowck-autoref-3261.rs @@ -10,8 +10,8 @@ struct X(Either<(uint,uint),extern fn()>); -pub impl &'self X { - fn with(blk: &fn(x: &Either<(uint,uint),extern fn()>)) { +pub impl X { + fn with(&self, blk: &fn(x: &Either<(uint,uint),extern fn()>)) { blk(&**self) } } diff --git a/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs b/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs index 61cf346ffa4..23debb4c5e2 100644 --- a/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs +++ b/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs @@ -20,7 +20,7 @@ impl ops::Add<int,int> for Point { } pub impl Point { - fn times(z: int) -> int { + fn times(&self, z: int) -> int { self.x * self.y * z } } diff --git a/src/test/compile-fail/borrowck-loan-rcvr.rs b/src/test/compile-fail/borrowck-loan-rcvr.rs index 85989bf9d21..4a7228dcca3 100644 --- a/src/test/compile-fail/borrowck-loan-rcvr.rs +++ b/src/test/compile-fail/borrowck-loan-rcvr.rs @@ -11,18 +11,18 @@ struct point { x: int, y: int } trait methods { - fn impurem(); - fn blockm(f: &fn()); - pure fn purem(); + fn impurem(&self); + fn blockm(&self, f: &fn()); + pure fn purem(&self); } impl methods for point { - fn impurem() { + fn impurem(&self) { } - fn blockm(f: &fn()) { f() } + fn blockm(&self, f: &fn()) { f() } - pure fn purem() { + pure fn purem(&self) { } } diff --git a/src/test/compile-fail/borrowck-mut-addr-of-imm-var.rs b/src/test/compile-fail/borrowck-mut-addr-of-imm-var.rs index 4e176e9fbae..d0b0f51d0cf 100644 --- a/src/test/compile-fail/borrowck-mut-addr-of-imm-var.rs +++ b/src/test/compile-fail/borrowck-mut-addr-of-imm-var.rs @@ -12,5 +12,5 @@ fn main() { let x: int = 3; let y: &mut int = &mut x; //~ ERROR illegal borrow *y = 5; - log (debug, *y); + debug!(*y); } diff --git a/src/test/compile-fail/borrowck-pat-enum-in-box.rs b/src/test/compile-fail/borrowck-pat-enum-in-box.rs index fe5f474a5f2..bd1001bf38c 100644 --- a/src/test/compile-fail/borrowck-pat-enum-in-box.rs +++ b/src/test/compile-fail/borrowck-pat-enum-in-box.rs @@ -22,17 +22,6 @@ fn match_const_box(v: &const @const Option<int>) -> int { } } -pure fn pure_process(_i: int) {} - -fn match_const_box_and_do_pure_things(v: &const @const Option<int>) { - match *v { - @Some(ref i) => { - pure_process(*i) - } - @None => {} - } -} - fn process(_i: int) {} fn match_const_box_and_do_bad_things(v: &const @const Option<int>) { diff --git a/src/test/compile-fail/borrowck-pure-scope-in-call.rs b/src/test/compile-fail/borrowck-pure-scope-in-call.rs deleted file mode 100644 index 7ff13739ba7..00000000000 --- a/src/test/compile-fail/borrowck-pure-scope-in-call.rs +++ /dev/null @@ -1,33 +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 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -pure fn pure_borrow(_x: &int, _y: ()) {} - -fn test1(x: @mut ~int) { - // Here, evaluating the second argument actually invalidates the - // first borrow, even though it occurs outside of the scope of the - // borrow! - pure_borrow(*x, *x = ~5); //~ ERROR illegal borrow unless pure - //~^ NOTE impure due to assigning to dereference of mutable @ pointer -} - -fn test2() { - let mut x = ~1; - - // Same, but for loanable data: - - pure_borrow(x, x = ~5); //~ ERROR assigning to mutable local variable prohibited due to outstanding loan - //~^ NOTE loan of mutable local variable granted here - - copy x; -} - -fn main() { -} diff --git a/src/test/compile-fail/class-cast-to-trait.rs b/src/test/compile-fail/class-cast-to-trait.rs index 092fb4a5b66..06627365451 100644 --- a/src/test/compile-fail/class-cast-to-trait.rs +++ b/src/test/compile-fail/class-cast-to-trait.rs @@ -9,7 +9,7 @@ // except according to those terms. trait noisy { - fn speak(); + fn speak(&self); } struct cat { @@ -21,7 +21,7 @@ struct cat { pub impl cat { - fn eat() -> bool { + fn eat(&self) -> bool { if self.how_hungry > 0 { error!("OM NOM NOM"); self.how_hungry -= 2; @@ -35,12 +35,12 @@ pub impl cat { } impl noisy for cat { - fn speak() { self.meow(); } + fn speak(&self) { self.meow(); } } priv impl cat { - fn meow() { + fn meow(&self) { error!("Meow"); self.meows += 1; if self.meows % 5 == 0 { @@ -58,6 +58,6 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { } fn main() { - let nyan : noisy = @cat(0, 2, ~"nyan") as @noisy; + let nyan : @noisy = @cat(0, 2, ~"nyan") as @noisy; nyan.eat(); //~ ERROR type `@noisy` does not implement any method in scope named `eat` } diff --git a/src/test/compile-fail/class-method-missing.rs b/src/test/compile-fail/class-method-missing.rs index 2a7e2cea6fa..f3c5ab2019d 100644 --- a/src/test/compile-fail/class-method-missing.rs +++ b/src/test/compile-fail/class-method-missing.rs @@ -10,7 +10,7 @@ // error-pattern:missing method `eat` trait animal { - fn eat(); + fn eat(&self); } struct cat { diff --git a/src/test/compile-fail/class-missing-self.rs b/src/test/compile-fail/class-missing-self.rs index 9d3eb644656..b78b065d028 100644 --- a/src/test/compile-fail/class-missing-self.rs +++ b/src/test/compile-fail/class-missing-self.rs @@ -13,8 +13,8 @@ struct cat { } priv impl cat { - fn sleep() { loop{} } - fn meow() { + fn sleep(&self) { loop{} } + fn meow(&self) { error!("Meow"); meows += 1u; //~ ERROR unresolved name sleep(); //~ ERROR unresolved name diff --git a/src/test/compile-fail/const-cast-different-types.rs b/src/test/compile-fail/const-cast-different-types.rs index 08fa6915106..45e39b47d23 100644 --- a/src/test/compile-fail/const-cast-different-types.rs +++ b/src/test/compile-fail/const-cast-different-types.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -const a: &static/str = &"foo"; +const a: &'static str = &"foo"; const b: *u8 = a as *u8; //~ ERROR non-scalar cast const c: *u8 = &a as *u8; //~ ERROR mismatched types diff --git a/src/test/compile-fail/copy-a-resource.rs b/src/test/compile-fail/copy-a-resource.rs index f1b31d66b3f..2767447d819 100644 --- a/src/test/compile-fail/copy-a-resource.rs +++ b/src/test/compile-fail/copy-a-resource.rs @@ -26,5 +26,5 @@ fn main() { let x = foo(10); let _y = copy x; //~^ ERROR copying a value of non-copyable type `foo` - log(error, x); + error!(x); } diff --git a/src/test/compile-fail/dead-code-ret.rs b/src/test/compile-fail/dead-code-ret.rs index f564f582182..182a41c1b17 100644 --- a/src/test/compile-fail/dead-code-ret.rs +++ b/src/test/compile-fail/dead-code-ret.rs @@ -12,7 +12,7 @@ // error-pattern: dead -fn f(caller: str) { log(debug, caller); } +fn f(caller: str) { debug!(caller); } fn main() { return f("main"); debug!("Paul is dead"); } diff --git a/src/test/compile-fail/explicit-call-to-supertrait-dtor.rs b/src/test/compile-fail/explicit-call-to-supertrait-dtor.rs index 3b1dda19448..26b13566f7a 100644 --- a/src/test/compile-fail/explicit-call-to-supertrait-dtor.rs +++ b/src/test/compile-fail/explicit-call-to-supertrait-dtor.rs @@ -13,7 +13,7 @@ struct Foo { } trait Bar : Drop { - fn blah(); + fn blah(&self); } impl Drop for Foo { @@ -23,7 +23,7 @@ impl Drop for Foo { } impl Bar for Foo { - fn blah() { + fn blah(&self) { self.finalize(); //~ ERROR explicit call to destructor } } diff --git a/src/test/compile-fail/if-without-else-result.rs b/src/test/compile-fail/if-without-else-result.rs index 58e78953d5a..e822be75945 100644 --- a/src/test/compile-fail/if-without-else-result.rs +++ b/src/test/compile-fail/if-without-else-result.rs @@ -12,5 +12,5 @@ fn main() { let a = if true { true }; - log(debug, a); + debug!(a); } diff --git a/src/test/compile-fail/index_message.rs b/src/test/compile-fail/index_message.rs index 1c5b1a117e0..3611dbb6866 100644 --- a/src/test/compile-fail/index_message.rs +++ b/src/test/compile-fail/index_message.rs @@ -10,5 +10,5 @@ fn main() { let z = (); - log(debug, z[0]); //~ ERROR cannot index a value of type `()` + debug!(z[0]); //~ ERROR cannot index a value of type `()` } diff --git a/src/test/compile-fail/infinite-instantiation.rs b/src/test/compile-fail/infinite-instantiation.rs index 21f49b11f66..605453d1bca 100644 --- a/src/test/compile-fail/infinite-instantiation.rs +++ b/src/test/compile-fail/infinite-instantiation.rs @@ -12,18 +12,18 @@ // issue 2258 trait to_opt { - fn to_option() -> Option<Self>; + fn to_option(&self) -> Option<Self>; } impl to_opt for uint { - fn to_option() -> Option<uint> { - Some(self) + fn to_option(&self) -> Option<uint> { + Some(*self) } } impl<T:Copy> to_opt for Option<T> { - fn to_option() -> Option<Option<T>> { - Some(self) + fn to_option(&self) -> Option<Option<T>> { + Some(*self) } } diff --git a/src/test/compile-fail/issue-1476.rs b/src/test/compile-fail/issue-1476.rs index 7a45ecc83b0..1d58a4229d3 100644 --- a/src/test/compile-fail/issue-1476.rs +++ b/src/test/compile-fail/issue-1476.rs @@ -9,5 +9,5 @@ // except according to those terms. fn main() { - log(error, x); //~ ERROR unresolved name: `x`. + error!(x); //~ ERROR unresolved name: `x`. } diff --git a/src/test/compile-fail/issue-2149.rs b/src/test/compile-fail/issue-2149.rs index 361a20ad451..da3728ff3ae 100644 --- a/src/test/compile-fail/issue-2149.rs +++ b/src/test/compile-fail/issue-2149.rs @@ -9,11 +9,11 @@ // except according to those terms. trait vec_monad<A> { - fn bind<B>(f: &fn(A) -> ~[B]); + fn bind<B>(&self, f: &fn(A) -> ~[B]); } impl<A> vec_monad<A> for ~[A] { - fn bind<B>(f: &fn(A) -> ~[B]) { + fn bind<B>(&self, f: &fn(A) -> ~[B]) { let mut r = fail!(); for self.each |elt| { r += f(*elt); } //~^ WARNING unreachable expression @@ -22,6 +22,6 @@ impl<A> vec_monad<A> for ~[A] { } fn main() { ["hi"].bind(|x| [x] ); - //~^ ERROR type `[&static/str * 1]` does not implement any method in scope named `bind` + //~^ ERROR type `[&'static str * 1]` does not implement any method in scope named `bind` //~^^ ERROR Unconstrained region variable } diff --git a/src/test/compile-fail/issue-2151.rs b/src/test/compile-fail/issue-2151.rs index a9f0ddbe743..e2bbda7d65a 100644 --- a/src/test/compile-fail/issue-2151.rs +++ b/src/test/compile-fail/issue-2151.rs @@ -10,7 +10,7 @@ fn main() { for vec::each(fail!()) |i| { - log (debug, i * 2); + debug!(i * 2); //~^ ERROR the type of this value must be known }; } diff --git a/src/test/compile-fail/issue-2330.rs b/src/test/compile-fail/issue-2330.rs index e255d46633a..d8acbf2893a 100644 --- a/src/test/compile-fail/issue-2330.rs +++ b/src/test/compile-fail/issue-2330.rs @@ -11,12 +11,12 @@ enum chan { } trait channel<T> { - fn send(v: T); + fn send(&self, v: T); } // `chan` is not a trait, it's an enum impl chan for int { //~ ERROR can only implement trait types - fn send(v: int) { fail!() } + fn send(&self, v: int) { fail!() } } fn main() { diff --git a/src/test/compile-fail/issue-2370-2.rs b/src/test/compile-fail/issue-2370-2.rs index a1126f305e7..540089bd59d 100644 --- a/src/test/compile-fail/issue-2370-2.rs +++ b/src/test/compile-fail/issue-2370-2.rs @@ -15,5 +15,5 @@ struct cat { fn main() { let kitty : cat = cat { x: () }; - log (error, *kitty); + error!(*kitty); } diff --git a/src/test/compile-fail/issue-2370.rs b/src/test/compile-fail/issue-2370.rs index 1d9d3de16d0..cd17cc2afaa 100644 --- a/src/test/compile-fail/issue-2370.rs +++ b/src/test/compile-fail/issue-2370.rs @@ -15,5 +15,5 @@ struct cat { fn main() { let nyan = cat { foo: () }; - log (error, *nyan); + error!(*nyan); } diff --git a/src/test/compile-fail/issue-2467.rs b/src/test/compile-fail/issue-2467.rs index 6d31deea3ff..aec14e7b719 100644 --- a/src/test/compile-fail/issue-2467.rs +++ b/src/test/compile-fail/issue-2467.rs @@ -11,6 +11,6 @@ enum test { thing = 3u } //~ ERROR mismatched types //~^ ERROR expected signed integer constant fn main() { - log(error, thing as int); + error!(thing as int); fail_unless!((thing as int == 3)); } diff --git a/src/test/compile-fail/issue-2478.rs b/src/test/compile-fail/issue-2478.rs index 5bde7c67935..2b52cab7fe7 100644 --- a/src/test/compile-fail/issue-2478.rs +++ b/src/test/compile-fail/issue-2478.rs @@ -9,7 +9,7 @@ // except according to those terms. // xfail-test -fn foo() -> &a/int { +fn foo() -> &'a int { return &x; } const x: int = 5; diff --git a/src/test/compile-fail/issue-2590.rs b/src/test/compile-fail/issue-2590.rs index 5f26adfcdc7..7a99ab8a94f 100644 --- a/src/test/compile-fail/issue-2590.rs +++ b/src/test/compile-fail/issue-2590.rs @@ -13,11 +13,11 @@ struct parser { } trait parse { - fn parse() -> ~[int]; + fn parse(&self) -> ~[int]; } impl parse for parser { - fn parse() -> ~[int] { + fn parse(&self) -> ~[int] { self.tokens //~ ERROR moving out of immutable field } } diff --git a/src/test/compile-fail/issue-2611-5.rs b/src/test/compile-fail/issue-2611-5.rs index b0e2878c46b..9840650fa2e 100644 --- a/src/test/compile-fail/issue-2611-5.rs +++ b/src/test/compile-fail/issue-2611-5.rs @@ -12,7 +12,7 @@ // an impl against a trait trait A { - fn b<C:Copy,D>(x: C) -> C; + fn b<C:Copy,D>(&self, x: C) -> C; } struct E { @@ -21,7 +21,7 @@ struct E { impl A for E { // n.b. The error message is awful -- see #3404 - fn b<F:Copy,G>(_x: G) -> G { fail!() } //~ ERROR method `b` has an incompatible type + fn b<F:Copy,G>(&self, _x: G) -> G { fail!() } //~ ERROR method `b` has an incompatible type } fn main() {} diff --git a/src/test/compile-fail/issue-3021-c.rs b/src/test/compile-fail/issue-3021-c.rs index f5bcae5377c..4fc4c005cf6 100644 --- a/src/test/compile-fail/issue-3021-c.rs +++ b/src/test/compile-fail/issue-3021-c.rs @@ -13,7 +13,7 @@ extern mod std; fn siphash<T>() { trait t { - fn g(x: T) -> T; //~ ERROR attempt to use a type argument out of scope + fn g(&self, x: T) -> T; //~ ERROR attempt to use a type argument out of scope //~^ ERROR attempt to use a type argument out of scope //~^^ ERROR use of undeclared type name `T` //~^^^ ERROR use of undeclared type name `T` diff --git a/src/test/compile-fail/issue-3021-d.rs b/src/test/compile-fail/issue-3021-d.rs index 4efbec92948..2daf3e7a210 100644 --- a/src/test/compile-fail/issue-3021-d.rs +++ b/src/test/compile-fail/issue-3021-d.rs @@ -11,8 +11,8 @@ extern mod std; trait siphash { - fn result() -> u64; - fn reset(); + fn result(&self) -> u64; + fn reset(&self); } fn siphash(k0 : u64, k1 : u64) -> siphash { @@ -29,13 +29,13 @@ fn siphash(k0 : u64, k1 : u64) -> siphash { } impl siphash for SipState { - fn reset() { + fn reset(&self) { self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture //~^ ERROR unresolved name: `k0`. self.v1 = k1 ^ 0x646f72616e646f6d; //~ ERROR attempted dynamic environment-capture //~^ ERROR unresolved name: `k1`. } - fn result() -> u64 { return mk_result(self); } + fn result(&self) -> u64 { return mk_result(self); } } } diff --git a/src/test/compile-fail/issue-3021.rs b/src/test/compile-fail/issue-3021.rs index 117156748ae..343683d79c1 100644 --- a/src/test/compile-fail/issue-3021.rs +++ b/src/test/compile-fail/issue-3021.rs @@ -11,7 +11,7 @@ extern mod std; trait SipHash { - fn reset(); + fn reset(&self); } fn siphash(k0 : u64) -> SipHash { @@ -20,7 +20,7 @@ fn siphash(k0 : u64) -> SipHash { } impl SipHash for SipState { - fn reset() { + fn reset(&self) { self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture //~^ ERROR unresolved name: `k0`. } diff --git a/src/test/compile-fail/issue-3038.rs b/src/test/compile-fail/issue-3038.rs index 7a20b83c034..4ed21bc30e1 100644 --- a/src/test/compile-fail/issue-3038.rs +++ b/src/test/compile-fail/issue-3038.rs @@ -19,13 +19,13 @@ fn main() { let _z = match g(1, 2) { - g(x, x) => { log(debug, x + x); } + g(x, x) => { debug!(x + x); } //~^ ERROR Identifier x is bound more than once in the same pattern }; let _z = match i(l(1, 2), m(3, 4)) { i(l(x, _), m(_, x)) //~ ERROR Identifier x is bound more than once in the same pattern - => { log(error, x + x); } + => { error!(x + x); } }; let _z = match (1, 2) { diff --git a/src/test/compile-fail/issue-3243.rs b/src/test/compile-fail/issue-3243.rs index 443fae619ba..f235c4bc97c 100644 --- a/src/test/compile-fail/issue-3243.rs +++ b/src/test/compile-fail/issue-3243.rs @@ -10,7 +10,7 @@ // xfail-test fn function() -> &mut [int] { - let mut x: &static/mut [int] = &[1,2,3]; + let mut x: &'static mut [int] = &[1,2,3]; x[0] = 12345; x //~ ERROR bad } diff --git a/src/test/compile-fail/issue-3311.rs b/src/test/compile-fail/issue-3311.rs index 8872357a8d4..1b83cefbf33 100644 --- a/src/test/compile-fail/issue-3311.rs +++ b/src/test/compile-fail/issue-3311.rs @@ -15,7 +15,7 @@ struct Foo { } pub impl Foo<'self> { - fn get_s(&self) -> &self/str { + fn get_s(&self) -> &'self str { self.s } } diff --git a/src/test/compile-fail/issue-3521-2.rs b/src/test/compile-fail/issue-3521-2.rs index d8f689be432..39c14b4d316 100644 --- a/src/test/compile-fail/issue-3521-2.rs +++ b/src/test/compile-fail/issue-3521-2.rs @@ -13,5 +13,5 @@ fn main() { const y: int = foo + 1; //~ ERROR: attempt to use a non-constant value in a constant - log(error, y); + error!(y); } diff --git a/src/test/compile-fail/issue-3521.rs b/src/test/compile-fail/issue-3521.rs index e8e63e0700b..d070a9735e4 100644 --- a/src/test/compile-fail/issue-3521.rs +++ b/src/test/compile-fail/issue-3521.rs @@ -15,5 +15,5 @@ fn main() { Bar = foo //~ ERROR attempt to use a non-constant value in a constant } - log(error, Bar); + error!(Bar); } diff --git a/src/test/compile-fail/issue-3563.rs b/src/test/compile-fail/issue-3563.rs index 9f7a0745c3b..0388f0fd290 100644 --- a/src/test/compile-fail/issue-3563.rs +++ b/src/test/compile-fail/issue-3563.rs @@ -10,7 +10,7 @@ trait A { fn a(&self) { - || self.b() //~ ERROR type `&self/self` does not implement any method in scope named `b` + || self.b() //~ ERROR type `&'self self` does not implement any method in scope named `b` } } fn main() {} diff --git a/src/test/compile-fail/issue-3668.rs b/src/test/compile-fail/issue-3668.rs index 2b25afeb0e7..1b121878697 100644 --- a/src/test/compile-fail/issue-3668.rs +++ b/src/test/compile-fail/issue-3668.rs @@ -10,11 +10,11 @@ struct P { child: Option<@mut P> } trait PTrait { - fn getChildOption() -> Option<@P>; + fn getChildOption(&self) -> Option<@P>; } impl PTrait for P { - fn getChildOption() -> Option<@P> { + fn getChildOption(&self) -> Option<@P> { const childVal: @P = self.child.get(); //~ ERROR attempt to use a non-constant value in a constant fail!(); } diff --git a/src/test/compile-fail/issue-3763.rs b/src/test/compile-fail/issue-3763.rs index 09a3f3d89c4..f6226032eee 100644 --- a/src/test/compile-fail/issue-3763.rs +++ b/src/test/compile-fail/issue-3763.rs @@ -16,7 +16,7 @@ mod my_mod { MyStruct {priv_field: 4} } pub impl MyStruct { - priv fn happyfun() {} + priv fn happyfun(&self) {} } } diff --git a/src/test/compile-fail/issue-3888.rs b/src/test/compile-fail/issue-3888.rs index 779265e5a29..482d1e9fe8a 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<T>(v: &r/[T]) -> Option< (&r/T, &r/[T]) > { +fn vec_peek<T>(v: &'r [T]) -> Option< (&'r T, &'r [T]) > { if v.len() == 0 { None } else { diff --git a/src/test/compile-fail/issue-4335.rs b/src/test/compile-fail/issue-4335.rs index 7242d993f33..ae147e628e4 100644 --- a/src/test/compile-fail/issue-4335.rs +++ b/src/test/compile-fail/issue-4335.rs @@ -11,7 +11,7 @@ // xfail-test fn id<T>(t: T) -> T { t } -fn f<T>(v: &r/T) -> &r/fn()->T { id::<&r/fn()->T>(|| *v) } //~ ERROR ??? +fn f<T>(v: &'r T) -> &'r fn()->T { id::<&'r fn()->T>(|| *v) } //~ ERROR ??? fn main() { let v = &5; diff --git a/src/test/compile-fail/issue-4523.rs b/src/test/compile-fail/issue-4523.rs index 6045ac6cba3..e8e27029371 100644 --- a/src/test/compile-fail/issue-4523.rs +++ b/src/test/compile-fail/issue-4523.rs @@ -10,7 +10,7 @@ fn foopy() {} -const f: &'static fn() = foopy; //~ ERROR mismatched types: expected `&static/fn()` +const f: &'static fn() = foopy; //~ ERROR mismatched types: expected `&'static fn()` fn main () { f(); diff --git a/src/test/compile-fail/kindck-owned-trait-contains.rs b/src/test/compile-fail/kindck-owned-trait-contains.rs index e0651a68fa9..dadc66b5029 100644 --- a/src/test/compile-fail/kindck-owned-trait-contains.rs +++ b/src/test/compile-fail/kindck-owned-trait-contains.rs @@ -8,23 +8,23 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait repeat<A> { fn get() -> A; } +trait repeat<A> { fn get(&self) -> A; } impl<A:Copy> repeat<A> for @A { - fn get() -> A { *self } + fn get(&self) -> A { **self } } -fn repeater<A:Copy>(v: @A) -> repeat<A> { +fn repeater<A:Copy>(v: @A) -> @repeat<A> { // Note: owned kind is not necessary as A appears in the trait type - @v as repeat::<A> // No + @v as @repeat<A> // No } fn main() { // Error results because the type of is inferred to be - // repeat<&blk/int> where blk is the lifetime of the block below. + // @repeat<&'blk int> where blk is the lifetime of the block below. let y = { //~ ERROR reference is not valid - let x: &blk/int = &3; + let x: &'blk int = &3; repeater(@x) }; fail_unless!(3 == *(y.get())); //~ ERROR reference is not valid diff --git a/src/test/compile-fail/kindck-owned-trait-scoped.rs b/src/test/compile-fail/kindck-owned-trait-scoped.rs index fbbac6e0a64..63690f03093 100644 --- a/src/test/compile-fail/kindck-owned-trait-scoped.rs +++ b/src/test/compile-fail/kindck-owned-trait-scoped.rs @@ -1,3 +1,6 @@ +// xfail-test +// xfail'd because to_foo() doesn't work. + // 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. @@ -9,14 +12,14 @@ // except according to those terms. // A dummy trait/impl that work close over any type. The trait will -// be parameterized by a region due to the &self/int constraint. +// be parameterized by a region due to the &'self int constraint. trait foo { - fn foo(i: &'self int) -> int; + fn foo(&self, i: &'self int) -> int; } -impl<T:Copy> foo<'self> for T { - fn foo(i: &'self int) -> int {*i} +impl<T:Copy> foo for T { + fn foo(&self, i: &'self int) -> int {*i} } fn to_foo<T:Copy>(t: T) { @@ -26,22 +29,22 @@ fn to_foo<T:Copy>(t: T) { // the fn body itself. let v = &3; struct F<T> { f: T } - let x = @F {f:t} as foo; + let x = @F {f:t} as @foo; fail_unless!(x.foo(v) == 3); } -fn to_foo_2<T:Copy>(t: T) -> foo { +fn to_foo_2<T:Copy>(t: T) -> @foo { // Not OK---T may contain borrowed ptrs and it is going to escape // as part of the returned foo value struct F<T> { f: T } - @F {f:t} as foo //~ ERROR value may contain borrowed pointers; use `&static` bound + @F {f:t} as @foo //~ ERROR value may contain borrowed pointers; use `&static` bound } -fn to_foo_3<T:Copy + &static>(t: T) -> foo { +fn to_foo_3<T:Copy + &static>(t: T) -> @foo { // OK---T may escape as part of the returned foo value, but it is // owned and hence does not contain borrowed ptrs struct F<T> { f: T } - @F {f:t} as foo + @F {f:t} as @foo } fn main() { diff --git a/src/test/compile-fail/kindck-owned-trait.rs b/src/test/compile-fail/kindck-owned-trait.rs index 30f6a5f9b2d..af6924ef608 100644 --- a/src/test/compile-fail/kindck-owned-trait.rs +++ b/src/test/compile-fail/kindck-owned-trait.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait foo { fn foo(); } +trait foo { fn foo(&self); } -fn to_foo<T:Copy + foo>(t: T) -> foo { +fn to_foo<T:Copy + foo>(t: T) -> @foo { @t as @foo //~ ERROR value may contain borrowed pointers; use `&static` bound } -fn to_foo2<T:Copy + foo + &static>(t: T) -> foo { +fn to_foo2<T:Copy + foo + &static>(t: T) -> @foo { @t as @foo } diff --git a/src/test/compile-fail/lambda-mutate-nested.rs b/src/test/compile-fail/lambda-mutate-nested.rs index 1ed18a0297a..8b009b91af9 100644 --- a/src/test/compile-fail/lambda-mutate-nested.rs +++ b/src/test/compile-fail/lambda-mutate-nested.rs @@ -16,10 +16,10 @@ fn f2(x: &fn()) { x(); } fn main() { let i = 0; let ctr: @fn() -> int = || { f2(|| i = i + 1 ); i }; - log(error, ctr()); - log(error, ctr()); - log(error, ctr()); - log(error, ctr()); - log(error, ctr()); - log(error, i); + error!(ctr()); + error!(ctr()); + error!(ctr()); + error!(ctr()); + error!(ctr()); + error!(i); } diff --git a/src/test/compile-fail/lambda-mutate.rs b/src/test/compile-fail/lambda-mutate.rs index eaa51a8c3dd..ee5b3d89684 100644 --- a/src/test/compile-fail/lambda-mutate.rs +++ b/src/test/compile-fail/lambda-mutate.rs @@ -13,10 +13,10 @@ fn main() { let i = 0; let ctr: @fn() -> int = || { i = i + 1; i }; - log(error, ctr()); - log(error, ctr()); - log(error, ctr()); - log(error, ctr()); - log(error, ctr()); - log(error, i); + error!(ctr()); + error!(ctr()); + error!(ctr()); + error!(ctr()); + error!(ctr()); + error!(i); } diff --git a/src/test/compile-fail/lint-deprecated-self.rs b/src/test/compile-fail/lint-deprecated-self.rs deleted file mode 100644 index 9da103396d8..00000000000 --- a/src/test/compile-fail/lint-deprecated-self.rs +++ /dev/null @@ -1,20 +0,0 @@ -#[forbid(deprecated_self)] -mod a { - trait T { - fn f(); //~ ERROR this method form is deprecated - } - - struct S { - x: int - } - - impl T for S { - fn f() { //~ ERROR this method form is deprecated - } - } -} - -fn main() { -} - - diff --git a/src/test/compile-fail/liveness-and-init.rs b/src/test/compile-fail/liveness-and-init.rs index 24fb1db3387..4fd2427799f 100644 --- a/src/test/compile-fail/liveness-and-init.rs +++ b/src/test/compile-fail/liveness-and-init.rs @@ -11,6 +11,6 @@ fn main() { let i: int; - log(debug, false && { i = 5; true }); - log(debug, i); //~ ERROR use of possibly uninitialized variable: `i` + debug!(false && { i = 5; true }); + debug!(i); //~ ERROR use of possibly uninitialized variable: `i` } diff --git a/src/test/compile-fail/liveness-bad-bang-2.rs b/src/test/compile-fail/liveness-bad-bang-2.rs index 6ef45a6818f..496b0f7042f 100644 --- a/src/test/compile-fail/liveness-bad-bang-2.rs +++ b/src/test/compile-fail/liveness-bad-bang-2.rs @@ -12,6 +12,6 @@ // Tests that a function with a ! annotation always actually fails // error-pattern: some control paths may return -fn bad_bang(i: uint) -> ! { log(debug, 3); } +fn bad_bang(i: uint) -> ! { debug!(3); } fn main() { bad_bang(5u); } diff --git a/src/test/compile-fail/liveness-block-unint.rs b/src/test/compile-fail/liveness-block-unint.rs index 75815d2643c..61610ca0ad1 100644 --- a/src/test/compile-fail/liveness-block-unint.rs +++ b/src/test/compile-fail/liveness-block-unint.rs @@ -12,6 +12,6 @@ fn force(f: &fn()) { f(); } fn main() { let x: int; force(|| { - log(debug, x); //~ ERROR capture of possibly uninitialized variable: `x` + debug!(x); //~ ERROR capture of possibly uninitialized variable: `x` }); } diff --git a/src/test/compile-fail/liveness-break-uninit-2.rs b/src/test/compile-fail/liveness-break-uninit-2.rs index 7e545850937..c87439db617 100644 --- a/src/test/compile-fail/liveness-break-uninit-2.rs +++ b/src/test/compile-fail/liveness-break-uninit-2.rs @@ -16,9 +16,9 @@ fn foo() -> int { x = 0; //~ WARNING unreachable statement } - log(debug, x); //~ ERROR use of possibly uninitialized variable: `x` + debug!(x); //~ ERROR use of possibly uninitialized variable: `x` return 17; } -fn main() { log(debug, foo()); } +fn main() { debug!(foo()); } diff --git a/src/test/compile-fail/liveness-break-uninit.rs b/src/test/compile-fail/liveness-break-uninit.rs index 553e4535796..07075e4ef63 100644 --- a/src/test/compile-fail/liveness-break-uninit.rs +++ b/src/test/compile-fail/liveness-break-uninit.rs @@ -16,9 +16,9 @@ fn foo() -> int { x = 0; //~ WARNING unreachable statement } - log(debug, x); //~ ERROR use of possibly uninitialized variable: `x` + debug!(x); //~ ERROR use of possibly uninitialized variable: `x` return 17; } -fn main() { log(debug, foo()); } +fn main() { debug!(foo()); } diff --git a/src/test/compile-fail/liveness-closure-require-ret.rs b/src/test/compile-fail/liveness-closure-require-ret.rs index b1fc6a870d0..22d321ffc09 100644 --- a/src/test/compile-fail/liveness-closure-require-ret.rs +++ b/src/test/compile-fail/liveness-closure-require-ret.rs @@ -9,4 +9,4 @@ // except according to those terms. fn force(f: &fn() -> int) -> int { f() } -fn main() { log(debug, force(|| {})); } //~ ERROR mismatched types +fn main() { debug!(force(|| {})); } //~ ERROR mismatched types diff --git a/src/test/compile-fail/liveness-if-no-else.rs b/src/test/compile-fail/liveness-if-no-else.rs index 5082151ce04..e37ee5bd4d4 100644 --- a/src/test/compile-fail/liveness-if-no-else.rs +++ b/src/test/compile-fail/liveness-if-no-else.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(x: int) { log(debug, x); } +fn foo(x: int) { debug!(x); } fn main() { let x: int; if 1 > 2 { x = 10; } diff --git a/src/test/compile-fail/liveness-if-with-else.rs b/src/test/compile-fail/liveness-if-with-else.rs index f7bf5d81221..6a436df6728 100644 --- a/src/test/compile-fail/liveness-if-with-else.rs +++ b/src/test/compile-fail/liveness-if-with-else.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(x: int) { log(debug, x); } +fn foo(x: int) { debug!(x); } fn main() { let x: int; diff --git a/src/test/compile-fail/liveness-init-in-fn-expr.rs b/src/test/compile-fail/liveness-init-in-fn-expr.rs index 13b8fb04a42..b7a715d2958 100644 --- a/src/test/compile-fail/liveness-init-in-fn-expr.rs +++ b/src/test/compile-fail/liveness-init-in-fn-expr.rs @@ -13,5 +13,5 @@ fn main() { let i: int; i //~ ERROR use of possibly uninitialized variable: `i` }; - log(error, f()); + error!(f()); } diff --git a/src/test/compile-fail/liveness-move-from-args.rs b/src/test/compile-fail/liveness-move-from-args.rs index d6c0be9f183..c60848e5cc6 100644 --- a/src/test/compile-fail/liveness-move-from-args.rs +++ b/src/test/compile-fail/liveness-move-from-args.rs @@ -10,10 +10,6 @@ fn take(_x: ~int) { } -fn from_by_value_arg(++x: ~int) { - take(x); //~ ERROR illegal move from argument `x`, which is not copy or move mode -} - fn from_by_ref_arg(&&x: ~int) { take(x); //~ ERROR illegal move from argument `x`, which is not copy or move mode } diff --git a/src/test/compile-fail/liveness-move-in-loop.rs b/src/test/compile-fail/liveness-move-in-loop.rs index cb9d028809e..d1663bc356b 100644 --- a/src/test/compile-fail/liveness-move-in-loop.rs +++ b/src/test/compile-fail/liveness-move-in-loop.rs @@ -12,7 +12,7 @@ fn main() { let y: ~int = ~42; let mut x: ~int; loop { - log(debug, y); + debug!(y); loop { loop { loop { diff --git a/src/test/compile-fail/liveness-move-in-while.rs b/src/test/compile-fail/liveness-move-in-while.rs index fa8ce00fb08..6b4147242d1 100644 --- a/src/test/compile-fail/liveness-move-in-while.rs +++ b/src/test/compile-fail/liveness-move-in-while.rs @@ -13,7 +13,7 @@ fn main() { let y: ~int = ~42; let mut x: ~int; loop { - log(debug, y); + debug!(y); // tjc: not sure why it prints the same error twice while true { while true { while true { x = y; copy x; } } } //~^ ERROR use of moved value: `y` diff --git a/src/test/compile-fail/liveness-or-init.rs b/src/test/compile-fail/liveness-or-init.rs index fb2bdb66ace..2c1aadc8bbf 100644 --- a/src/test/compile-fail/liveness-or-init.rs +++ b/src/test/compile-fail/liveness-or-init.rs @@ -11,6 +11,6 @@ fn main() { let i: int; - log(debug, false || { i = 5; true }); - log(debug, i); //~ ERROR use of possibly uninitialized variable: `i` + debug!(false || { i = 5; true }); + debug!(i); //~ ERROR use of possibly uninitialized variable: `i` } diff --git a/src/test/compile-fail/liveness-uninit.rs b/src/test/compile-fail/liveness-uninit.rs index 4ac500da699..8797132fd50 100644 --- a/src/test/compile-fail/liveness-uninit.rs +++ b/src/test/compile-fail/liveness-uninit.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(x: int) { log(debug, x); } +fn foo(x: int) { debug!(x); } fn main() { let x: int; diff --git a/src/test/compile-fail/liveness-use-after-move.rs b/src/test/compile-fail/liveness-use-after-move.rs index 16518261009..b7401db2a55 100644 --- a/src/test/compile-fail/liveness-use-after-move.rs +++ b/src/test/compile-fail/liveness-use-after-move.rs @@ -11,6 +11,6 @@ fn main() { let x = ~5; let y = x; - log(debug, *x); //~ ERROR use of moved value: `x` + debug!(*x); //~ ERROR use of moved value: `x` copy y; } diff --git a/src/test/compile-fail/liveness-use-after-send.rs b/src/test/compile-fail/liveness-use-after-send.rs index c0de60fa58e..fdc0392a74c 100644 --- a/src/test/compile-fail/liveness-use-after-send.rs +++ b/src/test/compile-fail/liveness-use-after-send.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn send<T:Owned>(ch: _chan<T>, -data: T) { - log(debug, ch); - log(debug, data); +fn send<T:Owned>(ch: _chan<T>, +data: T) { + debug!(ch); + debug!(data); fail!(); } @@ -20,7 +20,7 @@ struct _chan<T>(int); // message after the send deinitializes it fn test00_start(ch: _chan<~int>, message: ~int, _count: ~int) { send(ch, message); - log(debug, message); //~ ERROR use of moved value: `message` + debug!(message); //~ ERROR use of moved value: `message` } fn main() { fail!(); } diff --git a/src/test/compile-fail/map-types.rs b/src/test/compile-fail/map-types.rs index c8384c18831..6f71bd40aff 100644 --- a/src/test/compile-fail/map-types.rs +++ b/src/test/compile-fail/map-types.rs @@ -15,7 +15,7 @@ use core::hashmap::linear::LinearMap; fn main() { let x: @Map<~str, ~str> = @LinearMap::new::<~str, ~str>() as - Map::<~str, ~str>; + @Map<~str, ~str>; let y: @Map<uint, ~str> = @x; //~^ ERROR mismatched types: expected `@core::container::Map<uint,~str>` } diff --git a/src/test/compile-fail/mutable-arguments.rs b/src/test/compile-fail/mutable-arguments.rs index aefe8c02ecd..39e47fb1aab 100644 --- a/src/test/compile-fail/mutable-arguments.rs +++ b/src/test/compile-fail/mutable-arguments.rs @@ -19,18 +19,13 @@ fn mutate_by_ref(&&x: uint) { x = 0; //~ ERROR assigning to argument } -fn mutate_by_val(++x: uint) { - //~^ WARNING unused variable: `x` - x = 0; //~ ERROR assigning to argument -} - fn mutate_by_copy(+x: uint) { //~^ WARNING unused variable: `x` x = 0; //~ ERROR assigning to argument //~^ WARNING value assigned to `x` is never read } -fn mutate_by_move(-x: uint) { +fn mutate_by_move(+x: uint) { //~^ WARNING unused variable: `x` x = 0; //~ ERROR assigning to argument //~^ WARNING value assigned to `x` is never read diff --git a/src/test/compile-fail/mutable-class-fields-2.rs b/src/test/compile-fail/mutable-class-fields-2.rs index 3a63cdee20c..56c715c9847 100644 --- a/src/test/compile-fail/mutable-class-fields-2.rs +++ b/src/test/compile-fail/mutable-class-fields-2.rs @@ -16,7 +16,7 @@ struct cat { } pub impl cat { - fn eat() { + fn eat(&self) { self.how_hungry -= 5; } diff --git a/src/test/compile-fail/no-capture-arc.rs b/src/test/compile-fail/no-capture-arc.rs index a0c1bf040e3..5e17b168d55 100644 --- a/src/test/compile-fail/no-capture-arc.rs +++ b/src/test/compile-fail/no-capture-arc.rs @@ -24,5 +24,5 @@ fn main() { fail_unless!((*arc::get(&arc_v))[2] == 3); - log(info, arc_v); + info!(arc_v); } diff --git a/src/test/compile-fail/no-reuse-move-arc.rs b/src/test/compile-fail/no-reuse-move-arc.rs index 4cb78e7032b..90faec802a4 100644 --- a/src/test/compile-fail/no-reuse-move-arc.rs +++ b/src/test/compile-fail/no-reuse-move-arc.rs @@ -22,5 +22,5 @@ fn main() { fail_unless!((*arc::get(&arc_v))[2] == 3); //~ ERROR use of moved value: `arc_v` - log(info, arc_v); + info!(arc_v); } diff --git a/src/test/compile-fail/no-send-res-ports.rs b/src/test/compile-fail/no-send-res-ports.rs index 0d7e2d2377c..192cde21bf1 100644 --- a/src/test/compile-fail/no-send-res-ports.rs +++ b/src/test/compile-fail/no-send-res-ports.rs @@ -31,6 +31,6 @@ fn main() { do task::spawn { let y = x.take(); //~ ERROR value has non-owned type - log(error, y); + error!(y); } } 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 new file mode 100644 index 00000000000..86262008ff9 --- /dev/null +++ b/src/test/compile-fail/non-constant-expr-for-fixed-len-vec.rs @@ -0,0 +1,17 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that non-constant exprs do fail as count in fixed length vec type + +fn main() { + fn bar(n: int) { + let _x: [int * n]; //~ ERROR expected constant expr for vector length: Non-constant path in constant expr + } +} diff --git a/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs b/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs new file mode 100644 index 00000000000..2727db9d042 --- /dev/null +++ b/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs @@ -0,0 +1,17 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that non constant exprs fail for vector repeat syntax + +fn main() { + fn bar(n: int) { + let _x = [0, ..n]; //~ ERROR expected constant integer for repeat count but found variable + } +} diff --git a/src/test/compile-fail/noncopyable-class.rs b/src/test/compile-fail/noncopyable-class.rs index 42bad88633c..77e62497d07 100644 --- a/src/test/compile-fail/noncopyable-class.rs +++ b/src/test/compile-fail/noncopyable-class.rs @@ -39,5 +39,5 @@ fn foo(i:int) -> foo { fn main() { let x = foo(10); let _y = copy x; //~ ERROR copying a value of non-copyable type - log(error, x); + error!(x); } diff --git a/src/test/compile-fail/nonscalar-cast.rs b/src/test/compile-fail/nonscalar-cast.rs index d84775d02ac..999d96669ea 100644 --- a/src/test/compile-fail/nonscalar-cast.rs +++ b/src/test/compile-fail/nonscalar-cast.rs @@ -15,5 +15,5 @@ struct foo { } fn main() { - log(debug, foo{ x: 1 } as int); + debug!(foo{ x: 1 } as int); } diff --git a/src/test/compile-fail/oversized-literal.rs b/src/test/compile-fail/oversized-literal.rs index f2f021f9985..ce7b505cf09 100644 --- a/src/test/compile-fail/oversized-literal.rs +++ b/src/test/compile-fail/oversized-literal.rs @@ -10,4 +10,4 @@ // error-pattern:literal out of range -fn main() { log(debug, 300u8); } +fn main() { debug!(300u8); } diff --git a/src/test/compile-fail/pattern-tyvar.rs b/src/test/compile-fail/pattern-tyvar.rs index 6b3b6f1463f..506c71f493a 100644 --- a/src/test/compile-fail/pattern-tyvar.rs +++ b/src/test/compile-fail/pattern-tyvar.rs @@ -18,7 +18,7 @@ enum bar { t1((), Option<~[int]>), t2, } fn foo(t: bar) { match t { t1(_, Some::<int>(x)) => { - log(debug, x); + debug!(x); } _ => { fail!(); } } diff --git a/src/test/compile-fail/pinned-deep-copy.rs b/src/test/compile-fail/pinned-deep-copy.rs index 03ba317e731..5df65832099 100644 --- a/src/test/compile-fail/pinned-deep-copy.rs +++ b/src/test/compile-fail/pinned-deep-copy.rs @@ -31,7 +31,7 @@ fn main() { // Can't do this copy let x = ~~~A {y: r(i)}; let _z = copy x; //~ ERROR copying a value of non-copyable type - log(debug, x); + debug!(x); } - log(error, *i); + error!(*i); } diff --git a/src/test/compile-fail/private-impl-method.rs b/src/test/compile-fail/private-impl-method.rs index 1ab8d25bb30..74bdcdc7f82 100644 --- a/src/test/compile-fail/private-impl-method.rs +++ b/src/test/compile-fail/private-impl-method.rs @@ -14,7 +14,7 @@ mod a { } pub impl Foo { - priv fn foo() {} + priv fn foo(&self) {} } } diff --git a/src/test/compile-fail/private-method.rs b/src/test/compile-fail/private-method.rs index 363a5fd0d2b..c918758ad7c 100644 --- a/src/test/compile-fail/private-method.rs +++ b/src/test/compile-fail/private-method.rs @@ -18,7 +18,7 @@ mod kitties { } pub impl cat { - priv fn nap() { uint::range(1u, 10000u, |_i| false)} + priv fn nap(&self) { uint::range(1u, 10000u, |_i| false)} } pub fn cat(in_x : uint, in_y : int) -> cat { diff --git a/src/test/compile-fail/pure-higher-order.rs b/src/test/compile-fail/pure-higher-order.rs deleted file mode 100644 index 6d262bc04e1..00000000000 --- a/src/test/compile-fail/pure-higher-order.rs +++ /dev/null @@ -1,64 +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 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[legacy_modes]; - -// Test rules governing higher-order pure fns. - -struct S<'self> { - f: &'self fn(uint) -} - -pure fn range(from: uint, to: uint, f: &fn(uint)) { - let mut i = from; - while i < to { - f(i); // Note: legal to call argument, even if it is not pure. - i += 1u; - } -} - -pure fn range2(from: uint, to: uint, f: &fn(uint)) { - do range(from, to) |i| { - f(i*2u); - } -} - -pure fn range3(from: uint, to: uint, f: &fn(uint)) { - range(from, to, f) -} - -pure fn range4(from: uint, to: uint) { - range(from, to, print) //~ ERROR access to impure function prohibited in pure context -} - -pure fn range5<'a>(from: uint, to: uint, x: S<'a>) { - range(from, to, x.f) //~ ERROR access to impure function prohibited in pure context -} - -pure fn range6<'a>(from: uint, to: uint, x: @S<'a>) { - range(from, to, x.f) //~ ERROR access to impure function prohibited in pure context -} - -pure fn range7(from: uint, to: uint) { - do range(from, to) |i| { - print(i); //~ ERROR access to impure function prohibited in pure context - } -} - -pure fn range8(from: uint, to: uint) { - range(from, to, noop); -} - -fn print(i: uint) { error!("i=%u", i); } - -pure fn noop(_i: uint) {} - -fn main() { -} diff --git a/src/test/compile-fail/pure-loop-body.rs b/src/test/compile-fail/pure-loop-body.rs deleted file mode 100644 index 43a54981dcb..00000000000 --- a/src/test/compile-fail/pure-loop-body.rs +++ /dev/null @@ -1,35 +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 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct S<'self> { - x: &'self fn(uint) -} - -pure fn range<'a>(from: uint, to: uint, f: &'a fn(uint) -> bool) { - let mut i = from; - while i < to { - if !f(i) {return;} // Note: legal to call argument, even if it is not pure. - i += 1u; - } -} - -pure fn range2<'a>(from: uint, to: uint, f: &'a fn(uint)) { - for range(from, to) |i| { - f(i*2u); - } -} - -pure fn range3<'a>(from: uint, to: uint, f: S<'a>) { - for range(from, to) |i| { - (f.x)(i*2u); //~ ERROR access to impure function prohibited - } -} - -fn main() {} diff --git a/src/test/compile-fail/pure-subtyping.rs b/src/test/compile-fail/pure-subtyping.rs deleted file mode 100644 index 2744afb113d..00000000000 --- a/src/test/compile-fail/pure-subtyping.rs +++ /dev/null @@ -1,48 +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 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test rules governing higher-order pure fns. - -fn take<T>(_v: T) {} - -fn assign_to_pure(x: &pure fn(), y: &fn(), z: &unsafe fn()) { - take::<&pure fn()>(x); - take::<&pure fn()>(y); //~ ERROR expected pure fn but found impure fn - take::<&pure fn()>(z); //~ ERROR expected pure fn but found unsafe fn -} - -fn assign_to_impure(x: &pure fn(), y: &fn(), z: &unsafe fn()) { - take::<&fn()>(x); - take::<&fn()>(y); - take::<&fn()>(z); //~ ERROR expected impure fn but found unsafe fn -} - -fn assign_to_unsafe(x: &pure fn(), y: &fn(), z: &unsafe fn()) { - take::<&unsafe fn()>(x); - take::<&unsafe fn()>(y); - take::<&unsafe fn()>(z); -} - -fn assign_to_pure2(x: @pure fn(), y: @fn(), z: @unsafe fn()) { - take::<&pure fn()>(x); - take::<&pure fn()>(y); //~ ERROR expected pure fn but found impure fn - take::<&pure fn()>(z); //~ ERROR expected pure fn but found unsafe fn - - take::<~pure fn()>(x); //~ ERROR expected ~ closure, found @ closure - take::<~pure fn()>(y); //~ ERROR expected ~ closure, found @ closure - take::<~pure fn()>(z); //~ ERROR expected ~ closure, found @ closure - - take::<~unsafe fn()>(x); //~ ERROR expected ~ closure, found @ closure - take::<~unsafe fn()>(y); //~ ERROR expected ~ closure, found @ closure - take::<~unsafe fn()>(z); //~ ERROR expected ~ closure, found @ closure -} - -fn main() { -} diff --git a/src/test/compile-fail/regions-addr-of-self.rs b/src/test/compile-fail/regions-addr-of-self.rs index 96657edb5b1..732d946bf9e 100644 --- a/src/test/compile-fail/regions-addr-of-self.rs +++ b/src/test/compile-fail/regions-addr-of-self.rs @@ -14,12 +14,12 @@ struct dog { pub impl dog { fn chase_cat(&mut self) { - let p: &static/mut uint = &mut self.cats_chased; //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements + let p: &'static mut uint = &mut self.cats_chased; //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements *p += 1u; } fn chase_cat_2(&mut self) { - let p: &blk/mut uint = &mut self.cats_chased; + let p: &'blk mut uint = &mut self.cats_chased; *p += 1u; } } diff --git a/src/test/compile-fail/regions-blk.rs b/src/test/compile-fail/regions-blk.rs index 9b1895ba4bd..893e4c41178 100644 --- a/src/test/compile-fail/regions-blk.rs +++ b/src/test/compile-fail/regions-blk.rs @@ -10,13 +10,13 @@ fn foo(cond: bool) { let x = 5; - let mut y: &blk/int = &x; + let mut y: &'blk int = &x; - let mut z: &blk/int; + let mut z: &'blk int; if cond { z = &x; //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements } else { - let w: &blk/int = &x; + let w: &'blk int = &x; z = w; } } diff --git a/src/test/compile-fail/regions-bounds.rs b/src/test/compile-fail/regions-bounds.rs index 35bef5a407a..3821035a0f6 100644 --- a/src/test/compile-fail/regions-bounds.rs +++ b/src/test/compile-fail/regions-bounds.rs @@ -13,21 +13,14 @@ // checked. struct an_enum(&'self int); -trait a_trait { - fn foo() -> &'self int; -} struct a_class { x:&'self int } fn a_fn1(e: an_enum<'a>) -> an_enum<'b> { - return e; //~ ERROR mismatched types: expected `an_enum/&b` but found `an_enum/&a` -} - -fn a_fn2(e: a_trait<'a>) -> a_trait<'b> { - return e; //~ ERROR mismatched types: expected `@a_trait/&b` but found `@a_trait/&a` + return e; //~ ERROR mismatched types: expected `an_enum/&'b ` but found `an_enum/&'a ` } fn a_fn3(e: a_class<'a>) -> a_class<'b> { - return e; //~ ERROR mismatched types: expected `a_class/&b` but found `a_class/&a` + return e; //~ ERROR mismatched types: expected `a_class/&'b ` but found `a_class/&'a ` } fn a_fn4(e: int<'a>) -> int<'b> { 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 767d7c9174d..1b737c273db 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 @@ -9,11 +9,11 @@ // except according to those terms. trait deref { - fn get() -> int; + fn get(self) -> int; } impl deref for &'self int { - fn get() -> int { + fn get(self) -> int { *self } } diff --git a/src/test/compile-fail/regions-fn-bound.rs b/src/test/compile-fail/regions-fn-bound.rs index 6deef8cee9e..add53d3d9b0 100644 --- a/src/test/compile-fail/regions-fn-bound.rs +++ b/src/test/compile-fail/regions-fn-bound.rs @@ -1,3 +1,6 @@ +// xfail-test +// xfail'd because the first error does not show up. + // 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. @@ -8,24 +11,24 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn of<T>() -> @fn(T) { fail!(); } -fn subtype<T>(x: @fn(T)) { fail!(); } +fn of<T>() -> &fn(T) { fail!(); } +fn subtype<T>(x: &fn(T)) { fail!(); } -fn test_fn<T>(_x: &x/T, _y: &y/T, _z: &z/T) { +fn test_fn<T>(_x: &'x T, _y: &'y T, _z: &'z T) { // Here, x, y, and z are free. Other letters // are bound. Note that the arrangement // subtype::<T1>(of::<T2>()) will typecheck // iff T1 <: T2. // should be the default: - subtype::<@static/fn()>(of::<@fn()>()); - subtype::<@fn()>(of::<@static/fn()>()); + subtype::<&'static fn()>(of::<&fn()>()); + subtype::<&fn()>(of::<&'static fn()>()); // - subtype::<@x/fn()>(of::<@fn()>()); //~ ERROR mismatched types - subtype::<@x/fn()>(of::<@y/fn()>()); //~ ERROR mismatched types + subtype::<&'x fn()>(of::<&fn()>()); //~ ERROR mismatched types + subtype::<&'x fn()>(of::<&'y fn()>()); //~ ERROR mismatched types - subtype::<@x/fn()>(of::<@static/fn()>()); //~ ERROR mismatched types - subtype::<@static/fn()>(of::<@x/fn()>()); + subtype::<&'x fn()>(of::<&'static fn()>()); //~ ERROR mismatched types + subtype::<&'static fn()>(of::<&'x fn()>()); } diff --git a/src/test/compile-fail/regions-fn-subtyping.rs b/src/test/compile-fail/regions-fn-subtyping.rs index 50674ac81fe..a90b3d0f429 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<T>() -> @fn(T) { fail!(); } fn subtype<T>(x: @fn(T)) { fail!(); } -fn test_fn<T>(_x: &x/T, _y: &y/T, _z: &z/T) { +fn test_fn<T>(_x: &'x T, _y: &'y T, _z: &'z T) { // Here, x, y, and z are free. Other letters // are bound. Note that the arrangement // subtype::<T1>(of::<T2>()) will typecheck // iff T1 <: T2. - subtype::<&fn(&a/T)>( - of::<&fn(&a/T)>()); + subtype::<&fn(&'a T)>( + of::<&fn(&'a T)>()); - subtype::<&fn(&a/T)>( - of::<&fn(&b/T)>()); + subtype::<&fn(&'a T)>( + of::<&fn(&'b T)>()); - subtype::<&fn(&b/T)>( - of::<&fn(&x/T)>()); + subtype::<&fn(&'b T)>( + of::<&fn(&'x T)>()); - subtype::<&fn(&x/T)>( - of::<&fn(&b/T)>()); //~ ERROR mismatched types + subtype::<&fn(&'x T)>( + of::<&fn(&'b T)>()); //~ ERROR mismatched types - subtype::<&fn(&a/T, &b/T)>( - of::<&fn(&a/T, &a/T)>()); + subtype::<&fn(&'a T, &'b T)>( + of::<&fn(&'a T, &'a T)>()); - subtype::<&fn(&a/T, &a/T)>( - of::<&fn(&a/T, &b/T)>()); //~ ERROR mismatched types + subtype::<&fn(&'a T, &'a T)>( + of::<&fn(&'a T, &'b T)>()); //~ ERROR mismatched types - subtype::<&fn(&a/T, &b/T)>( - of::<&fn(&x/T, &y/T)>()); + subtype::<&fn(&'a T, &'b T)>( + of::<&fn(&'x T, &'y T)>()); - subtype::<&fn(&x/T, &y/T)>( - of::<&fn(&a/T, &b/T)>()); //~ ERROR mismatched types + subtype::<&fn(&'x T, &'y T)>( + of::<&fn(&'a T, &'b T)>()); //~ ERROR mismatched types - subtype::<&fn(&x/T) -> @fn(&a/T)>( - of::<&fn(&x/T) -> @fn(&a/T)>()); + subtype::<&fn(&'x T) -> @fn(&'a T)>( + of::<&fn(&'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 T) -> @fn(&'a T)>( + of::<&fn(&'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 T) -> @fn(&'a T)>( + of::<&fn(&'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 T) -> @fn(&'b T)>( + of::<&fn(&'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 a4f1825fcae..50eba71ac56 100644 --- a/src/test/compile-fail/regions-fns.rs +++ b/src/test/compile-fail/regions-fns.rs @@ -11,8 +11,8 @@ // Before fn subtyping was properly implemented, // we reported errors in this case: -fn not_ok(a: &uint, b: &b/uint) { - let mut g: @fn(x: &uint) = |x: &b/uint| {}; +fn not_ok(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-freevar.rs b/src/test/compile-fail/regions-freevar.rs index 6545892d0bb..f89c5eaa9c1 100644 --- a/src/test/compile-fail/regions-freevar.rs +++ b/src/test/compile-fail/regions-freevar.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn wants_static_fn(_x: &static/fn()) {} +fn wants_static_fn(_x: &'static fn()) {} fn main() { let i = 3; 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 82d75bcf5db..6402982a9e1 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(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 ef8f6748d36..c873e2519bd 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<T>(x: &r/T) -> &r/T {x} +fn borrow<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 49d3f6aee65..a3bc55228d8 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(x: &'r int, y: &'r int) -> &'r int { x } fn with<T>(f: &fn(x: &int) -> T) -> T { f(&20) } -fn manip(x: &a/int) -> int { +fn manip(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-ret.rs b/src/test/compile-fail/regions-infer-contravariance-due-to-ret.rs index 936aa79d032..d93713f3f23 100644 --- a/src/test/compile-fail/regions-infer-contravariance-due-to-ret.rs +++ b/src/test/compile-fail/regions-infer-contravariance-due-to-ret.rs @@ -14,7 +14,7 @@ // the normal case. struct contravariant { - f: @fn() -> &self/int + f: @fn() -> &'self int } fn to_same_lifetime(bi: contravariant/&r) { 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 27e1452d957..c527cdf233d 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 @@ -13,7 +13,7 @@ // You can upcast to a *larger region* but not a smaller one. struct covariant { - f: @fn(x: &self/int) -> int + f: @fn(x: &'self int) -> int } fn to_same_lifetime(bi: covariant/&r) { 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 c84afc6ca64..15b39d772f0 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 @@ -9,7 +9,7 @@ // except according to those terms. struct invariant { - f: @fn(x: @mut &self/int) + f: @fn(x: @mut &'self int) } fn to_same_lifetime(bi: invariant/&r) { 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 b958aa70aa4..ff2b4246f01 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 @@ -9,7 +9,7 @@ // except according to those terms. struct invariant { - f: @fn() -> @mut &self/int + f: @fn() -> @mut &'self int } fn to_same_lifetime(bi: invariant/&r) { diff --git a/src/test/compile-fail/regions-infer-paramd-indirect.rs b/src/test/compile-fail/regions-infer-paramd-indirect.rs index 7b2a760270c..e4ad93bde17 100644 --- a/src/test/compile-fail/regions-infer-paramd-indirect.rs +++ b/src/test/compile-fail/regions-infer-paramd-indirect.rs @@ -18,18 +18,18 @@ struct c<'self> { f: @b<'self> } -trait set_f<'self> { - fn set_f_ok(b: @b<'self>); - fn set_f_bad(b: @b); +trait set_f { + fn set_f_ok(&self, b: @b<'self>); + fn set_f_bad(&self, b: @b); } -impl<'self> set_f<'self> for c<'self> { - fn set_f_ok(b: @b<'self>) { +impl<'self> set_f for c<'self> { + fn set_f_ok(&self, b: @b<'self>) { self.f = b; } - fn set_f_bad(b: @b) { - self.f = b; //~ ERROR mismatched types: expected `@@&self/int` but found `@@&int` + fn set_f_bad(&self, b: @b) { + self.f = b; //~ ERROR mismatched types: expected `@@&'self int` but found `@@&int` } } diff --git a/src/test/compile-fail/regions-infer-paramd-method.rs b/src/test/compile-fail/regions-infer-paramd-method.rs index 32702663c6e..8c3195f020a 100644 --- a/src/test/compile-fail/regions-infer-paramd-method.rs +++ b/src/test/compile-fail/regions-infer-paramd-method.rs @@ -1,3 +1,6 @@ +// xfail-test +// xfail'd due to problems with by value self. + // 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. @@ -12,13 +15,13 @@ // refers to self. trait foo<'self> { - fn self_int() -> &'self int; + fn self_int(self) -> &'self int; - fn any_int() -> ∫ + fn any_int(self) -> ∫ } struct with_foo<'self> { - f: foo<'self> + f: @foo<'self> } trait set_foo_foo { @@ -34,7 +37,7 @@ impl<'self> set_foo_foo for with_foo<'self> { // Bar is not region parameterized. trait bar { - fn any_int() -> ∫ + fn any_int(&self) -> ∫ } struct with_bar { diff --git a/src/test/compile-fail/regions-nested-fns-2.rs b/src/test/compile-fail/regions-nested-fns-2.rs index b4cbbacea3f..26d6bbd5303 100644 --- a/src/test/compile-fail/regions-nested-fns-2.rs +++ b/src/test/compile-fail/regions-nested-fns-2.rs @@ -12,7 +12,7 @@ fn ignore<T>(_t: T) {} fn nested() { let y = 3; - ignore(|z: &z/int| -> &z/int { + ignore(|z: &'z int| -> &'z int { 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 714b863ca1d..6ef37efeb41 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: T) {} -fn nested(x: &x/int) { +fn nested(x: &'x int) { let y = 3; let mut ay = &y; //~ ERROR cannot infer an appropriate lifetime - ignore(|z: &z/int| { + ignore(|z: &'z int| { ay = x; ay = &y; //~ ERROR cannot infer an appropriate lifetime ay = z; }); - ignore(|z: &z/int| -> &z/int { + ignore(|z: &'z int| -> &'z int { if false { return x; } //~ ERROR mismatched types if false { return ay; } return z; diff --git a/src/test/compile-fail/regions-out-of-scope-slice.rs b/src/test/compile-fail/regions-out-of-scope-slice.rs index 102ff8b3998..b3db225700a 100644 --- a/src/test/compile-fail/regions-out-of-scope-slice.rs +++ b/src/test/compile-fail/regions-out-of-scope-slice.rs @@ -15,7 +15,7 @@ fn foo(cond: bool) { let mut x; //~ ERROR foo if cond { - x = &blk/[1,2,3]; + x = &'blk [1,2,3]; } } diff --git a/src/test/compile-fail/regions-ret-borrowed-1.rs b/src/test/compile-fail/regions-ret-borrowed-1.rs index ab6a37b58de..7218dcf379b 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<R>(f: &fn(x: &a/int) -> R) -> R { +fn with<R>(f: &fn(x: &'a int) -> R) -> R { f(&3) } -fn return_it() -> &a/int { +fn return_it() -> &'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 d43065e12fb..cecd847843c 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(_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 index e675d4d455f..f0c81d16b03 100644 --- a/src/test/compile-fail/regions-scoping.rs +++ b/src/test/compile-fail/regions-scoping.rs @@ -17,7 +17,7 @@ fn nested<'x>(x: &'x int) { // (1) 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 { + -> &'x int { if false { return z(x, y, x); } if false { return z(x, y, y); } @@ -40,9 +40,9 @@ fn nested<'x>(x: &'x int) { // (1) // 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 + // 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` + 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 diff --git a/src/test/compile-fail/regions-trait-1.rs b/src/test/compile-fail/regions-trait-1.rs index f4e41d951aa..74afdf11758 100644 --- a/src/test/compile-fail/regions-trait-1.rs +++ b/src/test/compile-fail/regions-trait-1.rs @@ -12,7 +12,7 @@ struct ctxt { v: uint } trait get_ctxt { // Here the `&` is bound in the method definition: - fn get_ctxt() -> &ctxt; + fn get_ctxt(&self) -> &ctxt; } struct has_ctxt { c: &'self ctxt } @@ -21,18 +21,18 @@ impl get_ctxt for has_ctxt<'self> { // Here an error occurs because we used `&self` but // the definition used `&`: - fn get_ctxt() -> &'self ctxt { //~ ERROR method `get_ctxt` has an incompatible type + fn get_ctxt(&self) -> &'self ctxt { //~ ERROR method `get_ctxt` has an incompatible type self.c } } -fn get_v(gc: get_ctxt) -> uint { +fn get_v(gc: @get_ctxt) -> uint { gc.get_ctxt().v } fn main() { let ctxt = ctxt { v: 22u }; let hc = has_ctxt { c: &ctxt }; - fail_unless!(get_v(@hc as get_ctxt) == 22u); + fail_unless!(get_v(@hc as @get_ctxt) == 22u); } diff --git a/src/test/compile-fail/regions-trait-2.rs b/src/test/compile-fail/regions-trait-2.rs index 12ab58ec890..5811496cab4 100644 --- a/src/test/compile-fail/regions-trait-2.rs +++ b/src/test/compile-fail/regions-trait-2.rs @@ -10,22 +10,22 @@ struct ctxt { v: uint } -trait get_ctxt<'self> { - fn get_ctxt() -> &'self ctxt; +trait get_ctxt { + fn get_ctxt(&self) -> &'self ctxt; } struct has_ctxt<'self> { c: &'self ctxt } -impl<'self> get_ctxt<'self> for has_ctxt<'self> { - fn get_ctxt() -> &self/ctxt { self.c } +impl<'self> get_ctxt for has_ctxt<'self> { + fn get_ctxt(&self) -> &'self ctxt { self.c } } -fn make_gc() -> get_ctxt { +fn make_gc() -> @get_ctxt { let ctxt = ctxt { v: 22u }; - let hc = has_ctxt { c: &ctxt }; //~ ERROR illegal borrow - return @hc as get_ctxt; + let hc = has_ctxt { c: &ctxt }; + return @hc as @get_ctxt; } fn main() { - make_gc().get_ctxt().v; + make_gc().get_ctxt().v; //~ ERROR illegal borrow } diff --git a/src/test/compile-fail/regions-trait-3.rs b/src/test/compile-fail/regions-trait-3.rs index a10c239617e..e947dbf9308 100644 --- a/src/test/compile-fail/regions-trait-3.rs +++ b/src/test/compile-fail/regions-trait-3.rs @@ -1,3 +1,6 @@ +// xfail-test +// xfail'd due to problems with by-value self. + // 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. @@ -9,10 +12,10 @@ // except according to those terms. trait get_ctxt { - fn get_ctxt() -> &self/uint; + fn get_ctxt(self) -> &'self uint; } -fn make_gc1(gc: get_ctxt/&a) -> get_ctxt/&b { +fn make_gc1(gc: @get_ctxt/&a) -> @get_ctxt/&b { return gc; //~ ERROR mismatched types: expected `@get_ctxt/&b` but found `@get_ctxt/&a` } @@ -20,12 +23,12 @@ struct Foo { r: &'self uint } -impl get_ctxt/&self for Foo/&self { - fn get_ctxt() -> &self/uint { self.r } +impl get_ctxt for Foo<'self> { + fn get_ctxt(&self) -> &'self uint { self.r } } -fn make_gc2(foo: Foo/&a) -> get_ctxt/&b { - return @foo as get_ctxt; //~ ERROR cannot infer an appropriate lifetime +fn make_gc2(foo: Foo/&a) -> @get_ctxt/&b { + return @foo as @get_ctxt; //~ ERROR cannot infer an appropriate lifetime } fn main() { diff --git a/src/test/compile-fail/selftype-traittype.rs b/src/test/compile-fail/selftype-traittype.rs index f704f408662..467154244b7 100644 --- a/src/test/compile-fail/selftype-traittype.rs +++ b/src/test/compile-fail/selftype-traittype.rs @@ -9,7 +9,7 @@ // except according to those terms. trait add { - fn plus(x: Self) -> Self; + fn plus(&self, x: Self) -> Self; } fn do_add(x: add, y: add) -> add { diff --git a/src/test/compile-fail/sendfn-is-not-a-lambda.rs b/src/test/compile-fail/sendfn-is-not-a-lambda.rs index 33bb06e4f26..847f85feb72 100644 --- a/src/test/compile-fail/sendfn-is-not-a-lambda.rs +++ b/src/test/compile-fail/sendfn-is-not-a-lambda.rs @@ -14,5 +14,5 @@ fn test(f: @fn(uint) -> uint) -> uint { fn main() { let f: ~fn(x: uint) -> uint = |x| 4u; - log(debug, test(f)); //~ ERROR expected @ closure, found ~ closure + debug!(test(f)); //~ ERROR expected @ closure, found ~ closure } diff --git a/src/test/compile-fail/staticness-mismatch.rs b/src/test/compile-fail/staticness-mismatch.rs index e67a4099987..531d722d8bc 100644 --- a/src/test/compile-fail/staticness-mismatch.rs +++ b/src/test/compile-fail/staticness-mismatch.rs @@ -14,7 +14,7 @@ trait foo { } impl foo for int { - fn bar() {} //~ ERROR method `bar` is declared as static in its trait, but not in its impl + fn bar(&self) {} //~ ERROR method `bar` is declared as static in its trait, but not in its impl } fn main() {} diff --git a/src/test/compile-fail/tps-invariant-trait.rs b/src/test/compile-fail/tps-invariant-trait.rs index 9569e5f1e82..127aa23d6ab 100644 --- a/src/test/compile-fail/tps-invariant-trait.rs +++ b/src/test/compile-fail/tps-invariant-trait.rs @@ -9,8 +9,8 @@ // except according to those terms. trait box_trait<T> { - fn get() -> T; - fn set(t: T); + fn get(&self) -> T; + fn set(&self, t: T); } struct box<T> { @@ -20,11 +20,11 @@ struct box<T> { struct box_impl<T>(box<T>); impl<T:Copy> box_trait<T> for box_impl<T> { - fn get() -> T { return self.f; } - fn set(t: T) { self.f = t; } + fn get(&self) -> T { return self.f; } + fn set(&self, t: T) { self.f = t; } } -fn set_box_trait<T>(b: box_trait<@const T>, v: @const T) { +fn set_box_trait<T>(b: @box_trait<@const T>, v: @const T) { b.set(v); } @@ -34,7 +34,7 @@ fn set_box_impl<T>(b: box_impl<@const T>, v: @const T) { fn main() { let b = box_impl::<@int>(box::<@int> {f: @3}); - set_box_trait(@b as box_trait::<@int>, @mut 5); + set_box_trait(@b as @box_trait<@int>, @mut 5); //~^ ERROR values differ in mutability set_box_impl(b, @mut 5); //~^ ERROR values differ in mutability diff --git a/src/test/compile-fail/trait-impl-can-not-have-untraitful-methods.rs b/src/test/compile-fail/trait-impl-can-not-have-untraitful-methods.rs index a20186c362b..1471d9232b2 100644 --- a/src/test/compile-fail/trait-impl-can-not-have-untraitful-methods.rs +++ b/src/test/compile-fail/trait-impl-can-not-have-untraitful-methods.rs @@ -11,7 +11,7 @@ trait A { } impl A for int { - fn foo() { } //~ ERROR method `foo` is not a member of trait `A` + fn foo(&self) { } //~ ERROR method `foo` is not a member of trait `A` } fn main() { } diff --git a/src/test/compile-fail/trait-impl-different-num-params.rs b/src/test/compile-fail/trait-impl-different-num-params.rs index f32793ad1e4..7039e050199 100644 --- a/src/test/compile-fail/trait-impl-different-num-params.rs +++ b/src/test/compile-fail/trait-impl-different-num-params.rs @@ -9,12 +9,12 @@ // except according to those terms. trait foo { - fn bar(x: uint) -> Self; + fn bar(&self, x: uint) -> Self; } impl foo for int { - fn bar() -> int { + fn bar(&self) -> int { //~^ ERROR method `bar` has 0 parameters but the trait has 1 - self + *self } } diff --git a/src/test/compile-fail/trait-impl-method-mismatch.rs b/src/test/compile-fail/trait-impl-method-mismatch.rs index 6931e680e08..6676cde3c96 100644 --- a/src/test/compile-fail/trait-impl-method-mismatch.rs +++ b/src/test/compile-fail/trait-impl-method-mismatch.rs @@ -9,15 +9,15 @@ // except according to those terms. trait Mumbo { - pure fn jumbo(&self, x: @uint) -> uint; + fn jumbo(&self, x: @uint) -> uint; fn jambo(&self, x: @const uint) -> uint; fn jbmbo(&self) -> @uint; } impl Mumbo for uint { // Cannot have a larger effect than the trait: - fn jumbo(&self, x: @uint) { *self + *x; } - //~^ ERROR expected pure fn but found impure fn + unsafe fn jumbo(&self, x: @uint) { *self + *x; } + //~^ ERROR expected impure fn but found unsafe fn // Cannot accept a narrower range of parameters: fn jambo(&self, x: @uint) { *self + *x; } diff --git a/src/test/compile-fail/trait-or-new-type-instead.rs b/src/test/compile-fail/trait-or-new-type-instead.rs index dc7c7cec65f..a5e37eb949d 100644 --- a/src/test/compile-fail/trait-or-new-type-instead.rs +++ b/src/test/compile-fail/trait-or-new-type-instead.rs @@ -10,7 +10,7 @@ // error-pattern: implement a trait or new type instead pub impl <T> Option<T> { - fn foo() { } + fn foo(&self) { } } fn main() { } diff --git a/src/test/compile-fail/trait-test-2.rs b/src/test/compile-fail/trait-test-2.rs index a00e63b60d7..ea04f74f078 100644 --- a/src/test/compile-fail/trait-test-2.rs +++ b/src/test/compile-fail/trait-test-2.rs @@ -8,12 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait bar { fn dup() -> Self; fn blah<X>(); } -impl bar for int { fn dup() -> int { self } fn blah<X>() {} } -impl bar for uint { fn dup() -> uint { self } fn blah<X>() {} } +trait bar { fn dup(&self) -> Self; fn blah<X>(&self); } +impl bar for int { fn dup(&self) -> int { *self } fn blah<X>(&self) {} } +impl bar for uint { fn dup(&self) -> uint { *self } fn blah<X>(&self) {} } fn main() { 10i.dup::<int>(); //~ ERROR does not take type parameters 10i.blah::<int, int>(); //~ ERROR incorrect number of type parameters - (@10 as bar).dup(); //~ ERROR contains a self-type + (@10 as @bar).dup(); //~ ERROR contains a self-type } diff --git a/src/test/compile-fail/trait-test.rs b/src/test/compile-fail/trait-test.rs index cd92801fb4d..1682e98fb23 100644 --- a/src/test/compile-fail/trait-test.rs +++ b/src/test/compile-fail/trait-test.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait foo { fn foo(); } +trait foo { fn foo(&self); } -impl int for uint { fn foo() {} } //~ ERROR trait +impl int for uint { fn foo(&self) {} } //~ ERROR trait fn main() {} diff --git a/src/test/compile-fail/unique-pinned-nocopy.rs b/src/test/compile-fail/unique-pinned-nocopy.rs index 12eef71f38b..a08f03d5628 100644 --- a/src/test/compile-fail/unique-pinned-nocopy.rs +++ b/src/test/compile-fail/unique-pinned-nocopy.rs @@ -19,5 +19,5 @@ impl Drop for r { fn main() { let i = ~r { b: true }; let _j = copy i; //~ ERROR copying a value of non-copyable type - log(debug, i); + debug!(i); } diff --git a/src/test/compile-fail/unique-vec-res.rs b/src/test/compile-fail/unique-vec-res.rs index 4ff9dd6f991..3f4636328b6 100644 --- a/src/test/compile-fail/unique-vec-res.rs +++ b/src/test/compile-fail/unique-vec-res.rs @@ -29,6 +29,6 @@ fn main() { f(copy r1, copy r2); //~^ ERROR copying a value of non-copyable type //~^^ ERROR copying a value of non-copyable type - log(debug, (r2, *i1)); - log(debug, (r1, *i2)); + debug!((r2, *i1)); + debug!((r1, *i2)); } diff --git a/src/test/compile-fail/unreachable-code.rs b/src/test/compile-fail/unreachable-code.rs index 8ddd934f580..f1fbc5b009e 100644 --- a/src/test/compile-fail/unreachable-code.rs +++ b/src/test/compile-fail/unreachable-code.rs @@ -12,5 +12,5 @@ fn main() { loop{} // red herring to make sure compilation fails - log(error, 42 == 'c'); + error!(42 == 'c'); } diff --git a/src/test/compile-fail/unsupported-cast.rs b/src/test/compile-fail/unsupported-cast.rs index b2f97aa63d2..3af012a6c3f 100644 --- a/src/test/compile-fail/unsupported-cast.rs +++ b/src/test/compile-fail/unsupported-cast.rs @@ -11,5 +11,5 @@ // error-pattern:unsupported cast fn main() { - log(debug, 1.0 as *libc::FILE); // Can't cast float to foreign. + debug!(1.0 as *libc::FILE); // Can't cast float to foreign. } diff --git a/src/test/compile-fail/vec-field.rs b/src/test/compile-fail/vec-field.rs index ca1da5a2ccd..b6d478aa3ec 100644 --- a/src/test/compile-fail/vec-field.rs +++ b/src/test/compile-fail/vec-field.rs @@ -13,7 +13,7 @@ fn f() { let v = ~[1i]; - log(debug, v.some_field_name); //type error + debug!(v.some_field_name); //type error } fn main() { } diff --git a/src/test/compile-fail/vec-res-add.rs b/src/test/compile-fail/vec-res-add.rs index b06f91d50f2..938e8c41e79 100644 --- a/src/test/compile-fail/vec-res-add.rs +++ b/src/test/compile-fail/vec-res-add.rs @@ -25,5 +25,5 @@ fn main() { let i = ~[r(0)]; let j = ~[r(1)]; let k = i + j; - log(debug, j); + debug!(j); } diff --git a/src/test/compile-fail/vtable-res-trait-param.rs b/src/test/compile-fail/vtable-res-trait-param.rs index c825118fa98..fab31f88e54 100644 --- a/src/test/compile-fail/vtable-res-trait-param.rs +++ b/src/test/compile-fail/vtable-res-trait-param.rs @@ -9,22 +9,22 @@ // except according to those terms. trait TraitA { - fn method_a() -> int; + fn method_a(&self) -> int; } trait TraitB { - fn gimme_an_a<A:TraitA>(a: A) -> int; + fn gimme_an_a<A:TraitA>(&self, a: A) -> int; } impl TraitB for int { - fn gimme_an_a<A:TraitA>(a: A) -> int { - a.method_a() + self + fn gimme_an_a<A:TraitA>(&self, a: A) -> int { + a.method_a() + *self } } fn call_it<B:TraitB>(b: B) -> int { let y = 4u; - b.gimme_an_a(y) //~ ERROR failed to find an implementation of trait @TraitA + b.gimme_an_a(y) //~ ERROR failed to find an implementation of trait TraitA } fn main() { diff --git a/src/test/debug-info/basic-types.rs b/src/test/debug-info/basic-types.rs new file mode 100644 index 00000000000..2441b35bc32 --- /dev/null +++ b/src/test/debug-info/basic-types.rs @@ -0,0 +1,68 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Caveats - gdb prints any 8-bit value (meaning rust i8 and u8 values) +// as its numerical value along with its associated ASCII char, there +// doesn't seem to be any way around this. Also, gdb doesn't know +// about UTF-32 character encoding and will print a rust char as only +// its numerical value. + +// compile-flags:-Z extra-debug-info +// debugger:break 67 +// debugger:run +// debugger:print b +// check:$1 = false +// debugger:print i +// check:$2 = -1 +// debugger:print c +// check:$3 = 97 +// debugger:print i8 +// check:$4 = 68 'D' +// debugger:print i16 +// check:$5 = -16 +// debugger:print i32 +// check:$6 = -32 +// debugger:print i64 +// check:$7 = -64 +// debugger:print u +// check:$8 = 1 +// debugger:print u8 +// check:$9 = 100 'd' +// debugger:print u16 +// check:$10 = 16 +// debugger:print u32 +// check:$11 = 32 +// debugger:print u64 +// check:$12 = 64 +// debugger:print f +// check:$13 = 1.5 +// debugger:print f32 +// check:$14 = 2.5 +// debugger:print f64 +// check:$15 = 3.5 + +fn main() { + let b: bool = false; + let i: int = -1; + let c: char = 'a'; + let i8: i8 = 68; + let i16: i16 = -16; + let i32: i32 = -32; + let i64: i64 = -64; + let u: uint = 1; + let u8: u8 = 100; + let u16: u16 = 16; + let u32: u32 = 32; + let u64: u64 = 64; + let f: float = 1.5; + let f32: f32 = 2.5; + let f64: f64 = 3.5; + let _z = (); +} diff --git a/src/test/debug-info/struct.rs b/src/test/debug-info/struct.rs index b3132914477..30f4b657c4e 100644 --- a/src/test/debug-info/struct.rs +++ b/src/test/debug-info/struct.rs @@ -8,15 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// xfail-test -// compile-flags:-g -// debugger:break 32 +// compile-flags:-Z extra-debug-info +// debugger:set print pretty off +// debugger:break 29 // debugger:run // debugger:print pair -// check:$1 = { -// check:x = 1, -// check:y = 2, -// check:} +// check:$1 = {x = 1, y = 2} // debugger:print pair.x // check:$2 = 1 // debugger:print pair.y @@ -29,5 +26,5 @@ struct Pair { fn main() { let pair = Pair { x: 1, y: 2 }; - debug!("x = %d, y = %d", pair.x, pair.y); + let _z = (); } diff --git a/src/test/debug-info/simple.rs b/src/test/debug-info/tuple.rs index 51bb177601a..a2cdc689fad 100644 --- a/src/test/debug-info/simple.rs +++ b/src/test/debug-info/tuple.rs @@ -8,14 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// xfail-test -// compile-flags:-g +// compile-flags:-Z extra-debug-info +// debugger:set print pretty off // debugger:break 20 // debugger:run -// debugger:print x -// check:$1 = 42 +// debugger:print t +// check:$1 = {4, 5.5, true} fn main() { - let x = 42; - debug!("The answer is %d", x); + let t = (4, 5.5, true); + let _z = (); } diff --git a/src/test/run-fail/alt-wildcards.rs b/src/test/run-fail/alt-wildcards.rs index 4730f1bc560..8aead798d5d 100644 --- a/src/test/run-fail/alt-wildcards.rs +++ b/src/test/run-fail/alt-wildcards.rs @@ -17,4 +17,4 @@ fn cmp() -> int { } } -fn main() { log(error, cmp()); } +fn main() { error!(cmp()); } diff --git a/src/test/run-fail/binop-fail-2.rs b/src/test/run-fail/binop-fail-2.rs index 2f1eb65a43a..2668570e6fb 100644 --- a/src/test/run-fail/binop-fail-2.rs +++ b/src/test/run-fail/binop-fail-2.rs @@ -9,5 +9,5 @@ // except according to those terms. // error-pattern:quux -fn my_err(s: ~str) -> ! { log(error, s); fail!(~"quux"); } +fn my_err(s: ~str) -> ! { error!(s); fail!(~"quux"); } fn main() { 3u == my_err(~"bye"); } diff --git a/src/test/run-fail/binop-fail.rs b/src/test/run-fail/binop-fail.rs index 2f1eb65a43a..2668570e6fb 100644 --- a/src/test/run-fail/binop-fail.rs +++ b/src/test/run-fail/binop-fail.rs @@ -9,5 +9,5 @@ // except according to those terms. // error-pattern:quux -fn my_err(s: ~str) -> ! { log(error, s); fail!(~"quux"); } +fn my_err(s: ~str) -> ! { error!(s); fail!(~"quux"); } fn main() { 3u == my_err(~"bye"); } diff --git a/src/test/run-fail/fail-arg.rs b/src/test/run-fail/fail-arg.rs index fc365613cf1..f1a26df924b 100644 --- a/src/test/run-fail/fail-arg.rs +++ b/src/test/run-fail/fail-arg.rs @@ -9,6 +9,6 @@ // except according to those terms. // error-pattern:woe -fn f(a: int) { log(debug, a); } +fn f(a: int) { debug!(a); } fn main() { f(fail!(~"woe")); } diff --git a/src/test/run-fail/if-check-fail.rs b/src/test/run-fail/if-check-fail.rs index 5f9da798ffa..a3831a10874 100644 --- a/src/test/run-fail/if-check-fail.rs +++ b/src/test/run-fail/if-check-fail.rs @@ -17,7 +17,7 @@ pure fn even(x: uint) -> bool { fn foo(x: uint) { if even(x) { - log(debug, x); + debug!(x); } else { fail!(~"Number is odd"); } diff --git a/src/test/run-fail/if-cond-bot.rs b/src/test/run-fail/if-cond-bot.rs index d558ff1e3b8..92063e76c34 100644 --- a/src/test/run-fail/if-cond-bot.rs +++ b/src/test/run-fail/if-cond-bot.rs @@ -9,5 +9,5 @@ // except according to those terms. // error-pattern:quux -fn my_err(s: ~str) -> ! { log(error, s); fail!(~"quux"); } +fn my_err(s: ~str) -> ! { error!(s); fail!(~"quux"); } fn main() { if my_err(~"bye") { } } diff --git a/src/test/run-fail/result-get-fail.rs b/src/test/run-fail/result-get-fail.rs index d9c17211cef..1e4e7685e27 100644 --- a/src/test/run-fail/result-get-fail.rs +++ b/src/test/run-fail/result-get-fail.rs @@ -10,5 +10,5 @@ // error-pattern:get called on error result: ~"kitty" fn main() { - log(error, result::get(&result::Err::<int,~str>(~"kitty"))); + error!(result::get(&result::Err::<int,~str>(~"kitty"))); } diff --git a/src/test/run-fail/rt-set-exit-status-fail.rs b/src/test/run-fail/rt-set-exit-status-fail.rs index ed08022f449..f6e9602470f 100644 --- a/src/test/run-fail/rt-set-exit-status-fail.rs +++ b/src/test/run-fail/rt-set-exit-status-fail.rs @@ -11,7 +11,7 @@ // error-pattern:whatever fn main() { - log(error, ~"whatever"); + error!(~"whatever"); // Setting the exit status only works when the scheduler terminates // normally. In this case we're going to fail, so instead of of // returning 50 the process will return the typical rt failure code. diff --git a/src/test/run-fail/rt-set-exit-status-fail2.rs b/src/test/run-fail/rt-set-exit-status-fail2.rs index 78de5c3b847..bf33b10cc61 100644 --- a/src/test/run-fail/rt-set-exit-status-fail2.rs +++ b/src/test/run-fail/rt-set-exit-status-fail2.rs @@ -30,7 +30,7 @@ fn r(x:int) -> r { } fn main() { - log(error, ~"whatever"); + error!(~"whatever"); do task::spawn { let i = r(5); }; diff --git a/src/test/run-fail/rt-set-exit-status.rs b/src/test/run-fail/rt-set-exit-status.rs index b20eb222025..2cff4ff09df 100644 --- a/src/test/run-fail/rt-set-exit-status.rs +++ b/src/test/run-fail/rt-set-exit-status.rs @@ -11,7 +11,7 @@ // error-pattern:whatever fn main() { - log(error, ~"whatever"); + error!(~"whatever"); // 101 is the code the runtime uses on task failure and the value // compiletest expects run-fail tests to return. os::set_exit_status(101); diff --git a/src/test/run-fail/small-negative-indexing.rs b/src/test/run-fail/small-negative-indexing.rs index fe3fb448f6f..87df00fcce5 100644 --- a/src/test/run-fail/small-negative-indexing.rs +++ b/src/test/run-fail/small-negative-indexing.rs @@ -12,5 +12,5 @@ fn main() { let v = vec::from_fn(1024u, {|n| n}); // this should trip a bounds check - log(error, v[-1i8]); + error!(v[-1i8]); } diff --git a/src/test/run-fail/too-much-recursion.rs b/src/test/run-fail/too-much-recursion.rs index 009dee8cb7c..04514b13455 100644 --- a/src/test/run-fail/too-much-recursion.rs +++ b/src/test/run-fail/too-much-recursion.rs @@ -13,6 +13,6 @@ // Test that the task fails after hiting the recursion limit fn main() { - log(debug, ~"don't optimize me out"); + debug!(~"don't optimize me out"); main(); } diff --git a/src/test/run-fail/unwind-box-fn-unique.rs b/src/test/run-fail/unwind-box-fn-unique.rs index 326c304ef3b..4ab74b485ab 100644 --- a/src/test/run-fail/unwind-box-fn-unique.rs +++ b/src/test/run-fail/unwind-box-fn-unique.rs @@ -17,8 +17,8 @@ fn failfn() { fn main() { let y = ~0; let x: @~fn() = @(|| { - log(error, copy y); + error!(copy y); }); failfn(); - log(error, x); + error!(x); } diff --git a/src/test/run-fail/unwind-box-fn.rs b/src/test/run-fail/unwind-box-fn.rs index a2227e6c94a..c62e13e77d7 100644 --- a/src/test/run-fail/unwind-box-fn.rs +++ b/src/test/run-fail/unwind-box-fn.rs @@ -17,8 +17,8 @@ fn failfn() { fn main() { let y = ~0; let x: @@fn() = @|| { - log(error, copy y); + error!(copy y); }; failfn(); - log(error, x); + error!(x); } diff --git a/src/test/run-fail/unwind-box-res.rs b/src/test/run-fail/unwind-box-res.rs index ba8f2fa37cb..e576faa16ea 100644 --- a/src/test/run-fail/unwind-box-res.rs +++ b/src/test/run-fail/unwind-box-res.rs @@ -39,6 +39,6 @@ fn main() { cast::forget(i1); let x = @r(i1p); failfn(); - log(error, x); + error!(x); } } diff --git a/src/test/run-fail/unwind-box-str.rs b/src/test/run-fail/unwind-box-str.rs index aaf714fff9c..213220164f1 100644 --- a/src/test/run-fail/unwind-box-str.rs +++ b/src/test/run-fail/unwind-box-str.rs @@ -17,5 +17,5 @@ fn failfn() { fn main() { let x = @~"hi"; failfn(); - log(error, x); + error!(x); } diff --git a/src/test/run-fail/unwind-box-trait.rs b/src/test/run-fail/unwind-box-trait.rs index 905670f8fb7..2ed3b39a445 100644 --- a/src/test/run-fail/unwind-box-trait.rs +++ b/src/test/run-fail/unwind-box-trait.rs @@ -15,15 +15,15 @@ fn failfn() { } trait i { - fn foo(); + fn foo(&self); } impl i for ~int { - fn foo() { } + fn foo(&self) { } } fn main() { let x = @~0 as @i; failfn(); - log(error, x); + error!(x); } diff --git a/src/test/run-fail/unwind-box-unique-unique.rs b/src/test/run-fail/unwind-box-unique-unique.rs index 22a5c72b68c..12b00f0c14b 100644 --- a/src/test/run-fail/unwind-box-unique-unique.rs +++ b/src/test/run-fail/unwind-box-unique-unique.rs @@ -17,5 +17,5 @@ fn failfn() { fn main() { let x = @~~0; failfn(); - log(error, x); + error!(x); } diff --git a/src/test/run-fail/unwind-box-unique.rs b/src/test/run-fail/unwind-box-unique.rs index 3ae4000c2b1..edc6ab9d984 100644 --- a/src/test/run-fail/unwind-box-unique.rs +++ b/src/test/run-fail/unwind-box-unique.rs @@ -17,5 +17,5 @@ fn failfn() { fn main() { let x = @~0; failfn(); - log(error, x); + error!(x); } diff --git a/src/test/run-fail/unwind-box-vec.rs b/src/test/run-fail/unwind-box-vec.rs index d8afdd5a661..0a579a8dbbf 100644 --- a/src/test/run-fail/unwind-box-vec.rs +++ b/src/test/run-fail/unwind-box-vec.rs @@ -17,5 +17,5 @@ fn failfn() { fn main() { let x = @~[0, 1, 2, 3, 4, 5]; failfn(); - log(error, x); + error!(x); } diff --git a/src/test/run-fail/unwind-move.rs b/src/test/run-fail/unwind-move.rs index b2d30688ec5..51e2eaa44fa 100644 --- a/src/test/run-fail/unwind-move.rs +++ b/src/test/run-fail/unwind-move.rs @@ -9,7 +9,7 @@ // except according to those terms. // error-pattern:fail -fn f(-_a: @int) { +fn f(+_a: @int) { fail!(); } diff --git a/src/test/run-pass/alt-bot.rs b/src/test/run-pass/alt-bot.rs index d4887c4415e..78892a1e4b8 100644 --- a/src/test/run-pass/alt-bot.rs +++ b/src/test/run-pass/alt-bot.rs @@ -12,5 +12,5 @@ pub fn main() { let i: int = match Some::<int>(3) { None::<int> => { fail!() } Some::<int>(_) => { 5 } }; - log(debug, i); + debug!("%?", i); } diff --git a/src/test/run-pass/alt-pattern-drop.rs b/src/test/run-pass/alt-pattern-drop.rs index 97b835f55be..131869a0c4e 100644 --- a/src/test/run-pass/alt-pattern-drop.rs +++ b/src/test/run-pass/alt-pattern-drop.rs @@ -19,12 +19,12 @@ fn foo(s: @int) { match x { make_t(y) => { - log(debug, y); // ref up then down + debug!("%?", y); // ref up then down } _ => { debug!("?"); fail!(); } } - log(debug, ::core::sys::refcount(s)); + debug!(::core::sys::refcount(s)); fail_unless!((::core::sys::refcount(s) == count + 1u)); let _ = ::core::sys::refcount(s); // don't get bitten by last-use. } @@ -36,7 +36,7 @@ pub fn main() { foo(s); // ref up then down - log(debug, ::core::sys::refcount(s)); + debug!("%u", ::core::sys::refcount(s)); let count2 = ::core::sys::refcount(s); let _ = ::core::sys::refcount(s); // don't get bitten by last-use. fail_unless!(count == count2); diff --git a/src/test/run-pass/alt-tag.rs b/src/test/run-pass/alt-tag.rs index aff2d9ad564..8051a14dac8 100644 --- a/src/test/run-pass/alt-tag.rs +++ b/src/test/run-pass/alt-tag.rs @@ -21,9 +21,9 @@ enum color { fn process(c: color) -> int { let mut x: int; match c { - rgb(r, _, _) => { debug!("rgb"); log(debug, r); x = r; } - rgba(_, _, _, a) => { debug!("rgba"); log(debug, a); x = a; } - hsl(_, s, _) => { debug!("hsl"); log(debug, s); x = s; } + rgb(r, _, _) => { x = r; } + rgba(_, _, _, a) => { x = a; } + hsl(_, s, _) => { x = s; } } return x; } diff --git a/src/test/run-pass/alt-value-binding-in-guard-3291.rs b/src/test/run-pass/alt-value-binding-in-guard-3291.rs index 5171d7d2a58..33785b2fbb0 100644 --- a/src/test/run-pass/alt-value-binding-in-guard-3291.rs +++ b/src/test/run-pass/alt-value-binding-in-guard-3291.rs @@ -11,7 +11,7 @@ fn foo(x: Option<~int>, b: bool) -> int { match x { None => { 1 } - Some(copy x) if b => { *x } + Some(ref x) if b => { *x.clone() } Some(_) => { 0 } } } diff --git a/src/test/run-pass/alt-with-ret-arm.rs b/src/test/run-pass/alt-with-ret-arm.rs index ccdbc744ca3..ad4d87fb87c 100644 --- a/src/test/run-pass/alt-with-ret-arm.rs +++ b/src/test/run-pass/alt-with-ret-arm.rs @@ -17,5 +17,5 @@ pub fn main() { Some(num) => num as u32 }; fail_unless!(f == 1234u32); - log(error, f) + error!(f) } diff --git a/src/test/run-pass/argument-passing.rs b/src/test/run-pass/argument-passing.rs index 186fdb28494..11f988bc296 100644 --- a/src/test/run-pass/argument-passing.rs +++ b/src/test/run-pass/argument-passing.rs @@ -12,7 +12,7 @@ struct X { x: int } -fn f1(a: &mut X, b: &mut int, -c: int) -> int { +fn f1(a: &mut X, b: &mut int, +c: int) -> int { let r = a.x + *b + c; a.x = 0; *b = 10; diff --git a/src/test/run-pass/arith-0.rs b/src/test/run-pass/arith-0.rs index 0725ac2e174..adfc1033d97 100644 --- a/src/test/run-pass/arith-0.rs +++ b/src/test/run-pass/arith-0.rs @@ -12,6 +12,6 @@ pub fn main() { let a: int = 10; - log(debug, a); + debug!(a); fail_unless!((a * (a - 1) == 90)); } diff --git a/src/test/run-pass/arith-1.rs b/src/test/run-pass/arith-1.rs index 3dc60d63bbe..1b98cf4dc5c 100644 --- a/src/test/run-pass/arith-1.rs +++ b/src/test/run-pass/arith-1.rs @@ -28,6 +28,6 @@ pub fn main() { fail_unless!((i32_b << 1 == i32_b << 1)); fail_unless!((i32_b >> 1 == i32_b >> 1)); fail_unless!((i32_b & i32_b << 1 == 0)); - log(debug, i32_b | i32_b << 1); + debug!(i32_b | i32_b << 1); fail_unless!((i32_b | i32_b << 1 == 0x30303030)); } diff --git a/src/test/run-pass/assignability-trait.rs b/src/test/run-pass/assignability-trait.rs index ae046babfdf..78bdee1430c 100644 --- a/src/test/run-pass/assignability-trait.rs +++ b/src/test/run-pass/assignability-trait.rs @@ -13,20 +13,20 @@ // it. trait iterable<A> { - fn iterate(blk: &fn(x: &A) -> bool); + fn iterate(&self, blk: &fn(x: &A) -> bool); } -impl<A> iterable<A> for &self/[A] { - fn iterate(f: &fn(x: &A) -> bool) { - for vec::each(self) |e| { +impl<A> iterable<A> for &'self [A] { + fn iterate(&self, f: &fn(x: &A) -> bool) { + for vec::each(*self) |e| { if !f(e) { break; } } } } impl<A> iterable<A> for ~[A] { - fn iterate(f: &fn(x: &A) -> bool) { - for vec::each(self) |e| { + fn iterate(&self, f: &fn(x: &A) -> bool) { + for vec::each(*self) |e| { if !f(e) { break; } } } @@ -43,7 +43,7 @@ pub fn main() { // Call a method for x.iterate() |y| { fail_unless!(x[*y] == *y); } // Call a parameterized function - fail_unless!(length(copy x) == vec::len(x)); + fail_unless!(length(x.clone()) == vec::len(x)); // Call a parameterized function, with type arguments that require // a borrow fail_unless!(length::<int, &[int]>(x) == vec::len(x)); diff --git a/src/test/run-pass/auto-instantiate.rs b/src/test/run-pass/auto-instantiate.rs index 4075ec56038..973f1dedea2 100644 --- a/src/test/run-pass/auto-instantiate.rs +++ b/src/test/run-pass/auto-instantiate.rs @@ -19,6 +19,6 @@ struct Triple { x: int, y: int, z: int } fn f<T:Copy,U:Copy>(x: T, y: U) -> Pair<T, U> { return Pair {a: x, b: y}; } pub fn main() { - log(debug, f(Triple {x: 3, y: 4, z: 5}, 4).a.x); - log(debug, f(5, 6).a); + debug!("%?", f(Triple {x: 3, y: 4, z: 5}, 4).a.x); + debug!("%?", f(5, 6).a); } 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 ea41a50e382..39fe34bfe52 100644 --- a/src/test/run-pass/auto-ref-slice-plus-ref.rs +++ b/src/test/run-pass/auto-ref-slice-plus-ref.rs @@ -39,7 +39,6 @@ pub fn main() { (&"test").test_imm(); // XXX: Other types of mutable vecs don't currently exist - (@mut [1]).test_imm(); ([1]).test_const(); (~[1]).test_const(); @@ -50,8 +49,6 @@ pub fn main() { (@"test").test_const(); (&"test").test_const(); - (@mut [1]).test_const(); - // NB: We don't do this double autoreffing for &mut self because that would // allow creating a mutable pointer to a temporary, which would be a source // of confusion diff --git a/src/test/run-pass/auto-ref.rs b/src/test/run-pass/auto-ref.rs index b6d71fcfb55..f7c0f513a9d 100644 --- a/src/test/run-pass/auto-ref.rs +++ b/src/test/run-pass/auto-ref.rs @@ -13,11 +13,11 @@ struct Foo { } trait Stuff { - fn printme(); + fn printme(&self); } -impl Stuff for &self/Foo { - fn printme() { +impl Stuff for Foo { + fn printme(&self) { io::println(fmt!("%d", self.x)); } } diff --git a/src/test/run-pass/autoderef-method-newtype.rs b/src/test/run-pass/autoderef-method-newtype.rs index 732c26694ad..a4dbab49c0c 100644 --- a/src/test/run-pass/autoderef-method-newtype.rs +++ b/src/test/run-pass/autoderef-method-newtype.rs @@ -9,11 +9,11 @@ // except according to those terms. trait double { - fn double() -> uint; + fn double(&self) -> uint; } impl double for uint { - fn double() -> uint { self * 2u } + fn double(&self) -> uint { *self * 2u } } struct foo(uint); diff --git a/src/test/run-pass/autoderef-method-on-trait.rs b/src/test/run-pass/autoderef-method-on-trait.rs index 3d64c5d0e42..3fabb95f2a3 100644 --- a/src/test/run-pass/autoderef-method-on-trait.rs +++ b/src/test/run-pass/autoderef-method-on-trait.rs @@ -9,11 +9,11 @@ // except according to those terms. trait double { - fn double() -> uint; + fn double(@self) -> uint; } impl double for uint { - fn double() -> uint { self * 2u } + fn double(@self) -> uint { *self * 2u } } pub fn main() { diff --git a/src/test/run-pass/autoderef-method-priority.rs b/src/test/run-pass/autoderef-method-priority.rs index a3d4e28dec7..e6efa6dc633 100644 --- a/src/test/run-pass/autoderef-method-priority.rs +++ b/src/test/run-pass/autoderef-method-priority.rs @@ -1,3 +1,6 @@ +// xfail-test +// xfail'd because of a problem with by-value self. + // 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. @@ -9,15 +12,15 @@ // except according to those terms. trait double { - fn double() -> uint; + fn double(self) -> uint; } impl double for uint { - fn double() -> uint { self } + fn double(self) -> uint { self } } impl double for @uint { - fn double() -> uint { *self * 2u } + fn double(self) -> uint { *self * 2u } } pub fn main() { diff --git a/src/test/run-pass/autoderef-method-twice-but-not-thrice.rs b/src/test/run-pass/autoderef-method-twice-but-not-thrice.rs index 9a6469bbca8..a54e77476cf 100644 --- a/src/test/run-pass/autoderef-method-twice-but-not-thrice.rs +++ b/src/test/run-pass/autoderef-method-twice-but-not-thrice.rs @@ -9,11 +9,11 @@ // except according to those terms. trait double { - fn double() -> uint; + fn double(@self) -> uint; } -impl double for @@uint { - fn double() -> uint { **self * 2u } +impl double for @uint { + fn double(@self) -> uint { **self * 2u } } pub fn main() { diff --git a/src/test/run-pass/autoderef-method-twice.rs b/src/test/run-pass/autoderef-method-twice.rs index c44ded77ec8..dde6ae9e5de 100644 --- a/src/test/run-pass/autoderef-method-twice.rs +++ b/src/test/run-pass/autoderef-method-twice.rs @@ -9,11 +9,11 @@ // except according to those terms. trait double { - fn double() -> uint; + fn double(@self) -> uint; } impl double for uint { - fn double() -> uint { self * 2u } + fn double(@self) -> uint { *self * 2u } } pub fn main() { diff --git a/src/test/run-pass/autoderef-method.rs b/src/test/run-pass/autoderef-method.rs index e6b05989903..f6e04c79d45 100644 --- a/src/test/run-pass/autoderef-method.rs +++ b/src/test/run-pass/autoderef-method.rs @@ -9,11 +9,11 @@ // except according to those terms. trait double { - fn double() -> uint; + fn double(@self) -> uint; } impl double for uint { - fn double() -> uint { self * 2u } + fn double(@self) -> uint { *self * 2u } } pub fn main() { diff --git a/src/test/run-pass/bare-static-string.rs b/src/test/run-pass/bare-static-string.rs index ceae1392d3b..d8015f0b92c 100644 --- a/src/test/run-pass/bare-static-string.rs +++ b/src/test/run-pass/bare-static-string.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let x: &static/str = "foo"; + let x: &'static str = "foo"; io::println(x); } diff --git a/src/test/run-pass/bitwise.rs b/src/test/run-pass/bitwise.rs index a2caf5e97f5..ec324bcf33b 100644 --- a/src/test/run-pass/bitwise.rs +++ b/src/test/run-pass/bitwise.rs @@ -26,8 +26,8 @@ fn general() { a ^= b; b ^= a; a = a ^ b; - log(debug, a); - log(debug, b); + debug!(a); + debug!(b); fail_unless!((b == 1)); fail_unless!((a == 2)); fail_unless!((!0xf0 & 0xff == 0xf)); diff --git a/src/test/run-pass/block-arg.rs b/src/test/run-pass/block-arg.rs index fa4a61549dc..fa8687e839c 100644 --- a/src/test/run-pass/block-arg.rs +++ b/src/test/run-pass/block-arg.rs @@ -14,7 +14,7 @@ pub fn main() { // Statement form does not require parentheses: for vec::each(v) |i| { - log(info, *i); + info!("%?", *i); } // Usable at all: diff --git a/src/test/run-pass/block-explicit-types.rs b/src/test/run-pass/block-explicit-types.rs index b24a655667a..ff65d963000 100644 --- a/src/test/run-pass/block-explicit-types.rs +++ b/src/test/run-pass/block-explicit-types.rs @@ -10,5 +10,5 @@ pub fn main() { fn as_buf<T>(s: ~str, f: &fn(~str) -> T) -> T { f(s) } - as_buf(~"foo", |foo: ~str| -> () log(error, foo) ); + as_buf(~"foo", |foo: ~str| -> () error!(foo) ); } diff --git a/src/test/run-pass/block-iter-1.rs b/src/test/run-pass/block-iter-1.rs index d0a24f80c0b..e6056382779 100644 --- a/src/test/run-pass/block-iter-1.rs +++ b/src/test/run-pass/block-iter-1.rs @@ -16,12 +16,10 @@ pub fn main() { let v = ~[1, 2, 3, 4, 5, 6, 7]; let mut odds = 0; iter_vec(v, |i| { - log(error, i); if *i % 2 == 1 { odds += 1; } - log(error, odds); }); - log(error, odds); + error!(odds); fail_unless!((odds == 4)); } diff --git a/src/test/run-pass/block-iter-2.rs b/src/test/run-pass/block-iter-2.rs index acffb6830de..96336f5569c 100644 --- a/src/test/run-pass/block-iter-2.rs +++ b/src/test/run-pass/block-iter-2.rs @@ -15,12 +15,11 @@ fn iter_vec<T>(v: ~[T], f: &fn(&T)) { for v.each |x| { f(x); } } pub fn main() { let v = ~[1, 2, 3, 4, 5]; let mut sum = 0; - iter_vec(copy v, |i| { - iter_vec(copy v, |j| { - log(error, *i * *j); + iter_vec(v.clone(), |i| { + iter_vec(v.clone(), |j| { sum += *i * *j; }); }); - log(error, sum); + error!(sum); fail_unless!((sum == 225)); } diff --git a/src/test/run-pass/block-vec-map2.rs b/src/test/run-pass/block-vec-map2.rs index 24f990ef7cd..28875da25a6 100644 --- a/src/test/run-pass/block-vec-map2.rs +++ b/src/test/run-pass/block-vec-map2.rs @@ -15,6 +15,6 @@ pub fn main() { vec::map2(~[1, 2, 3, 4, 5], ~[true, false, false, true, true], |i, b| if *b { -(*i) } else { *i } ); - log(error, copy v); + error!(v.clone()); fail_unless!((v == ~[-1, 2, 3, -4, -5])); } diff --git a/src/test/run-pass/borrowck-borrow-from-expr-block.rs b/src/test/run-pass/borrowck-borrow-from-expr-block.rs index 0422be9d333..f2e0b6c9ca0 100644 --- a/src/test/run-pass/borrowck-borrow-from-expr-block.rs +++ b/src/test/run-pass/borrowck-borrow-from-expr-block.rs @@ -13,7 +13,7 @@ fn borrow(x: &int, f: &fn(x: &int)) { } fn test1(x: @~int) { - do borrow(copy *x) |p| { + do borrow(&*x.clone()) |p| { let x_a = ptr::addr_of(&(**x)); fail_unless!((x_a as uint) != ptr::to_uint(p)); fail_unless!(unsafe{*x_a} == *p); diff --git a/src/test/run-pass/borrowck-lend-args.rs b/src/test/run-pass/borrowck-lend-args.rs index 44be8f2724a..0d51993e226 100644 --- a/src/test/run-pass/borrowck-lend-args.rs +++ b/src/test/run-pass/borrowck-lend-args.rs @@ -18,17 +18,9 @@ fn borrow_from_arg_mut_ref(v: &mut ~int) { borrow(*v); } -fn borrow_from_arg_move(-v: ~int) { - borrow(v); -} - fn borrow_from_arg_copy(+v: ~int) { borrow(v); } -fn borrow_from_arg_val(++v: ~int) { - borrow(v); -} - pub fn main() { } diff --git a/src/test/run-pass/borrowck-newtype-issue-2573.rs b/src/test/run-pass/borrowck-newtype-issue-2573.rs index 7e81345739f..7724836b5db 100644 --- a/src/test/run-pass/borrowck-newtype-issue-2573.rs +++ b/src/test/run-pass/borrowck-newtype-issue-2573.rs @@ -15,11 +15,11 @@ struct baz_ {baz: int} type baz = @mut baz_; trait frob { - fn frob(); + fn frob(&self); } impl frob for foo { - fn frob() { + fn frob(&self) { really_impure(self.bar); } } diff --git a/src/test/run-pass/borrowck-preserve-box-sometimes-needed.rs b/src/test/run-pass/borrowck-preserve-box-sometimes-needed.rs index a0f1801ce29..e3f8f98f4b6 100644 --- a/src/test/run-pass/borrowck-preserve-box-sometimes-needed.rs +++ b/src/test/run-pass/borrowck-preserve-box-sometimes-needed.rs @@ -13,7 +13,7 @@ fn switcher(x: Option<@int>) { let mut x = x; match x { - Some(@y) => { copy y; x = None; } + Some(@y) => { y.clone(); x = None; } None => { } } } diff --git a/src/test/run-pass/borrowck-root-while-cond.rs b/src/test/run-pass/borrowck-root-while-cond.rs index 285796db20e..a8823c477aa 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<T>(x: &r/T) -> &r/T {x} +fn borrow<T>(x: &'r T) -> &'r T {x} struct Rec { f: @int } diff --git a/src/test/run-pass/borrowck-wg-borrow-mut-to-imm-3.rs b/src/test/run-pass/borrowck-wg-borrow-mut-to-imm-3.rs index d8612155f6c..0699df703c6 100644 --- a/src/test/run-pass/borrowck-wg-borrow-mut-to-imm-3.rs +++ b/src/test/run-pass/borrowck-wg-borrow-mut-to-imm-3.rs @@ -1,5 +1,5 @@ struct Wizard { - spells: ~[&static/str] + spells: ~[&'static str] } pub impl Wizard { diff --git a/src/test/run-pass/borrowed-ptr-pattern-3.rs b/src/test/run-pass/borrowed-ptr-pattern-3.rs index 9043018b816..1e9175ac196 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(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 d0d276a8c8c..42c0795b3dd 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<int>, y: &r/Option<int>) -> &r/Option<int> { +fn select(x: &'r Option<int>, y: &'r Option<int>) -> &'r Option<int> { match (x, y) { (&None, &None) => x, (&Some(_), _) => x, diff --git a/src/test/run-pass/boxed-trait-with-vstore.rs b/src/test/run-pass/boxed-trait-with-vstore.rs index 1d2c30108f1..1aac86238dc 100644 --- a/src/test/run-pass/boxed-trait-with-vstore.rs +++ b/src/test/run-pass/boxed-trait-with-vstore.rs @@ -9,11 +9,11 @@ // except according to those terms. trait Foo { - fn foo(); + fn foo(@self); } impl Foo for int { - fn foo() { + fn foo(@self) { io::println("Hello world!"); } } diff --git a/src/test/run-pass/class-cast-to-trait-multiple-types.rs b/src/test/run-pass/class-cast-to-trait-multiple-types.rs index 50a3d5cc617..eefa78cc3c9 100644 --- a/src/test/run-pass/class-cast-to-trait-multiple-types.rs +++ b/src/test/run-pass/class-cast-to-trait-multiple-types.rs @@ -9,7 +9,7 @@ // except according to those terms. trait noisy { - fn speak() -> int; + fn speak(&self) -> int; } struct dog { @@ -19,7 +19,7 @@ struct dog { } pub impl dog { - priv fn bark() -> int { + priv fn bark(&self) -> int { debug!("Woof %u %d", *self.barks, *self.volume); *self.barks += 1u; if *self.barks % 3u == 0u { @@ -34,7 +34,7 @@ pub impl dog { } impl noisy for dog { - fn speak() -> int { self.bark() } + fn speak(&self) -> int { self.bark() } } fn dog() -> dog { @@ -52,15 +52,15 @@ struct cat { } impl noisy for cat { - fn speak() -> int { self.meow() as int } + fn speak(&self) -> int { self.meow() as int } } pub impl cat { - fn meow_count() -> uint { *self.meows } + fn meow_count(&self) -> uint { *self.meows } } priv impl cat { - fn meow() -> uint { + fn meow(&self) -> uint { debug!("Meow"); *self.meows += 1u; if *self.meows % 5u == 0u { diff --git a/src/test/run-pass/class-exports.rs b/src/test/run-pass/class-exports.rs index 85cbbcc23a3..6a665f770ff 100644 --- a/src/test/run-pass/class-exports.rs +++ b/src/test/run-pass/class-exports.rs @@ -22,7 +22,7 @@ mod kitty { } pub impl cat { - fn get_name() -> ~str { copy self.name } + fn get_name(&self) -> ~str { self.name.clone() } } pub fn cat(in_name: ~str) -> cat { 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 6cb0749ddb5..a0a4ea19964 100644 --- a/src/test/run-pass/class-impl-very-parameterized-trait.rs +++ b/src/test/run-pass/class-impl-very-parameterized-trait.rs @@ -62,8 +62,8 @@ impl<T> BaseIter<(int, &'self T)> for cat<T> { } impl<T> Container for cat<T> { - pure fn len(&self) -> uint { self.meows as uint } - pure fn is_empty(&self) -> bool { self.meows == 0 } + pure fn len(&const self) -> uint { self.meows as uint } + pure fn is_empty(&const self) -> bool { self.meows == 0 } } impl<T> Mutable for cat<T> { @@ -81,6 +81,10 @@ impl<T> Map<int, T> for cat<T> { for self.each |&(_, v)| { if !f(v) { break; } loop;}; } + fn mutate_values(&mut self, f: &fn(&int, &mut T) -> bool) { + fail!(~"nope") + } + fn insert(&mut self, k: int, _: T) -> bool { self.meows += k; true diff --git a/src/test/run-pass/class-implement-traits.rs b/src/test/run-pass/class-implement-traits.rs index 9e6637c9b17..7cd2753ee15 100644 --- a/src/test/run-pass/class-implement-traits.rs +++ b/src/test/run-pass/class-implement-traits.rs @@ -53,7 +53,7 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { cat { meows: in_x, how_hungry: in_y, - name: copy in_name + name: in_name.clone() } } diff --git a/src/test/run-pass/class-poly-methods.rs b/src/test/run-pass/class-poly-methods.rs index 88fe2be2bdb..95db23f6c5a 100644 --- a/src/test/run-pass/class-poly-methods.rs +++ b/src/test/run-pass/class-poly-methods.rs @@ -22,7 +22,7 @@ pub impl<U> cat<U> { fn meow_count(&mut self) -> uint { self.meows } } -fn cat<U>(in_x : uint, in_y : int, -in_info: ~[U]) -> cat<U> { +fn cat<U>(in_x : uint, in_y : int, +in_info: ~[U]) -> cat<U> { cat { meows: in_x, how_hungry: in_y, diff --git a/src/test/run-pass/class-separate-impl.rs b/src/test/run-pass/class-separate-impl.rs index 7cba1456ee7..bb07597a188 100644 --- a/src/test/run-pass/class-separate-impl.rs +++ b/src/test/run-pass/class-separate-impl.rs @@ -9,8 +9,6 @@ // except according to those terms. // xfail-fast -use core::to_str::*; - struct cat { priv meows : uint, @@ -53,7 +51,12 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { } impl ToStr for cat { - pure fn to_str(&self) -> ~str { copy self.name } + pure fn to_str(&self) -> ~str { + // FIXME #5384: this unsafe block is to work around purity + unsafe { + self.name.clone() + } + } } fn print_out(thing: @ToStr, expected: ~str) { diff --git a/src/test/run-pass/coerce-reborrow-imm-ptr-arg.rs b/src/test/run-pass/coerce-reborrow-imm-ptr-arg.rs index 37770f4d59b..905046756f6 100644 --- a/src/test/run-pass/coerce-reborrow-imm-ptr-arg.rs +++ b/src/test/run-pass/coerce-reborrow-imm-ptr-arg.rs @@ -10,8 +10,4 @@ fn negate_imm(y: &int) -> int { negate(y) } -fn negate_const(y: &const int) -> int { - negate(y) -} - pub fn main() {} diff --git a/src/test/run-pass/coerce-reborrow-imm-ptr-rcvr.rs b/src/test/run-pass/coerce-reborrow-imm-ptr-rcvr.rs index 8fab061b4de..54d9758aa21 100644 --- a/src/test/run-pass/coerce-reborrow-imm-ptr-rcvr.rs +++ b/src/test/run-pass/coerce-reborrow-imm-ptr-rcvr.rs @@ -3,7 +3,7 @@ struct SpeechMaker { } pub impl SpeechMaker { - pure fn how_many(&self) -> uint { self.speeches } + pure fn how_many(&const self) -> uint { self.speeches } } fn foo(speaker: &const SpeechMaker) -> uint { 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 ba7d78ba04f..a18b4a2b0c6 100644 --- a/src/test/run-pass/coerce-reborrow-imm-vec-arg.rs +++ b/src/test/run-pass/coerce-reborrow-imm-vec-arg.rs @@ -1,3 +1,5 @@ +// xfail-test + pure fn sum(x: &[int]) -> int { let mut sum = 0; for x.each |y| { 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 7ab63f43769..bf86472d900 100644 --- a/src/test/run-pass/coerce-reborrow-imm-vec-rcvr.rs +++ b/src/test/run-pass/coerce-reborrow-imm-vec-rcvr.rs @@ -1,3 +1,5 @@ +// xfail-test + fn foo(v: &[const uint]) -> ~[uint] { v.to_vec() } diff --git a/src/test/run-pass/comm.rs b/src/test/run-pass/comm.rs index c9c04562201..601bae85d4f 100644 --- a/src/test/run-pass/comm.rs +++ b/src/test/run-pass/comm.rs @@ -16,7 +16,7 @@ pub fn main() { let t = task::spawn(|| child(&ch) ); let y = p.recv(); error!("received"); - log(error, y); + error!(y); fail_unless!((y == 10)); } diff --git a/src/test/run-pass/complex.rs b/src/test/run-pass/complex.rs index de60a56ba4a..733e8466154 100644 --- a/src/test/run-pass/complex.rs +++ b/src/test/run-pass/complex.rs @@ -37,7 +37,7 @@ fn foo(x: int) -> int { pub fn main() { let x: int = 2 + 2; - log(debug, x); + debug!("%?", x); debug!("hello, world"); - log(debug, 10); + debug!("%?", 10); } diff --git a/src/test/run-pass/conditional-compile.rs b/src/test/run-pass/conditional-compile.rs index fa6f59999f8..3a626ca6ac1 100644 --- a/src/test/run-pass/conditional-compile.rs +++ b/src/test/run-pass/conditional-compile.rs @@ -137,25 +137,25 @@ mod test_methods { impl Fooable for Foo { #[cfg(bogus)] - static fn what() { } + static fn what(&self) { } - static fn what() { } + static fn what(&self) { } #[cfg(bogus)] - fn the() { } + fn the(&self) { } - fn the() { } + fn the(&self) { } } trait Fooable { #[cfg(bogus)] - static fn what(); + static fn what(&self); - static fn what(); + static fn what(&self); #[cfg(bogus)] - fn the(); + fn the(&self); - fn the(); + fn the(&self); } } diff --git a/src/test/run-pass/const-cast.rs b/src/test/run-pass/const-cast.rs index dca68b4c2a3..64c6f368f2b 100644 --- a/src/test/run-pass/const-cast.rs +++ b/src/test/run-pass/const-cast.rs @@ -12,7 +12,7 @@ extern fn foo() {} const x: *u8 = foo; const y: *libc::c_void = x as *libc::c_void; -const a: &static/int = &10; +const a: &'static int = &10; const b: *int = a as *int; fn main() { diff --git a/src/test/run-pass/const-cross-crate-const.rs b/src/test/run-pass/const-cross-crate-const.rs index a7c30593ecb..e01519ae8a5 100644 --- a/src/test/run-pass/const-cross-crate-const.rs +++ b/src/test/run-pass/const-cross-crate-const.rs @@ -12,7 +12,7 @@ // aux-build:cci_const.rs extern mod cci_const; -const foo: &static/str = cci_const::foopy; +const foo: &'static str = cci_const::foopy; const a: uint = cci_const::uint_val; const b: uint = cci_const::uint_expr + 5; diff --git a/src/test/run-pass/const-enum-ptr.rs b/src/test/run-pass/const-enum-ptr.rs index 6004f9b9001..594350d2988 100644 --- a/src/test/run-pass/const-enum-ptr.rs +++ b/src/test/run-pass/const-enum-ptr.rs @@ -9,7 +9,7 @@ // except according to those terms. enum E { V0, V1(int) } -const C: &static/E = &V0; +const C: &'static E = &V0; pub fn main() { match *C { diff --git a/src/test/run-pass/const-enum-vec-ptr.rs b/src/test/run-pass/const-enum-vec-ptr.rs index c4017b549e6..b398bfbf0d5 100644 --- a/src/test/run-pass/const-enum-vec-ptr.rs +++ b/src/test/run-pass/const-enum-vec-ptr.rs @@ -9,7 +9,7 @@ // except according to those terms. enum E { V1(int), V0 } -const C: &static/[E] = &[V0, V1(0xDEADBEE), V0]; +const C: &'static [E] = &[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 new file mode 100644 index 00000000000..aa5c4cbbc1d --- /dev/null +++ b/src/test/run-pass/const-expr-in-fixed-length-vec.rs @@ -0,0 +1,19 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that constant expressions can be used for declaring the +// type of a fixed length vector. + +fn main() { + + const FOO: int = 2; + let _v: [int * FOO*3]; + +} diff --git a/src/test/run-fail/issue-1459.rs b/src/test/run-pass/const-expr-in-vec-repeat.rs index 7f8cc7459de..76952ef730f 100644 --- a/src/test/run-fail/issue-1459.rs +++ b/src/test/run-pass/const-expr-in-vec-repeat.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,7 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:roflcopter +// Check that constant expressions can be used in vec repeat syntax. + fn main() { - log (fail!(~"roflcopter"), 2); + + const FOO: int = 2; + let _v = [0, ..FOO*3*2/2]; + } diff --git a/src/test/run-pass/const-str-ptr.rs b/src/test/run-pass/const-str-ptr.rs index d0773a73923..a1637f6ebb8 100644 --- a/src/test/run-pass/const-str-ptr.rs +++ b/src/test/run-pass/const-str-ptr.rs @@ -9,7 +9,7 @@ // except according to those terms. const a: [u8 * 3] = ['h' as u8, 'i' as u8, 0 as u8]; -const c: &static/[u8 * 3] = &a; +const c: &'static [u8 * 3] = &a; const b: *u8 = c as *u8; fn main() { diff --git a/src/test/run-pass/const.rs b/src/test/run-pass/const.rs index 28cca2f413b..e935a2cd434 100644 --- a/src/test/run-pass/const.rs +++ b/src/test/run-pass/const.rs @@ -12,4 +12,4 @@ const i: int = 10; -pub fn main() { log(debug, i); } +pub fn main() { debug!("%i", i); } diff --git a/src/test/run-pass/default-method-simple.rs b/src/test/run-pass/default-method-simple.rs index 4e17506d6ea..62b29d4e4eb 100644 --- a/src/test/run-pass/default-method-simple.rs +++ b/src/test/run-pass/default-method-simple.rs @@ -11,11 +11,11 @@ #[allow(default_methods)]; trait Foo { - fn f() { + fn f(&self) { io::println("Hello!"); self.g(); } - fn g(); + fn g(&self); } struct A { @@ -23,7 +23,7 @@ struct A { } impl Foo for A { - fn g() { + fn g(&self) { io::println("Goodbye!"); } } diff --git a/src/test/run-pass/deref-lval.rs b/src/test/run-pass/deref-lval.rs index ec5cc6293e4..6841c4d7f63 100644 --- a/src/test/run-pass/deref-lval.rs +++ b/src/test/run-pass/deref-lval.rs @@ -10,4 +10,4 @@ -pub fn main() { let x = @mut 5; *x = 1000; log(debug, *x); } +pub fn main() { let x = @mut 5; *x = 1000; debug!("%?", *x); } diff --git a/src/test/run-pass/early-vtbl-resolution.rs b/src/test/run-pass/early-vtbl-resolution.rs index 0191934d608..4728f718463 100644 --- a/src/test/run-pass/early-vtbl-resolution.rs +++ b/src/test/run-pass/early-vtbl-resolution.rs @@ -10,10 +10,10 @@ trait thing<A> { - fn foo() -> Option<A>; + fn foo(&self) -> Option<A>; } impl<A> thing<A> for int { - fn foo() -> Option<A> { None } + fn foo(&self) -> Option<A> { None } } fn foo_func<A, B: thing<A>>(x: B) -> Option<A> { x.foo() } diff --git a/src/test/run-pass/estr-slice.rs b/src/test/run-pass/estr-slice.rs index 3e6b5fca0d2..869ea6007c2 100644 --- a/src/test/run-pass/estr-slice.rs +++ b/src/test/run-pass/estr-slice.rs @@ -14,8 +14,8 @@ pub fn main() { let v = &"hello"; let mut y : &str = &"there"; - log(debug, x); - log(debug, y); + debug!(x); + debug!(y); fail_unless!(x[0] == 'h' as u8); fail_unless!(x[4] == 'o' as u8); @@ -30,7 +30,7 @@ pub fn main() { let c = &"cccc"; let cc = &"ccccc"; - log(debug, a); + debug!(a); fail_unless!(a < b); fail_unless!(a <= b); @@ -38,7 +38,7 @@ pub fn main() { fail_unless!(b >= a); fail_unless!(b > a); - log(debug, b); + debug!(b); fail_unless!(a < c); fail_unless!(a <= c); @@ -46,7 +46,7 @@ pub fn main() { fail_unless!(c >= a); fail_unless!(c > a); - log(debug, c); + debug!(c); fail_unless!(c < cc); fail_unless!(c <= cc); @@ -54,5 +54,5 @@ pub fn main() { fail_unless!(cc >= c); fail_unless!(cc > c); - log(debug, cc); + debug!(cc); } diff --git a/src/test/run-pass/evec-slice.rs b/src/test/run-pass/evec-slice.rs index 0ca9af6c03a..0d14670a6db 100644 --- a/src/test/run-pass/evec-slice.rs +++ b/src/test/run-pass/evec-slice.rs @@ -20,7 +20,7 @@ pub fn main() { let c : &[int] = &[2,2,2,2,3]; let cc : &[int] = &[2,2,2,2,2,2]; - log(debug, a); + debug!(a); fail_unless!(a < b); fail_unless!(a <= b); @@ -28,7 +28,7 @@ pub fn main() { fail_unless!(b >= a); fail_unless!(b > a); - log(debug, b); + debug!(b); fail_unless!(b < c); fail_unless!(b <= c); @@ -42,7 +42,7 @@ pub fn main() { fail_unless!(c >= a); fail_unless!(c > a); - log(debug, c); + debug!(c); fail_unless!(a < cc); fail_unless!(a <= cc); @@ -50,5 +50,5 @@ pub fn main() { fail_unless!(cc >= a); fail_unless!(cc > a); - log(debug, cc); + debug!(cc); } diff --git a/src/test/run-pass/explicit-self.rs b/src/test/run-pass/explicit-self.rs index 44edbd44bd3..1a21fa0a5d7 100644 --- a/src/test/run-pass/explicit-self.rs +++ b/src/test/run-pass/explicit-self.rs @@ -29,13 +29,13 @@ fn compute_area(shape: &shape) -> float { pub impl shape { // self is in the implicit self region fn select<T>(&self, threshold: float, - a: &r/T, b: &r/T) -> &r/T { + a: &'r T, b: &'r T) -> &'r T { if compute_area(self) > threshold {a} else {b} } } fn select_based_on_unit_circle<T>( - threshold: float, a: &r/T, b: &r/T) -> &r/T { + threshold: float, a: &'r T, b: &'r T) -> &'r T { let shape = &circle(Point{x: 0.0, y: 0.0}, 1.0); shape.select(threshold, a, b) @@ -58,7 +58,7 @@ pub impl thing { fn foo(@self) -> int { *self.x.a } fn bar(~self) -> int { *self.x.a } fn quux(&self) -> int { *self.x.a } - fn baz(&self) -> &self/A { &self.x } + fn baz(&self) -> &'self A { &self.x } fn spam(self) -> int { *self.x.a } } diff --git a/src/test/run-pass/expr-alt-generic-unique1.rs b/src/test/run-pass/expr-alt-generic-unique1.rs index b24ac9de009..74a88bb5c87 100644 --- a/src/test/run-pass/expr-alt-generic-unique1.rs +++ b/src/test/run-pass/expr-alt-generic-unique1.rs @@ -13,9 +13,9 @@ // -*- rust -*- type compare<T> = @fn(~T, ~T) -> bool; -fn test_generic<T:Copy>(expected: ~T, eq: compare<T>) { +fn test_generic<T:Copy+Clone>(expected: ~T, eq: compare<T>) { let actual: ~T = match true { - true => { copy expected }, + true => { expected.clone() }, _ => fail!(~"wat") }; fail_unless!((eq(expected, actual))); diff --git a/src/test/run-pass/expr-alt-generic-unique2.rs b/src/test/run-pass/expr-alt-generic-unique2.rs index 7bbd0bfc380..c9efe753f57 100644 --- a/src/test/run-pass/expr-alt-generic-unique2.rs +++ b/src/test/run-pass/expr-alt-generic-unique2.rs @@ -13,9 +13,9 @@ type compare<T> = @fn(T, T) -> bool; -fn test_generic<T:Copy>(expected: T, eq: compare<T>) { +fn test_generic<T:Copy+Clone>(expected: T, eq: compare<T>) { let actual: T = match true { - true => copy expected, + true => expected.clone(), _ => fail!(~"wat") }; fail_unless!((eq(expected, actual))); diff --git a/src/test/run-pass/expr-block-generic-box1.rs b/src/test/run-pass/expr-block-generic-box1.rs index 925c1b2cc4d..6aca1b994d9 100644 --- a/src/test/run-pass/expr-block-generic-box1.rs +++ b/src/test/run-pass/expr-block-generic-box1.rs @@ -21,8 +21,8 @@ fn test_generic<T>(expected: @T, eq: compare<T>) { fn test_box() { fn compare_box(b1: @bool, b2: @bool) -> bool { - log(debug, *b1); - log(debug, *b2); + debug!(*b1); + debug!(*b2); return *b1 == *b2; } test_generic::<bool>(@true, compare_box); diff --git a/src/test/run-pass/expr-block-generic-unique1.rs b/src/test/run-pass/expr-block-generic-unique1.rs index 9600d36bbbb..a9fe128661d 100644 --- a/src/test/run-pass/expr-block-generic-unique1.rs +++ b/src/test/run-pass/expr-block-generic-unique1.rs @@ -13,15 +13,15 @@ // -*- rust -*- type compare<T> = @fn(~T, ~T) -> bool; -fn test_generic<T:Copy>(expected: ~T, eq: compare<T>) { - let actual: ~T = { copy expected }; +fn test_generic<T:Copy+Clone>(expected: ~T, eq: compare<T>) { + let actual: ~T = { expected.clone() }; fail_unless!((eq(expected, actual))); } fn test_box() { fn compare_box(b1: ~bool, b2: ~bool) -> bool { - log(debug, *b1); - log(debug, *b2); + debug!(*b1); + debug!(*b2); return *b1 == *b2; } test_generic::<bool>(~true, compare_box); diff --git a/src/test/compile-fail/pure-modifies-aliased.rs b/src/test/run-pass/extern-pass-TwoU64s-ref.rs index 2aa81dd4fa2..00754afa703 100644 --- a/src/test/compile-fail/pure-modifies-aliased.rs +++ b/src/test/run-pass/extern-pass-TwoU64s-ref.rs @@ -8,25 +8,24 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Check that pure functions cannot modify aliased state. +// Test that we ignore modes when calling extern functions. -struct S { - f: int, -} +// xfail-test --- broken on 32-bit ABIs! (#5347) -pure fn modify_in_box(sum: @mut S) { - sum.f = 3; //~ ERROR assigning to mutable field prohibited in pure context +#[deriving_eq] +struct TwoU64s { + one: u64, two: u64 } -trait modify_in_box_rec { - pure fn modify_in_box_rec(sum: @mut S); +pub extern { + pub fn rust_dbg_extern_identity_TwoU64s(&&u: TwoU64s) -> TwoU64s; } -impl modify_in_box_rec for int { - pure fn modify_in_box_rec(sum: @mut S) { - sum.f = self; //~ ERROR assigning to mutable field prohibited in pure context +pub fn main() { + unsafe { + let x = TwoU64s {one: 22, two: 23}; + let y = rust_dbg_extern_identity_TwoU64s(x); + fail_unless!(x == y); } } -fn main() { -} diff --git a/src/test/run-pass/extern-pass-TwoU64s.rs b/src/test/run-pass/extern-pass-TwoU64s.rs new file mode 100644 index 00000000000..2baf383ce54 --- /dev/null +++ b/src/test/run-pass/extern-pass-TwoU64s.rs @@ -0,0 +1,32 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test a foreign function that accepts and returns a struct +// by value. + +// xfail-test --- broken on 32-bit ABIs! (#5347) + +#[deriving_eq] +struct TwoU64s { + one: u64, two: u64 +} + +pub extern { + pub fn rust_dbg_extern_identity_TwoU64s(v: TwoU64s) -> TwoU64s; +} + +pub fn main() { + unsafe { + let x = TwoU64s {one: 22, two: 23}; + let y = rust_dbg_extern_identity_TwoU64s(x); + fail_unless!(x == y); + } +} + diff --git a/src/test/compile-fail/purity-infer-fail.rs b/src/test/run-pass/extern-pass-char.rs index 3e5296530fa..104ea342cd5 100644 --- a/src/test/compile-fail/purity-infer-fail.rs +++ b/src/test/run-pass/extern-pass-char.rs @@ -8,9 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn something(f: &pure fn()) { f(); } +// Test a function that takes/returns a u8. -fn main() { - let mut x = ~[]; - something(|| x.push(0) ); //~ ERROR access to impure function prohibited in pure context +pub extern { + pub fn rust_dbg_extern_identity_u8(v: u8) -> u8; } + +pub fn main() { + unsafe { + fail_unless!(22_u8 == rust_dbg_extern_identity_u8(22_u8)); + } +} + diff --git a/src/test/compile-fail/nontrivial-fn-arg-pattern-in-pure-fn.rs b/src/test/run-pass/extern-pass-double.rs index c60eec6edd5..afdec4d1002 100644 --- a/src/test/compile-fail/nontrivial-fn-arg-pattern-in-pure-fn.rs +++ b/src/test/run-pass/extern-pass-double.rs @@ -8,9 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pure fn call_first((x, _y): (&fn(), &fn())) { - x(); //~ ERROR access to impure function prohibited in pure context +pub extern { + pub fn rust_dbg_extern_identity_double(v: f64) -> f64; } -fn main() {} +pub fn main() { + unsafe { + fail_unless!(22.0_f64 == rust_dbg_extern_identity_double(22.0_f64)); + } +} diff --git a/src/test/run-pass/extern-pass-u32.rs b/src/test/run-pass/extern-pass-u32.rs new file mode 100644 index 00000000000..0d6220e7b25 --- /dev/null +++ b/src/test/run-pass/extern-pass-u32.rs @@ -0,0 +1,22 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test a function that takes/returns a u32. + +pub extern { + pub fn rust_dbg_extern_identity_u32(v: u32) -> u32; +} + +pub fn main() { + unsafe { + fail_unless!(22_u32 == rust_dbg_extern_identity_u32(22_u32)); + } +} + diff --git a/src/test/run-pass/extern-pass-u64.rs b/src/test/run-pass/extern-pass-u64.rs new file mode 100644 index 00000000000..31777035238 --- /dev/null +++ b/src/test/run-pass/extern-pass-u64.rs @@ -0,0 +1,22 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test a call to a function that takes/returns a u64. + +pub extern { + pub fn rust_dbg_extern_identity_u64(v: u64) -> u64; +} + +pub fn main() { + unsafe { + fail_unless!(22_u64 == rust_dbg_extern_identity_u64(22_u64)); + } +} + diff --git a/src/test/run-pass/fact.rs b/src/test/run-pass/fact.rs index 21ac3fcdf5f..958e2e1e79e 100644 --- a/src/test/run-pass/fact.rs +++ b/src/test/run-pass/fact.rs @@ -15,7 +15,7 @@ fn f(x: int) -> int { // debug!("in f:"); - log(debug, x); + debug!(x); if x == 1 { // debug!("bottoming out"); @@ -26,7 +26,7 @@ fn f(x: int) -> int { let y: int = x * f(x - 1); // debug!("returned"); - log(debug, y); + debug!(y); return y; } } diff --git a/src/test/run-pass/fat-arrow-alt.rs b/src/test/run-pass/fat-arrow-alt.rs index 0c19655c9f5..4b8b552bfae 100644 --- a/src/test/run-pass/fat-arrow-alt.rs +++ b/src/test/run-pass/fat-arrow-alt.rs @@ -17,7 +17,7 @@ enum color { } pub fn main() { - log(error, match red { + error!(match red { red => { 1 } green => { 2 } blue => { 3 } diff --git a/src/test/run-pass/float-signature.rs b/src/test/run-pass/float-signature.rs index aeb94760e63..7d4c3db242d 100644 --- a/src/test/run-pass/float-signature.rs +++ b/src/test/run-pass/float-signature.rs @@ -14,5 +14,5 @@ pub fn main() { fn foo(n: float) -> float { return n + 0.12345; } let n: float = 0.1; let m: float = foo(n); - log(debug, m); + debug!(m); } diff --git a/src/test/run-pass/float.rs b/src/test/run-pass/float.rs index 53e19b62a28..1c2d7f42264 100644 --- a/src/test/run-pass/float.rs +++ b/src/test/run-pass/float.rs @@ -12,7 +12,7 @@ pub fn main() { let pi = 3.1415927; - log(debug, -pi * (pi + 2.0 / pi) - pi * 5.0); + debug!(-pi * (pi + 2.0 / pi) - pi * 5.0); if pi == 5.0 || pi < 10.0 || pi <= 2.0 || pi != 22.0 / 7.0 || pi >= 10.0 || pi > 1.0 { debug!("yes"); diff --git a/src/test/run-pass/foreach-put-structured.rs b/src/test/run-pass/foreach-put-structured.rs index 1a71cf52de2..dfee5557124 100644 --- a/src/test/run-pass/foreach-put-structured.rs +++ b/src/test/run-pass/foreach-put-structured.rs @@ -21,8 +21,8 @@ pub fn main() { let mut j: int = 0; do pairs() |p| { let (_0, _1) = p; - log(debug, _0); - log(debug, _1); + debug!(_0); + debug!(_1); fail_unless!((_0 + 10 == i)); i += 1; j = _1; diff --git a/src/test/run-pass/foreach-simple-outer-slot.rs b/src/test/run-pass/foreach-simple-outer-slot.rs index 1c0b28982db..7e07232c32f 100644 --- a/src/test/run-pass/foreach-simple-outer-slot.rs +++ b/src/test/run-pass/foreach-simple-outer-slot.rs @@ -14,9 +14,9 @@ // -*- rust -*- pub fn main() { let mut sum: int = 0; - do first_ten |i| { debug!("main"); log(debug, i); sum = sum + i; } + do first_ten |i| { debug!("main"); debug!(i); sum = sum + i; } debug!("sum"); - log(debug, sum); + debug!(sum); fail_unless!((sum == 45)); } diff --git a/src/test/run-pass/generic-alias-box.rs b/src/test/run-pass/generic-alias-box.rs index 1d791471f8f..3da699640ac 100644 --- a/src/test/run-pass/generic-alias-box.rs +++ b/src/test/run-pass/generic-alias-box.rs @@ -15,6 +15,6 @@ fn id<T:Copy>(t: T) -> T { return t; } pub fn main() { let expected = @100; let actual = id::<@int>(expected); - log(debug, *actual); + debug!(*actual); fail_unless!((*expected == *actual)); } diff --git a/src/test/run-pass/generic-alias-unique.rs b/src/test/run-pass/generic-alias-unique.rs index f09780706b9..287fc260bf8 100644 --- a/src/test/run-pass/generic-alias-unique.rs +++ b/src/test/run-pass/generic-alias-unique.rs @@ -14,7 +14,7 @@ fn id<T:Copy + Owned>(t: T) -> T { return t; } pub fn main() { let expected = ~100; - let actual = id::<~int>(copy expected); - log(debug, *actual); + let actual = id::<~int>(expected.clone()); + debug!(*actual); fail_unless!((*expected == *actual)); } diff --git a/src/test/run-pass/generic-derived-type.rs b/src/test/run-pass/generic-derived-type.rs index 003b760465d..e58fd884da6 100644 --- a/src/test/run-pass/generic-derived-type.rs +++ b/src/test/run-pass/generic-derived-type.rs @@ -22,8 +22,8 @@ fn f<T:Copy>(t: T) -> Pair<T> { pub fn main() { let b = f::<int>(10); - log(debug, b.a); - log(debug, b.b); + debug!(b.a); + debug!(b.b); fail_unless!((b.a == 10)); fail_unless!((b.b == 10)); } diff --git a/src/test/run-pass/generic-fn-box.rs b/src/test/run-pass/generic-fn-box.rs index 0a496b2bcf5..85d8198049f 100644 --- a/src/test/run-pass/generic-fn-box.rs +++ b/src/test/run-pass/generic-fn-box.rs @@ -12,4 +12,4 @@ fn f<T>(x: @T) -> @T { return x; } -pub fn main() { let x = f(@3); log(debug, *x); } +pub fn main() { let x = f(@3); debug!(*x); } diff --git a/src/test/run-pass/generic-fn-unique.rs b/src/test/run-pass/generic-fn-unique.rs index d41cd86bcc1..9892c935658 100644 --- a/src/test/run-pass/generic-fn-unique.rs +++ b/src/test/run-pass/generic-fn-unique.rs @@ -11,4 +11,4 @@ fn f<T:Copy>(x: ~T) -> ~T { return x; } -pub fn main() { let x = f(~3); log(debug, *x); } +pub fn main() { let x = f(~3); debug!(*x); } diff --git a/src/test/run-pass/generic-fn.rs b/src/test/run-pass/generic-fn.rs index 8f0158df642..4c0248c488f 100644 --- a/src/test/run-pass/generic-fn.rs +++ b/src/test/run-pass/generic-fn.rs @@ -24,14 +24,14 @@ pub fn main() { let p: Triple = Triple {x: 65, y: 66, z: 67}; let mut q: Triple = Triple {x: 68, y: 69, z: 70}; y = id::<int>(x); - log(debug, y); + debug!(y); fail_unless!((x == y)); b = id::<char>(a); - log(debug, b); + debug!(b); fail_unless!((a == b)); q = id::<Triple>(p); x = p.z; y = q.z; - log(debug, y); + debug!(y); fail_unless!((x == y)); } diff --git a/src/test/run-pass/generic-object.rs b/src/test/run-pass/generic-object.rs index 60e1c1a7c37..acdd3fc4600 100644 --- a/src/test/run-pass/generic-object.rs +++ b/src/test/run-pass/generic-object.rs @@ -9,7 +9,7 @@ // except according to those terms. trait Foo<T> { - fn get() -> T; + fn get(&self) -> T; } struct S { @@ -17,7 +17,7 @@ struct S { } impl Foo<int> for S { - fn get() -> int { + fn get(&self) -> int { self.x } } diff --git a/src/test/run-pass/generic-tag-values.rs b/src/test/run-pass/generic-tag-values.rs index 56395bf8cb0..30738ee33fd 100644 --- a/src/test/run-pass/generic-tag-values.rs +++ b/src/test/run-pass/generic-tag-values.rs @@ -18,12 +18,12 @@ struct Pair { x: int, y: int } pub fn main() { let nop: noption<int> = some::<int>(5); - match nop { some::<int>(n) => { log(debug, n); fail_unless!((n == 5)); } } + match nop { some::<int>(n) => { debug!(n); fail_unless!((n == 5)); } } let nop2: noption<Pair> = some(Pair{x: 17, y: 42}); match nop2 { some(t) => { - log(debug, t.x); - log(debug, t.y); + debug!(t.x); + debug!(t.y); fail_unless!((t.x == 17)); fail_unless!((t.y == 42)); } diff --git a/src/test/run-pass/generic-temporary.rs b/src/test/run-pass/generic-temporary.rs index 5c9d63610a8..ce419ff002f 100644 --- a/src/test/run-pass/generic-temporary.rs +++ b/src/test/run-pass/generic-temporary.rs @@ -12,7 +12,7 @@ fn mk() -> int { return 1; } -fn chk(a: int) { log(debug, a); fail_unless!((a == 1)); } +fn chk(a: int) { debug!(a); fail_unless!((a == 1)); } fn apply<T>(produce: extern fn() -> T, consume: extern fn(T)) { diff --git a/src/test/run-pass/generic-tup.rs b/src/test/run-pass/generic-tup.rs index bb4e5ea14ad..e80bc8da717 100644 --- a/src/test/run-pass/generic-tup.rs +++ b/src/test/run-pass/generic-tup.rs @@ -11,7 +11,7 @@ fn get_third<T:Copy>(t: (T, T, T)) -> T { let (_, _, x) = t; return x; } pub fn main() { - log(debug, get_third((1, 2, 3))); + debug!(get_third((1, 2, 3))); fail_unless!((get_third((1, 2, 3)) == 3)); fail_unless!((get_third((5u8, 6u8, 7u8)) == 7u8)); } diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index 72d4ab7aeab..5d8ac2f1ab5 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -38,8 +38,8 @@ mod map_reduce { fn start_mappers(ctrl: SharedChan<ctrl_proto>, inputs: ~[~str]) { for inputs.each |i| { let ctrl = ctrl.clone(); - let i = copy *i; - task::spawn(|| map_task(ctrl.clone(), copy i) ); + let i = i.clone(); + task::spawn(|| map_task(ctrl.clone(), i.clone()) ); } } @@ -57,7 +57,7 @@ mod map_reduce { ctrl.send(find_reducer(str::to_bytes(key), cc)); error!("receiving"); c = pp.recv(); - log(error, c); + error!(c); im.insert(key, c); } } @@ -79,7 +79,7 @@ mod map_reduce { reducers = oldmap::HashMap(); - start_mappers(ctrl_chan, copy inputs); + start_mappers(ctrl_chan, inputs.clone()); let mut num_mappers = vec::len(inputs) as int; diff --git a/src/test/run-pass/if-bot.rs b/src/test/run-pass/if-bot.rs index 8c6a82b4144..8f00b16ccd9 100644 --- a/src/test/run-pass/if-bot.rs +++ b/src/test/run-pass/if-bot.rs @@ -12,5 +12,5 @@ pub fn main() { let i: int = if false { fail!() } else { 5 }; - log(debug, i); + debug!(i); } diff --git a/src/test/run-pass/if-check.rs b/src/test/run-pass/if-check.rs index 5a516ba9861..3ee0808fa95 100644 --- a/src/test/run-pass/if-check.rs +++ b/src/test/run-pass/if-check.rs @@ -16,7 +16,7 @@ pure fn even(x: uint) -> bool { fn foo(x: uint) { if even(x) { - log(debug, x); + debug!(x); } else { fail!(); } diff --git a/src/test/run-pass/impl-implicit-trait.rs b/src/test/run-pass/impl-implicit-trait.rs index 88e220670ba..10a5661a324 100644 --- a/src/test/run-pass/impl-implicit-trait.rs +++ b/src/test/run-pass/impl-implicit-trait.rs @@ -14,7 +14,7 @@ enum option_<T> { } pub impl<T> option_<T> { - fn foo() -> bool { true } + fn foo(&self) -> bool { true } } enum option__ { @@ -23,7 +23,7 @@ enum option__ { } pub impl option__ { - fn foo() -> bool { true } + fn foo(&self) -> bool { true } } pub fn main() { diff --git a/src/test/run-pass/impl-variance.rs b/src/test/run-pass/impl-variance.rs index d772b76108e..31375edb5de 100644 --- a/src/test/run-pass/impl-variance.rs +++ b/src/test/run-pass/impl-variance.rs @@ -9,11 +9,11 @@ // except according to those terms. trait foo { - fn foo() -> uint; + fn foo(&self) -> uint; } impl<T> foo for ~[const T] { - fn foo() -> uint { vec::len(self) } + fn foo(&self) -> uint { vec::len(*self) } } pub fn main() { diff --git a/src/test/run-pass/import-in-block.rs b/src/test/run-pass/import-in-block.rs index a6d8eac3bd1..659b7b5be6f 100644 --- a/src/test/run-pass/import-in-block.rs +++ b/src/test/run-pass/import-in-block.rs @@ -10,9 +10,9 @@ pub fn main() { use core::vec::from_fn; - log(debug, ::core::vec::len(from_fn(2, |i| i))); + debug!(::core::vec::len(from_fn(2, |i| i))); { use core::vec::*; - log(debug, len(~[2])); + debug!(len(~[2])); } } diff --git a/src/test/run-pass/import.rs b/src/test/run-pass/import.rs index be515172de1..317082b1d82 100644 --- a/src/test/run-pass/import.rs +++ b/src/test/run-pass/import.rs @@ -11,7 +11,7 @@ // except according to those terms. mod foo { - pub fn x(y: int) { log(debug, y); } + pub fn x(y: int) { debug!(y); } } mod bar { diff --git a/src/test/run-pass/import8.rs b/src/test/run-pass/import8.rs index 229374c861e..869e61d0d4c 100644 --- a/src/test/run-pass/import8.rs +++ b/src/test/run-pass/import8.rs @@ -15,7 +15,7 @@ use foo::x; use z = foo::x; mod foo { - pub fn x(y: int) { log(debug, y); } + pub fn x(y: int) { debug!(y); } } pub fn main() { x(10); z(10); } diff --git a/src/test/run-pass/integral-indexing.rs b/src/test/run-pass/integral-indexing.rs index e4b195a0204..711e4e9cdf4 100644 --- a/src/test/run-pass/integral-indexing.rs +++ b/src/test/run-pass/integral-indexing.rs @@ -20,11 +20,11 @@ pub fn main() { fail_unless!((v[3i8] == 3)); fail_unless!((v[3u32] == 3)); fail_unless!((v[3i32] == 3)); - log(debug, v[3u8]); + debug!(v[3u8]); fail_unless!((s[3u] == 'd' as u8)); fail_unless!((s[3u8] == 'd' as u8)); fail_unless!((s[3i8] == 'd' as u8)); fail_unless!((s[3u32] == 'd' as u8)); fail_unless!((s[3i32] == 'd' as u8)); - log(debug, s[3u8]); + debug!(s[3u8]); } diff --git a/src/test/run-pass/intrinsic-move-val.rs b/src/test/run-pass/intrinsic-move-val.rs index 7e0a8173f7e..7544c89197b 100644 --- a/src/test/run-pass/intrinsic-move-val.rs +++ b/src/test/run-pass/intrinsic-move-val.rs @@ -11,8 +11,8 @@ mod rusti { #[abi = "rust-intrinsic"] pub extern { - pub fn move_val_init<T>(dst: &mut T, -src: T); - pub fn move_val<T>(dst: &mut T, -src: T); + pub fn move_val_init<T>(dst: &mut T, +src: T); + pub fn move_val<T>(dst: &mut T, +src: T); } } diff --git a/src/test/run-pass/issue-1696.rs b/src/test/run-pass/issue-1696.rs index fb61e34f351..8697e5c8c3c 100644 --- a/src/test/run-pass/issue-1696.rs +++ b/src/test/run-pass/issue-1696.rs @@ -16,5 +16,5 @@ use std::oldmap::HashMap; pub fn main() { let m = HashMap(); m.insert(str::to_bytes(~"foo"), str::to_bytes(~"bar")); - log(error, m); + error!(m); } diff --git a/src/test/run-pass/issue-2284.rs b/src/test/run-pass/issue-2284.rs index ebf7eec470c..b8c9ada8b1e 100644 --- a/src/test/run-pass/issue-2284.rs +++ b/src/test/run-pass/issue-2284.rs @@ -9,7 +9,7 @@ // except according to those terms. trait Send { - fn f(); + fn f(&self); } fn f<T:Send>(t: T) { diff --git a/src/test/run-pass/issue-2288.rs b/src/test/run-pass/issue-2288.rs index 85ed524118b..9aef66fd35c 100644 --- a/src/test/run-pass/issue-2288.rs +++ b/src/test/run-pass/issue-2288.rs @@ -9,14 +9,14 @@ // except according to those terms. trait clam<A:Copy> { - fn chowder(y: A); + fn chowder(&self, y: A); } struct foo<A> { x: A, } impl<A:Copy> clam<A> for foo<A> { - fn chowder(y: A) { + fn chowder(&self, y: A) { } } @@ -26,13 +26,13 @@ fn foo<A:Copy>(b: A) -> foo<A> { } } -fn f<A:Copy>(x: clam<A>, a: A) { +fn f<A:Copy>(x: @clam<A>, a: A) { x.chowder(a); } pub fn main() { let c = foo(42); - let d: clam<int> = @c as clam::<int>; + let d: @clam<int> = @c as @clam<int>; f(d, c.x); } diff --git a/src/test/run-pass/issue-2311-2.rs b/src/test/run-pass/issue-2311-2.rs index f60db84eb86..5f47e7ccb9f 100644 --- a/src/test/run-pass/issue-2311-2.rs +++ b/src/test/run-pass/issue-2311-2.rs @@ -14,7 +14,7 @@ struct foo<A> { } pub impl<A:Copy> foo<A> { - fn bar<B,C:clam<A>>(c: C) -> B { + fn bar<B,C:clam<A>>(&self, c: C) -> B { fail!(); } } diff --git a/src/test/run-pass/issue-2311.rs b/src/test/run-pass/issue-2311.rs index f3ced02c122..dc873ed08d7 100644 --- a/src/test/run-pass/issue-2311.rs +++ b/src/test/run-pass/issue-2311.rs @@ -10,7 +10,7 @@ trait clam<A> { } trait foo<A> { - fn bar<B,C:clam<A>>(c: C) -> B; + fn bar<B,C:clam<A>>(&self, c: C) -> B; } pub fn main() { } diff --git a/src/test/run-pass/issue-2312.rs b/src/test/run-pass/issue-2312.rs index ad6320aed2b..f3aa96298f0 100644 --- a/src/test/run-pass/issue-2312.rs +++ b/src/test/run-pass/issue-2312.rs @@ -15,7 +15,7 @@ trait clam<A> { } struct foo(int); pub impl foo { - fn bar<B,C:clam<B>>(c: C) -> B { fail!(); } + fn bar<B,C:clam<B>>(&self, c: C) -> B { fail!(); } } pub fn main() { } diff --git a/src/test/run-pass/issue-2445-b.rs b/src/test/run-pass/issue-2445-b.rs index 73bf97ad7af..55c72a41a6a 100644 --- a/src/test/run-pass/issue-2445-b.rs +++ b/src/test/run-pass/issue-2445-b.rs @@ -13,7 +13,7 @@ struct c1<T> { } pub impl<T:Copy> c1<T> { - fn f1(x: int) { + fn f1(&self, x: int) { } } @@ -24,7 +24,7 @@ fn c1<T:Copy>(x: T) -> c1<T> { } pub impl<T:Copy> c1<T> { - fn f2(x: int) { + fn f2(&self, x: int) { } } diff --git a/src/test/run-pass/issue-2445.rs b/src/test/run-pass/issue-2445.rs index 973b8d85161..5a82b534015 100644 --- a/src/test/run-pass/issue-2445.rs +++ b/src/test/run-pass/issue-2445.rs @@ -13,7 +13,7 @@ struct c1<T> { } pub impl<T:Copy> c1<T> { - fn f1(x: T) {} + fn f1(&self, x: T) {} } fn c1<T:Copy>(x: T) -> c1<T> { @@ -23,7 +23,7 @@ fn c1<T:Copy>(x: T) -> c1<T> { } pub impl<T:Copy> c1<T> { - fn f2(x: T) {} + fn f2(&self, x: T) {} } diff --git a/src/test/run-pass/issue-2487-a.rs b/src/test/run-pass/issue-2487-a.rs index 138860ce72d..388160e538a 100644 --- a/src/test/run-pass/issue-2487-a.rs +++ b/src/test/run-pass/issue-2487-a.rs @@ -18,10 +18,9 @@ impl Drop for socket { } pub impl socket { - - fn set_identity() { + fn set_identity(&self) { do closure { - setsockopt_bytes(copy self.sock) + setsockopt_bytes(self.sock.clone()) } } } diff --git a/src/test/run-pass/issue-2502.rs b/src/test/run-pass/issue-2502.rs index c7a7dc53965..cfae757aee8 100644 --- a/src/test/run-pass/issue-2502.rs +++ b/src/test/run-pass/issue-2502.rs @@ -13,12 +13,12 @@ struct font { } pub impl font/&self { - fn buf() -> &self/~[u8] { + fn buf(&self) -> &'self ~[u8] { self.fontbuf } } -fn font(fontbuf: &r/~[u8]) -> font/&r { +fn font(fontbuf: &'r ~[u8]) -> font/&r { font { fontbuf: fontbuf } diff --git a/src/test/run-pass/issue-2633-2.rs b/src/test/run-pass/issue-2633-2.rs index 5c3a2f0a4f6..2c3b4b71bb8 100644 --- a/src/test/run-pass/issue-2633-2.rs +++ b/src/test/run-pass/issue-2633-2.rs @@ -14,5 +14,5 @@ fn a_val(&&x: ~int, +y: ~int) -> int { pub fn main() { let z = ~22; - a_val(copy z, copy z); + a_val(z.clone(), z.clone()); } diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 1376f20571b..ae927ff7918 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -70,7 +70,7 @@ pub mod pipes { } } - pub fn send<T:Owned>(mut p: send_packet<T>, -payload: T) { + pub fn send<T:Owned>(mut p: send_packet<T>, +payload: T) { let mut p = p.unwrap(); let mut p = unsafe { uniquify(p) }; fail_unless!((*p).payload.is_none()); @@ -228,7 +228,7 @@ pub mod pingpong { pub struct ping(::pipes::send_packet<pong>); pub struct pong(::pipes::send_packet<ping>); - pub fn liberate_ping(-p: ping) -> ::pipes::send_packet<pong> { + pub fn liberate_ping(+p: ping) -> ::pipes::send_packet<pong> { unsafe { let addr : *::pipes::send_packet<pong> = match &p { &ping(ref x) => { cast::transmute(ptr::addr_of(x)) } @@ -239,7 +239,7 @@ pub mod pingpong { } } - pub fn liberate_pong(-p: pong) -> ::pipes::send_packet<ping> { + pub fn liberate_pong(+p: pong) -> ::pipes::send_packet<ping> { unsafe { let addr : *::pipes::send_packet<ping> = match &p { &pong(ref x) => { cast::transmute(ptr::addr_of(x)) } @@ -261,14 +261,14 @@ pub mod pingpong { pub type ping = ::pipes::send_packet<pingpong::ping>; pub type pong = ::pipes::recv_packet<pingpong::pong>; - pub fn do_ping(-c: ping) -> pong { + pub fn do_ping(+c: ping) -> pong { let (sp, rp) = ::pipes::entangle(); ::pipes::send(c, pingpong::ping(sp)); rp } - pub fn do_pong(-c: pong) -> (ping, ()) { + pub fn do_pong(+c: pong) -> (ping, ()) { let packet = ::pipes::recv(c); if packet.is_none() { fail!(~"sender closed the connection") @@ -283,7 +283,7 @@ pub mod pingpong { pub type ping = ::pipes::recv_packet<pingpong::ping>; pub type pong = ::pipes::send_packet<pingpong::pong>; - pub fn do_ping(-c: ping) -> (pong, ()) { + pub fn do_ping(+c: ping) -> (pong, ()) { let packet = ::pipes::recv(c); if packet.is_none() { fail!(~"sender closed the connection") @@ -291,7 +291,7 @@ pub mod pingpong { (pingpong::liberate_ping(option::unwrap(packet)), ()) } - pub fn do_pong(-c: pong) -> ping { + pub fn do_pong(+c: pong) -> ping { let (sp, rp) = ::pipes::entangle(); ::pipes::send(c, pingpong::pong(sp)); rp @@ -299,18 +299,18 @@ pub mod pingpong { } } -fn client(-chan: pingpong::client::ping) { +fn client(+chan: pingpong::client::ping) { let chan = pingpong::client::do_ping(chan); - log(error, ~"Sent ping"); + error!(~"Sent ping"); let (_chan, _data) = pingpong::client::do_pong(chan); - log(error, ~"Received pong"); + error!(~"Received pong"); } -fn server(-chan: pingpong::server::ping) { +fn server(+chan: pingpong::server::ping) { let (chan, _data) = pingpong::server::do_ping(chan); - log(error, ~"Received ping"); + error!(~"Received ping"); let _chan = pingpong::server::do_pong(chan); - log(error, ~"Sent pong"); + error!(~"Sent pong"); } pub fn main() { diff --git a/src/test/run-pass/issue-2734.rs b/src/test/run-pass/issue-2734.rs index a76d2242b40..35c3d6a88ee 100644 --- a/src/test/run-pass/issue-2734.rs +++ b/src/test/run-pass/issue-2734.rs @@ -11,7 +11,7 @@ trait hax { } impl<A> hax for A { } -fn perform_hax<T:&static>(x: @T) -> hax { +fn perform_hax<T:&static>(x: @T) -> @hax { @x as @hax } diff --git a/src/test/run-pass/issue-2735.rs b/src/test/run-pass/issue-2735.rs index 14e27dce63d..ef6363043ee 100644 --- a/src/test/run-pass/issue-2735.rs +++ b/src/test/run-pass/issue-2735.rs @@ -11,7 +11,7 @@ trait hax { } impl<A> hax for A { } -fn perform_hax<T:&static>(x: @T) -> hax { +fn perform_hax<T:&static>(x: @T) -> @hax { @x as @hax } diff --git a/src/test/run-pass/issue-2748-b.rs b/src/test/run-pass/issue-2748-b.rs index 7e5730a3db1..62016abf74b 100644 --- a/src/test/run-pass/issue-2748-b.rs +++ b/src/test/run-pass/issue-2748-b.rs @@ -8,7 +8,7 @@ // 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(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-2935.rs b/src/test/run-pass/issue-2935.rs index 64af4de46a2..c1f4e1e49aa 100644 --- a/src/test/run-pass/issue-2935.rs +++ b/src/test/run-pass/issue-2935.rs @@ -13,11 +13,11 @@ type t = bool; trait it { - fn f(); + fn f(&self); } impl it for t { - fn f() { } + fn f(&self) { } } pub fn main() { @@ -25,7 +25,7 @@ pub fn main() { // let y = @({a: 4i}); // let z = @({a: 4i} as it); // let z = @({a: true} as it); - let z = @(@true as it); + let z = @(@true as @it); // x.f(); // y.f(); // (*z).f(); diff --git a/src/test/run-pass/issue-2936.rs b/src/test/run-pass/issue-2936.rs index 2e343e9afe6..5acae2da1ce 100644 --- a/src/test/run-pass/issue-2936.rs +++ b/src/test/run-pass/issue-2936.rs @@ -9,7 +9,7 @@ // except according to those terms. trait bar<T> { - fn get_bar() -> T; + fn get_bar(&self) -> T; } fn foo<T, U: bar<T>>(b: U) -> T { @@ -21,7 +21,7 @@ struct cbar { } impl bar<int> for cbar { - fn get_bar() -> int { + fn get_bar(&self) -> int { self.x } } diff --git a/src/test/run-pass/issue-2989.rs b/src/test/run-pass/issue-2989.rs index 72af21368f1..10b845a923d 100644 --- a/src/test/run-pass/issue-2989.rs +++ b/src/test/run-pass/issue-2989.rs @@ -11,11 +11,11 @@ extern mod std; trait methods { - fn to_bytes() -> ~[u8]; + fn to_bytes(&self) -> ~[u8]; } impl methods for () { - fn to_bytes() -> ~[u8] { + fn to_bytes(&self) -> ~[u8] { vec::from_elem(0, 0) } } diff --git a/src/test/run-pass/issue-3109.rs b/src/test/run-pass/issue-3109.rs index be38e9080e5..6af1075544e 100644 --- a/src/test/run-pass/issue-3109.rs +++ b/src/test/run-pass/issue-3109.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn main() { - log(error, ("hi there!", "you")); + error!(("hi there!", "you")); } diff --git a/src/test/run-pass/issue-3389.rs b/src/test/run-pass/issue-3389.rs index 55558670734..6203f14f10f 100644 --- a/src/test/run-pass/issue-3389.rs +++ b/src/test/run-pass/issue-3389.rs @@ -27,6 +27,6 @@ pub fn main() { let v = ~[~"123", ~"abc"]; node.content = ~[~"123", ~"abc"]; print_str_vector(v); - print_str_vector(copy node.content); + print_str_vector(node.content.clone()); } diff --git a/src/test/run-pass/issue-3563-2.rs b/src/test/run-pass/issue-3563-2.rs index 332127d0204..52d6792f401 100644 --- a/src/test/run-pass/issue-3563-2.rs +++ b/src/test/run-pass/issue-3563-2.rs @@ -10,8 +10,8 @@ #[allow(default_methods)] trait Canvas { - fn add_point(point: &int); - fn add_points(shapes: &[int]) { + fn add_point(&self, point: &int); + fn add_points(&self, shapes: &[int]) { for shapes.each |pt| { self.add_point(pt) } diff --git a/src/test/run-pass/issue-3609.rs b/src/test/run-pass/issue-3609.rs index d0afd0107ee..fc6ceb4130f 100644 --- a/src/test/run-pass/issue-3609.rs +++ b/src/test/run-pass/issue-3609.rs @@ -19,7 +19,7 @@ fn foo(name: ~str, samples_chan: Chan<Msg>) { for uint::range(0, buffer.len()) |i| {error!("%?: %f", i, buffer[i])} }; - samples_chan.send(GetSamples(copy name, callback)); + samples_chan.send(GetSamples(name.clone(), callback)); }; } diff --git a/src/test/run-pass/issue-3683.rs b/src/test/run-pass/issue-3683.rs index 79e205d262a..edbc7852542 100644 --- a/src/test/run-pass/issue-3683.rs +++ b/src/test/run-pass/issue-3683.rs @@ -11,14 +11,14 @@ #[allow(default_methods)]; trait Foo { - fn a() -> int; - fn b() -> int { + fn a(&self) -> int; + fn b(&self) -> int { self.a() + 2 } } impl Foo for int { - fn a() -> int { + fn a(&self) -> int { 3 } } diff --git a/src/test/run-pass/issue-3753.rs b/src/test/run-pass/issue-3753.rs index 920736a976e..948ff1afd81 100644 --- a/src/test/run-pass/issue-3753.rs +++ b/src/test/run-pass/issue-3753.rs @@ -23,7 +23,7 @@ pub enum Shape { } pub impl Shape { - pub fn area(sh: Shape) -> float { + pub fn area(&self, sh: Shape) -> float { match sh { Circle(_, size) => float::consts::pi * size * size, Rectangle(Point {x, y}, Point {x: x2, y: y2}) => (x2 - x) * (y2 - y) diff --git a/src/test/run-pass/issue-3860.rs b/src/test/run-pass/issue-3860.rs index b113e902963..18839fa3c7f 100644 --- a/src/test/run-pass/issue-3860.rs +++ b/src/test/run-pass/issue-3860.rs @@ -11,7 +11,7 @@ struct Foo { x: int } pub impl Foo { - fn stuff(&mut self) -> &self/mut Foo { + fn stuff(&mut self) -> &'self mut Foo { return self; } } diff --git a/src/test/run-pass/issue-3888-2.rs b/src/test/run-pass/issue-3888-2.rs index 06e652cc7cd..38aeab0888c 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<T>(v: &r/[T]) -> &r/[T] { +fn vec_peek<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/issue-4448.rs b/src/test/run-pass/issue-4448.rs index 80cc9a72c33..0a9c731e9b8 100644 --- a/src/test/run-pass/issue-4448.rs +++ b/src/test/run-pass/issue-4448.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let (port, chan) = comm::stream::<&static/str>(); + let (port, chan) = comm::stream::<&'static str>(); do task::spawn { fail_unless!(port.recv() == "hello, world"); diff --git a/src/test/run-pass/issue-4541.rs b/src/test/run-pass/issue-4541.rs index fdc2cc1b013..37e91cf1eb2 100644 --- a/src/test/run-pass/issue-4541.rs +++ b/src/test/run-pass/issue-4541.rs @@ -14,7 +14,7 @@ fn parse_args() -> ~str { let mut n = 0; while n < args.len() { - match copy args[n] { + match args[n].clone() { ~"-v" => (), s => { return s; diff --git a/src/test/run-pass/issue-4542.rs b/src/test/run-pass/issue-4542.rs index f708b099c37..a5e5b10d076 100644 --- a/src/test/run-pass/issue-4542.rs +++ b/src/test/run-pass/issue-4542.rs @@ -11,7 +11,7 @@ // xfail-test pub fn main() { for os::args().each |arg| { - match copy *arg { + match arg.clone() { s => { } } } diff --git a/src/test/run-pass/istr.rs b/src/test/run-pass/istr.rs index 55ffd15259d..e6e39311626 100644 --- a/src/test/run-pass/istr.rs +++ b/src/test/run-pass/istr.rs @@ -10,7 +10,7 @@ fn test_stack_assign() { let s: ~str = ~"a"; - log(debug, copy s); + debug!(s.clone()); let t: ~str = ~"a"; fail_unless!((s == t)); let u: ~str = ~"b"; @@ -27,7 +27,7 @@ fn test_heap_assign() { fail_unless!((s != u)); } -fn test_heap_log() { let s = ~"a big ol' string"; log(debug, s); } +fn test_heap_log() { let s = ~"a big ol' string"; debug!(s); } fn test_stack_add() { fail_unless!((~"a" + ~"b" == ~"ab")); @@ -49,7 +49,7 @@ fn test_append() { let mut s = ~"a"; s += ~"b"; - log(debug, copy s); + debug!(s.clone()); fail_unless!((s == ~"ab")); let mut s = ~"c"; diff --git a/src/test/run-pass/iter-range.rs b/src/test/run-pass/iter-range.rs index 0ec8eea5236..983f47e8ab7 100644 --- a/src/test/run-pass/iter-range.rs +++ b/src/test/run-pass/iter-range.rs @@ -19,5 +19,5 @@ fn range(a: int, b: int, it: &fn(int)) { pub fn main() { let mut sum: int = 0; range(0, 100, |x| sum += x ); - log(debug, sum); + debug!(sum); } diff --git a/src/test/run-pass/kindck-owned-trait-contains-1.rs b/src/test/run-pass/kindck-owned-trait-contains-1.rs index bb6ed754ab6..0a39472025d 100644 --- a/src/test/run-pass/kindck-owned-trait-contains-1.rs +++ b/src/test/run-pass/kindck-owned-trait-contains-1.rs @@ -8,15 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait repeat<A> { fn get() -> A; } +trait repeat<A> { fn get(&self) -> A; } impl<A:Copy> repeat<A> for @A { - fn get() -> A { *self } + fn get(&self) -> A { **self } } -fn repeater<A:Copy>(v: @A) -> repeat<A> { +fn repeater<A:Copy>(v: @A) -> @repeat<A> { // Note: owned kind is not necessary as A appears in the trait type - @v as repeat::<A> // No + @v as @repeat<A> // No } pub fn main() { diff --git a/src/test/run-pass/lambda-infer-unresolved.rs b/src/test/run-pass/lambda-infer-unresolved.rs index a1f57b380c1..2e70e900389 100644 --- a/src/test/run-pass/lambda-infer-unresolved.rs +++ b/src/test/run-pass/lambda-infer-unresolved.rs @@ -16,6 +16,6 @@ struct Refs { refs: ~[int], n: int } pub fn main() { let e = @mut Refs{refs: ~[], n: 0}; - let f: @fn() = || log(error, e.n); + let f: @fn() = || error!(copy e.n); e.refs += ~[1]; } diff --git a/src/test/run-pass/lambda-no-leak.rs b/src/test/run-pass/lambda-no-leak.rs index 2dc7079af53..e19503240f0 100644 --- a/src/test/run-pass/lambda-no-leak.rs +++ b/src/test/run-pass/lambda-no-leak.rs @@ -12,6 +12,6 @@ fn force(f: @fn()) { f() } pub fn main() { let x = 7; - let _f: @fn() = || log(error, x); - force(|| log(error, x)); + let _f: @fn() = || error!(x); + force(|| error!(x)); } diff --git a/src/test/run-pass/last-use-in-cap-clause.rs b/src/test/run-pass/last-use-in-cap-clause.rs index 40075e12f4b..3d121d08745 100644 --- a/src/test/run-pass/last-use-in-cap-clause.rs +++ b/src/test/run-pass/last-use-in-cap-clause.rs @@ -14,7 +14,7 @@ struct A { a: ~int } fn foo() -> @fn() -> int { let k = ~22; - let _u = A {a: copy k}; + let _u = A {a: k.clone()}; let result: @fn() -> int = || 22; result } diff --git a/src/test/run-pass/last-use-is-capture.rs b/src/test/run-pass/last-use-is-capture.rs index 0535e63fcb4..2c62b6894d0 100644 --- a/src/test/run-pass/last-use-is-capture.rs +++ b/src/test/run-pass/last-use-is-capture.rs @@ -15,6 +15,6 @@ struct A { a: ~int } pub fn main() { fn invoke(f: @fn()) { f(); } let k = ~22; - let _u = A {a: copy k}; - invoke(|| log(error, copy k) ) + let _u = A {a: k.clone()}; + invoke(|| error!(k.clone()) ) } diff --git a/src/test/run-pass/lazy-and-or.rs b/src/test/run-pass/lazy-and-or.rs index b86f7974bc3..e16229eec53 100644 --- a/src/test/run-pass/lazy-and-or.rs +++ b/src/test/run-pass/lazy-and-or.rs @@ -16,7 +16,7 @@ pub fn main() { let x = 1 == 2 || 3 == 3; fail_unless!((x)); let mut y: int = 10; - log(debug, x || incr(&mut y)); + debug!(x || incr(&mut y)); fail_unless!((y == 10)); if true && x { fail_unless!((true)); } else { fail_unless!((false)); } } diff --git a/src/test/run-pass/lazy-init.rs b/src/test/run-pass/lazy-init.rs index 0ccecba58c0..37208bf145b 100644 --- a/src/test/run-pass/lazy-init.rs +++ b/src/test/run-pass/lazy-init.rs @@ -10,6 +10,6 @@ -fn foo(x: int) { log(debug, x); } +fn foo(x: int) { debug!(x); } pub fn main() { let mut x: int; if 1 > 2 { x = 12; } else { x = 10; } foo(x); } diff --git a/src/test/run-pass/linear-for-loop.rs b/src/test/run-pass/linear-for-loop.rs index c232ab42dfc..1d8662de7c2 100644 --- a/src/test/run-pass/linear-for-loop.rs +++ b/src/test/run-pass/linear-for-loop.rs @@ -13,8 +13,8 @@ pub fn main() { let x = ~[1, 2, 3]; let mut y = 0; - for x.each |i| { log(debug, *i); y += *i; } - log(debug, y); + for x.each |i| { debug!(*i); y += *i; } + debug!(y); fail_unless!((y == 6)); let s = ~"hello there"; let mut i: int = 0; @@ -27,8 +27,8 @@ pub fn main() { // ... i += 1; - log(debug, i); - log(debug, c); + debug!(i); + debug!(c); } fail_unless!((i == 11)); } diff --git a/src/test/run-pass/liveness-move-in-loop.rs b/src/test/run-pass/liveness-move-in-loop.rs index 8c4b7d57bc2..658885124c2 100644 --- a/src/test/run-pass/liveness-move-in-loop.rs +++ b/src/test/run-pass/liveness-move-in-loop.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn take(-x: int) -> int {x} +fn take(+x: int) -> int {x} fn the_loop() { let mut list = ~[]; diff --git a/src/test/run-pass/log-err-phi.rs b/src/test/run-pass/log-err-phi.rs index df4f754ae7e..31c0c98fa96 100644 --- a/src/test/run-pass/log-err-phi.rs +++ b/src/test/run-pass/log-err-phi.rs @@ -10,4 +10,4 @@ -pub fn main() { if false { log(error, ~"foo" + ~"bar"); } } +pub fn main() { if false { error!(~"foo" + ~"bar"); } } diff --git a/src/test/run-pass/log-linearized.rs b/src/test/run-pass/log-linearized.rs index 465e5b63d6b..919c53e0330 100644 --- a/src/test/run-pass/log-linearized.rs +++ b/src/test/run-pass/log-linearized.rs @@ -26,7 +26,7 @@ fn mk<T>() -> @mut Smallintmap<T> { fn f<T,U>() { let mut sim = mk::<U>(); - log(error, sim); + error!(sim); } pub fn main() { diff --git a/src/test/run-pass/loop-break-cont.rs b/src/test/run-pass/loop-break-cont.rs index 753c7c019b5..b0ea375228f 100644 --- a/src/test/run-pass/loop-break-cont.rs +++ b/src/test/run-pass/loop-break-cont.rs @@ -11,7 +11,7 @@ pub fn main() { let mut i = 0u; loop { - log(error, ~"a"); + error!(~"a"); i += 1u; if i == 10u { break; @@ -23,7 +23,7 @@ pub fn main() { if i == 21u { break; } - log(error, ~"b"); + error!(~"b"); is_even = false; i += 1u; if i % 2u != 0u { @@ -33,7 +33,7 @@ pub fn main() { } fail_unless!(!is_even); loop { - log(error, ~"c"); + error!(~"c"); if i == 22u { break; } diff --git a/src/test/run-pass/max-min-classes.rs b/src/test/run-pass/max-min-classes.rs index 56c16d92874..58dcb24edf9 100644 --- a/src/test/run-pass/max-min-classes.rs +++ b/src/test/run-pass/max-min-classes.rs @@ -9,7 +9,7 @@ // except according to those terms. trait Product { - fn product() -> int; + fn product(&self) -> int; } struct Foo { @@ -18,13 +18,13 @@ struct Foo { } pub impl Foo { - fn sum() -> int { + fn sum(&self) -> int { self.x + self.y } } impl Product for Foo { - fn product() -> int { + fn product(&self) -> int { self.x * self.y } } diff --git a/src/test/run-pass/maybe-mutable.rs b/src/test/run-pass/maybe-mutable.rs index c2532369942..155046bcccc 100644 --- a/src/test/run-pass/maybe-mutable.rs +++ b/src/test/run-pass/maybe-mutable.rs @@ -20,7 +20,7 @@ fn len(v: ~[const int]) -> uint { pub fn main() { let v0 = ~[1, 2, 3, 4, 5]; - log(debug, len(v0)); + debug!(len(v0)); let mut v1 = ~[1, 2, 3, 4, 5]; - log(debug, len(v1)); + debug!(len(v1)); } diff --git a/src/test/run-pass/method-attributes.rs b/src/test/run-pass/method-attributes.rs index 20cd9643b08..db7440738da 100644 --- a/src/test/run-pass/method-attributes.rs +++ b/src/test/run-pass/method-attributes.rs @@ -13,20 +13,20 @@ #[frobable] trait frobable { #[frob_attr] - fn frob(); + fn frob(&self); #[defrob_attr] - fn defrob(); + fn defrob(&self); } #[int_frobable] impl frobable for int { #[frob_attr1] - fn frob() { + fn frob(&self) { #[frob_attr2]; } #[defrob_attr1] - fn defrob() { + fn defrob(&self) { #[defrob_attr2]; } } diff --git a/src/test/run-pass/monad.rs b/src/test/run-pass/monad.rs index b21b3b6c7fb..f046adc30b4 100644 --- a/src/test/run-pass/monad.rs +++ b/src/test/run-pass/monad.rs @@ -11,11 +11,11 @@ // xfail-fast trait vec_monad<A> { - fn bind<B:Copy>(f: &fn(&A) -> ~[B]) -> ~[B]; + fn bind<B:Copy>(&self, f: &fn(&A) -> ~[B]) -> ~[B]; } impl<A> vec_monad<A> for ~[A] { - fn bind<B:Copy>(f: &fn(&A) -> ~[B]) -> ~[B] { + fn bind<B:Copy>(&self, f: &fn(&A) -> ~[B]) -> ~[B] { let mut r = ~[]; for self.each |elt| { r += f(elt); } r @@ -23,14 +23,14 @@ impl<A> vec_monad<A> for ~[A] { } trait option_monad<A> { - fn bind<B>(f: &fn(&A) -> Option<B>) -> Option<B>; + fn bind<B>(&self, f: &fn(&A) -> Option<B>) -> Option<B>; } impl<A> option_monad<A> for Option<A> { - fn bind<B>(f: &fn(&A) -> Option<B>) -> Option<B> { - match self { - Some(ref a) => { f(a) } - None => { None } + fn bind<B>(&self, f: &fn(&A) -> Option<B>) -> Option<B> { + match *self { + Some(ref a) => { f(a) } + None => { None } } } } @@ -43,7 +43,7 @@ pub fn main() { fail_unless!(transform(Some(10)) == Some(~"11")); fail_unless!(transform(None) == None); fail_unless!((~[~"hi"]) - .bind(|x| ~[copy *x, *x + ~"!"] ) - .bind(|x| ~[copy *x, *x + ~"?"] ) == + .bind(|x| ~[x.clone(), *x + ~"!"] ) + .bind(|x| ~[x.clone(), *x + ~"?"] ) == ~[~"hi", ~"hi?", ~"hi!", ~"hi!?"]); } diff --git a/src/test/run-pass/monomorphize-trait-in-fn-at.rs b/src/test/run-pass/monomorphize-trait-in-fn-at.rs index 6e5d92da1cb..a591c3034d2 100644 --- a/src/test/run-pass/monomorphize-trait-in-fn-at.rs +++ b/src/test/run-pass/monomorphize-trait-in-fn-at.rs @@ -17,11 +17,11 @@ fn mk_nil<C:ty_ops>(cx: C) -> uint { } trait ty_ops { - fn mk() -> uint; + fn mk(&self) -> uint; } impl ty_ops for () { - fn mk() -> uint { 22u } + fn mk(&self) -> uint { 22u } } pub fn main() { diff --git a/src/test/run-pass/monomorphized-callees-with-ty-params-3314.rs b/src/test/run-pass/monomorphized-callees-with-ty-params-3314.rs index 88c317a3c07..90b3e623f5e 100644 --- a/src/test/run-pass/monomorphized-callees-with-ty-params-3314.rs +++ b/src/test/run-pass/monomorphized-callees-with-ty-params-3314.rs @@ -14,22 +14,22 @@ trait Serializer { } trait Serializable { - fn serialize<S:Serializer>(s: S); + fn serialize<S:Serializer>(&self, s: S); } impl Serializable for int { - fn serialize<S:Serializer>(_s: S) { } + fn serialize<S:Serializer>(&self, _s: S) { } } struct F<A> { a: A } impl<A:Copy + Serializable> Serializable for F<A> { - fn serialize<S:Serializer>(s: S) { + fn serialize<S:Serializer>(&self, s: S) { self.a.serialize(s); } } -impl Serializer for io::Writer { +impl Serializer for @io::Writer { } pub fn main() { diff --git a/src/test/run-pass/move-arg-2-unique.rs b/src/test/run-pass/move-arg-2-unique.rs index 4275513d61e..c0adcc8c03c 100644 --- a/src/test/run-pass/move-arg-2-unique.rs +++ b/src/test/run-pass/move-arg-2-unique.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn test(-foo: ~~[int]) { fail_unless!((foo[0] == 10)); } +fn test(+foo: ~~[int]) { fail_unless!((foo[0] == 10)); } pub fn main() { let x = ~~[10]; diff --git a/src/test/run-pass/move-arg-2.rs b/src/test/run-pass/move-arg-2.rs index 24444f5ebdb..41a82977175 100644 --- a/src/test/run-pass/move-arg-2.rs +++ b/src/test/run-pass/move-arg-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn test(-foo: @~[int]) { fail_unless!((foo[0] == 10)); } +fn test(+foo: @~[int]) { fail_unless!((foo[0] == 10)); } pub fn main() { let x = @~[10]; diff --git a/src/test/run-pass/move-arg.rs b/src/test/run-pass/move-arg.rs index 288abb6fb39..b763317dfe1 100644 --- a/src/test/run-pass/move-arg.rs +++ b/src/test/run-pass/move-arg.rs @@ -8,6 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn test(-foo: int) { fail_unless!((foo == 10)); } +fn test(+foo: int) { fail_unless!((foo == 10)); } pub fn main() { let x = 10; test(x); } diff --git a/src/test/run-pass/move-nullary-fn.rs b/src/test/run-pass/move-nullary-fn.rs index 48f4a75ed4e..eb4c5f871af 100644 --- a/src/test/run-pass/move-nullary-fn.rs +++ b/src/test/run-pass/move-nullary-fn.rs @@ -9,9 +9,9 @@ // except according to those terms. // Issue #922 -fn f2(-thing: @fn()) { } +fn f2(+thing: @fn()) { } -fn f(-thing: @fn()) { +fn f(+thing: @fn()) { f2(thing); } diff --git a/src/test/run-pass/mutable-alias-vec.rs b/src/test/run-pass/mutable-alias-vec.rs index 36f8b436753..e08bd5f85a9 100644 --- a/src/test/run-pass/mutable-alias-vec.rs +++ b/src/test/run-pass/mutable-alias-vec.rs @@ -21,6 +21,6 @@ pub fn main() { grow(&mut v); grow(&mut v); let len = vec::len::<int>(v); - log(debug, len); + debug!(len); fail_unless!((len == 3 as uint)); } diff --git a/src/test/run-pass/nested-alts.rs b/src/test/run-pass/nested-alts.rs index 5ba4e1208c8..dfbd583f16e 100644 --- a/src/test/run-pass/nested-alts.rs +++ b/src/test/run-pass/nested-alts.rs @@ -16,7 +16,7 @@ fn foo() { Some::<int>(x) => { let mut bar; match None::<int> { None::<int> => { bar = 5; } _ => { baz(); } } - log(debug, bar); + debug!(bar); } None::<int> => { debug!("hello"); } } diff --git a/src/test/run-pass/nested-class.rs b/src/test/run-pass/nested-class.rs index eeda69e621d..6447d46ad89 100644 --- a/src/test/run-pass/nested-class.rs +++ b/src/test/run-pass/nested-class.rs @@ -15,7 +15,7 @@ pub fn main() { } pub impl b { - fn do_stuff() -> int { return 37; } + fn do_stuff(&self) -> int { return 37; } } fn b(i:int) -> b { diff --git a/src/test/run-pass/opeq.rs b/src/test/run-pass/opeq.rs index 3a0d0c29441..98bec28e398 100644 --- a/src/test/run-pass/opeq.rs +++ b/src/test/run-pass/opeq.rs @@ -15,15 +15,15 @@ pub fn main() { let mut x: int = 1; x *= 2; - log(debug, x); + debug!(x); fail_unless!((x == 2)); x += 3; - log(debug, x); + debug!(x); fail_unless!((x == 5)); x *= x; - log(debug, x); + debug!(x); fail_unless!((x == 25)); x /= 5; - log(debug, x); + debug!(x); fail_unless!((x == 5)); } diff --git a/src/test/run-pass/over-constrained-vregs.rs b/src/test/run-pass/over-constrained-vregs.rs index 14756904693..5f7ae2f755c 100644 --- a/src/test/run-pass/over-constrained-vregs.rs +++ b/src/test/run-pass/over-constrained-vregs.rs @@ -17,6 +17,6 @@ pub fn main() { while b <= 32u { 0u << b; b <<= 1u; - log(debug, b); + debug!(b); } } diff --git a/src/test/run-pass/parse-fail.rs b/src/test/run-pass/parse-fail.rs index 087926e8da5..0ac899d5e31 100644 --- a/src/test/run-pass/parse-fail.rs +++ b/src/test/run-pass/parse-fail.rs @@ -12,6 +12,6 @@ // -*- rust -*- -fn dont_call_me() { fail!(); log(debug, 1); } +fn dont_call_me() { fail!(); debug!(1); } pub fn main() { } diff --git a/src/test/run-pass/pass-by-copy.rs b/src/test/run-pass/pass-by-copy.rs index 44ec68dd346..c3ab589b66c 100644 --- a/src/test/run-pass/pass-by-copy.rs +++ b/src/test/run-pass/pass-by-copy.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn magic(+x: A) { log(debug, x); } -fn magic2(+x: @int) { log(debug, x); } +fn magic(+x: A) { debug!(x); } +fn magic2(+x: @int) { debug!(x); } struct A { a: @int } diff --git a/src/test/run-pass/pipe-bank-proto.rs b/src/test/run-pass/pipe-bank-proto.rs index 20daa894bc1..d6b8acd94de 100644 --- a/src/test/run-pass/pipe-bank-proto.rs +++ b/src/test/run-pass/pipe-bank-proto.rs @@ -53,7 +53,7 @@ fn switch<T:Owned,U>(+endp: pipes::RecvPacket<T>, f(pipes::try_recv(endp)) } -fn move_it<T>(-x: T) -> T { x } +fn move_it<T>(+x: T) -> T { x } macro_rules! follow ( { diff --git a/src/test/run-pass/pipe-pingpong-bounded.rs b/src/test/run-pass/pipe-pingpong-bounded.rs index f1686080f46..7dea787e1a1 100644 --- a/src/test/run-pass/pipe-pingpong-bounded.rs +++ b/src/test/run-pass/pipe-pingpong-bounded.rs @@ -91,22 +91,22 @@ mod test { use core::pipes::recv; use pingpong::{ping, pong}; - pub fn client(-chan: ::pingpong::client::ping) { + pub fn client(+chan: ::pingpong::client::ping) { use pingpong::client; let chan = client::ping(chan); return; - log(error, "Sent ping"); + error!("Sent ping"); let pong(_chan) = recv(chan); - log(error, "Received pong"); + error!("Received pong"); } - pub fn server(-chan: ::pingpong::server::ping) { + pub fn server(+chan: ::pingpong::server::ping) { use pingpong::server; let ping(chan) = recv(chan); return; - log(error, "Received ping"); + error!("Received ping"); let _chan = server::pong(chan); - log(error, "Sent pong"); + error!("Sent pong"); } } diff --git a/src/test/run-pass/pipe-pingpong-proto.rs b/src/test/run-pass/pipe-pingpong-proto.rs index c51c0733622..65a5672941f 100644 --- a/src/test/run-pass/pipe-pingpong-proto.rs +++ b/src/test/run-pass/pipe-pingpong-proto.rs @@ -29,22 +29,22 @@ mod test { use core::pipes::recv; use pingpong::{ping, pong}; - pub fn client(-chan: ::pingpong::client::ping) { + pub fn client(+chan: ::pingpong::client::ping) { use pingpong::client; let chan = client::ping(chan); - log(error, ~"Sent ping"); + error!(~"Sent ping"); let pong(_chan) = recv(chan); - log(error, ~"Received pong"); + error!(~"Received pong"); } - pub fn server(-chan: ::pingpong::server::ping) { + pub fn server(+chan: ::pingpong::server::ping) { use pingpong::server; let ping(chan) = recv(chan); - log(error, ~"Received ping"); + error!(~"Received ping"); let _chan = server::pong(chan); - log(error, ~"Sent pong"); + error!(~"Sent pong"); } } diff --git a/src/test/run-pass/platform_thread.rs b/src/test/run-pass/platform_thread.rs index 40b9a7b92c0..5e4830b0bbd 100644 --- a/src/test/run-pass/platform_thread.rs +++ b/src/test/run-pass/platform_thread.rs @@ -18,7 +18,7 @@ pub fn main() { fn run(i: int) { - log(debug, i); + debug!(i); if i == 0 { return; diff --git a/src/test/run-pass/propagate-expected-type-through-block.rs b/src/test/run-pass/propagate-expected-type-through-block.rs index 20a6d130774..c68771e4a94 100644 --- a/src/test/run-pass/propagate-expected-type-through-block.rs +++ b/src/test/run-pass/propagate-expected-type-through-block.rs @@ -5,7 +5,7 @@ pub fn main() { let y = ~3; let foo: @fn(&int) -> int = { - let y = copy y; + let y = y.clone(); |x| *x + *y }; fail_unless!(foo(@22) == 25); diff --git a/src/test/run-pass/purity-infer.rs b/src/test/run-pass/purity-infer.rs index d546909de8e..ce9b3b78a9c 100644 --- a/src/test/run-pass/purity-infer.rs +++ b/src/test/run-pass/purity-infer.rs @@ -11,5 +11,5 @@ fn something(f: &pure fn()) { f(); } pub fn main() { - something(|| log(error, "hi!") ); + something(|| error!("hi!") ); } diff --git a/src/test/run-pass/rcvr-borrowed-to-region.rs b/src/test/run-pass/rcvr-borrowed-to-region.rs index a7daa566480..f9a132f8a2c 100644 --- a/src/test/run-pass/rcvr-borrowed-to-region.rs +++ b/src/test/run-pass/rcvr-borrowed-to-region.rs @@ -1,3 +1,6 @@ +// xfail-test +// xfail'd due to segfaults with by-value self. + // 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. @@ -9,13 +12,13 @@ // except according to those terms. trait get { - fn get() -> int; + fn get(self) -> int; } // Note: impl on a slice impl get for &'self int { - fn get() -> int { - return *self; + fn get(self) -> int { + return **self; } } diff --git a/src/test/run-pass/rcvr-borrowed-to-slice.rs b/src/test/run-pass/rcvr-borrowed-to-slice.rs index f7f6b9b05e3..9328189c47c 100644 --- a/src/test/run-pass/rcvr-borrowed-to-slice.rs +++ b/src/test/run-pass/rcvr-borrowed-to-slice.rs @@ -9,12 +9,12 @@ // except according to those terms. trait sum { - fn sum() -> int; + fn sum(self) -> int; } // Note: impl on a slice impl sum for &'self [int] { - fn sum() -> int { + fn sum(self) -> int { let mut sum = 0; for vec::each(self) |e| { sum += *e; } return sum; diff --git a/src/test/run-pass/rec-auto.rs b/src/test/run-pass/rec-auto.rs index 7dd13001de4..62cb3296f60 100644 --- a/src/test/run-pass/rec-auto.rs +++ b/src/test/run-pass/rec-auto.rs @@ -19,6 +19,6 @@ struct X { foo: ~str, bar: ~str } pub fn main() { let x = X {foo: ~"hello", bar: ~"world"}; - log(debug, copy x.foo); - log(debug, copy x.bar); + debug!(x.foo.clone()); + debug!(x.bar.clone()); } diff --git a/src/test/run-pass/reflect-visit-data.rs b/src/test/run-pass/reflect-visit-data.rs index 0f3f4db3bbf..8e363c3d5db 100644 --- a/src/test/run-pass/reflect-visit-data.rs +++ b/src/test/run-pass/reflect-visit-data.rs @@ -19,7 +19,7 @@ use intrinsic::{TyDesc, get_tydesc, visit_tydesc, TyVisitor}; /// Trait for visitor that wishes to reflect on data. trait movable_ptr { - fn move_ptr(adjustment: &fn(*c_void) -> *c_void); + fn move_ptr(&self, adjustment: &fn(*c_void) -> *c_void); } /// Helper function for alignment calculation. @@ -33,26 +33,26 @@ struct ptr_visit_adaptor<V>(Inner<V>); pub impl<V:TyVisitor + movable_ptr> ptr_visit_adaptor<V> { #[inline(always)] - fn bump(sz: uint) { + fn bump(&self, sz: uint) { do self.inner.move_ptr() |p| { ((p as uint) + sz) as *c_void }; } #[inline(always)] - fn align(a: uint) { + fn align(&self, a: uint) { do self.inner.move_ptr() |p| { align(p as uint, a) as *c_void }; } #[inline(always)] - fn align_to<T>() { + fn align_to<T>(&self) { self.align(sys::min_align_of::<T>()); } #[inline(always)] - fn bump_past<T>() { + fn bump_past<T>(&self) { self.bump(sys::size_of::<T>()); } @@ -201,9 +201,9 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> { } fn visit_estr_slice(&self) -> bool { - self.align_to::<&static/str>(); + self.align_to::<&'static str>(); if ! self.inner.visit_estr_slice() { return false; } - self.bump_past::<&static/str>(); + self.bump_past::<&'static str>(); true } @@ -238,9 +238,9 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> { } fn visit_rptr(&self, mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<&static/u8>(); + self.align_to::<&'static u8>(); if ! self.inner.visit_rptr(mtbl, inner) { return false; } - self.bump_past::<&static/u8>(); + self.bump_past::<&'static u8>(); true } @@ -276,9 +276,9 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> { } fn visit_evec_slice(&self, mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<&static/[u8]>(); + self.align_to::<&'static [u8]>(); if ! self.inner.visit_evec_slice(mtbl, inner) { return false; } - self.bump_past::<&static/[u8]>(); + self.bump_past::<&'static [u8]>(); true } @@ -439,9 +439,9 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> { } fn visit_self(&self) -> bool { - self.align_to::<&static/u8>(); + self.align_to::<&'static u8>(); if ! self.inner.visit_self() { return false; } - self.align_to::<&static/u8>(); + self.align_to::<&'static u8>(); true } @@ -479,15 +479,15 @@ struct Stuff { } pub impl my_visitor { - fn get<T>(f: &fn(T)) { + fn get<T>(&self, f: &fn(T)) { unsafe { f(*(self.ptr1 as *T)); } } - fn visit_inner(inner: *TyDesc) -> bool { + fn visit_inner(&self, inner: *TyDesc) -> bool { unsafe { - let u = my_visitor(*self); + let u = my_visitor(**self); let v = ptr_visit_adaptor::<my_visitor>(Inner {inner: u}); visit_tydesc(inner, @v as @TyVisitor); true @@ -498,7 +498,7 @@ pub impl my_visitor { struct Inner<V> { inner: V } impl movable_ptr for my_visitor { - fn move_ptr(adjustment: &fn(*c_void) -> *c_void) { + fn move_ptr(&self, adjustment: &fn(*c_void) -> *c_void) { self.ptr1 = adjustment(self.ptr1); self.ptr2 = adjustment(self.ptr2); } @@ -647,10 +647,10 @@ pub fn main() { let v = @v as @TyVisitor; visit_tydesc(td, v); - for (copy u.vals).each |s| { + for (u.vals.clone()).each |s| { io::println(fmt!("val: %s", *s)); } - error!("%?", copy u.vals); + error!("%?", u.vals.clone()); fail_unless!(u.vals == ~[ ~"1", ~"2", ~"3", ~"true", ~"false", ~"5", ~"4", ~"3", ~"12" ]); diff --git a/src/test/run-pass/reflect-visit-type.rs b/src/test/run-pass/reflect-visit-type.rs index bc67ece79de..6576a6c3fa9 100644 --- a/src/test/run-pass/reflect-visit-type.rs +++ b/src/test/run-pass/reflect-visit-type.rs @@ -150,7 +150,7 @@ pub fn main() { visit_ty::<i16>(vv); visit_ty::<~[int]>(vv); - for (copy v.types).each {|s| + for (v.types.clone()).each {|s| io::println(fmt!("type: %s", s)); } fail_unless!(v.types == ["bool", "int", "i8", "i16", diff --git a/src/test/run-pass/region-dependent-addr-of.rs b/src/test/run-pass/region-dependent-addr-of.rs index a3f5c41e1ac..6cad8c74592 100644 --- a/src/test/run-pass/region-dependent-addr-of.rs +++ b/src/test/run-pass/region-dependent-addr-of.rs @@ -25,54 +25,54 @@ struct C { f: int } -fn get_v1(a: &v/A) -> &v/int { +fn get_v1(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(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(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(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(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(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(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(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(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 59dbbde7b77..ced2948545f 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<T>(opt: &r/Option<T>) -> &r/T { +fn get<T>(opt: &'r Option<T>) -> &'r T { match *opt { Some(ref v) => v, None => fail!(~"none") diff --git a/src/test/run-pass/regions-addr-of-ret.rs b/src/test/run-pass/regions-addr-of-ret.rs index 88a378e7b49..622a1eb9954 100644 --- a/src/test/run-pass/regions-addr-of-ret.rs +++ b/src/test/run-pass/regions-addr-of-ret.rs @@ -8,12 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(x : &a/int) -> &a/int { +fn f(x : &'a int) -> &'a int { return &*x; } pub fn main() { let three = &3; - log(error, fmt!("%d", *f(three))); + error!(fmt!("%d", *f(three))); } diff --git a/src/test/run-pass/regions-bot.rs b/src/test/run-pass/regions-bot.rs index 3be9d72c690..96ae71f0ff3 100644 --- a/src/test/run-pass/regions-bot.rs +++ b/src/test/run-pass/regions-bot.rs @@ -10,7 +10,7 @@ // A very limited test of the "bottom" region -fn produce_static<T>() -> &static/T { fail!(); } +fn produce_static<T>() -> &'static T { fail!(); } fn foo<T>(x: &T) -> &uint { produce_static() } diff --git a/src/test/run-pass/regions-equiv-fns.rs b/src/test/run-pass/regions-equiv-fns.rs index e78a6e69bdd..86b997a6008 100644 --- a/src/test/run-pass/regions-equiv-fns.rs +++ b/src/test/run-pass/regions-equiv-fns.rs @@ -13,7 +13,7 @@ fn ok(a: &uint) { // Here &r is an alias for &: - let mut g: @fn(x: &uint) = |x: &r/uint| {}; + let mut g: @fn(x: &uint) = |x: &'r uint| {}; g(a); } 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 6a03b4f910b..e38bd64da64 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(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 b28d8534fec..981eace6754 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(y: &'r uint) = |x: &'r uint| { }; 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(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 e5e24a55843..5aff0274dc4 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<T>(x: &r/[T]) -> &r/[T] {x} +fn view<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 69945a31f6d..fd48402dd10 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<T>(x: &r/T) -> &r/T {x} +fn borrow<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 9c4cb0d436d..b5dbf0fde5c 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(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 dc38a7baacd..74c4c4260fc 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<T>(f: &fn(x: &int) -> T) -> T { f(&20) } -fn has_one(x: &a/int) -> int { +fn has_one(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 0477bd2d196..66baaf40108 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(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 b1fa7287fdb..c45212eaa62 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 @@ -12,7 +12,7 @@ struct boxed_int { f: &'self int, } -fn max(bi: &r/boxed_int, f: &r/int) -> int { +fn max(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 index 1c263a6f0c6..7d966b06e35 100644 --- a/src/test/run-pass/regions-infer-contravariance.rs +++ b/src/test/run-pass/regions-infer-contravariance.rs @@ -16,11 +16,11 @@ fn get(bi: &'r boxed_int<'r>) -> &'r int { bi.f } -fn with(bi: &r/boxed_int) { +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; + let bi: &'blk boxed_int/&blk = bi; fail_unless!(*get(bi) == 22); } diff --git a/src/test/run-pass/regions-params.rs b/src/test/run-pass/regions-params.rs index 0049653dea9..1066c5fd4ca 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(x: &'r uint) -> &'r uint { x } fn apply<T>(t: T, f: &fn(T) -> T) -> T { f(t) } diff --git a/src/test/run-pass/regions-self-impls.rs b/src/test/run-pass/regions-self-impls.rs index 22eec65b02a..16b6364093e 100644 --- a/src/test/run-pass/regions-self-impls.rs +++ b/src/test/run-pass/regions-self-impls.rs @@ -13,16 +13,16 @@ struct Clam<'self> { } trait get_chowder<'self> { - fn get_chowder() -> &'self int; + fn get_chowder(&self) -> &'self int; } -impl<'self> get_chowder<'self> for Clam<'self> { - fn get_chowder() -> &'self int { return self.chowder; } +impl<'self> get_chowder for Clam<'self> { + fn get_chowder(&self) -> &'self int { return self.chowder; } } pub fn main() { let clam = Clam { chowder: &3 }; - log(debug, *clam.get_chowder()); + debug!(*clam.get_chowder()); clam.get_chowder(); } diff --git a/src/test/run-pass/regions-self-in-enums.rs b/src/test/run-pass/regions-self-in-enums.rs index 6f1044e3054..e71dbb0054b 100644 --- a/src/test/run-pass/regions-self-in-enums.rs +++ b/src/test/run-pass/regions-self-in-enums.rs @@ -19,6 +19,6 @@ pub fn main() { match y { int_wrapper_ctor(zz) => { z = zz; } } - log(debug, *z); + debug!(*z); } diff --git a/src/test/run-pass/regions-simple.rs b/src/test/run-pass/regions-simple.rs index c32e08fc76b..f7a50e6b114 100644 --- a/src/test/run-pass/regions-simple.rs +++ b/src/test/run-pass/regions-simple.rs @@ -12,7 +12,7 @@ pub fn main() { let mut x: int = 3; let y: &mut int = &mut x; *y = 5; - log (debug, *y); + debug!(*y); } diff --git a/src/test/run-pass/regions-trait.rs b/src/test/run-pass/regions-trait.rs index 22cdd477077..481f25745cd 100644 --- a/src/test/run-pass/regions-trait.rs +++ b/src/test/run-pass/regions-trait.rs @@ -11,18 +11,18 @@ struct Ctxt { v: uint } trait get_ctxt { - fn get_ctxt() -> &self/Ctxt; + fn get_ctxt(&self) -> &'self Ctxt; } struct HasCtxt { c: &'self Ctxt } -impl get_ctxt<'self> for HasCtxt<'self> { - fn get_ctxt() -> &self/Ctxt { +impl get_ctxt for HasCtxt<'self> { + fn get_ctxt(&self) -> &'self Ctxt { self.c } } -fn get_v(gc: get_ctxt) -> uint { +fn get_v(gc: @get_ctxt) -> uint { gc.get_ctxt().v } diff --git a/src/test/run-pass/resource-assign-is-not-copy.rs b/src/test/run-pass/resource-assign-is-not-copy.rs index f4ba34807d3..df084c13427 100644 --- a/src/test/run-pass/resource-assign-is-not-copy.rs +++ b/src/test/run-pass/resource-assign-is-not-copy.rs @@ -31,7 +31,7 @@ pub fn main() { let a = r(i); let b = (a, 10); let (c, _d) = b; - log(debug, c); + debug!(c); } fail_unless!(*i == 1); } diff --git a/src/test/run-pass/resource-destruct.rs b/src/test/run-pass/resource-destruct.rs index 9894d2382dd..db444f08fab 100644 --- a/src/test/run-pass/resource-destruct.rs +++ b/src/test/run-pass/resource-destruct.rs @@ -14,12 +14,12 @@ struct shrinky_pointer { impl Drop for shrinky_pointer { fn finalize(&self) { - log(error, ~"Hello!"); **(self.i) -= 1; + error!(~"Hello!"); **(self.i) -= 1; } } pub impl shrinky_pointer { - fn look_at() -> int { return **(self.i); } + fn look_at(&self) -> int { return **(self.i); } } fn shrinky_pointer(i: @@mut int) -> shrinky_pointer { @@ -31,6 +31,6 @@ fn shrinky_pointer(i: @@mut int) -> shrinky_pointer { pub fn main() { let my_total = @@mut 10; { let pt = shrinky_pointer(my_total); fail_unless!((pt.look_at() == 10)); } - log(error, fmt!("my_total = %d", **my_total)); + error!("my_total = %d", **my_total); fail_unless!((**my_total == 9)); } diff --git a/src/test/run-pass/ret-bang.rs b/src/test/run-pass/ret-bang.rs index 167c4c14a1e..881294c4f33 100644 --- a/src/test/run-pass/ret-bang.rs +++ b/src/test/run-pass/ret-bang.rs @@ -12,7 +12,7 @@ // -*- rust -*- -fn my_err(s: ~str) -> ! { log(error, s); fail!(); } +fn my_err(s: ~str) -> ! { error!(s); fail!(); } fn okay(i: uint) -> int { if i == 3u { my_err(~"I don't like three"); } else { return 42; } diff --git a/src/test/run-pass/ret-break-cont-in-block.rs b/src/test/run-pass/ret-break-cont-in-block.rs index 6fe75758842..6fe5831644f 100644 --- a/src/test/run-pass/ret-break-cont-in-block.rs +++ b/src/test/run-pass/ret-break-cont-in-block.rs @@ -20,9 +20,9 @@ fn iter<T>(v: ~[T], it: &fn(&T) -> bool) { } } -fn find_pos<T:Eq + Copy>(n: T, h: ~[T]) -> Option<uint> { +fn find_pos<T:Eq + Copy + Clone>(n: T, h: ~[T]) -> Option<uint> { let mut i = 0u; - for iter(copy h) |e| { + for iter(h.clone()) |e| { if *e == n { return Some(i); } i += 1u; } @@ -31,8 +31,8 @@ fn find_pos<T:Eq + Copy>(n: T, h: ~[T]) -> Option<uint> { fn bail_deep(x: ~[~[bool]]) { let mut seen = false; - for iter(copy x) |x| { - for iter(copy *x) |x| { + for iter(x.clone()) |x| { + for iter(x.clone()) |x| { fail_unless!(!seen); if *x { seen = true; return; } } diff --git a/src/test/run-pass/sendfn-generic-fn.rs b/src/test/run-pass/sendfn-generic-fn.rs index 08434011a1c..6322d24ffd9 100644 --- a/src/test/run-pass/sendfn-generic-fn.rs +++ b/src/test/run-pass/sendfn-generic-fn.rs @@ -20,12 +20,12 @@ fn make_generic_record<A:Copy,B:Copy>(a: A, b: B) -> Pair<A,B> { fn test05_start(f: &~fn(v: float, v: ~str) -> Pair<float, ~str>) { let p = (*f)(22.22f, ~"Hi"); - log(debug, copy p); + debug!(copy p); fail_unless!(p.a == 22.22f); fail_unless!(p.b == ~"Hi"); let q = (*f)(44.44f, ~"Ho"); - log(debug, copy q); + debug!(copy q); fail_unless!(q.a == 44.44f); fail_unless!(q.b == ~"Ho"); } diff --git a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs index 726efd2946d..a4d88e7f25b 100644 --- a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs +++ b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs @@ -17,7 +17,7 @@ fn test05_start(&&f: ~fn(int)) { fn test05() { let three = ~3; let fn_to_send: ~fn(int) = |n| { - log(error, *three + n); // will copy x into the closure + error!(*three + n); // will copy x into the closure fail_unless!((*three == 3)); }; task::spawn(|| { diff --git a/src/test/run-pass/shadow.rs b/src/test/run-pass/shadow.rs index 0c6ab3c65b1..716138a30ed 100644 --- a/src/test/run-pass/shadow.rs +++ b/src/test/run-pass/shadow.rs @@ -17,7 +17,7 @@ fn foo(c: ~[int]) { match none::<int> { some::<int>(_) => { for c.each |i| { - log(debug, a); + debug!(a); let a = 17; b += ~[a]; } diff --git a/src/test/run-pass/shape_intrinsic_tag_then_rec.rs b/src/test/run-pass/shape_intrinsic_tag_then_rec.rs index 578e8d9318f..25ac00d174f 100644 --- a/src/test/run-pass/shape_intrinsic_tag_then_rec.rs +++ b/src/test/run-pass/shape_intrinsic_tag_then_rec.rs @@ -39,6 +39,6 @@ pub fn main() { let p_: Path_ = Path_ { global: true, idents: ~[~"hi"], types: ~[t] }; let p: path = Spanned { data: p_, span: sp }; let x = X { sp: sp, path: p }; - log(error, copy x.path); - log(error, copy x); + error!(copy x.path); + error!(copy x); } diff --git a/src/test/run-pass/simple-infer.rs b/src/test/run-pass/simple-infer.rs index 137c973d590..e7115a41179 100644 --- a/src/test/run-pass/simple-infer.rs +++ b/src/test/run-pass/simple-infer.rs @@ -10,4 +10,4 @@ -pub fn main() { let mut n; n = 1; log(debug, n); } +pub fn main() { let mut n; n = 1; debug!(n); } diff --git a/src/test/run-pass/size-and-align.rs b/src/test/run-pass/size-and-align.rs index 89ba351e6e4..5bc7e18bdd8 100644 --- a/src/test/run-pass/size-and-align.rs +++ b/src/test/run-pass/size-and-align.rs @@ -16,7 +16,7 @@ enum clam<T> { a(T, int), b, } fn uhoh<T>(v: ~[clam<T>]) { match v[1] { - a::<T>(ref t, ref u) => { debug!("incorrect"); log(debug, u); fail!(); } + a::<T>(ref t, ref u) => { debug!("incorrect"); debug!(u); fail!(); } b::<T> => { debug!("correct"); } } } diff --git a/src/test/run-pass/spawn-fn.rs b/src/test/run-pass/spawn-fn.rs index c2a0015f6e6..37501a61066 100644 --- a/src/test/run-pass/spawn-fn.rs +++ b/src/test/run-pass/spawn-fn.rs @@ -11,8 +11,8 @@ fn x(s: ~str, n: int) { - log(debug, s); - log(debug, n); + debug!(s); + debug!(n); } pub fn main() { diff --git a/src/test/run-pass/spawn.rs b/src/test/run-pass/spawn.rs index 31281355258..4da560b8b92 100644 --- a/src/test/run-pass/spawn.rs +++ b/src/test/run-pass/spawn.rs @@ -17,7 +17,7 @@ pub fn main() { task::spawn(|| child(10) ); } -fn child(&&i: int) { log(error, i); fail_unless!((i == 10)); } +fn child(&&i: int) { error!(i); fail_unless!((i == 10)); } // Local Variables: // mode: rust; diff --git a/src/test/run-pass/spawn2.rs b/src/test/run-pass/spawn2.rs index 7327c3b84ad..6bd3af73dd0 100644 --- a/src/test/run-pass/spawn2.rs +++ b/src/test/run-pass/spawn2.rs @@ -13,15 +13,15 @@ pub fn main() { task::spawn(|| child((10, 20, 30, 40, 50, 60, 70, 80, 90)) ); } fn child(&&args: (int, int, int, int, int, int, int, int, int)) { let (i1, i2, i3, i4, i5, i6, i7, i8, i9) = args; - log(error, i1); - log(error, i2); - log(error, i3); - log(error, i4); - log(error, i5); - log(error, i6); - log(error, i7); - log(error, i8); - log(error, i9); + error!(i1); + error!(i2); + error!(i3); + error!(i4); + error!(i5); + error!(i6); + error!(i7); + error!(i8); + error!(i9); fail_unless!((i1 == 10)); fail_unless!((i2 == 20)); fail_unless!((i3 == 30)); diff --git a/src/test/run-pass/stat.rs b/src/test/run-pass/stat.rs index 1613eec7405..f2e12294b09 100644 --- a/src/test/run-pass/stat.rs +++ b/src/test/run-pass/stat.rs @@ -20,7 +20,7 @@ pub fn main() { { match io::file_writer(&path, [io::Create, io::Truncate]) { - Err(copy e) => fail!(e), + Err(ref e) => fail!(e.clone()), Ok(f) => { for uint::range(0, 1000) |_i| { f.write_u8(0); diff --git a/src/test/run-pass/static-impl.rs b/src/test/run-pass/static-impl.rs index 2ee6f631ea5..560406c9c40 100644 --- a/src/test/run-pass/static-impl.rs +++ b/src/test/run-pass/static-impl.rs @@ -11,42 +11,42 @@ // xfail-fast pub trait plus { - fn plus() -> int; + fn plus(&self) -> int; } mod a { use plus; - impl plus for uint { fn plus() -> int { self as int + 20 } } + impl plus for uint { fn plus(&self) -> int { *self as int + 20 } } } mod b { use plus; - impl plus for ~str { fn plus() -> int { 200 } } + impl plus for ~str { fn plus(&self) -> int { 200 } } } trait uint_utils { - fn str() -> ~str; - fn multi(f: &fn(uint)); + fn str(&self) -> ~str; + fn multi(&self, f: &fn(uint)); } impl uint_utils for uint { - fn str() -> ~str { uint::to_str(self) } - fn multi(f: &fn(uint)) { + fn str(&self) -> ~str { uint::to_str(*self) } + fn multi(&self, f: &fn(uint)) { let mut c = 0u; - while c < self { f(c); c += 1u; } + while c < *self { f(c); c += 1u; } } } trait vec_utils<T> { - fn length_() -> uint; - fn iter_(f: &fn(&T)); - fn map_<U:Copy>(f: &fn(&T) -> U) -> ~[U]; + fn length_(&self, ) -> uint; + fn iter_(&self, f: &fn(&T)); + fn map_<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U]; } impl<T> vec_utils<T> for ~[T] { - fn length_() -> uint { vec::len(self) } - fn iter_(f: &fn(&T)) { for self.each |x| { f(x); } } - fn map_<U:Copy>(f: &fn(&T) -> U) -> ~[U] { + fn length_(&self) -> uint { vec::len(*self) } + fn iter_(&self, f: &fn(&T)) { for self.each |x| { f(x); } } + fn map_<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U] { let mut r = ~[]; for self.each |elt| { r += ~[f(elt)]; } r diff --git a/src/test/run-pass/static-method-in-trait-with-tps-intracrate.rs b/src/test/run-pass/static-method-in-trait-with-tps-intracrate.rs index f51eb6e1ae2..1146412ec4f 100644 --- a/src/test/run-pass/static-method-in-trait-with-tps-intracrate.rs +++ b/src/test/run-pass/static-method-in-trait-with-tps-intracrate.rs @@ -9,15 +9,15 @@ // except according to those terms. trait Deserializer { - fn read_int() -> int; + fn read_int(&self) -> int; } trait Deserializable<D:Deserializer> { - static fn deserialize(d: &D) -> Self; + static fn deserialize(&self, d: &D) -> Self; } impl<D:Deserializer> Deserializable<D> for int { - static fn deserialize(d: &D) -> int { + static fn deserialize(&self, d: &D) -> int { return d.read_int(); } } @@ -25,7 +25,7 @@ impl<D:Deserializer> Deserializable<D> for int { struct FromThinAir { dummy: () } impl Deserializer for FromThinAir { - fn read_int() -> int { 22 } + fn read_int(&self) -> int { 22 } } pub fn main() { diff --git a/src/test/run-pass/str-append.rs b/src/test/run-pass/str-append.rs index 085b9c5d349..d1592c46dc9 100644 --- a/src/test/run-pass/str-append.rs +++ b/src/test/run-pass/str-append.rs @@ -16,7 +16,7 @@ extern mod std; fn test1() { let mut s: ~str = ~"hello"; s += ~"world"; - log(debug, copy s); + debug!(s.clone()); fail_unless!((s[9] == 'd' as u8)); } @@ -26,8 +26,8 @@ fn test2() { let ff: ~str = ~"abc"; let a: ~str = ff + ~"ABC" + ff; let b: ~str = ~"ABC" + ff + ~"ABC"; - log(debug, copy a); - log(debug, copy b); + debug!(a.clone()); + debug!(b.clone()); fail_unless!((a == ~"abcABCabc")); fail_unless!((b == ~"ABCabcABC")); } diff --git a/src/test/run-pass/str-concat.rs b/src/test/run-pass/str-concat.rs index 10bec14c285..107998d3def 100644 --- a/src/test/run-pass/str-concat.rs +++ b/src/test/run-pass/str-concat.rs @@ -16,6 +16,6 @@ pub fn main() { let a: ~str = ~"hello"; let b: ~str = ~"world"; let s: ~str = a + b; - log(debug, copy s); + debug!(s.clone()); fail_unless!((s[9] == 'd' as u8)); } diff --git a/src/test/run-pass/str-idx.rs b/src/test/run-pass/str-idx.rs index a61a7818ca3..a2146d8770a 100644 --- a/src/test/run-pass/str-idx.rs +++ b/src/test/run-pass/str-idx.rs @@ -13,6 +13,6 @@ pub fn main() { let s = ~"hello"; let c: u8 = s[4]; - log(debug, c); + debug!(c); fail_unless!((c == 0x6f as u8)); } diff --git a/src/test/run-pass/string-self-append.rs b/src/test/run-pass/string-self-append.rs index f9f700a6ec8..a1243d33062 100644 --- a/src/test/run-pass/string-self-append.rs +++ b/src/test/run-pass/string-self-append.rs @@ -16,7 +16,7 @@ pub fn main() { let mut i = 20; let mut expected_len = 1u; while i > 0 { - log(error, str::len(a)); + error!(str::len(a)); fail_unless!((str::len(a) == expected_len)); a = a + a; // FIXME(#3387)---can't write a += a i -= 1; diff --git a/src/test/run-pass/supported-cast.rs b/src/test/run-pass/supported-cast.rs index cc9214121e9..791f493b5cc 100644 --- a/src/test/run-pass/supported-cast.rs +++ b/src/test/run-pass/supported-cast.rs @@ -10,251 +10,251 @@ pub fn main() { let f = 1 as *libc::FILE; - log(debug, f as int); - log(debug, f as uint); - log(debug, f as i8); - log(debug, f as i16); - log(debug, f as i32); - log(debug, f as i64); - log(debug, f as u8); - log(debug, f as u16); - log(debug, f as u32); - log(debug, f as u64); + debug!(f as int); + debug!(f as uint); + debug!(f as i8); + debug!(f as i16); + debug!(f as i32); + debug!(f as i64); + debug!(f as u8); + debug!(f as u16); + debug!(f as u32); + debug!(f as u64); - log(debug, 1 as int); - log(debug, 1 as uint); - log(debug, 1 as float); - log(debug, 1 as bool); - log(debug, 1 as *libc::FILE); - log(debug, 1 as i8); - log(debug, 1 as i16); - log(debug, 1 as i32); - log(debug, 1 as i64); - log(debug, 1 as u8); - log(debug, 1 as u16); - log(debug, 1 as u32); - log(debug, 1 as u64); - log(debug, 1 as f32); - log(debug, 1 as f64); + debug!(1 as int); + debug!(1 as uint); + debug!(1 as float); + debug!(1 as bool); + debug!(1 as *libc::FILE); + debug!(1 as i8); + debug!(1 as i16); + debug!(1 as i32); + debug!(1 as i64); + debug!(1 as u8); + debug!(1 as u16); + debug!(1 as u32); + debug!(1 as u64); + debug!(1 as f32); + debug!(1 as f64); - log(debug, 1u as int); - log(debug, 1u as uint); - log(debug, 1u as float); - log(debug, 1u as bool); - log(debug, 1u as *libc::FILE); - log(debug, 1u as i8); - log(debug, 1u as i16); - log(debug, 1u as i32); - log(debug, 1u as i64); - log(debug, 1u as u8); - log(debug, 1u as u16); - log(debug, 1u as u32); - log(debug, 1u as u64); - log(debug, 1u as f32); - log(debug, 1u as f64); + debug!(1u as int); + debug!(1u as uint); + debug!(1u as float); + debug!(1u as bool); + debug!(1u as *libc::FILE); + debug!(1u as i8); + debug!(1u as i16); + debug!(1u as i32); + debug!(1u as i64); + debug!(1u as u8); + debug!(1u as u16); + debug!(1u as u32); + debug!(1u as u64); + debug!(1u as f32); + debug!(1u as f64); - log(debug, 1i8 as int); - log(debug, 1i8 as uint); - log(debug, 1i8 as float); - log(debug, 1i8 as bool); - log(debug, 1i8 as *libc::FILE); - log(debug, 1i8 as i8); - log(debug, 1i8 as i16); - log(debug, 1i8 as i32); - log(debug, 1i8 as i64); - log(debug, 1i8 as u8); - log(debug, 1i8 as u16); - log(debug, 1i8 as u32); - log(debug, 1i8 as u64); - log(debug, 1i8 as f32); - log(debug, 1i8 as f64); + debug!(1i8 as int); + debug!(1i8 as uint); + debug!(1i8 as float); + debug!(1i8 as bool); + debug!(1i8 as *libc::FILE); + debug!(1i8 as i8); + debug!(1i8 as i16); + debug!(1i8 as i32); + debug!(1i8 as i64); + debug!(1i8 as u8); + debug!(1i8 as u16); + debug!(1i8 as u32); + debug!(1i8 as u64); + debug!(1i8 as f32); + debug!(1i8 as f64); - log(debug, 1u8 as int); - log(debug, 1u8 as uint); - log(debug, 1u8 as float); - log(debug, 1u8 as bool); - log(debug, 1u8 as *libc::FILE); - log(debug, 1u8 as i8); - log(debug, 1u8 as i16); - log(debug, 1u8 as i32); - log(debug, 1u8 as i64); - log(debug, 1u8 as u8); - log(debug, 1u8 as u16); - log(debug, 1u8 as u32); - log(debug, 1u8 as u64); - log(debug, 1u8 as f32); - log(debug, 1u8 as f64); + debug!(1u8 as int); + debug!(1u8 as uint); + debug!(1u8 as float); + debug!(1u8 as bool); + debug!(1u8 as *libc::FILE); + debug!(1u8 as i8); + debug!(1u8 as i16); + debug!(1u8 as i32); + debug!(1u8 as i64); + debug!(1u8 as u8); + debug!(1u8 as u16); + debug!(1u8 as u32); + debug!(1u8 as u64); + debug!(1u8 as f32); + debug!(1u8 as f64); - log(debug, 1i16 as int); - log(debug, 1i16 as uint); - log(debug, 1i16 as float); - log(debug, 1i16 as bool); - log(debug, 1i16 as *libc::FILE); - log(debug, 1i16 as i8); - log(debug, 1i16 as i16); - log(debug, 1i16 as i32); - log(debug, 1i16 as i64); - log(debug, 1i16 as u8); - log(debug, 1i16 as u16); - log(debug, 1i16 as u32); - log(debug, 1i16 as u64); - log(debug, 1i16 as f32); - log(debug, 1i16 as f64); + debug!(1i16 as int); + debug!(1i16 as uint); + debug!(1i16 as float); + debug!(1i16 as bool); + debug!(1i16 as *libc::FILE); + debug!(1i16 as i8); + debug!(1i16 as i16); + debug!(1i16 as i32); + debug!(1i16 as i64); + debug!(1i16 as u8); + debug!(1i16 as u16); + debug!(1i16 as u32); + debug!(1i16 as u64); + debug!(1i16 as f32); + debug!(1i16 as f64); - log(debug, 1u16 as int); - log(debug, 1u16 as uint); - log(debug, 1u16 as float); - log(debug, 1u16 as bool); - log(debug, 1u16 as *libc::FILE); - log(debug, 1u16 as i8); - log(debug, 1u16 as i16); - log(debug, 1u16 as i32); - log(debug, 1u16 as i64); - log(debug, 1u16 as u8); - log(debug, 1u16 as u16); - log(debug, 1u16 as u32); - log(debug, 1u16 as u64); - log(debug, 1u16 as f32); - log(debug, 1u16 as f64); + debug!(1u16 as int); + debug!(1u16 as uint); + debug!(1u16 as float); + debug!(1u16 as bool); + debug!(1u16 as *libc::FILE); + debug!(1u16 as i8); + debug!(1u16 as i16); + debug!(1u16 as i32); + debug!(1u16 as i64); + debug!(1u16 as u8); + debug!(1u16 as u16); + debug!(1u16 as u32); + debug!(1u16 as u64); + debug!(1u16 as f32); + debug!(1u16 as f64); - log(debug, 1i32 as int); - log(debug, 1i32 as uint); - log(debug, 1i32 as float); - log(debug, 1i32 as bool); - log(debug, 1i32 as *libc::FILE); - log(debug, 1i32 as i8); - log(debug, 1i32 as i16); - log(debug, 1i32 as i32); - log(debug, 1i32 as i64); - log(debug, 1i32 as u8); - log(debug, 1i32 as u16); - log(debug, 1i32 as u32); - log(debug, 1i32 as u64); - log(debug, 1i32 as f32); - log(debug, 1i32 as f64); + debug!(1i32 as int); + debug!(1i32 as uint); + debug!(1i32 as float); + debug!(1i32 as bool); + debug!(1i32 as *libc::FILE); + debug!(1i32 as i8); + debug!(1i32 as i16); + debug!(1i32 as i32); + debug!(1i32 as i64); + debug!(1i32 as u8); + debug!(1i32 as u16); + debug!(1i32 as u32); + debug!(1i32 as u64); + debug!(1i32 as f32); + debug!(1i32 as f64); - log(debug, 1u32 as int); - log(debug, 1u32 as uint); - log(debug, 1u32 as float); - log(debug, 1u32 as bool); - log(debug, 1u32 as *libc::FILE); - log(debug, 1u32 as i8); - log(debug, 1u32 as i16); - log(debug, 1u32 as i32); - log(debug, 1u32 as i64); - log(debug, 1u32 as u8); - log(debug, 1u32 as u16); - log(debug, 1u32 as u32); - log(debug, 1u32 as u64); - log(debug, 1u32 as f32); - log(debug, 1u32 as f64); + debug!(1u32 as int); + debug!(1u32 as uint); + debug!(1u32 as float); + debug!(1u32 as bool); + debug!(1u32 as *libc::FILE); + debug!(1u32 as i8); + debug!(1u32 as i16); + debug!(1u32 as i32); + debug!(1u32 as i64); + debug!(1u32 as u8); + debug!(1u32 as u16); + debug!(1u32 as u32); + debug!(1u32 as u64); + debug!(1u32 as f32); + debug!(1u32 as f64); - log(debug, 1i64 as int); - log(debug, 1i64 as uint); - log(debug, 1i64 as float); - log(debug, 1i64 as bool); - log(debug, 1i64 as *libc::FILE); - log(debug, 1i64 as i8); - log(debug, 1i64 as i16); - log(debug, 1i64 as i32); - log(debug, 1i64 as i64); - log(debug, 1i64 as u8); - log(debug, 1i64 as u16); - log(debug, 1i64 as u32); - log(debug, 1i64 as u64); - log(debug, 1i64 as f32); - log(debug, 1i64 as f64); + debug!(1i64 as int); + debug!(1i64 as uint); + debug!(1i64 as float); + debug!(1i64 as bool); + debug!(1i64 as *libc::FILE); + debug!(1i64 as i8); + debug!(1i64 as i16); + debug!(1i64 as i32); + debug!(1i64 as i64); + debug!(1i64 as u8); + debug!(1i64 as u16); + debug!(1i64 as u32); + debug!(1i64 as u64); + debug!(1i64 as f32); + debug!(1i64 as f64); - log(debug, 1u64 as int); - log(debug, 1u64 as uint); - log(debug, 1u64 as float); - log(debug, 1u64 as bool); - log(debug, 1u64 as *libc::FILE); - log(debug, 1u64 as i8); - log(debug, 1u64 as i16); - log(debug, 1u64 as i32); - log(debug, 1u64 as i64); - log(debug, 1u64 as u8); - log(debug, 1u64 as u16); - log(debug, 1u64 as u32); - log(debug, 1u64 as u64); - log(debug, 1u64 as f32); - log(debug, 1u64 as f64); + debug!(1u64 as int); + debug!(1u64 as uint); + debug!(1u64 as float); + debug!(1u64 as bool); + debug!(1u64 as *libc::FILE); + debug!(1u64 as i8); + debug!(1u64 as i16); + debug!(1u64 as i32); + debug!(1u64 as i64); + debug!(1u64 as u8); + debug!(1u64 as u16); + debug!(1u64 as u32); + debug!(1u64 as u64); + debug!(1u64 as f32); + debug!(1u64 as f64); - log(debug, 1u64 as int); - log(debug, 1u64 as uint); - log(debug, 1u64 as float); - log(debug, 1u64 as bool); - log(debug, 1u64 as *libc::FILE); - log(debug, 1u64 as i8); - log(debug, 1u64 as i16); - log(debug, 1u64 as i32); - log(debug, 1u64 as i64); - log(debug, 1u64 as u8); - log(debug, 1u64 as u16); - log(debug, 1u64 as u32); - log(debug, 1u64 as u64); - log(debug, 1u64 as f32); - log(debug, 1u64 as f64); + debug!(1u64 as int); + debug!(1u64 as uint); + debug!(1u64 as float); + debug!(1u64 as bool); + debug!(1u64 as *libc::FILE); + debug!(1u64 as i8); + debug!(1u64 as i16); + debug!(1u64 as i32); + debug!(1u64 as i64); + debug!(1u64 as u8); + debug!(1u64 as u16); + debug!(1u64 as u32); + debug!(1u64 as u64); + debug!(1u64 as f32); + debug!(1u64 as f64); - log(debug, true as int); - log(debug, true as uint); - log(debug, true as float); - log(debug, true as bool); - log(debug, true as *libc::FILE); - log(debug, true as i8); - log(debug, true as i16); - log(debug, true as i32); - log(debug, true as i64); - log(debug, true as u8); - log(debug, true as u16); - log(debug, true as u32); - log(debug, true as u64); - log(debug, true as f32); - log(debug, true as f64); + debug!(true as int); + debug!(true as uint); + debug!(true as float); + debug!(true as bool); + debug!(true as *libc::FILE); + debug!(true as i8); + debug!(true as i16); + debug!(true as i32); + debug!(true as i64); + debug!(true as u8); + debug!(true as u16); + debug!(true as u32); + debug!(true as u64); + debug!(true as f32); + debug!(true as f64); - log(debug, 1. as int); - log(debug, 1. as uint); - log(debug, 1. as float); - log(debug, 1. as bool); - log(debug, 1. as i8); - log(debug, 1. as i16); - log(debug, 1. as i32); - log(debug, 1. as i64); - log(debug, 1. as u8); - log(debug, 1. as u16); - log(debug, 1. as u32); - log(debug, 1. as u64); - log(debug, 1. as f32); - log(debug, 1. as f64); + debug!(1. as int); + debug!(1. as uint); + debug!(1. as float); + debug!(1. as bool); + debug!(1. as i8); + debug!(1. as i16); + debug!(1. as i32); + debug!(1. as i64); + debug!(1. as u8); + debug!(1. as u16); + debug!(1. as u32); + debug!(1. as u64); + debug!(1. as f32); + debug!(1. as f64); - log(debug, 1f32 as int); - log(debug, 1f32 as uint); - log(debug, 1f32 as float); - log(debug, 1f32 as bool); - log(debug, 1f32 as i8); - log(debug, 1f32 as i16); - log(debug, 1f32 as i32); - log(debug, 1f32 as i64); - log(debug, 1f32 as u8); - log(debug, 1f32 as u16); - log(debug, 1f32 as u32); - log(debug, 1f32 as u64); - log(debug, 1f32 as f32); - log(debug, 1f32 as f64); + debug!(1f32 as int); + debug!(1f32 as uint); + debug!(1f32 as float); + debug!(1f32 as bool); + debug!(1f32 as i8); + debug!(1f32 as i16); + debug!(1f32 as i32); + debug!(1f32 as i64); + debug!(1f32 as u8); + debug!(1f32 as u16); + debug!(1f32 as u32); + debug!(1f32 as u64); + debug!(1f32 as f32); + debug!(1f32 as f64); - log(debug, 1f64 as int); - log(debug, 1f64 as uint); - log(debug, 1f64 as float); - log(debug, 1f64 as bool); - log(debug, 1f64 as i8); - log(debug, 1f64 as i16); - log(debug, 1f64 as i32); - log(debug, 1f64 as i64); - log(debug, 1f64 as u8); - log(debug, 1f64 as u16); - log(debug, 1f64 as u32); - log(debug, 1f64 as u64); - log(debug, 1f64 as f32); - log(debug, 1f64 as f64); + debug!(1f64 as int); + debug!(1f64 as uint); + debug!(1f64 as float); + debug!(1f64 as bool); + debug!(1f64 as i8); + debug!(1f64 as i16); + debug!(1f64 as i32); + debug!(1f64 as i64); + debug!(1f64 as u8); + debug!(1f64 as u16); + debug!(1f64 as u32); + debug!(1f64 as u64); + debug!(1f64 as f32); + debug!(1f64 as f64); } diff --git a/src/test/run-pass/syntax-extension-fmt.rs b/src/test/run-pass/syntax-extension-fmt.rs index 1c0f31165d3..3af58274bfb 100644 --- a/src/test/run-pass/syntax-extension-fmt.rs +++ b/src/test/run-pass/syntax-extension-fmt.rs @@ -11,8 +11,8 @@ extern mod std; fn test(actual: ~str, expected: ~str) { - log(debug, copy actual); - log(debug, copy expected); + debug!(actual.clone()); + debug!(expected.clone()); fail_unless!((actual == expected)); } diff --git a/src/test/run-pass/tail-cps.rs b/src/test/run-pass/tail-cps.rs index 8a413b53c2d..0f3131e3967 100644 --- a/src/test/run-pass/tail-cps.rs +++ b/src/test/run-pass/tail-cps.rs @@ -18,12 +18,12 @@ pub fn main() { let k = checktrue; evenk(42, k); oddk(45, k); } fn evenk(n: int, k: extern fn(bool) -> bool) -> bool { debug!("evenk"); - log(debug, n); + debug!(n); if n == 0 { return k(true); } else { return oddk(n - 1, k); } } fn oddk(n: int, k: extern fn(bool) -> bool) -> bool { debug!("oddk"); - log(debug, n); + debug!(n); if n == 0 { return k(false); } else { return evenk(n - 1, k); } } diff --git a/src/test/run-pass/task-comm-0.rs b/src/test/run-pass/task-comm-0.rs index b163703ca48..6a93df01395 100644 --- a/src/test/run-pass/task-comm-0.rs +++ b/src/test/run-pass/task-comm-0.rs @@ -31,10 +31,10 @@ fn test05() { let (po, ch) = comm::stream(); task::spawn(|| test05_start(ch) ); let mut value = po.recv(); - log(error, value); + error!(value); value = po.recv(); - log(error, value); + error!(value); value = po.recv(); - log(error, value); + error!(value); fail_unless!((value == 30)); } diff --git a/src/test/run-pass/task-comm-10.rs b/src/test/run-pass/task-comm-10.rs index 2e5da9a1a23..3fd55a7310e 100644 --- a/src/test/run-pass/task-comm-10.rs +++ b/src/test/run-pass/task-comm-10.rs @@ -20,10 +20,10 @@ fn start(c: &comm::Chan<comm::Chan<~str>>) { let mut b; a = p.recv(); fail_unless!(a == ~"A"); - log(error, a); + error!(a); b = p.recv(); fail_unless!(b == ~"B"); - log(error, b); + error!(b); } pub fn main() { diff --git a/src/test/run-pass/task-comm-14.rs b/src/test/run-pass/task-comm-14.rs index 053499ee5ed..4f0eb7c101f 100644 --- a/src/test/run-pass/task-comm-14.rs +++ b/src/test/run-pass/task-comm-14.rs @@ -16,7 +16,7 @@ pub fn main() { // Spawn 10 tasks each sending us back one int. let mut i = 10; while (i > 0) { - log(debug, i); + debug!(i); let (p, ch) = comm::stream(); po.add(p); task::spawn({let i = i; || child(i, &ch)}); @@ -28,7 +28,7 @@ pub fn main() { i = 10; while (i > 0) { - log(debug, i); + debug!(i); po.recv(); i = i - 1; } @@ -37,6 +37,6 @@ pub fn main() { } fn child(x: int, ch: &comm::Chan<int>) { - log(debug, x); + debug!(x); ch.send(x); } diff --git a/src/test/run-pass/task-comm-3.rs b/src/test/run-pass/task-comm-3.rs index 9772c0d181d..8c8f38f5e12 100644 --- a/src/test/run-pass/task-comm-3.rs +++ b/src/test/run-pass/task-comm-3.rs @@ -64,7 +64,7 @@ fn test00() { for results.each |r| { r.recv(); } debug!("Completed: Final number is: "); - log(error, sum); + error!(sum); // assert (sum == (((number_of_tasks * (number_of_tasks - 1)) / 2) * // number_of_messages)); fail_unless!((sum == 480)); diff --git a/src/test/run-pass/task-comm-4.rs b/src/test/run-pass/task-comm-4.rs index 5e43ea1f493..11191ba9658 100644 --- a/src/test/run-pass/task-comm-4.rs +++ b/src/test/run-pass/task-comm-4.rs @@ -20,31 +20,31 @@ fn test00() { c.send(4); r = p.recv(); sum += r; - log(debug, r); + debug!(r); r = p.recv(); sum += r; - log(debug, r); + debug!(r); r = p.recv(); sum += r; - log(debug, r); + debug!(r); r = p.recv(); sum += r; - log(debug, r); + debug!(r); c.send(5); c.send(6); c.send(7); c.send(8); r = p.recv(); sum += r; - log(debug, r); + debug!(r); r = p.recv(); sum += r; - log(debug, r); + debug!(r); r = p.recv(); sum += r; - log(debug, r); + debug!(r); r = p.recv(); sum += r; - log(debug, r); + debug!(r); fail_unless!((sum == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8)); } diff --git a/src/test/run-pass/task-comm-9.rs b/src/test/run-pass/task-comm-9.rs index 95fe7867d0c..57e07221c3d 100644 --- a/src/test/run-pass/task-comm-9.rs +++ b/src/test/run-pass/task-comm-9.rs @@ -35,7 +35,7 @@ fn test00() { let mut i: int = 0; while i < number_of_messages { sum += p.recv(); - log(debug, r); + debug!(r); i += 1; } diff --git a/src/test/run-pass/threads.rs b/src/test/run-pass/threads.rs index bd7bab60cb3..f736ded3db2 100644 --- a/src/test/run-pass/threads.rs +++ b/src/test/run-pass/threads.rs @@ -18,5 +18,5 @@ pub fn main() { debug!("main thread exiting"); } -fn child(&&x: int) { log(debug, x); } +fn child(&&x: int) { debug!(x); } diff --git a/src/test/run-pass/trait-bounds.rs b/src/test/run-pass/trait-bounds.rs index a07e5c6cf3f..6dcd2a41e07 100644 --- a/src/test/run-pass/trait-bounds.rs +++ b/src/test/run-pass/trait-bounds.rs @@ -9,22 +9,22 @@ // except according to those terms. trait connection { - fn read() -> int; + fn read(&self) -> int; } trait connection_factory<C:connection> { - fn create() -> C; + fn create(&self) -> C; } type my_connection = (); type my_connection_factory = (); impl connection for () { - fn read() -> int { 43 } + fn read(&self) -> int { 43 } } impl connection_factory<my_connection> for my_connection_factory { - fn create() -> my_connection { () } + fn create(&self) -> my_connection { () } } pub fn main() { diff --git a/src/test/run-pass/trait-composition-trivial.rs b/src/test/run-pass/trait-composition-trivial.rs index 56645b48218..328c0b6888c 100644 --- a/src/test/run-pass/trait-composition-trivial.rs +++ b/src/test/run-pass/trait-composition-trivial.rs @@ -9,11 +9,11 @@ // except according to those terms. trait Foo { - fn foo(); + fn foo(&self); } trait Bar : Foo { - fn bar(); + fn bar(&self); } pub fn main() {} diff --git a/src/test/run-pass/trait-default-method-bound-subst2.rs b/src/test/run-pass/trait-default-method-bound-subst2.rs index cba45c6bb23..ce72c7e9a44 100644 --- a/src/test/run-pass/trait-default-method-bound-subst2.rs +++ b/src/test/run-pass/trait-default-method-bound-subst2.rs @@ -11,7 +11,7 @@ // xfail-test trait A<T> { - fn g(x: T) -> T { x } + fn g(&self, x: T) -> T { x } } impl A<int> for int { } diff --git a/src/test/run-pass/trait-default-method-bound-subst3.rs b/src/test/run-pass/trait-default-method-bound-subst3.rs index 5a9b4fbb9e6..3c1e6a59d03 100644 --- a/src/test/run-pass/trait-default-method-bound-subst3.rs +++ b/src/test/run-pass/trait-default-method-bound-subst3.rs @@ -11,7 +11,7 @@ #[allow(default_methods)]; trait A { - fn g<T>(x: T, y: T) -> (T, T) { (x, y) } + fn g<T>(&self, x: T, y: T) -> (T, T) { (x, y) } } impl A for int { } diff --git a/src/test/run-pass/trait-default-method-bound-subst4.rs b/src/test/run-pass/trait-default-method-bound-subst4.rs index ee0feafa5c1..9ac66bfb737 100644 --- a/src/test/run-pass/trait-default-method-bound-subst4.rs +++ b/src/test/run-pass/trait-default-method-bound-subst4.rs @@ -11,7 +11,7 @@ #[allow(default_methods)]; trait A<T> { - fn g(x: uint) -> uint { x } + fn g(&self, x: uint) -> uint { x } } impl<T> A<T> for int { } diff --git a/src/test/run-pass/trait-default-method-bound.rs b/src/test/run-pass/trait-default-method-bound.rs index 4c2c030eaab..627bc96e6ae 100644 --- a/src/test/run-pass/trait-default-method-bound.rs +++ b/src/test/run-pass/trait-default-method-bound.rs @@ -11,7 +11,7 @@ #[allow(default_methods)]; trait A { - fn g() -> int { 10 } + fn g(&self) -> int { 10 } } impl A for int { } diff --git a/src/test/run-pass/trait-generic.rs b/src/test/run-pass/trait-generic.rs index 7b8ebe6d34c..c11ece62813 100644 --- a/src/test/run-pass/trait-generic.rs +++ b/src/test/run-pass/trait-generic.rs @@ -11,23 +11,23 @@ // xfail-fast trait to_str { - fn to_str() -> ~str; + fn to_str(&self) -> ~str; } impl to_str for int { - fn to_str() -> ~str { int::to_str(self) } + fn to_str(&self) -> ~str { int::to_str(*self) } } impl to_str for ~str { - fn to_str() -> ~str { copy self } + fn to_str(&self) -> ~str { self.clone() } } impl to_str for () { - fn to_str() -> ~str { ~"()" } + fn to_str(&self) -> ~str { ~"()" } } trait map<T> { - fn map<U:Copy>(f: &fn(&T) -> U) -> ~[U]; + fn map<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U]; } impl<T> map<T> for ~[T] { - fn map<U:Copy>(f: &fn(&T) -> U) -> ~[U] { + fn map<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U] { let mut r = ~[]; for self.each |x| { r += ~[f(x)]; } r diff --git a/src/test/run-pass/trait-inheritance-auto-xc.rs b/src/test/run-pass/trait-inheritance-auto-xc.rs index 1efdd06767c..ccb55f1d164 100644 --- a/src/test/run-pass/trait-inheritance-auto-xc.rs +++ b/src/test/run-pass/trait-inheritance-auto-xc.rs @@ -17,9 +17,9 @@ use aux::{Foo, Bar, Baz, Quux}; struct A { x: int } -impl Foo for A { fn f() -> int { 10 } } -impl Bar for A { fn g() -> int { 20 } } -impl Baz for A { fn h() -> int { 30 } } +impl Foo for A { fn f(&self) -> int { 10 } } +impl Bar for A { fn g(&self) -> int { 20 } } +impl Baz for A { fn h(&self) -> int { 30 } } fn f<T:Quux>(a: &T) { fail_unless!(a.f() == 10); diff --git a/src/test/run-pass/trait-inheritance-auto.rs b/src/test/run-pass/trait-inheritance-auto.rs index efc4cfa6156..51a3168f6e8 100644 --- a/src/test/run-pass/trait-inheritance-auto.rs +++ b/src/test/run-pass/trait-inheritance-auto.rs @@ -12,17 +12,17 @@ // A is already a Foo Bar Baz impl<T:Foo + Bar + Baz> Quux for T { } -trait Foo { fn f() -> int; } -trait Bar { fn g() -> int; } -trait Baz { fn h() -> int; } +trait Foo { fn f(&self) -> int; } +trait Bar { fn g(&self) -> int; } +trait Baz { fn h(&self) -> int; } trait Quux: Foo + Bar + Baz { } struct A { x: int } -impl Foo for A { fn f() -> int { 10 } } -impl Bar for A { fn g() -> int { 20 } } -impl Baz for A { fn h() -> int { 30 } } +impl Foo for A { fn f(&self) -> int { 10 } } +impl Bar for A { fn g(&self) -> int { 20 } } +impl Baz for A { fn h(&self) -> int { 30 } } fn f<T:Quux>(a: &T) { fail_unless!(a.f() == 10); diff --git a/src/test/run-pass/trait-inheritance-call-bound-inherited.rs b/src/test/run-pass/trait-inheritance-call-bound-inherited.rs index 75dea9c500a..dcc1deed846 100644 --- a/src/test/run-pass/trait-inheritance-call-bound-inherited.rs +++ b/src/test/run-pass/trait-inheritance-call-bound-inherited.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait Foo { fn f() -> int; } -trait Bar : Foo { fn g() -> int; } +trait Foo { fn f(&self) -> int; } +trait Bar : Foo { fn g(&self) -> int; } struct A { x: int } -impl Foo for A { fn f() -> int { 10 } } -impl Bar for A { fn g() -> int { 20 } } +impl Foo for A { fn f(&self) -> int { 10 } } +impl Bar for A { fn g(&self) -> int { 20 } } // Call a function on Foo, given a T: Bar fn gg<T:Bar>(a: &T) -> int { diff --git a/src/test/run-pass/trait-inheritance-call-bound-inherited2.rs b/src/test/run-pass/trait-inheritance-call-bound-inherited2.rs index e8d553dae18..ad23cab016e 100644 --- a/src/test/run-pass/trait-inheritance-call-bound-inherited2.rs +++ b/src/test/run-pass/trait-inheritance-call-bound-inherited2.rs @@ -8,15 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait Foo { fn f() -> int; } -trait Bar : Foo { fn g() -> int; } -trait Baz : Bar { fn h() -> int; } +trait Foo { fn f(&self) -> int; } +trait Bar : Foo { fn g(&self) -> int; } +trait Baz : Bar { fn h(&self) -> int; } struct A { x: int } -impl Foo for A { fn f() -> int { 10 } } -impl Bar for A { fn g() -> int { 20 } } -impl Baz for A { fn h() -> int { 30 } } +impl Foo for A { fn f(&self) -> int { 10 } } +impl Bar for A { fn g(&self) -> int { 20 } } +impl Baz for A { fn h(&self) -> int { 30 } } // Call a function on Foo, given a T: Baz, // which is inherited via Bar diff --git a/src/test/run-pass/trait-inheritance-cast-without-call-to-supertrait.rs b/src/test/run-pass/trait-inheritance-cast-without-call-to-supertrait.rs index 3447cbad84a..39565382118 100644 --- a/src/test/run-pass/trait-inheritance-cast-without-call-to-supertrait.rs +++ b/src/test/run-pass/trait-inheritance-cast-without-call-to-supertrait.rs @@ -12,11 +12,11 @@ // methods. Not testing supertrait methods trait Foo { - fn f() -> int; + fn f(&self) -> int; } trait Bar : Foo { - fn g() -> int; + fn g(&self) -> int; } struct A { @@ -24,11 +24,11 @@ struct A { } impl Foo for A { - fn f() -> int { 10 } + fn f(&self) -> int { 10 } } impl Bar for A { - fn g() -> int { 20 } + fn g(&self) -> int { 20 } } pub fn main() { diff --git a/src/test/run-pass/trait-inheritance-cross-trait-call-xc.rs b/src/test/run-pass/trait-inheritance-cross-trait-call-xc.rs index cc6d5fa736f..a5f163a9cfa 100644 --- a/src/test/run-pass/trait-inheritance-cross-trait-call-xc.rs +++ b/src/test/run-pass/trait-inheritance-cross-trait-call-xc.rs @@ -16,11 +16,11 @@ extern mod aux(name = "trait_inheritance_cross_trait_call_xc_aux"); use aux::Foo; trait Bar : Foo { - fn g() -> int; + fn g(&self) -> int; } impl Bar for aux::A { - fn g() -> int { self.f() } + fn g(&self) -> int { self.f() } } pub fn main() { diff --git a/src/test/run-pass/trait-inheritance-cross-trait-call.rs b/src/test/run-pass/trait-inheritance-cross-trait-call.rs index 47b5f60233b..2cde60ecf58 100644 --- a/src/test/run-pass/trait-inheritance-cross-trait-call.rs +++ b/src/test/run-pass/trait-inheritance-cross-trait-call.rs @@ -8,16 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait Foo { fn f() -> int; } -trait Bar : Foo { fn g() -> int; } +trait Foo { fn f(&self) -> int; } +trait Bar : Foo { fn g(&self) -> int; } struct A { x: int } -impl Foo for A { fn f() -> int { 10 } } +impl Foo for A { fn f(&self) -> int { 10 } } impl Bar for A { // Testing that this impl can call the impl of Foo - fn g() -> int { self.f() } + fn g(&self) -> int { self.f() } } pub fn main() { diff --git a/src/test/run-pass/trait-inheritance-simple.rs b/src/test/run-pass/trait-inheritance-simple.rs index f56a50f1430..9ca3ccaa22c 100644 --- a/src/test/run-pass/trait-inheritance-simple.rs +++ b/src/test/run-pass/trait-inheritance-simple.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait Foo { fn f() -> int; } -trait Bar : Foo { fn g() -> int; } +trait Foo { fn f(&self) -> int; } +trait Bar : Foo { fn g(&self) -> int; } struct A { x: int } -impl Foo for A { fn f() -> int { 10 } } -impl Bar for A { fn g() -> int { 20 } } +impl Foo for A { fn f(&self) -> int { 10 } } +impl Bar for A { fn g(&self) -> int { 20 } } fn ff<T:Foo>(a: &T) -> int { a.f() diff --git a/src/test/run-pass/trait-inheritance-subst.rs b/src/test/run-pass/trait-inheritance-subst.rs index 5900805e957..c1ee7a2c00a 100644 --- a/src/test/run-pass/trait-inheritance-subst.rs +++ b/src/test/run-pass/trait-inheritance-subst.rs @@ -9,7 +9,7 @@ // except according to those terms. pub trait Add<RHS,Result> { - pure fn add(rhs: &RHS) -> Result; + pure fn add(&self, rhs: &RHS) -> Result; } trait MyNum : Add<Self,Self> { } @@ -17,7 +17,7 @@ trait MyNum : Add<Self,Self> { } struct MyInt { val: int } impl Add<MyInt, MyInt> for MyInt { - pure fn add(other: &MyInt) -> MyInt { mi(self.val + other.val) } + pure fn add(&self, other: &MyInt) -> MyInt { mi(self.val + other.val) } } impl MyNum for MyInt; diff --git a/src/test/run-pass/trait-inheritance-subst2.rs b/src/test/run-pass/trait-inheritance-subst2.rs index 77e15a802e4..20b7d529fae 100644 --- a/src/test/run-pass/trait-inheritance-subst2.rs +++ b/src/test/run-pass/trait-inheritance-subst2.rs @@ -9,11 +9,11 @@ // except according to those terms. trait Panda<T> { - fn chomp(bamboo: &T) -> T; + fn chomp(&self, bamboo: &T) -> T; } trait Add<RHS,Result>: Panda<RHS> { - fn add(rhs: &RHS) -> Result; + fn add(&self, rhs: &RHS) -> Result; } trait MyNum : Add<Self,Self> { } @@ -21,13 +21,13 @@ trait MyNum : Add<Self,Self> { } struct MyInt { val: int } impl Panda<MyInt> for MyInt { - fn chomp(bamboo: &MyInt) -> MyInt { + fn chomp(&self, bamboo: &MyInt) -> MyInt { mi(self.val + bamboo.val) } } impl Add<MyInt, MyInt> for MyInt { - fn add(other: &MyInt) -> MyInt { self.chomp(other) } + fn add(&self, other: &MyInt) -> MyInt { self.chomp(other) } } impl MyNum for MyInt; diff --git a/src/test/run-pass/trait-inheritance-visibility.rs b/src/test/run-pass/trait-inheritance-visibility.rs index 861e9c0c84a..c70c2ecf976 100644 --- a/src/test/run-pass/trait-inheritance-visibility.rs +++ b/src/test/run-pass/trait-inheritance-visibility.rs @@ -9,9 +9,9 @@ // except according to those terms. mod traits { - pub trait Foo { fn f() -> int; } + pub trait Foo { fn f(&self) -> int; } - impl Foo for int { fn f() -> int { 10 } } + impl Foo for int { fn f(&self) -> int { 10 } } } trait Quux: traits::Foo { } diff --git a/src/test/run-pass/trait-inheritance2.rs b/src/test/run-pass/trait-inheritance2.rs index 78e3b43730e..d18452f11fa 100644 --- a/src/test/run-pass/trait-inheritance2.rs +++ b/src/test/run-pass/trait-inheritance2.rs @@ -8,17 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait Foo { fn f() -> int; } -trait Bar { fn g() -> int; } -trait Baz { fn h() -> int; } +trait Foo { fn f(&self) -> int; } +trait Bar { fn g(&self) -> int; } +trait Baz { fn h(&self) -> int; } trait Quux: Foo + Bar + Baz { } struct A { x: int } -impl Foo for A { fn f() -> int { 10 } } -impl Bar for A { fn g() -> int { 20 } } -impl Baz for A { fn h() -> int { 30 } } +impl Foo for A { fn f(&self) -> int { 10 } } +impl Bar for A { fn g(&self) -> int { 20 } } +impl Baz for A { fn h(&self) -> int { 30 } } impl Quux for A; fn f<T:Quux + Foo + Bar + Baz>(a: &T) { diff --git a/src/test/run-pass/trait-region-pointer-simple.rs b/src/test/run-pass/trait-region-pointer-simple.rs index d55ca35fff2..1ce2cddc29b 100644 --- a/src/test/run-pass/trait-region-pointer-simple.rs +++ b/src/test/run-pass/trait-region-pointer-simple.rs @@ -9,7 +9,7 @@ // except according to those terms. trait Foo { - fn f() -> int; + fn f(&self) -> int; } struct A { @@ -17,7 +17,7 @@ struct A { } impl Foo for A { - fn f() -> int { + fn f(&self) -> int { io::println(~"Today's number is " + self.x.to_str()); return self.x; } diff --git a/src/test/run-pass/trait-to-str.rs b/src/test/run-pass/trait-to-str.rs index 29de9d1df81..40850186e28 100644 --- a/src/test/run-pass/trait-to-str.rs +++ b/src/test/run-pass/trait-to-str.rs @@ -17,16 +17,16 @@ extern mod core; use core::{str, int, vec}; trait to_str { - fn to_str() -> ~str; + fn to_str(&self) -> ~str; } impl to_str for int { - fn to_str() -> ~str { int::to_str(self) } + fn to_str(&self) -> ~str { int::to_str(*self) } } impl<T:to_str> to_str for ~[T] { - fn to_str() -> ~str { - ~"[" + str::connect(vec::map(self, |e| e.to_str() ), ~", ") + ~"]" + fn to_str(&self) -> ~str { + ~"[" + str::connect(vec::map(*self, |e| e.to_str() ), ~", ") + ~"]" } } diff --git a/src/test/run-pass/traits-default-method-macro.rs b/src/test/run-pass/traits-default-method-macro.rs index f3f20cc50be..21e05aba27b 100644 --- a/src/test/run-pass/traits-default-method-macro.rs +++ b/src/test/run-pass/traits-default-method-macro.rs @@ -11,7 +11,7 @@ #[allow(default_methods)]; trait Foo { - fn bar() -> ~str { + fn bar(&self) -> ~str { fmt!("test") } } diff --git a/src/test/run-pass/traits-default-method-trivial.rs b/src/test/run-pass/traits-default-method-trivial.rs index fbfce37242d..8edb83ce60e 100644 --- a/src/test/run-pass/traits-default-method-trivial.rs +++ b/src/test/run-pass/traits-default-method-trivial.rs @@ -11,16 +11,16 @@ #[allow(default_methods)]; trait Cat { - fn meow() -> bool; - fn scratch() -> bool; - fn purr() -> bool { true } + fn meow(&self) -> bool; + fn scratch(&self) -> bool; + fn purr(&self) -> bool { true } } impl Cat for int { - fn meow() -> bool { + fn meow(&self) -> bool { self.scratch() } - fn scratch() -> bool { + fn scratch(&self) -> bool { self.purr() } } diff --git a/src/test/run-pass/trivial-message.rs b/src/test/run-pass/trivial-message.rs index 7800ebd7310..059d7ea5f70 100644 --- a/src/test/run-pass/trivial-message.rs +++ b/src/test/run-pass/trivial-message.rs @@ -16,5 +16,5 @@ pub fn main() { let (po, ch) = comm::stream(); ch.send(42); let r = po.recv(); - log(error, r); + error!(r); } diff --git a/src/test/run-pass/typeclasses-eq-example-static.rs b/src/test/run-pass/typeclasses-eq-example-static.rs index 1a2250b7691..cd914aaa318 100644 --- a/src/test/run-pass/typeclasses-eq-example-static.rs +++ b/src/test/run-pass/typeclasses-eq-example-static.rs @@ -61,5 +61,5 @@ pub fn main() { fail_unless!(!Equal::isEq(branch(@leaf(magenta), @leaf(cyan)), branch(@leaf(magenta), @leaf(magenta)))); - log(error, "Assertions all succeeded!"); + error!("Assertions all succeeded!"); } diff --git a/src/test/run-pass/typeclasses-eq-example.rs b/src/test/run-pass/typeclasses-eq-example.rs index 87a62f81e6d..a18965e9abc 100644 --- a/src/test/run-pass/typeclasses-eq-example.rs +++ b/src/test/run-pass/typeclasses-eq-example.rs @@ -11,14 +11,14 @@ // Example from lkuper's intern talk, August 2012. trait Equal { - fn isEq(a: Self) -> bool; + fn isEq(&self, a: Self) -> bool; } enum Color { cyan, magenta, yellow, black } impl Equal for Color { - fn isEq(a: Color) -> bool { - match (self, a) { + fn isEq(&self, a: Color) -> bool { + match (*self, a) { (cyan, cyan) => { true } (magenta, magenta) => { true } (yellow, yellow) => { true } @@ -34,8 +34,8 @@ enum ColorTree { } impl Equal for ColorTree { - fn isEq(a: ColorTree) -> bool { - match (self, a) { + fn isEq(&self, a: ColorTree) -> bool { + match (*self, a) { (leaf(x), leaf(y)) => { x.isEq(y) } (branch(l1, r1), branch(l2, r2)) => { (*l1).isEq(*l2) && (*r1).isEq(*r2) diff --git a/src/test/run-pass/unary-minus-suffix-inference.rs b/src/test/run-pass/unary-minus-suffix-inference.rs index d48b8bd7b4e..3277b878a41 100644 --- a/src/test/run-pass/unary-minus-suffix-inference.rs +++ b/src/test/run-pass/unary-minus-suffix-inference.rs @@ -11,43 +11,43 @@ pub fn main() { let a = 1; let a_neg: i8 = -a; - log(error, a_neg); + error!(a_neg); let b = 1; let b_neg: i16 = -b; - log(error, b_neg); + error!(b_neg); let c = 1; let c_neg: i32 = -c; - log(error, b_neg); + error!(b_neg); let d = 1; let d_neg: i64 = -d; - log(error, b_neg); + error!(b_neg); let e = 1; let e_neg: int = -e; - log(error, b_neg); + error!(b_neg); // intentional overflows let f = 1; let f_neg: u8 = -f; - log(error, f_neg); + error!(f_neg); let g = 1; let g_neg: u16 = -g; - log(error, g_neg); + error!(g_neg); let h = 1; let h_neg: u32 = -h; - log(error, h_neg); + error!(h_neg); let i = 1; let i_neg: u64 = -i; - log(error, i_neg); + error!(i_neg); let j = 1; let j_neg: uint = -j; - log(error, j_neg); + error!(j_neg); } diff --git a/src/test/run-pass/unique-assign-copy.rs b/src/test/run-pass/unique-assign-copy.rs index 340a247c241..8ecff0719a2 100644 --- a/src/test/run-pass/unique-assign-copy.rs +++ b/src/test/run-pass/unique-assign-copy.rs @@ -12,7 +12,7 @@ pub fn main() { let mut i = ~1; // Should be a copy let mut j; - j = copy i; + j = i.clone(); *i = 2; *j = 3; fail_unless!(*i == 2); diff --git a/src/test/run-pass/unique-decl-init-copy.rs b/src/test/run-pass/unique-decl-init-copy.rs index 2d15f09021e..177b3ed5c24 100644 --- a/src/test/run-pass/unique-decl-init-copy.rs +++ b/src/test/run-pass/unique-decl-init-copy.rs @@ -11,7 +11,7 @@ pub fn main() { let mut i = ~1; // Should be a copy - let mut j = copy i; + let mut j = i.clone(); *i = 2; *j = 3; fail_unless!(*i == 2); diff --git a/src/test/run-pass/unique-fn-arg-move.rs b/src/test/run-pass/unique-fn-arg-move.rs index 850af69b347..5a318d04e55 100644 --- a/src/test/run-pass/unique-fn-arg-move.rs +++ b/src/test/run-pass/unique-fn-arg-move.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(-i: ~int) { +fn f(+i: ~int) { fail_unless!(*i == 100); } diff --git a/src/test/run-pass/unique-in-tag.rs b/src/test/run-pass/unique-in-tag.rs index f6f1c3814c6..e46a79d364f 100644 --- a/src/test/run-pass/unique-in-tag.rs +++ b/src/test/run-pass/unique-in-tag.rs @@ -14,7 +14,7 @@ fn test1() { let x = u(~10); fail_unless!(match x { u(a) => { - log(error, a); + error!(a); *a } _ => { 66 } diff --git a/src/test/run-pass/unique-in-vec-copy.rs b/src/test/run-pass/unique-in-vec-copy.rs index 95b95913e98..1033fa1c22c 100644 --- a/src/test/run-pass/unique-in-vec-copy.rs +++ b/src/test/run-pass/unique-in-vec-copy.rs @@ -10,7 +10,7 @@ pub fn main() { let mut a = ~[~10]; - let b = copy a; + let b = a.clone(); fail_unless!(*a[0] == 10); fail_unless!(*b[0] == 10); diff --git a/src/test/run-pass/unique-log.rs b/src/test/run-pass/unique-log.rs index b619140d509..37cf6a26235 100644 --- a/src/test/run-pass/unique-log.rs +++ b/src/test/run-pass/unique-log.rs @@ -10,5 +10,5 @@ pub fn main() { let i = ~100; - log(error, i); + error!(i); } diff --git a/src/test/run-pass/unique-pat-3.rs b/src/test/run-pass/unique-pat-3.rs index 61d37842e15..14fc1cca4e5 100644 --- a/src/test/run-pass/unique-pat-3.rs +++ b/src/test/run-pass/unique-pat-3.rs @@ -14,7 +14,7 @@ enum bar { u(~int), w(int), } pub fn main() { fail_unless!(match u(~10) { u(a) => { - log(error, a); + error!(a); *a } _ => { 66 } diff --git a/src/test/run-pass/unreachable-code.rs b/src/test/run-pass/unreachable-code.rs index fa93dfd0fe1..153df44e2ef 100644 --- a/src/test/run-pass/unreachable-code.rs +++ b/src/test/run-pass/unreachable-code.rs @@ -20,14 +20,6 @@ fn call_id_2() { id(true) && id(return); } fn call_id_3() { id(return) && id(return); } -fn log_fail() { log(error, fail!()); } - -fn log_ret() { log(error, return); } - -fn log_break() { loop { log(error, break); } } - -fn log_again() { loop { log(error, loop); } } - fn ret_ret() -> int { return (return 2) + 3; } fn ret_guard() { diff --git a/src/test/run-pass/use-trait-before-def.rs b/src/test/run-pass/use-trait-before-def.rs index 1bd68bfa4b6..0b59ced98c9 100644 --- a/src/test/run-pass/use-trait-before-def.rs +++ b/src/test/run-pass/use-trait-before-def.rs @@ -10,6 +10,6 @@ // Issue #1761 -impl foo for int { fn foo() -> int { 10 } } -trait foo { fn foo() -> int; } +impl foo for int { fn foo(&self) -> int { 10 } } +trait foo { fn foo(&self) -> int; } pub fn main() {} diff --git a/src/test/run-pass/use-uninit-alt.rs b/src/test/run-pass/use-uninit-alt.rs index 17600f5f514..f4943ed09bd 100644 --- a/src/test/run-pass/use-uninit-alt.rs +++ b/src/test/run-pass/use-uninit-alt.rs @@ -18,4 +18,4 @@ fn foo<T>(o: myoption<T>) -> int { enum myoption<T> { none, some(T), } -pub fn main() { log(debug, 5); } +pub fn main() { debug!(5); } diff --git a/src/test/run-pass/use-uninit-alt2.rs b/src/test/run-pass/use-uninit-alt2.rs index 37ba2260a08..802c861f88b 100644 --- a/src/test/run-pass/use-uninit-alt2.rs +++ b/src/test/run-pass/use-uninit-alt2.rs @@ -18,4 +18,4 @@ fn foo<T>(o: myoption<T>) -> int { enum myoption<T> { none, some(T), } -pub fn main() { log(debug, 5); } +pub fn main() { debug!(5); } diff --git a/src/test/run-pass/utf8.rs b/src/test/run-pass/utf8.rs index c2b4049c306..a78461ff4ee 100644 --- a/src/test/run-pass/utf8.rs +++ b/src/test/run-pass/utf8.rs @@ -42,10 +42,10 @@ pub fn main() { fn check_str_eq(a: ~str, b: ~str) { let mut i: int = 0; for str::each(a) |ab| { - log(debug, i); - log(debug, ab); + debug!(i); + debug!(ab); let bb: u8 = b[i]; - log(debug, bb); + debug!(bb); fail_unless!((ab == bb)); i += 1; } diff --git a/src/test/run-pass/vec-concat.rs b/src/test/run-pass/vec-concat.rs index a7371f5fcf3..7023c50d0bd 100644 --- a/src/test/run-pass/vec-concat.rs +++ b/src/test/run-pass/vec-concat.rs @@ -13,7 +13,7 @@ pub fn main() { let a: ~[int] = ~[1, 2, 3, 4, 5]; let b: ~[int] = ~[6, 7, 8, 9, 0]; let v: ~[int] = a + b; - log(debug, v[9]); + debug!(v[9]); fail_unless!((v[0] == 1)); fail_unless!((v[7] == 8)); fail_unless!((v[9] == 0)); diff --git a/src/test/run-pass/vec-ivec-deadlock.rs b/src/test/run-pass/vec-ivec-deadlock.rs index 505b57ec7bb..8b6e037e840 100644 --- a/src/test/run-pass/vec-ivec-deadlock.rs +++ b/src/test/run-pass/vec-ivec-deadlock.rs @@ -10,6 +10,6 @@ pub fn main() { let a = ~[1, 2, 3, 4, 5]; - let mut b = ~[copy a, copy a]; + let mut b = ~[a.clone(), a.clone()]; b = b + b; // FIXME(#3387)---can't write b += b } diff --git a/src/test/run-pass/vec-late-init.rs b/src/test/run-pass/vec-late-init.rs index 918f7e70f4e..3f7501f34da 100644 --- a/src/test/run-pass/vec-late-init.rs +++ b/src/test/run-pass/vec-late-init.rs @@ -13,5 +13,5 @@ pub fn main() { let mut later: ~[int]; if true { later = ~[1]; } else { later = ~[2]; } - log(debug, later[0]); + debug!(later[0]); } diff --git a/src/test/run-pass/vec-matching-fold.rs b/src/test/run-pass/vec-matching-fold.rs index 1df90bf681c..dfd4f025c13 100644 --- a/src/test/run-pass/vec-matching-fold.rs +++ b/src/test/run-pass/vec-matching-fold.rs @@ -1,4 +1,4 @@ -fn foldl<T, U: Copy>( +fn foldl<T, U: Copy+Clone>( values: &[T], initial: U, function: &fn(partial: U, element: &T) -> U @@ -6,11 +6,11 @@ fn foldl<T, U: Copy>( match values { [head, ..tail] => foldl(tail, function(initial, &head), function), - [] => copy initial + [] => initial.clone() } } -fn foldr<T, U: Copy>( +fn foldr<T, U: Copy+Clone>( values: &[T], initial: U, function: &fn(element: &T, partial: U) -> U @@ -18,7 +18,7 @@ fn foldr<T, U: Copy>( match values { [..head, tail] => foldr(head, function(&tail, initial), function), - [] => copy initial + [] => initial.clone() } } diff --git a/src/test/run-pass/vec-self-append.rs b/src/test/run-pass/vec-self-append.rs index 614a884c08c..00b55aa9a01 100644 --- a/src/test/run-pass/vec-self-append.rs +++ b/src/test/run-pass/vec-self-append.rs @@ -47,7 +47,7 @@ fn test_loop() { let mut i = 20; let mut expected_len = 1u; while i > 0 { - log(error, vec::len(a)); + error!(vec::len(a)); fail_unless!((vec::len(a) == expected_len)); a = a + a; // FIXME(#3387)---can't write a += a i -= 1; diff --git a/src/test/run-pass/weird-exprs.rs b/src/test/run-pass/weird-exprs.rs index a652ed64945..a7ac8554b3d 100644 --- a/src/test/run-pass/weird-exprs.rs +++ b/src/test/run-pass/weird-exprs.rs @@ -55,10 +55,6 @@ fn notsure() { let _b = (_y <-> _z) == (_y <-> _z); } -fn hammertime() -> int { - let _x = log(debug, true == (return 0)); -} - fn canttouchthis() -> uint { pure fn p() -> bool { true } let _a = (fail_unless!((true)) == (fail_unless!(p()))); @@ -81,7 +77,6 @@ pub fn main() { what(); zombiejesus(); notsure(); - hammertime(); canttouchthis(); angrydome(); evil_lincoln(); diff --git a/src/test/run-pass/while-cont.rs b/src/test/run-pass/while-cont.rs index 9181f721305..5a67f98423d 100644 --- a/src/test/run-pass/while-cont.rs +++ b/src/test/run-pass/while-cont.rs @@ -13,7 +13,7 @@ pub fn main() { let mut i = 1; while i > 0 { fail_unless!((i > 0)); - log(debug, i); + debug!(i); i -= 1; loop; } diff --git a/src/test/run-pass/while-loop-constraints-2.rs b/src/test/run-pass/while-loop-constraints-2.rs index 39d3e2d9747..13376eddc41 100644 --- a/src/test/run-pass/while-loop-constraints-2.rs +++ b/src/test/run-pass/while-loop-constraints-2.rs @@ -16,7 +16,7 @@ pub fn main() { while z < 50 { z += 1; while false { x = y; y = z; } - log(debug, y); + debug!(y); } fail_unless!((y == 42 && z == 50)); } diff --git a/src/test/run-pass/while-with-break.rs b/src/test/run-pass/while-with-break.rs index dafae6b77c7..0644c55f8c8 100644 --- a/src/test/run-pass/while-with-break.rs +++ b/src/test/run-pass/while-with-break.rs @@ -5,7 +5,7 @@ pub fn main() { let mut i: int = 90; while i < 100 { - log(debug, i); + debug!(i); i = i + 1; if i == 95 { let v: ~[int] = diff --git a/src/test/run-pass/while.rs b/src/test/run-pass/while.rs index 64de4963b8a..70a88a025de 100644 --- a/src/test/run-pass/while.rs +++ b/src/test/run-pass/while.rs @@ -13,10 +13,10 @@ pub fn main() { let mut x: int = 10; let mut y: int = 0; - while y < x { log(debug, y); debug!("hello"); y = y + 1; } + while y < x { debug!(y); debug!("hello"); y = y + 1; } while x > 0 { debug!("goodbye"); x = x - 1; - log(debug, x); + debug!(x); } } diff --git a/src/test/run-pass/yield2.rs b/src/test/run-pass/yield2.rs index eaaa226c286..83b60d1863e 100644 --- a/src/test/run-pass/yield2.rs +++ b/src/test/run-pass/yield2.rs @@ -11,5 +11,5 @@ pub fn main() { let mut i: int = 0; - while i < 100 { i = i + 1; log(error, i); task::yield(); } + while i < 100 { i = i + 1; error!(i); task::yield(); } } |
