}
impl cat : ToStr {
- pure fn to_str() -> ~str { self.name }
+ pure fn to_str() -> ~str { copy self.name }
}
priv impl cat {
// the unused ty param is necessary so this gets monomorphized
fn request<T: Copy>(req: header_map) {
- let _x = *(*req.get(~"METHOD"))[0u];
+ let _x = *(copy *req.get(~"METHOD"))[0u];
}
}
impl ~str: to_strz {
- fn to_strz() -> ~str { self }
+ fn to_strz() -> ~str { copy self }
}
}
pub impl MyInt : Add<MyInt, MyInt> {
- pure fn add(other: &MyInt) -> MyInt { mi(self.val + other.val) }
+ pure fn add(&self, other: &MyInt) -> MyInt { mi(self.val + other.val) }
}
pub impl MyInt : Sub<MyInt, MyInt> {
fn main() {
let x = ~{mut a: ~10, b: ~20};
match x {
- ~{ref a, ref b} => { assert **a == 10; (*x).a = ~30; assert **a == 30; }
+ ~{a: ref a, b: ref b} => {
+ assert **a == 10; (*x).a = ~30; assert **a == 30;
+ }
}
}
match getopts(args, opts) {
result::Ok(ref m) =>
assert !opt_present(m, "b"),
- result::Err(f) => fail fail_str(f)
+ result::Err(ref f) => fail fail_str(*f)
};
-}
\ No newline at end of file
+}
fn main() {
let z = ~22;
- a_val(z, z);
+ a_val(copy z, copy z);
}
fn main() {
let mut kitty = cat();
- nyan(kitty, {kitty: kitty});
+ nyan(copy kitty, {kitty: copy kitty});
}
{
match table.find(&key)
{
- option::Some(std::json::String(s)) =>
+ option::Some(std::json::String(copy s)) =>
{
- s
+ copy s
}
option::Some(value) =>
{
{
match &data
{
- &std::json::Object(interface) =>
+ &std::json::Object(copy interface) =>
{
- let name = lookup(interface, ~"ifDescr", ~"");
+ let name = lookup(copy interface, ~"ifDescr", ~"");
let label = fmt!("%s-%s", managed_ip, name);
(label, bool_value(false))
fn test_stack_assign() {
let s: ~str = ~"a";
- log(debug, s);
+ log(debug, copy s);
let t: ~str = ~"a";
assert (s == t);
let u: ~str = ~"b";
let mut s = ~"a";
s += ~"b";
- log(debug, s);
+ log(debug, copy s);
assert (s == ~"ab");
let mut s = ~"c";
// Check that no false positives are found in loops.
let mut q = ~40, p = 10;
loop {
- let i = q;
+ let i = copy q;
p += *i;
if p > 100 { break; }
}
fn foo() -> fn@() -> int {
let k = ~22;
- let _u = {a: k};
+ let _u = {a: copy k};
return fn@(move k) -> int { 22 };
}
fn main() {
fn invoke(f: fn@()) { f(); }
let k = ~22;
- let _u = {a: k};
+ let _u = {a: copy k};
invoke(|| log(error, k) )
}
// We switched stacks, go back and try to hit the dynamic linker
frame_backoff
} else {
- let frame_backoff = runtest2(f, frame_backoff, curr_stk);
+ let frame_backoff = runtest2(copy f, frame_backoff, curr_stk);
if frame_backoff > 1u32 {
frame_backoff - 1u32
} else if frame_backoff == 1u32 {
enum myvec<X> = ~[X];
-fn myvec_deref<X: Copy>(mv: myvec<X>) -> ~[X] { return *mv; }
+fn myvec_deref<X: Copy>(mv: myvec<X>) -> ~[X] { return copy *mv; }
fn myvec_elt<X: Copy>(mv: myvec<X>) -> X { return mv[0]; }
}
impl Point : ops::Add<Point,Point> {
- pure fn add(other: &Point) -> Point {
+ pure fn add(&self, other: &Point) -> Point {
Point {x: self.x + (*other).x, y: self.y + (*other).y}
}
}
// Issue #50.
fn main() {
let x = {foo: ~"hello", bar: ~"world"};
- log(debug, x.foo);
- log(debug, x.bar);
+ log(debug, copy x.foo);
+ log(debug, copy x.bar);
}
fn bail_deep(x: ~[~[bool]]) {
let mut seen = false;
- for iter(x) |x| {
- for iter(x) |x| {
+ for iter(copy x) |x| {
+ for iter(copy x) |x| {
assert !seen;
if x { seen = true; return; }
}
fn test05_start(&&f: fn~(&&v: float, &&v: ~str) -> pair<float, ~str>) {
let p = f(22.22f, ~"Hi");
- log(debug, p);
+ log(debug, copy p);
assert p.a == 22.22f;
assert p.b == ~"Hi";
let q = f(44.44f, ~"Ho");
- log(debug, q);
+ log(debug, copy q);
assert q.a == 44.44f;
assert q.b == ~"Ho";
}
let p_: path_ = { global: true, idents: ~[~"hi"], types: ~[t] };
let p: path = { data: p_, span: sp };
let x = { sp: sp, path: p };
- log(error, x.path);
- log(error, x);
+ log(error, copy x.path);
+ log(error, copy x);
}
{
match io::file_writer(&path, [io::Create, io::Truncate]) {
- Err(e) => fail e,
+ Err(copy e) => fail e,
Ok(f) => {
for uint::range(0, 1000) |_i| {
f.write_u8(0);
fn test1() {
let mut s: ~str = ~"hello";
s += ~"world";
- log(debug, s);
+ log(debug, copy s);
assert (s[9] == 'd' as u8);
}
let ff: ~str = ~"abc";
let a: ~str = ff + ~"ABC" + ff;
let b: ~str = ~"ABC" + ff + ~"ABC";
- log(debug, a);
- log(debug, b);
+ log(debug, copy a);
+ log(debug, copy b);
assert (a == ~"abcABCabc");
assert (b == ~"ABCabcABC");
}
let a: ~str = ~"hello";
let b: ~str = ~"world";
let s: ~str = a + b;
- log(debug, s);
+ log(debug, copy s);
assert (s[9] == 'd' as u8);
}
extern mod std;
fn test(actual: ~str, expected: ~str) {
- log(debug, actual);
- log(debug, expected);
+ log(debug, copy actual);
+ log(debug, copy expected);
assert (actual == expected);
}
assert ~"99" == fmt!("%.0f", 98.5);
assert ~"7.0000" == fmt!("%.4f", 6.999999999);
assert ~"3.141590000" == fmt!("%.9f", 3.14159);
-}
\ No newline at end of file
+}
struct MyInt { val: int }
impl MyInt : Add<MyInt, 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 MyInt : Sub<MyInt, MyInt> {
let i = ~mut 1;
// Should be a copy
let mut j;
- j = i;
+ j = copy i;
*i = 2;
*j = 3;
assert *i == 2;
assert *j == 3;
-}
\ No newline at end of file
+}
let i = ~@1;
let j = ~@2;
let rc1 = refcount(*i);
- let j = i;
+ let j = copy i;
let rc2 = refcount(*i);
error!("rc1: %u rc2: %u", rc1, rc2);
assert rc1 + 1u == rc2;
-}
\ No newline at end of file
+}
fn main() {
let a = ~[~mut 10];
- let b = a;
+ let b = copy a;
assert *a[0] == 10;
assert *b[0] == 10;
assert *a[0] == 20;
assert *b[0] == 10;
-}
\ No newline at end of file
+}
fn main() {
let a = ~[1, 2, 3, 4, 5];
- let mut b = ~[a, a];
+ let mut b = ~[copy a, copy a];
b = b + b; // FIXME(#3387)---can't write b += b
}