test: Fix rustdoc and tests.
This commit is contained in:
parent
a170183ba3
commit
90d3da9711
|
@ -1469,34 +1469,6 @@ cannot be stored in data structures or returned from
|
||||||
functions. Despite these limitations, stack closures are used
|
functions. Despite these limitations, stack closures are used
|
||||||
pervasively in Rust code.
|
pervasively in Rust code.
|
||||||
|
|
||||||
## Managed closures
|
|
||||||
|
|
||||||
When you need to store a closure in a data structure, a stack closure
|
|
||||||
will not do, since the compiler will refuse to let you store it. For
|
|
||||||
this purpose, Rust provides a type of closure that has an arbitrary
|
|
||||||
lifetime, written `@fn` (boxed closure, analogous to the `@` pointer
|
|
||||||
type described earlier). This type of closure *is* first-class.
|
|
||||||
|
|
||||||
A managed closure does not directly access its environment, but merely
|
|
||||||
copies out the values that it closes over into a private data
|
|
||||||
structure. This means that it can not assign to these variables, and
|
|
||||||
cannot observe updates to them.
|
|
||||||
|
|
||||||
This code creates a closure that adds a given string to its argument,
|
|
||||||
returns it from a function, and then calls it:
|
|
||||||
|
|
||||||
~~~~
|
|
||||||
fn mk_appender(suffix: ~str) -> @fn(~str) -> ~str {
|
|
||||||
// The compiler knows that we intend this closure to be of type @fn
|
|
||||||
return |s| s + suffix;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let shout = mk_appender(~"!");
|
|
||||||
println(shout(~"hey ho, let's go"));
|
|
||||||
}
|
|
||||||
~~~~
|
|
||||||
|
|
||||||
## Owned closures
|
## Owned closures
|
||||||
|
|
||||||
Owned closures, written `~fn` in analogy to the `~` pointer type,
|
Owned closures, written `~fn` in analogy to the `~` pointer type,
|
||||||
|
|
|
@ -162,8 +162,11 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Runnable for LibcFree {
|
impl Runnable for LibcFree {
|
||||||
|
#[fixed_stack_segment]
|
||||||
fn run(~self) {
|
fn run(~self) {
|
||||||
libc::free(self.mem)
|
unsafe {
|
||||||
|
libc::free(self.mem)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1065,8 +1065,12 @@ mod test {
|
||||||
Err(f) => fail!("test_switch_implies_cfg_test: %s", f.to_err_msg())
|
Err(f) => fail!("test_switch_implies_cfg_test: %s", f.to_err_msg())
|
||||||
};
|
};
|
||||||
let sessopts = build_session_options(
|
let sessopts = build_session_options(
|
||||||
@"rustc", matches, diagnostic::emit);
|
@"rustc",
|
||||||
let sess = build_session(sessopts, diagnostic::emit);
|
matches,
|
||||||
|
@diagnostic::DefaultEmitter as @diagnostic::Emitter);
|
||||||
|
let sess = build_session(sessopts,
|
||||||
|
@diagnostic::DefaultEmitter as
|
||||||
|
@diagnostic::Emitter);
|
||||||
let cfg = build_configuration(sess);
|
let cfg = build_configuration(sess);
|
||||||
assert!((attr::contains_name(cfg, "test")));
|
assert!((attr::contains_name(cfg, "test")));
|
||||||
}
|
}
|
||||||
|
@ -1083,8 +1087,12 @@ mod test {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let sessopts = build_session_options(
|
let sessopts = build_session_options(
|
||||||
@"rustc", matches, diagnostic::emit);
|
@"rustc",
|
||||||
let sess = build_session(sessopts, diagnostic::emit);
|
matches,
|
||||||
|
@diagnostic::DefaultEmitter as @diagnostic::Emitter);
|
||||||
|
let sess = build_session(sessopts,
|
||||||
|
@diagnostic::DefaultEmitter as
|
||||||
|
@diagnostic::Emitter);
|
||||||
let cfg = build_configuration(sess);
|
let cfg = build_configuration(sess);
|
||||||
let mut test_items = cfg.iter().filter(|m| "test" == m.name());
|
let mut test_items = cfg.iter().filter(|m| "test" == m.name());
|
||||||
assert!(test_items.next().is_some());
|
assert!(test_items.next().is_some());
|
||||||
|
|
|
@ -118,14 +118,3 @@ fn test_owned() {
|
||||||
spawn_with_finalizer(owned);
|
spawn_with_finalizer(owned);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_managed() {
|
|
||||||
let i = @mut 10;
|
|
||||||
let managed: @fn() -> int = || {
|
|
||||||
let r = *i;
|
|
||||||
*i += 10;
|
|
||||||
r
|
|
||||||
};
|
|
||||||
assert_eq!(do managed.finally {}, 10);
|
|
||||||
assert_eq!(*i, 20);
|
|
||||||
}
|
|
||||||
|
|
|
@ -217,7 +217,8 @@ pub fn syntax_expander_table() -> SyntaxEnv {
|
||||||
}));
|
}));
|
||||||
syntax_expanders.insert(intern(&"macro_rules"),
|
syntax_expanders.insert(intern(&"macro_rules"),
|
||||||
@SE(IdentTT(@SyntaxExpanderTTItem {
|
@SE(IdentTT(@SyntaxExpanderTTItem {
|
||||||
expander: SyntaxExpanderTTItemExpanderWithContext(ext::tt::macro_rules::add_new_extension),
|
expander: SyntaxExpanderTTItemExpanderWithContext(
|
||||||
|
ext::tt::macro_rules::add_new_extension),
|
||||||
span: None,
|
span: None,
|
||||||
} as @SyntaxExpanderTTItemTrait,
|
} as @SyntaxExpanderTTItemTrait,
|
||||||
None)));
|
None)));
|
||||||
|
|
|
@ -772,7 +772,7 @@ impl ast_fold for IdentRenamer {
|
||||||
|
|
||||||
// given a mutable list of renames, return a tree-folder that applies those
|
// given a mutable list of renames, return a tree-folder that applies those
|
||||||
// renames.
|
// renames.
|
||||||
fn renames_to_fold(renames: @mut ~[(ast::Ident,ast::Name)]) -> @ast_fold {
|
pub fn renames_to_fold(renames: @mut ~[(ast::Ident,ast::Name)]) -> @ast_fold {
|
||||||
@IdentRenamer {
|
@IdentRenamer {
|
||||||
renames: renames,
|
renames: renames,
|
||||||
} as @ast_fold
|
} as @ast_fold
|
||||||
|
@ -1524,7 +1524,7 @@ mod test {
|
||||||
let ident_str = @"x";
|
let ident_str = @"x";
|
||||||
let tts = string_to_tts(ident_str);
|
let tts = string_to_tts(ident_str);
|
||||||
let fm = fresh_mark();
|
let fm = fresh_mark();
|
||||||
let marked_once = fold::fold_tts(tts,new_mark_folder(fm) as @fold::ast_fold);
|
let marked_once = fold::fold_tts(tts,new_mark_folder(fm));
|
||||||
assert_eq!(marked_once.len(),1);
|
assert_eq!(marked_once.len(),1);
|
||||||
let marked_once_ctxt =
|
let marked_once_ctxt =
|
||||||
match marked_once[0] {
|
match marked_once[0] {
|
||||||
|
|
|
@ -869,7 +869,7 @@ mod test {
|
||||||
use parse::token;
|
use parse::token;
|
||||||
use print::pprust;
|
use print::pprust;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
// this version doesn't care about getting comments or docstrings in.
|
// this version doesn't care about getting comments or docstrings in.
|
||||||
fn fake_print_crate(s: @pprust::ps, crate: &ast::Crate) {
|
fn fake_print_crate(s: @pprust::ps, crate: &ast::Crate) {
|
||||||
pprust::print_mod(s, &crate.module, crate.attrs);
|
pprust::print_mod(s, &crate.module, crate.attrs);
|
||||||
|
@ -879,7 +879,7 @@ mod test {
|
||||||
struct ToZzIdentFolder;
|
struct ToZzIdentFolder;
|
||||||
|
|
||||||
impl ast_fold for ToZzIdentFolder {
|
impl ast_fold for ToZzIdentFolder {
|
||||||
fn fold_ident(&self, _: ident) -> ident {
|
fn fold_ident(&self, _: ast::Ident) -> ast::Ident {
|
||||||
token::str_to_ident("zz")
|
token::str_to_ident("zz")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -921,16 +921,5 @@ mod test {
|
||||||
token::get_ident_interner()),
|
token::get_ident_interner()),
|
||||||
~"zz!zz((zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+)))");
|
~"zz!zz((zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+)))");
|
||||||
}
|
}
|
||||||
|
|
||||||
// and in cast expressions... this appears to be an existing bug.
|
|
||||||
#[test] fn ident_transformation_in_types () {
|
|
||||||
let zz_fold = ToZzIdentFolder;
|
|
||||||
let ast = string_to_crate(@"fn a() {let z = 13 as int;}");
|
|
||||||
assert_pred!(matches_codepattern,
|
|
||||||
"matches_codepattern",
|
|
||||||
pprust::to_str(&zz_fold.fold_crate(ast),fake_print_crate,
|
|
||||||
token::get_ident_interner()),
|
|
||||||
~"fn zz(){let zz=13 as zz;}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub struct Entry<A,B> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct alist<A,B> {
|
pub struct alist<A,B> {
|
||||||
eq_fn: @fn(A,A) -> bool,
|
eq_fn: extern "Rust" fn(A,A) -> bool,
|
||||||
data: @mut ~[Entry<A,B>]
|
data: @mut ~[Entry<A,B>]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +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.
|
|
||||||
|
|
||||||
pub fn to_closure<A:'static + Clone>(x: A) -> @fn() -> A {
|
|
||||||
let result: @fn() -> A = || x.clone();
|
|
||||||
result
|
|
||||||
}
|
|
|
@ -46,7 +46,6 @@ type nillist = List<()>;
|
||||||
struct State {
|
struct State {
|
||||||
box: @nillist,
|
box: @nillist,
|
||||||
unique: ~nillist,
|
unique: ~nillist,
|
||||||
fn_box: @fn() -> @nillist,
|
|
||||||
tuple: (@nillist, ~nillist),
|
tuple: (@nillist, ~nillist),
|
||||||
vec: ~[@nillist],
|
vec: ~[@nillist],
|
||||||
res: r
|
res: r
|
||||||
|
@ -79,19 +78,15 @@ fn recurse_or_fail(depth: int, st: Option<State>) {
|
||||||
State {
|
State {
|
||||||
box: @Nil,
|
box: @Nil,
|
||||||
unique: ~Nil,
|
unique: ~Nil,
|
||||||
fn_box: || @Nil::<()>,
|
|
||||||
tuple: (@Nil, ~Nil),
|
tuple: (@Nil, ~Nil),
|
||||||
vec: ~[@Nil],
|
vec: ~[@Nil],
|
||||||
res: r(@Nil)
|
res: r(@Nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(st) => {
|
Some(st) => {
|
||||||
let fn_box = st.fn_box;
|
|
||||||
|
|
||||||
State {
|
State {
|
||||||
box: @Cons((), st.box),
|
box: @Cons((), st.box),
|
||||||
unique: ~Cons((), @*st.unique),
|
unique: ~Cons((), @*st.unique),
|
||||||
fn_box: || @Cons((), fn_box()),
|
|
||||||
tuple: (@Cons((), st.tuple.first()),
|
tuple: (@Cons((), st.tuple.first()),
|
||||||
~Cons((), @*st.tuple.second())),
|
~Cons((), @*st.tuple.second())),
|
||||||
vec: st.vec + &[@Cons((), *st.vec.last())],
|
vec: st.vec + &[@Cons((), *st.vec.last())],
|
||||||
|
|
|
@ -1,27 +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.
|
|
||||||
|
|
||||||
fn foo(x: @int) -> @fn() -> &'static int {
|
|
||||||
let result: @fn() -> &'static int = || &*x; //~ ERROR cannot root
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bar(x: @int) -> @fn() -> &int {
|
|
||||||
let result: @fn() -> &int = || &*x; //~ ERROR cannot root
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
fn zed(x: @int) -> @fn() -> int {
|
|
||||||
let result: @fn() -> int = || *&*x;
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
}
|
|
|
@ -1,13 +1,13 @@
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let foo = ~3;
|
let foo = ~3;
|
||||||
let _pfoo = &foo;
|
let _pfoo = &foo;
|
||||||
let _f: @fn() -> int = || *foo + 5;
|
let _f: ~fn() -> int = || *foo + 5;
|
||||||
//~^ ERROR cannot move `foo`
|
//~^ ERROR cannot move `foo`
|
||||||
|
|
||||||
// FIXME(#2202) - Due to the way that borrowck treats closures,
|
// FIXME(#2202) - Due to the way that borrowck treats closures,
|
||||||
// you get two error reports here.
|
// you get two error reports here.
|
||||||
let bar = ~3;
|
let bar = ~3;
|
||||||
let _g = || { //~ ERROR capture of moved value
|
let _g = || { //~ ERROR capture of moved value
|
||||||
let _h: @fn() -> int = || *bar; //~ ERROR capture of moved value
|
let _h: ~fn() -> int = || *bar; //~ ERROR capture of moved value
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
struct X {
|
struct X {
|
||||||
field: @fn:Send(),
|
field: ~fn:Send(),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foo(blk: @fn:()) -> X {
|
fn foo(blk: ~fn:()) -> X {
|
||||||
return X { field: blk }; //~ ERROR expected bounds `Send` but found no bounds
|
return X { field: blk }; //~ ERROR expected bounds `Send` but found no bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn f(f: @fn(int) -> bool) -> bool { f(10i) }
|
fn f(f: &fn(int) -> bool) -> bool { f(10i) }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
assert!(do f() |i| { i == 10i } == 10i);
|
assert!(do f() |i| { i == 10i } == 10i);
|
||||||
|
|
|
@ -1,30 +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.
|
|
||||||
|
|
||||||
fn reproduce<T>(t: T) -> @fn() -> T {
|
|
||||||
let result: @fn() -> T = || t;
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
// type of x is the variable X,
|
|
||||||
// with the lower bound @mut int
|
|
||||||
let x = @mut 3;
|
|
||||||
|
|
||||||
// type of r is @fn() -> X
|
|
||||||
let r = reproduce(x);
|
|
||||||
|
|
||||||
// Requires that X be a subtype of
|
|
||||||
// @mut int.
|
|
||||||
let f: @mut int = r();
|
|
||||||
|
|
||||||
// Bad.
|
|
||||||
let h: @int = r(); //~ ERROR (values differ in mutability)
|
|
||||||
}
|
|
|
@ -1,32 +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.
|
|
||||||
|
|
||||||
fn mk_identity<T>() -> @fn(T) -> T {
|
|
||||||
let result: @fn(t: T) -> T = |t| t;
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
// type of r is @fn(X) -> X
|
|
||||||
// for some fresh X
|
|
||||||
let r = mk_identity();
|
|
||||||
|
|
||||||
// @mut int <: X
|
|
||||||
r(@mut 3);
|
|
||||||
|
|
||||||
// @int <: X
|
|
||||||
//
|
|
||||||
// Here the type check fails because @const is gone and there is no
|
|
||||||
// supertype.
|
|
||||||
r(@3); //~ ERROR mismatched types
|
|
||||||
|
|
||||||
// Here the type check succeeds.
|
|
||||||
*r(@mut 3) = 4;
|
|
||||||
}
|
|
|
@ -9,8 +9,8 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// xfail-test
|
// xfail-test
|
||||||
struct T { f: @fn() };
|
struct T { f: extern "Rust" fn() };
|
||||||
struct S { f: @fn() };
|
struct S { f: extern "Rust" fn() };
|
||||||
|
|
||||||
fn fooS(t: S) {
|
fn fooS(t: S) {
|
||||||
}
|
}
|
||||||
|
@ -22,11 +22,11 @@ fn bar() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x: @fn() = bar;
|
let x: extern "Rust" fn() = bar;
|
||||||
fooS(S {f: x});
|
fooS(S {f: x});
|
||||||
fooS(S {f: bar});
|
fooS(S {f: bar});
|
||||||
|
|
||||||
let x: @fn() = bar;
|
let x: extern "Rust" fn() = bar;
|
||||||
fooT(T {f: x});
|
fooT(T {f: x});
|
||||||
fooT(T {f: bar});
|
fooT(T {f: bar});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <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 that we require managed closures to be rooted when borrowed.
|
|
||||||
|
|
||||||
struct boxedFn<'self> { theFn: &'self fn() -> uint }
|
|
||||||
|
|
||||||
fn createClosure (closedUint: uint) -> boxedFn {
|
|
||||||
let theFn: @fn() -> uint = || closedUint;
|
|
||||||
boxedFn {theFn: theFn} //~ ERROR cannot root
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main () {
|
|
||||||
let aFn: boxedFn = createClosure(10);
|
|
||||||
|
|
||||||
let myInt: uint = (aFn.theFn)();
|
|
||||||
|
|
||||||
assert_eq!(myInt, 10);
|
|
||||||
}
|
|
|
@ -10,11 +10,11 @@
|
||||||
|
|
||||||
// xfail-test
|
// xfail-test
|
||||||
fn main() {
|
fn main() {
|
||||||
let one: @fn() -> uint = || {
|
let one: &fn() -> uint = || {
|
||||||
enum r { a };
|
enum r { a };
|
||||||
a as uint
|
a as uint
|
||||||
};
|
};
|
||||||
let two = @fn() -> uint = || {
|
let two = &fn() -> uint = || {
|
||||||
enum r { a };
|
enum r { a };
|
||||||
a as uint
|
a as uint
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// xfail-test
|
||||||
|
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||||
// file at the top-level directory of this distribution and at
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
|
|
@ -1,28 +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.
|
|
||||||
|
|
||||||
fn copy1<T:Clone>(t: T) -> @fn() -> T {
|
|
||||||
let result: @fn() -> T = || t.clone(); //~ ERROR does not fulfill `'static`
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
fn copy2<T:Clone + 'static>(t: T) -> @fn() -> T {
|
|
||||||
let result: @fn() -> T = || t.clone();
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let x = &3;
|
|
||||||
copy2(&x); //~ ERROR does not fulfill `'static`
|
|
||||||
|
|
||||||
copy2(@3);
|
|
||||||
copy2(@&x); //~ ERROR value may contain borrowed pointers
|
|
||||||
//~^ ERROR does not fulfill `'static`
|
|
||||||
}
|
|
|
@ -1,25 +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.
|
|
||||||
|
|
||||||
// Make sure that nesting a block within a @fn doesn't let us
|
|
||||||
// mutate upvars from a @fn.
|
|
||||||
fn f2(x: &fn()) { x(); }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let i = 0;
|
|
||||||
let ctr: @fn() -> int = || { f2(|| i = i + 1 ); i };
|
|
||||||
//~^ ERROR cannot assign
|
|
||||||
error!(ctr());
|
|
||||||
error!(ctr());
|
|
||||||
error!(ctr());
|
|
||||||
error!(ctr());
|
|
||||||
error!(ctr());
|
|
||||||
error!(i);
|
|
||||||
}
|
|
|
@ -1,22 +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.
|
|
||||||
|
|
||||||
// Make sure we can't write to upvars from @fns
|
|
||||||
fn main() {
|
|
||||||
let i = 0;
|
|
||||||
let ctr: @fn() -> int = || { i = i + 1; i };
|
|
||||||
//~^ ERROR cannot assign
|
|
||||||
error!(ctr());
|
|
||||||
error!(ctr());
|
|
||||||
error!(ctr());
|
|
||||||
error!(ctr());
|
|
||||||
error!(ctr());
|
|
||||||
error!(i);
|
|
||||||
}
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let j: @fn() -> int = || {
|
let j: &fn() -> int = || {
|
||||||
let i: int;
|
let i: int;
|
||||||
i //~ ERROR use of possibly uninitialized variable: `i`
|
i //~ ERROR use of possibly uninitialized variable: `i`
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let f: @fn() -> int = || {
|
let f: &fn() -> int = || {
|
||||||
let i: int;
|
let i: int;
|
||||||
i //~ ERROR use of possibly uninitialized variable: `i`
|
i //~ ERROR use of possibly uninitialized variable: `i`
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn of<T>() -> @fn(T) { fail!(); }
|
fn of<T>() -> &fn(T) { fail!(); }
|
||||||
fn subtype<T>(x: @fn(T)) { fail!(); }
|
fn subtype<T>(x: &fn(T)) { fail!(); }
|
||||||
|
|
||||||
fn test_fn<'x,'y,'z,T>(_x: &'x T, _y: &'y T, _z: &'z T) {
|
fn test_fn<'x,'y,'z,T>(_x: &'x T, _y: &'y T, _z: &'z T) {
|
||||||
// Here, x, y, and z are free. Other letters
|
// Here, x, y, and z are free. Other letters
|
||||||
|
@ -40,18 +40,6 @@ fn test_fn<'x,'y,'z,T>(_x: &'x T, _y: &'y T, _z: &'z T) {
|
||||||
|
|
||||||
subtype::<&fn<'x,'y>(&'x T, &'y T)>(
|
subtype::<&fn<'x,'y>(&'x T, &'y T)>(
|
||||||
of::<&fn<'a,'b>(&'a T, &'b T)>()); //~ ERROR mismatched types
|
of::<&fn<'a,'b>(&'a T, &'b T)>()); //~ ERROR mismatched types
|
||||||
|
|
||||||
subtype::<&fn<'x,'a>(&'x T) -> @fn(&'a T)>(
|
|
||||||
of::<&fn<'x,'a>(&'x T) -> @fn(&'a T)>());
|
|
||||||
|
|
||||||
subtype::<&fn<'a>(&'a T) -> @fn(&'a T)>(
|
|
||||||
of::<&fn<'a,'b>(&'a T) -> @fn(&'b T)>()); //~ ERROR mismatched types
|
|
||||||
|
|
||||||
subtype::<&fn<'a>(&'a T) -> @fn(&'a T)>(
|
|
||||||
of::<&fn<'x,'b>(&'x T) -> @fn(&'b T)>()); //~ ERROR mismatched types
|
|
||||||
|
|
||||||
subtype::<&fn<'a,'b>(&'a T) -> @fn(&'b T)>(
|
|
||||||
of::<&fn<'a>(&'a T) -> @fn(&'a T)>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// we reported errors in this case:
|
// we reported errors in this case:
|
||||||
|
|
||||||
fn not_ok<'b>(a: &uint, b: &'b uint) {
|
fn not_ok<'b>(a: &uint, b: &'b uint) {
|
||||||
let mut g: @fn(x: &uint) = |x: &'b uint| {};
|
let mut g: &fn(x: &uint) = |x: &'b uint| {};
|
||||||
//~^ ERROR mismatched types
|
//~^ ERROR mismatched types
|
||||||
g(a);
|
g(a);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,11 @@ struct parameterized1<'self> {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct not_parameterized1 {
|
struct not_parameterized1 {
|
||||||
g: @fn()
|
g: &'static fn()
|
||||||
}
|
}
|
||||||
|
|
||||||
struct not_parameterized2 {
|
struct not_parameterized2 {
|
||||||
g: @fn()
|
g: &'static fn()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn take1(p: parameterized1) -> parameterized1 { p }
|
fn take1(p: parameterized1) -> parameterized1 { p }
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
// the normal case.
|
// the normal case.
|
||||||
|
|
||||||
struct contravariant<'self> {
|
struct contravariant<'self> {
|
||||||
f: @fn() -> &'self int
|
f: &'static fn() -> &'self int
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_same_lifetime<'r>(bi: contravariant<'r>) {
|
fn to_same_lifetime<'r>(bi: contravariant<'r>) {
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// You can upcast to a *larger region* but not a smaller one.
|
// You can upcast to a *larger region* but not a smaller one.
|
||||||
|
|
||||||
struct covariant<'self> {
|
struct covariant<'self> {
|
||||||
f: @fn(x: &'self int) -> int
|
f: &'static fn(x: &'self int) -> int
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_same_lifetime<'r>(bi: covariant<'r>) {
|
fn to_same_lifetime<'r>(bi: covariant<'r>) {
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
struct invariant<'self> {
|
struct invariant<'self> {
|
||||||
f: @fn(x: @mut &'self int)
|
f: &'static fn(x: @mut &'self int)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_same_lifetime<'r>(bi: invariant<'r>) {
|
fn to_same_lifetime<'r>(bi: invariant<'r>) {
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
struct invariant<'self> {
|
struct invariant<'self> {
|
||||||
f: @fn() -> @mut &'self int
|
f: &'static fn() -> @mut &'self int
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_same_lifetime<'r>(bi: invariant<'r>) {
|
fn to_same_lifetime<'r>(bi: invariant<'r>) {
|
||||||
|
|
|
@ -14,12 +14,12 @@ struct direct<'self> {
|
||||||
|
|
||||||
struct indirect1 {
|
struct indirect1 {
|
||||||
// Here the lifetime parameter of direct is bound by the fn()
|
// Here the lifetime parameter of direct is bound by the fn()
|
||||||
g: @fn(direct)
|
g: &'static fn(direct)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct indirect2<'self> {
|
struct indirect2<'self> {
|
||||||
// But here it is set to 'self
|
// But here it is set to 'self
|
||||||
g: @fn(direct<'self>)
|
g: &'static fn(direct<'self>)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn take_direct(p: direct) -> direct { p } //~ ERROR mismatched types
|
fn take_direct(p: direct) -> direct { p } //~ ERROR mismatched types
|
||||||
|
|
|
@ -1,18 +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.
|
|
||||||
|
|
||||||
fn test(f: @fn(uint) -> uint) -> uint {
|
|
||||||
return f(22u);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let f: ~fn(x: uint) -> uint = |x| 4u;
|
|
||||||
info!(test(f)); //~ ERROR expected @ closure, found ~ closure
|
|
||||||
}
|
|
|
@ -1,77 +0,0 @@
|
||||||
// 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.
|
|
||||||
|
|
||||||
// compile-flags:-Z extra-debug-info
|
|
||||||
// debugger:rbreak zzz
|
|
||||||
// debugger:run
|
|
||||||
|
|
||||||
// debugger:finish
|
|
||||||
// debugger:print x
|
|
||||||
// check:$1 = false
|
|
||||||
// debugger:continue
|
|
||||||
|
|
||||||
// debugger:finish
|
|
||||||
// debugger:print x
|
|
||||||
// check:$2 = false
|
|
||||||
// debugger:continue
|
|
||||||
|
|
||||||
// debugger:finish
|
|
||||||
// debugger:print x
|
|
||||||
// check:$3 = 1000
|
|
||||||
// debugger:continue
|
|
||||||
|
|
||||||
// debugger:finish
|
|
||||||
// debugger:print x
|
|
||||||
// check:$4 = 2.5
|
|
||||||
// debugger:continue
|
|
||||||
|
|
||||||
// debugger:finish
|
|
||||||
// debugger:print x
|
|
||||||
// check:$5 = true
|
|
||||||
// debugger:continue
|
|
||||||
|
|
||||||
// debugger:finish
|
|
||||||
// debugger:print x
|
|
||||||
// check:$6 = false
|
|
||||||
// debugger:continue
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
|
|
||||||
let x = false;
|
|
||||||
|
|
||||||
zzz();
|
|
||||||
sentinel();
|
|
||||||
|
|
||||||
let managed_closure: @fn(int) = |x| {
|
|
||||||
zzz();
|
|
||||||
sentinel();
|
|
||||||
|
|
||||||
let x = 2.5;
|
|
||||||
|
|
||||||
zzz();
|
|
||||||
sentinel();
|
|
||||||
|
|
||||||
let x = true;
|
|
||||||
|
|
||||||
zzz();
|
|
||||||
sentinel();
|
|
||||||
};
|
|
||||||
|
|
||||||
zzz();
|
|
||||||
sentinel();
|
|
||||||
|
|
||||||
managed_closure(1000);
|
|
||||||
|
|
||||||
zzz();
|
|
||||||
sentinel();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn zzz() {()}
|
|
||||||
fn sentinel() {()}
|
|
|
@ -1,56 +0,0 @@
|
||||||
// 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.
|
|
||||||
|
|
||||||
// compile-flags:-Z extra-debug-info
|
|
||||||
// debugger:rbreak zzz
|
|
||||||
// debugger:run
|
|
||||||
// debugger:finish
|
|
||||||
|
|
||||||
// debugger:print constant
|
|
||||||
// check:$1 = 1
|
|
||||||
// debugger:print a_struct
|
|
||||||
// check:$2 = {a = -2, b = 3.5, c = 4}
|
|
||||||
// debugger:print *owned
|
|
||||||
// check:$3 = 5
|
|
||||||
// debugger:print managed->val
|
|
||||||
// check:$4 = 6
|
|
||||||
|
|
||||||
#[allow(unused_variable)];
|
|
||||||
|
|
||||||
struct Struct {
|
|
||||||
a: int,
|
|
||||||
b: float,
|
|
||||||
c: uint
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let constant = 1;
|
|
||||||
|
|
||||||
let a_struct = Struct {
|
|
||||||
a: -2,
|
|
||||||
b: 3.5,
|
|
||||||
c: 4
|
|
||||||
};
|
|
||||||
|
|
||||||
let owned = ~5;
|
|
||||||
let managed = @6;
|
|
||||||
|
|
||||||
let closure: @fn() = || {
|
|
||||||
zzz();
|
|
||||||
do_something(&constant, &a_struct.a, owned, managed);
|
|
||||||
};
|
|
||||||
|
|
||||||
closure();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn do_something(_: &int, _:&int, _:&int, _:&int) {
|
|
||||||
}
|
|
||||||
|
|
||||||
fn zzz() {()}
|
|
|
@ -1,12 +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.
|
|
||||||
|
|
||||||
fn blk1(_b: &fn()) -> @fn() { return || { }; }
|
|
||||||
fn test1() { (do blk1 { info!("hi"); })(); }
|
|
|
@ -10,6 +10,6 @@
|
||||||
|
|
||||||
// pp-exact
|
// pp-exact
|
||||||
|
|
||||||
fn f(f: @fn(int)) { f(10) }
|
fn f(f: &fn(int)) { f(10) }
|
||||||
|
|
||||||
fn main() { do f |i| { assert!(i == 10) } }
|
fn main() { do f |i| { assert!(i == 10) } }
|
||||||
|
|
|
@ -12,6 +12,5 @@
|
||||||
|
|
||||||
fn from_foreign_fn(_x: extern "Rust" fn()) { }
|
fn from_foreign_fn(_x: extern "Rust" fn()) { }
|
||||||
fn from_stack_closure(_x: &fn()) { }
|
fn from_stack_closure(_x: &fn()) { }
|
||||||
fn from_box_closure(_x: @fn()) { }
|
|
||||||
fn from_unique_closure(_x: ~fn()) { }
|
fn from_unique_closure(_x: ~fn()) { }
|
||||||
fn main() { }
|
fn main() { }
|
||||||
|
|
|
@ -1,24 +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.
|
|
||||||
|
|
||||||
// error-pattern:fail
|
|
||||||
|
|
||||||
fn failfn() {
|
|
||||||
fail!();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let y = ~0;
|
|
||||||
let x: @@fn() = @|| {
|
|
||||||
error!(y.clone());
|
|
||||||
};
|
|
||||||
failfn();
|
|
||||||
error!(x);
|
|
||||||
}
|
|
|
@ -1,21 +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.
|
|
||||||
|
|
||||||
// error-pattern:fail
|
|
||||||
|
|
||||||
fn f(_a: @int) {
|
|
||||||
fail!();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let b = @0;
|
|
||||||
let g: @fn() = || f(b);
|
|
||||||
g();
|
|
||||||
}
|
|
|
@ -14,7 +14,7 @@ fn main() {
|
||||||
let cheese = ~"roquefort";
|
let cheese = ~"roquefort";
|
||||||
let carrots = @~"crunchy";
|
let carrots = @~"crunchy";
|
||||||
|
|
||||||
let result: @fn(@~str, &fn(~str)) = (|tasties, macerate| {
|
let result: &'static fn(@~str, &fn(~str)) = (|tasties, macerate| {
|
||||||
macerate((*tasties).clone());
|
macerate((*tasties).clone());
|
||||||
});
|
});
|
||||||
result(carrots, |food| {
|
result(carrots, |food| {
|
||||||
|
|
|
@ -12,13 +12,30 @@ struct pair<A,B> {
|
||||||
a: A, b: B
|
a: A, b: B
|
||||||
}
|
}
|
||||||
|
|
||||||
fn f<A:Clone + 'static>(a: A, b: u16) -> @fn() -> (A, u16) {
|
trait Invokable<A> {
|
||||||
let result: @fn() -> (A, u16) = || (a.clone(), b);
|
fn f(&self) -> (A, u16);
|
||||||
result
|
}
|
||||||
|
|
||||||
|
struct Invoker<A> {
|
||||||
|
a: A,
|
||||||
|
b: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<A:Clone> Invokable<A> for Invoker<A> {
|
||||||
|
fn f(&self) -> (A, u16) {
|
||||||
|
(self.a.clone(), self.b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn f<A:Clone + 'static>(a: A, b: u16) -> @Invokable<A> {
|
||||||
|
@Invoker {
|
||||||
|
a: a,
|
||||||
|
b: b,
|
||||||
|
} as @Invokable<A>
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let (a, b) = f(22_u64, 44u16)();
|
let (a, b) = f(22_u64, 44u16).f();
|
||||||
info!("a=%? b=%?", a, b);
|
info!("a=%? b=%?", a, b);
|
||||||
assert_eq!(a, 22u64);
|
assert_eq!(a, 22u64);
|
||||||
assert_eq!(b, 44u16);
|
assert_eq!(b, 44u16);
|
||||||
|
|
|
@ -23,13 +23,30 @@ fn make_cycle<A:'static>(a: A) {
|
||||||
g.rec = Some(g);
|
g.rec = Some(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Invoker<A,B> {
|
||||||
|
a: A,
|
||||||
|
b: B,
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Invokable<A,B> {
|
||||||
|
fn f(&self) -> (A, B);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<A:Clone,B:Clone> Invokable<A,B> for Invoker<A,B> {
|
||||||
|
fn f(&self) -> (A, B) {
|
||||||
|
(self.a.clone(), self.b.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn f<A:Send + Clone + 'static,
|
fn f<A:Send + Clone + 'static,
|
||||||
B:Send + Clone + 'static>(
|
B:Send + Clone + 'static>(
|
||||||
a: A,
|
a: A,
|
||||||
b: B)
|
b: B)
|
||||||
-> @fn() -> (A, B) {
|
-> @Invokable<A,B> {
|
||||||
let result: @fn() -> (A, B) = || (a.clone(), b.clone());
|
@Invoker {
|
||||||
result
|
a: a,
|
||||||
|
b: b,
|
||||||
|
} as @Invokable<A,B>
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
@ -37,7 +54,7 @@ pub fn main() {
|
||||||
let y = 44_u64;
|
let y = 44_u64;
|
||||||
let z = f(~x, y);
|
let z = f(~x, y);
|
||||||
make_cycle(z);
|
make_cycle(z);
|
||||||
let (a, b) = z();
|
let (a, b) = z.f();
|
||||||
info!("a=%u b=%u", *a as uint, b as uint);
|
info!("a=%u b=%u", *a as uint, b as uint);
|
||||||
assert_eq!(*a, x);
|
assert_eq!(*a, x);
|
||||||
assert_eq!(b, y);
|
assert_eq!(b, y);
|
||||||
|
|
|
@ -14,10 +14,6 @@ fn asSendfn( f : ~fn()->uint ) -> uint {
|
||||||
return f();
|
return f();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn asLambda( f : @fn()->uint ) -> uint {
|
|
||||||
return f();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn asBlock( f : &fn()->uint ) -> uint {
|
fn asBlock( f : &fn()->uint ) -> uint {
|
||||||
return f();
|
return f();
|
||||||
}
|
}
|
||||||
|
@ -25,8 +21,6 @@ fn asBlock( f : &fn()->uint ) -> uint {
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x = asSendfn(|| 22u);
|
let x = asSendfn(|| 22u);
|
||||||
assert_eq!(x, 22u);
|
assert_eq!(x, 22u);
|
||||||
let x = asLambda(|| 22u);
|
|
||||||
assert_eq!(x, 22u);
|
|
||||||
let x = asBlock(|| 22u);
|
let x = asBlock(|| 22u);
|
||||||
assert_eq!(x, 22u);
|
assert_eq!(x, 22u);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +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.
|
|
||||||
|
|
||||||
fn to_lambda(f: @fn(uint) -> uint) -> @fn(uint) -> uint {
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
let x: @fn(uint) -> uint = to_lambda(|x| x * 2u );
|
|
||||||
let y = to_lambda(x);
|
|
||||||
|
|
||||||
let x_r = x(22u);
|
|
||||||
let y_r = y(x_r);
|
|
||||||
|
|
||||||
assert_eq!(x_r, 44u);
|
|
||||||
assert_eq!(y_r, 88u);
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let bar = ~3;
|
let bar = ~3;
|
||||||
let h: @fn() -> int = || *bar;
|
let h: ~fn() -> int = || *bar;
|
||||||
assert_eq!(h(), 3);
|
assert_eq!(h(), 3);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
fn foo() -> int { 22 }
|
fn foo() -> int { 22 }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let mut x: ~[@fn() -> int] = ~[];
|
let mut x: ~[extern "Rust" fn() -> int] = ~[];
|
||||||
x.push(foo);
|
x.push(foo);
|
||||||
assert_eq!((x[0])(), 22);
|
assert_eq!((x[0])(), 22);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,16 +11,6 @@
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x = ~1;
|
|
||||||
let y = ptr::to_unsafe_ptr(&(*x)) as uint;
|
|
||||||
let lam_move: @fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint;
|
|
||||||
assert_eq!(lam_move(), y);
|
|
||||||
|
|
||||||
let x = ~2;
|
|
||||||
let y = ptr::to_unsafe_ptr(&(*x)) as uint;
|
|
||||||
let lam_move: @fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint;
|
|
||||||
assert_eq!(lam_move(), y);
|
|
||||||
|
|
||||||
let x = ~3;
|
let x = ~3;
|
||||||
let y = ptr::to_unsafe_ptr(&(*x)) as uint;
|
let y = ptr::to_unsafe_ptr(&(*x)) as uint;
|
||||||
let snd_move: ~fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint;
|
let snd_move: ~fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint;
|
||||||
|
|
|
@ -16,13 +16,30 @@ struct Pair<A,B> {
|
||||||
a: A, b: B
|
a: A, b: B
|
||||||
}
|
}
|
||||||
|
|
||||||
fn f<A:Clone + 'static>(a: A, b: u16) -> @fn() -> (A, u16) {
|
struct Invoker<A> {
|
||||||
let result: @fn() -> (A, u16) = || (a.clone(), b);
|
a: A,
|
||||||
result
|
b: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Invokable<A> {
|
||||||
|
fn f(&self) -> (A, u16);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<A:Clone> Invokable<A> for Invoker<A> {
|
||||||
|
fn f(&self) -> (A, u16) {
|
||||||
|
(self.a.clone(), self.b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn f<A:Clone + 'static>(a: A, b: u16) -> @Invokable<A> {
|
||||||
|
@Invoker {
|
||||||
|
a: a,
|
||||||
|
b: b,
|
||||||
|
} as @Invokable<A>
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let (a, b) = f(22_u64, 44u16)();
|
let (a, b) = f(22_u64, 44u16).f();
|
||||||
info!("a=%? b=%?", a, b);
|
info!("a=%? b=%?", a, b);
|
||||||
assert_eq!(a, 22u64);
|
assert_eq!(a, 22u64);
|
||||||
assert_eq!(b, 44u16);
|
assert_eq!(b, 44u16);
|
||||||
|
|
|
@ -8,13 +8,33 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
struct foo { z: @fn() }
|
struct foo {
|
||||||
|
z: Option<@Invokable>,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Thing {
|
||||||
|
w: @mut foo,
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Invokable {
|
||||||
|
fn f(&self);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Invokable for Thing {
|
||||||
|
fn f(&self) {
|
||||||
|
nop_foo(self.w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn nop() { }
|
fn nop() { }
|
||||||
fn nop_foo(_x : @mut foo) { }
|
fn nop_foo(_x : @mut foo) { }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let w = @mut foo{ z: || nop() };
|
let w = @mut foo {
|
||||||
let x: @fn() = || nop_foo(w);
|
z: None,
|
||||||
w.z = x;
|
};
|
||||||
|
let x = @Thing {
|
||||||
|
w: w,
|
||||||
|
} as @Invokable;
|
||||||
|
w.z = Some(x);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <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 foo { z : @fn() }
|
|
||||||
|
|
||||||
fn nop() { }
|
|
||||||
fn nop_foo(_y: ~[int], _x : @mut foo) { }
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
let w = @mut foo{ z: || nop() };
|
|
||||||
let x : @fn() = || nop_foo(~[], w);
|
|
||||||
w.z = x;
|
|
||||||
}
|
|
|
@ -1,22 +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 foo { z: @fn() }
|
|
||||||
|
|
||||||
fn nop() { }
|
|
||||||
fn nop_foo(_y: @int, _x: @mut foo) { }
|
|
||||||
|
|
||||||
fn o() -> @int { @10 }
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
let w = @mut foo { z: || nop() };
|
|
||||||
let x : @fn() = || nop_foo(o(), w);
|
|
||||||
w.z = x;
|
|
||||||
}
|
|
|
@ -10,9 +10,9 @@
|
||||||
|
|
||||||
// Testing that we can drop the || in do exprs
|
// Testing that we can drop the || in do exprs
|
||||||
|
|
||||||
fn f(_f: @fn() -> bool) -> bool { true }
|
fn f(_f: &fn() -> bool) -> bool { true }
|
||||||
|
|
||||||
fn d(_f: @fn()) { }
|
fn d(_f: &fn()) { }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
do d { }
|
do d { }
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn f(f: @fn(int)) { f(10) }
|
fn f(f: &fn(int)) { f(10) }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
do f() |i| { assert!(i == 10) }
|
do f() |i| { assert!(i == 10) }
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn f(f: @fn(int) -> int) -> int { f(10) }
|
fn f(f: &fn(int) -> int) -> int { f(10) }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
assert_eq!(do f() |i| { i }, 10);
|
assert_eq!(do f() |i| { i }, 10);
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn f(f: @fn(int) -> int) -> int { f(10) }
|
fn f(f: &fn(int) -> int) -> int { f(10) }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
assert_eq!(do f |i| { i }, 10);
|
assert_eq!(do f |i| { i }, 10);
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
|
|
||||||
fn test_fn() {
|
fn test_fn() {
|
||||||
type t = @fn() -> int;
|
type t = &'static fn() -> int;
|
||||||
fn ten() -> int { return 10; }
|
fn ten() -> int { return 10; }
|
||||||
let rs: t = { ten };
|
let rs: t = { ten };
|
||||||
assert!((rs() == 10));
|
assert!((rs() == 10));
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
|
|
||||||
// -*- rust -*-
|
// -*- rust -*-
|
||||||
type compare<T> = @fn(@T, @T) -> bool;
|
type compare<T> = &'static fn(@T, @T) -> bool;
|
||||||
|
|
||||||
fn test_generic<T>(expected: @T, eq: compare<T>) {
|
fn test_generic<T>(expected: @T, eq: compare<T>) {
|
||||||
let actual: @T = { expected };
|
let actual: @T = { expected };
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
// xfail-fast
|
// xfail-fast
|
||||||
|
|
||||||
type compare<T> = @fn(T, T) -> bool;
|
type compare<'self, T> = &'self fn(T, T) -> bool;
|
||||||
|
|
||||||
fn test_generic<T:Clone>(expected: T, eq: compare<T>) {
|
fn test_generic<T:Clone>(expected: T, eq: compare<T>) {
|
||||||
let actual: T = { expected.clone() };
|
let actual: T = { expected.clone() };
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
|
|
||||||
// -*- rust -*-
|
// -*- rust -*-
|
||||||
type compare<T> = @fn(~T, ~T) -> bool;
|
type compare<'self, T> = &'self fn(~T, ~T) -> bool;
|
||||||
|
|
||||||
fn test_generic<T:Clone>(expected: ~T, eq: compare<T>) {
|
fn test_generic<T:Clone>(expected: ~T, eq: compare<T>) {
|
||||||
let actual: ~T = { expected.clone() };
|
let actual: ~T = { expected.clone() };
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
// xfail-fast
|
// xfail-fast
|
||||||
// -*- rust -*-
|
// -*- rust -*-
|
||||||
|
|
||||||
type compare<T> = @fn(T, T) -> bool;
|
type compare<'self, T> = &'self fn(T, T) -> bool;
|
||||||
|
|
||||||
fn test_generic<T:Clone>(expected: T, eq: compare<T>) {
|
fn test_generic<T:Clone>(expected: T, eq: compare<T>) {
|
||||||
let actual: T = { expected.clone() };
|
let actual: T = { expected.clone() };
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// xfail-fast
|
// xfail-fast
|
||||||
|
|
||||||
// Tests for standalone blocks as expressions with dynamic type sizes
|
// Tests for standalone blocks as expressions with dynamic type sizes
|
||||||
type compare<T> = @fn(T, T) -> bool;
|
type compare<'self, T> = &'self fn(T, T) -> bool;
|
||||||
|
|
||||||
fn test_generic<T:Clone>(expected: T, eq: compare<T>) {
|
fn test_generic<T:Clone>(expected: T, eq: compare<T>) {
|
||||||
let actual: T = { expected.clone() };
|
let actual: T = { expected.clone() };
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
|
|
||||||
// -*- rust -*-
|
// -*- rust -*-
|
||||||
type compare<T> = @fn(@T, @T) -> bool;
|
type compare<T> = &'static fn(@T, @T) -> bool;
|
||||||
|
|
||||||
fn test_generic<T>(expected: @T, not_expected: @T, eq: compare<T>) {
|
fn test_generic<T>(expected: @T, not_expected: @T, eq: compare<T>) {
|
||||||
let actual: @T = if true { expected } else { not_expected };
|
let actual: @T = if true { expected } else { not_expected };
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
// xfail-fast
|
// xfail-fast
|
||||||
// -*- rust -*-
|
// -*- rust -*-
|
||||||
|
|
||||||
type compare<T> = @fn(T, T) -> bool;
|
type compare<T> = &'static fn(T, T) -> bool;
|
||||||
|
|
||||||
fn test_generic<T:Clone>(expected: T, not_expected: T, eq: compare<T>) {
|
fn test_generic<T:Clone>(expected: T, not_expected: T, eq: compare<T>) {
|
||||||
let actual: T = if true { expected.clone() } else { not_expected };
|
let actual: T = if true { expected.clone() } else { not_expected };
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// -*- rust -*-
|
// -*- rust -*-
|
||||||
|
|
||||||
// Tests for if as expressions with dynamic type sizes
|
// Tests for if as expressions with dynamic type sizes
|
||||||
type compare<T> = @fn(T, T) -> bool;
|
type compare<T> = &'static fn(T, T) -> bool;
|
||||||
|
|
||||||
fn test_generic<T:Clone>(expected: T, not_expected: T, eq: compare<T>) {
|
fn test_generic<T:Clone>(expected: T, not_expected: T, eq: compare<T>) {
|
||||||
let actual: T = if true { expected.clone() } else { not_expected };
|
let actual: T = if true { expected.clone() } else { not_expected };
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
|
|
||||||
// -*- rust -*-
|
// -*- rust -*-
|
||||||
type compare<T> = @fn(@T, @T) -> bool;
|
type compare<T> = &'static fn(@T, @T) -> bool;
|
||||||
|
|
||||||
fn test_generic<T>(expected: @T, eq: compare<T>) {
|
fn test_generic<T>(expected: @T, eq: compare<T>) {
|
||||||
let actual: @T = match true { true => { expected }, _ => fail!() };
|
let actual: @T = match true { true => { expected }, _ => fail!() };
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
// xfail-fast
|
// xfail-fast
|
||||||
// -*- rust -*-
|
// -*- rust -*-
|
||||||
|
|
||||||
type compare<T> = @fn(T, T) -> bool;
|
type compare<T> = &'static fn(T, T) -> bool;
|
||||||
|
|
||||||
fn test_generic<T:Clone>(expected: T, eq: compare<T>) {
|
fn test_generic<T:Clone>(expected: T, eq: compare<T>) {
|
||||||
let actual: T = match true { true => { expected.clone() }, _ => fail!("wat") };
|
let actual: T = match true { true => { expected.clone() }, _ => fail!("wat") };
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
|
|
||||||
// -*- rust -*-
|
// -*- rust -*-
|
||||||
type compare<T> = @fn(~T, ~T) -> bool;
|
type compare<T> = &'static fn(~T, ~T) -> bool;
|
||||||
|
|
||||||
fn test_generic<T:Clone>(expected: ~T, eq: compare<T>) {
|
fn test_generic<T:Clone>(expected: ~T, eq: compare<T>) {
|
||||||
let actual: ~T = match true {
|
let actual: ~T = match true {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
// xfail-fast
|
// xfail-fast
|
||||||
// -*- rust -*-
|
// -*- rust -*-
|
||||||
|
|
||||||
type compare<T> = @fn(T, T) -> bool;
|
type compare<'self, T> = &'self fn(T, T) -> bool;
|
||||||
|
|
||||||
fn test_generic<T:Clone>(expected: T, eq: compare<T>) {
|
fn test_generic<T:Clone>(expected: T, eq: compare<T>) {
|
||||||
let actual: T = match true {
|
let actual: T = match true {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
// xfail-fast
|
// xfail-fast
|
||||||
// -*- rust -*-
|
// -*- rust -*-
|
||||||
|
|
||||||
type compare<T> = @fn(T, T) -> bool;
|
type compare<T> = extern "Rust" fn(T, T) -> bool;
|
||||||
|
|
||||||
fn test_generic<T:Clone>(expected: T, eq: compare<T>) {
|
fn test_generic<T:Clone>(expected: T, eq: compare<T>) {
|
||||||
let actual: T = match true { true => { expected.clone() }, _ => fail!("wat") };
|
let actual: T = match true { true => { expected.clone() }, _ => fail!("wat") };
|
||||||
|
|
|
@ -1,30 +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.
|
|
||||||
|
|
||||||
// xfail-fast
|
|
||||||
|
|
||||||
fn fix_help<A, B>(f: extern fn(@fn(A) -> B, A) -> B, x: A) -> B {
|
|
||||||
return f( |a| fix_help(f, a), x);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fix<A, B>(f: extern fn(@fn(A) -> B, A) -> B) -> @fn(A) -> B {
|
|
||||||
return |a| fix_help(f, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fact_(f: @fn(v: int) -> int, n: int) -> int {
|
|
||||||
// fun fact 0 = 1
|
|
||||||
return if n == 0 { 1 } else { n * f(n - 1) };
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
let fact = fix(fact_);
|
|
||||||
assert_eq!(fact(5), 120);
|
|
||||||
assert_eq!(fact(2), 2);
|
|
||||||
}
|
|
|
@ -1,30 +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.
|
|
||||||
|
|
||||||
// xfail-fast
|
|
||||||
|
|
||||||
fn fix_help<A:'static,B:Send>(f: extern fn(@fn(A) -> B, A) -> B, x: A) -> B {
|
|
||||||
return f(|a| fix_help(f, a), x);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fix<A:'static,B:Send>(f: extern fn(@fn(A) -> B, A) -> B) -> @fn(A) -> B {
|
|
||||||
return |a| fix_help(f, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fact_(f: @fn(v: int) -> int, n: int) -> int {
|
|
||||||
// fun fact 0 = 1
|
|
||||||
return if n == 0 { 1 } else { n * f(n - 1) };
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
let fact = fix(fact_);
|
|
||||||
assert_eq!(fact(5), 120);
|
|
||||||
assert_eq!(fact(2), 2);
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <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.
|
|
||||||
|
|
||||||
fn add(n: int) -> @fn(int) -> int {
|
|
||||||
let result: @fn(int) -> int = |m| m + n;
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
assert_eq!(add(3)(4), 7);
|
|
||||||
let add3 : &fn(int)->int = add(3);
|
|
||||||
assert_eq!(add3(4), 7);
|
|
||||||
}
|
|
|
@ -1,28 +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.
|
|
||||||
|
|
||||||
fn add(n: int) -> @fn(int) -> int {
|
|
||||||
let result: @fn(int) -> int = |m| m + n;
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn main()
|
|
||||||
{
|
|
||||||
assert_eq!(add(3)(4), 7);
|
|
||||||
|
|
||||||
let add1 : @fn(int)->int = add(1);
|
|
||||||
assert_eq!(add1(6), 7);
|
|
||||||
|
|
||||||
let add2 : &(@fn(int)->int) = &add(2);
|
|
||||||
assert_eq!((*add2)(5), 7);
|
|
||||||
|
|
||||||
let add3 : &fn(int)->int = add(3);
|
|
||||||
assert_eq!(add3(4), 7);
|
|
||||||
}
|
|
|
@ -1,17 +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.
|
|
||||||
|
|
||||||
fn bare() {}
|
|
||||||
|
|
||||||
fn likes_shared(f: @fn()) { f() }
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
likes_shared(bare);
|
|
||||||
}
|
|
|
@ -8,8 +8,8 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
struct r {
|
struct r<'self> {
|
||||||
field: @fn()
|
field: &'self fn()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#[allow(unused_variable)];
|
#[allow(unused_variable)];
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
// We should be able to type infer inside of @fns.
|
// We should be able to type infer inside of &fns.
|
||||||
let _f = || {
|
let _f = || {
|
||||||
let i = 10;
|
let i = 10;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn ho(f: @fn(int) -> int) -> int { let n: int = f(3); return n; }
|
fn ho(f: &fn(int) -> int) -> int { let n: int = f(3); return n; }
|
||||||
|
|
||||||
fn direct(x: int) -> int { return x + 1; }
|
fn direct(x: int) -> int { return x + 1; }
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ mod map_reduce {
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::task;
|
use std::task;
|
||||||
|
|
||||||
pub type putter = @fn(~str, ~str);
|
pub type putter<'self> = &'self fn(~str, ~str);
|
||||||
|
|
||||||
pub type mapper = extern fn(~str, putter);
|
pub type mapper = extern fn(~str, putter);
|
||||||
|
|
||||||
|
|
|
@ -1,25 +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.
|
|
||||||
|
|
||||||
// Tests the passing down of expected types through boxing and
|
|
||||||
// wrapping in a record or tuple. (The a.x would complain about 'this
|
|
||||||
// type must be known in this context' if the passing down doesn't
|
|
||||||
// happen.)
|
|
||||||
|
|
||||||
fn eat_tup(_r: ~@(int, @fn(Pair) -> int)) {}
|
|
||||||
fn eat_rec(_r: ~Rec) {}
|
|
||||||
|
|
||||||
struct Rec<'self> { a: int, b: &'self fn(Pair) -> int }
|
|
||||||
struct Pair { x: int, y: int }
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
eat_tup(~@(10, |a| a.x ));
|
|
||||||
eat_rec(~Rec{a: 10, b: |a| a.x });
|
|
||||||
}
|
|
|
@ -9,5 +9,5 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let early_error: @fn(&str) -> ! = |_msg| { fail!() };
|
let early_error: &'static fn(&str) -> ! = |_msg| { fail!() };
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,11 @@
|
||||||
//
|
//
|
||||||
// Running /usr/local/bin/rustc:
|
// Running /usr/local/bin/rustc:
|
||||||
// issue-2185.rs:24:0: 26:1 error: conflicting implementations for a trait
|
// issue-2185.rs:24:0: 26:1 error: conflicting implementations for a trait
|
||||||
// issue-2185.rs:24 impl iterable<uint> for @fn(&fn(uint)) {
|
// issue-2185.rs:24 impl iterable<uint> for &'static fn(&fn(uint)) {
|
||||||
// issue-2185.rs:25 fn iter(&self, blk: &fn(v: uint)) { self( |i| blk(i) ) }
|
// issue-2185.rs:25 fn iter(&self, blk: &fn(v: uint)) { self( |i| blk(i) ) }
|
||||||
// issue-2185.rs:26 }
|
// issue-2185.rs:26 }
|
||||||
// issue-2185.rs:20:0: 22:1 note: note conflicting implementation here
|
// issue-2185.rs:20:0: 22:1 note: note conflicting implementation here
|
||||||
// issue-2185.rs:20 impl<A> iterable<A> for @fn(&fn(A)) {
|
// issue-2185.rs:20 impl<A> iterable<A> for &'static fn(&fn(A)) {
|
||||||
// issue-2185.rs:21 fn iter(&self, blk: &fn(A)) { self(blk); }
|
// issue-2185.rs:21 fn iter(&self, blk: &fn(A)) { self(blk); }
|
||||||
// issue-2185.rs:22 }
|
// issue-2185.rs:22 }
|
||||||
//
|
//
|
||||||
|
@ -42,15 +42,17 @@ trait iterable<A> {
|
||||||
fn iter(&self, blk: &fn(A));
|
fn iter(&self, blk: &fn(A));
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A> iterable<A> for @fn(&fn(A)) {
|
impl<A> iterable<A> for &'static fn(&fn(A)) {
|
||||||
fn iter(&self, blk: &fn(A)) { self(blk); }
|
fn iter(&self, blk: &fn(A)) { self(blk); }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl iterable<uint> for @fn(&fn(uint)) {
|
impl iterable<uint> for &'static fn(&fn(uint)) {
|
||||||
fn iter(&self, blk: &fn(v: uint)) { self( |i| blk(i) ) }
|
fn iter(&self, blk: &fn(v: uint)) { self( |i| blk(i) ) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filter<A,IA:iterable<A>>(self: IA, prd: @fn(A) -> bool, blk: &fn(A)) {
|
fn filter<A,IA:iterable<A>>(self: IA,
|
||||||
|
prd: &'static fn(A) -> bool,
|
||||||
|
blk: &fn(A)) {
|
||||||
do self.iter |a| {
|
do self.iter |a| {
|
||||||
if prd(a) { blk(a) }
|
if prd(a) { blk(a) }
|
||||||
}
|
}
|
||||||
|
@ -73,8 +75,8 @@ fn range(lo: uint, hi: uint, it: &fn(uint)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let range: @fn(&fn(uint)) = |a| range(0u, 1000u, a);
|
let range: &'static fn(&fn(uint)) = |a| range(0u, 1000u, a);
|
||||||
let filt: @fn(&fn(v: uint)) = |a| filter(
|
let filt: &'static fn(&fn(v: uint)) = |a| filter(
|
||||||
range,
|
range,
|
||||||
|&&n: uint| n % 3u != 0u && n % 5u != 0u,
|
|&&n: uint| n % 3u != 0u && n % 5u != 0u,
|
||||||
a);
|
a);
|
||||||
|
|
|
@ -9,12 +9,16 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
struct cat {
|
struct cat {
|
||||||
meow: @fn(),
|
meow: extern "Rust" fn(),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn meow() {
|
||||||
|
error!("meow")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cat() -> cat {
|
fn cat() -> cat {
|
||||||
cat {
|
cat {
|
||||||
meow: || error!("meow")
|
meow: meow,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
type Connection = @fn(~[u8]);
|
type Connection = &'static fn(~[u8]);
|
||||||
|
|
||||||
fn f() -> Option<Connection> {
|
fn f() -> Option<Connection> {
|
||||||
let mock_connection: Connection = |_| {};
|
let mock_connection: Connection = |_| {};
|
||||||
|
|
|
@ -10,6 +10,6 @@
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x = 1;
|
let x = 1;
|
||||||
let y: @fn() -> int = || x;
|
let y: &fn() -> int = || x;
|
||||||
let _z = y();
|
let _z = y();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
// 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.
|
|
||||||
|
|
||||||
fn make_adder(x: int) -> @fn(int) -> int { |y| x + y }
|
|
||||||
pub fn main() { }
|
|
|
@ -1,19 +0,0 @@
|
||||||
// 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.
|
|
||||||
|
|
||||||
// Issue #5783
|
|
||||||
// Nondeterministic behavior when referencing a closure more than once
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let a: &fn(int) -> @fn(int) -> int = |x:int| |y:int| -> int x + y;
|
|
||||||
let b = a(2);
|
|
||||||
assert!(a(2)(3) == 5);
|
|
||||||
assert!(b(6) == 8);
|
|
||||||
}
|
|
|
@ -1,25 +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.
|
|
||||||
|
|
||||||
// xfail-fast - check-fast doesn't understand aux-build
|
|
||||||
// aux-build:issue4516_ty_param_lib.rs
|
|
||||||
|
|
||||||
// Trigger a bug concerning inlining of generic functions.
|
|
||||||
// The def-ids in type parameters were not being correctly
|
|
||||||
// resolved and hence when we checked the type of the closure
|
|
||||||
// variable (see the library mod) to determine if the value
|
|
||||||
// should be moved into the closure, trans failed to find
|
|
||||||
// the relevant kind bounds.
|
|
||||||
|
|
||||||
extern mod issue4516_ty_param_lib;
|
|
||||||
use issue4516_ty_param_lib::to_closure;
|
|
||||||
pub fn main() {
|
|
||||||
to_closure(22)();
|
|
||||||
}
|
|
|
@ -9,13 +9,13 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// This should typecheck even though the type of e is not fully
|
// This should typecheck even though the type of e is not fully
|
||||||
// resolved when we finish typechecking the @fn.
|
// resolved when we finish typechecking the &fn.
|
||||||
|
|
||||||
|
|
||||||
struct Refs { refs: ~[int], n: int }
|
struct Refs { refs: ~[int], n: int }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let e = @mut Refs{refs: ~[], n: 0};
|
let e = @mut Refs{refs: ~[], n: 0};
|
||||||
let _f: @fn() = || error!(e.n);
|
let _f: &fn() = || error!(e.n);
|
||||||
e.refs.push(1);
|
e.refs.push(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +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.
|
|
||||||
|
|
||||||
// Make sure we don't leak @fns in silly ways.
|
|
||||||
fn force(f: @fn()) { f() }
|
|
||||||
pub fn main() {
|
|
||||||
let x = 7;
|
|
||||||
let _f: @fn() = || error!(x);
|
|
||||||
force(|| error!(x));
|
|
||||||
}
|
|
|
@ -12,10 +12,10 @@
|
||||||
|
|
||||||
struct A { a: ~int }
|
struct A { a: ~int }
|
||||||
|
|
||||||
fn foo() -> @fn() -> int {
|
fn foo() -> &'static fn() -> int {
|
||||||
let k = ~22;
|
let k = ~22;
|
||||||
let _u = A {a: k.clone()};
|
let _u = A {a: k.clone()};
|
||||||
let result: @fn() -> int = || 22;
|
let result: &'static fn() -> int = || 22;
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
struct A { a: ~int }
|
struct A { a: ~int }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
fn invoke(f: @fn()) { f(); }
|
fn invoke(f: &fn()) { f(); }
|
||||||
let k = ~22;
|
let k = ~22;
|
||||||
let _u = A {a: k.clone()};
|
let _u = A {a: k.clone()};
|
||||||
invoke(|| error!(k.clone()) )
|
invoke(|| error!(k.clone()) )
|
||||||
|
|
|
@ -1,30 +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 that invoking functions which require
|
|
||||||
// dictionaries from inside an @fn works
|
|
||||||
// (at one point, it didn't)
|
|
||||||
|
|
||||||
fn mk_nil<C:ty_ops>(cx: C) -> uint {
|
|
||||||
cx.mk()
|
|
||||||
}
|
|
||||||
|
|
||||||
trait ty_ops {
|
|
||||||
fn mk(&self) -> uint;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ty_ops for () {
|
|
||||||
fn mk(&self) -> uint { 22u }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
let fn_env: @fn() -> uint = || mk_nil(());
|
|
||||||
assert_eq!(fn_env(), 22u);
|
|
||||||
}
|
|
|
@ -9,9 +9,9 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// Issue #922
|
// Issue #922
|
||||||
fn f2(_thing: @fn()) { }
|
fn f2(_thing: &fn()) { }
|
||||||
|
|
||||||
fn f(thing: @fn()) {
|
fn f(thing: &fn()) {
|
||||||
f2(thing);
|
f2(thing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
// Test that the lambda kind is inferred correctly as a return
|
// Test that the lambda kind is inferred correctly as a return
|
||||||
// expression
|
// expression
|
||||||
|
|
||||||
fn shared() -> @fn() { return || (); }
|
|
||||||
|
|
||||||
fn unique() -> ~fn() { return || (); }
|
fn unique() -> ~fn() { return || (); }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
// Test that the lambda kind is inferred correctly as a return
|
// Test that the lambda kind is inferred correctly as a return
|
||||||
// expression
|
// expression
|
||||||
|
|
||||||
fn shared() -> @fn() { || () }
|
|
||||||
|
|
||||||
fn unique() -> ~fn() { || () }
|
fn unique() -> ~fn() { || () }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
|
|
@ -14,16 +14,9 @@ fn f(i: int, f: &fn(int) -> int) -> int { f(i) }
|
||||||
|
|
||||||
fn g(_g: &fn()) { }
|
fn g(_g: &fn()) { }
|
||||||
|
|
||||||
fn ff() -> @fn(int) -> int {
|
|
||||||
return |x| x + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
assert_eq!(f(10, |a| a), 10);
|
assert_eq!(f(10, |a| a), 10);
|
||||||
g(||());
|
g(||());
|
||||||
assert_eq!(do f(10) |a| { a }, 10);
|
assert_eq!(do f(10) |a| { a }, 10);
|
||||||
do g() { }
|
do g() { }
|
||||||
let _x: @fn() -> int = || 10;
|
|
||||||
let _y: @fn(int) -> int = |a| a;
|
|
||||||
assert_eq!(ff()(10), 11);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
// Test that expected type propagates through `{}` expressions. If it
|
|
||||||
// did not, then the type of `x` would not be known and a compilation
|
|
||||||
// error would result.
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
let y = ~3;
|
|
||||||
let foo: @fn(&int) -> int = {
|
|
||||||
let y = y.clone();
|
|
||||||
|x| *x + *y
|
|
||||||
};
|
|
||||||
assert_eq!(foo(@22), 25);
|
|
||||||
}
|
|
|
@ -460,9 +460,9 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_closure_ptr(&mut self, ck: uint) -> bool {
|
fn visit_closure_ptr(&mut self, ck: uint) -> bool {
|
||||||
self.align_to::<@fn()>();
|
self.align_to::<(uint,uint)>();
|
||||||
if ! self.inner.visit_closure_ptr(ck) { return false; }
|
if ! self.inner.visit_closure_ptr(ck) { return false; }
|
||||||
self.bump_past::<@fn()>();
|
self.bump_past::<(uint,uint)>();
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue