Add 'copy' bounds to functions that were faultily accepted without

Issue #1390
This commit is contained in:
Marijn Haverbeke 2012-01-02 15:31:58 +01:00
parent 8c14943dea
commit 15be2fc73a
9 changed files with 12 additions and 12 deletions

View File

@ -36,7 +36,7 @@ pure fn get<copy T>(opt: t<T>) -> T {
/*
*/
fn map<T, U>(opt: t<T>, f: block(T) -> U) -> t<U> {
fn map<T, copy U>(opt: t<T>, f: block(T) -> U) -> t<U> {
alt opt { some(x) { some(f(x)) } none. { none } }
}
@ -61,7 +61,7 @@ Function: from_maybe
Returns the contained value or a default
*/
pure fn from_maybe<T>(def: T, opt: t<T>) -> T {
pure fn from_maybe<copy T>(def: T, opt: t<T>) -> T {
alt opt { some(x) { x } none. { def } }
}
@ -70,7 +70,7 @@ Function: maybe
Applies a function to the contained value or returns a default
*/
fn maybe<T, U>(def: U, opt: t<T>, f: block(T) -> U) -> U {
fn maybe<T, copy U>(def: U, opt: t<T>, f: block(T) -> U) -> U {
alt opt { none. { def } some(t) { f(t) } }
}

View File

@ -37,7 +37,7 @@ Failure:
If the result is an error
*/
fn get<T, U>(res: t<T, U>) -> T {
fn get<copy T, U>(res: t<T, U>) -> T {
alt res {
ok(t) { t }
err(_) {
@ -57,7 +57,7 @@ Failure:
If the result is not an error
*/
fn get_err<T, U>(res: t<T, U>) -> U {
fn get_err<T, copy U>(res: t<T, U>) -> U {
alt res {
err(u) { u }
ok(_) {

View File

@ -57,7 +57,7 @@ fn create<copy T>() -> t<T> {
ret rv;
}
fn get<T>(elts: [mutable cell<T>], i: uint) -> T {
fn get<copy T>(elts: [mutable cell<T>], i: uint) -> T {
ret alt elts[i] { option::some(t) { t } _ { fail } };
}
obj deque<copy T>(mutable nelts: uint,

View File

@ -7,7 +7,7 @@ Function: id
The identity function
*/
pure fn id<T>(x: T) -> T { x }
pure fn id<copy T>(x: T) -> T { x }
/*
Function: unreachable

View File

@ -4,7 +4,7 @@
// -*- rust -*-
type compare<T> = fn@(T, T) -> bool;
fn test_generic<T>(expected: T, eq: compare<T>) {
fn test_generic<copy T>(expected: T, eq: compare<T>) {
let actual: T = alt true { true { expected } };
assert (eq(expected, actual));
}

View File

@ -3,7 +3,7 @@
// -*- rust -*-
type compare<T> = fn@(~T, ~T) -> bool;
fn test_generic<T>(expected: ~T, eq: compare<T>) {
fn test_generic<copy T>(expected: ~T, eq: compare<T>) {
let actual: ~T = alt true { true { expected } };
assert (eq(expected, actual));
}

View File

@ -4,7 +4,7 @@
// -*- rust -*-
type compare<T> = fn@(T, T) -> bool;
fn test_generic<T>(expected: T, eq: compare<T>) {
fn test_generic<copy T>(expected: T, eq: compare<T>) {
let actual: T = alt true { true { expected } };
assert (eq(expected, actual));
}

View File

@ -4,7 +4,7 @@
// -*- rust -*-
type compare<T> = fn@(T, T) -> bool;
fn test_generic<T>(expected: T, eq: compare<T>) {
fn test_generic<copy T>(expected: T, eq: compare<T>) {
let actual: T = alt true { true { expected } };
assert (eq(expected, actual));
}

View File

@ -9,7 +9,7 @@ fn test_vec() {
}
fn test_generic() {
fn f<T>(t: T) -> T { t }
fn f<copy T>(t: T) -> T { t }
assert (f(10) == 10);
}