From 90d3da971148a471c5766b544dc4ba50a15e5b96 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 16 Sep 2013 23:37:54 -0700 Subject: [PATCH] test: Fix rustdoc and tests. --- doc/tutorial.md | 28 ------- src/libextra/c_vec.rs | 5 +- src/librustc/driver/driver.rs | 16 +++- src/libstd/unstable/finally.rs | 11 --- src/libsyntax/ext/base.rs | 3 +- src/libsyntax/ext/expand.rs | 4 +- src/libsyntax/fold.rs | 15 +--- src/test/auxiliary/cci_nested_lib.rs | 2 +- src/test/auxiliary/issue4516_ty_param_lib.rs | 14 ---- src/test/bench/task-perf-alloc-unwind.rs | 5 -- .../compile-fail/borrowck-addr-of-upvar.rs | 27 ------- .../compile-fail/borrowck-move-by-capture.rs | 4 +- ...bounds-cant-promote-superkind-in-struct.rs | 4 +- src/test/compile-fail/do2.rs | 2 +- src/test/compile-fail/fn-variance-2.rs | 30 -------- src/test/compile-fail/fn-variance-3.rs | 32 -------- src/test/compile-fail/issue-1451.rs | 8 +- src/test/compile-fail/issue-1896-1.rs | 26 ------- src/test/compile-fail/issue-2074.rs | 4 +- src/test/compile-fail/issue-897.rs | 2 + src/test/compile-fail/kindck-owned.rs | 28 ------- src/test/compile-fail/lambda-mutate-nested.rs | 25 ------ src/test/compile-fail/lambda-mutate.rs | 22 ------ .../liveness-init-in-called-fn-expr.rs | 2 +- .../compile-fail/liveness-init-in-fn-expr.rs | 2 +- src/test/compile-fail/regions-fn-subtyping.rs | 16 +--- src/test/compile-fail/regions-fns.rs | 2 +- .../regions-infer-at-fn-not-param.rs | 4 +- ...regions-infer-contravariance-due-to-ret.rs | 2 +- .../regions-infer-covariance-due-to-arg.rs | 2 +- ...ns-infer-invariance-due-to-mutability-3.rs | 2 +- ...ns-infer-invariance-due-to-mutability-4.rs | 2 +- .../compile-fail/regions-infer-not-param.rs | 4 +- .../compile-fail/sendfn-is-not-a-lambda.rs | 18 ----- .../lexical-scope-in-managed-closure.rs | 77 ------------------- .../var-captured-in-managed-closure.rs | 56 -------------- src/test/pretty/block-arg-disambig.rs | 12 --- src/test/pretty/do1.rs | 2 +- src/test/pretty/fn-types.rs | 1 - src/test/run-fail/unwind-box-fn.rs | 24 ------ src/test/run-fail/unwind-closure.rs | 21 ----- src/test/run-fail/unwind-lambda.rs | 2 +- src/test/run-pass/alignment-gep-tup-like-1.rs | 25 +++++- src/test/run-pass/alignment-gep-tup-like-2.rs | 25 +++++- src/test/run-pass/block-arg-call-as.rs | 6 -- src/test/run-pass/block-arg-used-as-lambda.rs | 24 ------ .../run-pass/borrowck-move-by-capture-ok.rs | 2 +- .../call-closure-from-overloaded-op.rs | 2 +- src/test/run-pass/cap-clause-move.rs | 10 --- .../close-over-big-then-small-data.rs | 25 +++++- src/test/run-pass/cycle-collection2.rs | 28 ++++++- src/test/run-pass/cycle-collection4.rs | 20 ----- src/test/run-pass/cycle-collection5.rs | 22 ------ src/test/run-pass/do-no-args.rs | 4 +- src/test/run-pass/do1.rs | 2 +- src/test/run-pass/do2.rs | 2 +- src/test/run-pass/do3.rs | 2 +- src/test/run-pass/expr-block-fn.rs | 2 +- src/test/run-pass/expr-block-generic-box1.rs | 2 +- src/test/run-pass/expr-block-generic-box2.rs | 2 +- .../run-pass/expr-block-generic-unique1.rs | 2 +- .../run-pass/expr-block-generic-unique2.rs | 2 +- src/test/run-pass/expr-block-generic.rs | 2 +- src/test/run-pass/expr-if-generic-box1.rs | 2 +- src/test/run-pass/expr-if-generic-box2.rs | 2 +- src/test/run-pass/expr-if-generic.rs | 2 +- src/test/run-pass/expr-match-generic-box1.rs | 2 +- src/test/run-pass/expr-match-generic-box2.rs | 2 +- .../run-pass/expr-match-generic-unique1.rs | 2 +- .../run-pass/expr-match-generic-unique2.rs | 2 +- src/test/run-pass/expr-match-generic.rs | 2 +- src/test/run-pass/fixed-point-bind-box.rs | 30 -------- src/test/run-pass/fixed-point-bind-unique.rs | 30 -------- .../run-pass/fn-assign-managed-to-bare-1.rs | 20 ----- .../run-pass/fn-assign-managed-to-bare-2.rs | 28 ------- src/test/run-pass/fn-bare-coerce-to-shared.rs | 17 ---- src/test/run-pass/fn-coerce-field.rs | 4 +- src/test/run-pass/fn-type-infer.rs | 2 +- src/test/run-pass/fun-call-variants.rs | 2 +- src/test/run-pass/hashmap-memory.rs | 2 +- src/test/run-pass/infer-with-expected.rs | 25 ------ src/test/run-pass/issue-1516.rs | 2 +- src/test/run-pass/issue-2185.rs | 16 ++-- src/test/run-pass/issue-2633.rs | 8 +- src/test/run-pass/issue-3052.rs | 2 +- src/test/run-pass/issue-3429.rs | 2 +- src/test/run-pass/issue-4929.rs | 12 --- src/test/run-pass/issue-5783.rs | 19 ----- src/test/run-pass/issue4516_ty_param.rs | 25 ------ src/test/run-pass/lambda-infer-unresolved.rs | 4 +- src/test/run-pass/lambda-no-leak.rs | 17 ---- src/test/run-pass/last-use-in-cap-clause.rs | 4 +- src/test/run-pass/last-use-is-capture.rs | 2 +- .../run-pass/monomorphize-trait-in-fn-at.rs | 30 -------- src/test/run-pass/move-nullary-fn.rs | 4 +- src/test/run-pass/newlambdas-ret-infer.rs | 2 - src/test/run-pass/newlambdas-ret-infer2.rs | 2 - src/test/run-pass/newlambdas.rs | 7 -- .../propagate-expected-type-through-block.rs | 12 --- src/test/run-pass/reflect-visit-data.rs | 4 +- src/test/run-pass/regions-fn-subtyping.rs | 8 +- src/test/run-pass/unused-move-capture.rs | 2 +- 102 files changed, 196 insertions(+), 943 deletions(-) delete mode 100644 src/test/auxiliary/issue4516_ty_param_lib.rs delete mode 100644 src/test/compile-fail/borrowck-addr-of-upvar.rs delete mode 100644 src/test/compile-fail/fn-variance-2.rs delete mode 100644 src/test/compile-fail/fn-variance-3.rs delete mode 100644 src/test/compile-fail/issue-1896-1.rs delete mode 100644 src/test/compile-fail/kindck-owned.rs delete mode 100644 src/test/compile-fail/lambda-mutate-nested.rs delete mode 100644 src/test/compile-fail/lambda-mutate.rs delete mode 100644 src/test/compile-fail/sendfn-is-not-a-lambda.rs delete mode 100644 src/test/debug-info/lexical-scope-in-managed-closure.rs delete mode 100644 src/test/debug-info/var-captured-in-managed-closure.rs delete mode 100644 src/test/pretty/block-arg-disambig.rs delete mode 100644 src/test/run-fail/unwind-box-fn.rs delete mode 100644 src/test/run-fail/unwind-closure.rs delete mode 100644 src/test/run-pass/block-arg-used-as-lambda.rs delete mode 100644 src/test/run-pass/cycle-collection4.rs delete mode 100644 src/test/run-pass/cycle-collection5.rs delete mode 100644 src/test/run-pass/fixed-point-bind-box.rs delete mode 100644 src/test/run-pass/fixed-point-bind-unique.rs delete mode 100644 src/test/run-pass/fn-assign-managed-to-bare-1.rs delete mode 100644 src/test/run-pass/fn-assign-managed-to-bare-2.rs delete mode 100644 src/test/run-pass/fn-bare-coerce-to-shared.rs delete mode 100644 src/test/run-pass/infer-with-expected.rs delete mode 100644 src/test/run-pass/issue-4929.rs delete mode 100644 src/test/run-pass/issue-5783.rs delete mode 100644 src/test/run-pass/issue4516_ty_param.rs delete mode 100644 src/test/run-pass/lambda-no-leak.rs delete mode 100644 src/test/run-pass/monomorphize-trait-in-fn-at.rs delete mode 100644 src/test/run-pass/propagate-expected-type-through-block.rs diff --git a/doc/tutorial.md b/doc/tutorial.md index dd552f45f4e..a8d384226a3 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1469,34 +1469,6 @@ cannot be stored in data structures or returned from functions. Despite these limitations, stack closures are used 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, written `~fn` in analogy to the `~` pointer type, diff --git a/src/libextra/c_vec.rs b/src/libextra/c_vec.rs index 99bb67ad89c..bd3ce20742e 100644 --- a/src/libextra/c_vec.rs +++ b/src/libextra/c_vec.rs @@ -162,8 +162,11 @@ mod tests { } impl Runnable for LibcFree { + #[fixed_stack_segment] fn run(~self) { - libc::free(self.mem) + unsafe { + libc::free(self.mem) + } } } diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index ae1133e1880..c9a5ca2c61c 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -1065,8 +1065,12 @@ mod test { Err(f) => fail!("test_switch_implies_cfg_test: %s", f.to_err_msg()) }; let sessopts = build_session_options( - @"rustc", matches, diagnostic::emit); - let sess = build_session(sessopts, diagnostic::emit); + @"rustc", + matches, + @diagnostic::DefaultEmitter as @diagnostic::Emitter); + let sess = build_session(sessopts, + @diagnostic::DefaultEmitter as + @diagnostic::Emitter); let cfg = build_configuration(sess); assert!((attr::contains_name(cfg, "test"))); } @@ -1083,8 +1087,12 @@ mod test { } }; let sessopts = build_session_options( - @"rustc", matches, diagnostic::emit); - let sess = build_session(sessopts, diagnostic::emit); + @"rustc", + matches, + @diagnostic::DefaultEmitter as @diagnostic::Emitter); + let sess = build_session(sessopts, + @diagnostic::DefaultEmitter as + @diagnostic::Emitter); let cfg = build_configuration(sess); let mut test_items = cfg.iter().filter(|m| "test" == m.name()); assert!(test_items.next().is_some()); diff --git a/src/libstd/unstable/finally.rs b/src/libstd/unstable/finally.rs index d98c13083de..ba5986aa4ab 100644 --- a/src/libstd/unstable/finally.rs +++ b/src/libstd/unstable/finally.rs @@ -118,14 +118,3 @@ fn test_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); -} diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 63816072c29..48eb9a350f1 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -217,7 +217,8 @@ pub fn syntax_expander_table() -> SyntaxEnv { })); syntax_expanders.insert(intern(&"macro_rules"), @SE(IdentTT(@SyntaxExpanderTTItem { - expander: SyntaxExpanderTTItemExpanderWithContext(ext::tt::macro_rules::add_new_extension), + expander: SyntaxExpanderTTItemExpanderWithContext( + ext::tt::macro_rules::add_new_extension), span: None, } as @SyntaxExpanderTTItemTrait, None))); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 60aa7cc5f92..004a889fb4d 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -772,7 +772,7 @@ impl ast_fold for IdentRenamer { // given a mutable list of renames, return a tree-folder that applies those // 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 { renames: renames, } as @ast_fold @@ -1524,7 +1524,7 @@ mod test { let ident_str = @"x"; let tts = string_to_tts(ident_str); 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); let marked_once_ctxt = match marked_once[0] { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 66fe125aef4..a25f267c458 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -869,7 +869,7 @@ mod test { use parse::token; use print::pprust; use super::*; - + // this version doesn't care about getting comments or docstrings in. fn fake_print_crate(s: @pprust::ps, crate: &ast::Crate) { pprust::print_mod(s, &crate.module, crate.attrs); @@ -879,7 +879,7 @@ mod test { struct 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") } } @@ -921,16 +921,5 @@ mod test { token::get_ident_interner()), ~"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;}"); - } } diff --git a/src/test/auxiliary/cci_nested_lib.rs b/src/test/auxiliary/cci_nested_lib.rs index c9809438d94..350bd09826f 100644 --- a/src/test/auxiliary/cci_nested_lib.rs +++ b/src/test/auxiliary/cci_nested_lib.rs @@ -14,7 +14,7 @@ pub struct Entry { } pub struct alist { - eq_fn: @fn(A,A) -> bool, + eq_fn: extern "Rust" fn(A,A) -> bool, data: @mut ~[Entry] } diff --git a/src/test/auxiliary/issue4516_ty_param_lib.rs b/src/test/auxiliary/issue4516_ty_param_lib.rs deleted file mode 100644 index cd90c9b06c4..00000000000 --- a/src/test/auxiliary/issue4516_ty_param_lib.rs +++ /dev/null @@ -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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -pub fn to_closure(x: A) -> @fn() -> A { - let result: @fn() -> A = || x.clone(); - result -} diff --git a/src/test/bench/task-perf-alloc-unwind.rs b/src/test/bench/task-perf-alloc-unwind.rs index f383f7a101f..991c102e9f0 100644 --- a/src/test/bench/task-perf-alloc-unwind.rs +++ b/src/test/bench/task-perf-alloc-unwind.rs @@ -46,7 +46,6 @@ type nillist = List<()>; struct State { box: @nillist, unique: ~nillist, - fn_box: @fn() -> @nillist, tuple: (@nillist, ~nillist), vec: ~[@nillist], res: r @@ -79,19 +78,15 @@ fn recurse_or_fail(depth: int, st: Option) { State { box: @Nil, unique: ~Nil, - fn_box: || @Nil::<()>, tuple: (@Nil, ~Nil), vec: ~[@Nil], res: r(@Nil) } } Some(st) => { - let fn_box = st.fn_box; - State { box: @Cons((), st.box), unique: ~Cons((), @*st.unique), - fn_box: || @Cons((), fn_box()), tuple: (@Cons((), st.tuple.first()), ~Cons((), @*st.tuple.second())), vec: st.vec + &[@Cons((), *st.vec.last())], diff --git a/src/test/compile-fail/borrowck-addr-of-upvar.rs b/src/test/compile-fail/borrowck-addr-of-upvar.rs deleted file mode 100644 index 83baedc7892..00000000000 --- a/src/test/compile-fail/borrowck-addr-of-upvar.rs +++ /dev/null @@ -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 or the MIT license -// , 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() { -} diff --git a/src/test/compile-fail/borrowck-move-by-capture.rs b/src/test/compile-fail/borrowck-move-by-capture.rs index ecb18993d93..5994b9e85d5 100644 --- a/src/test/compile-fail/borrowck-move-by-capture.rs +++ b/src/test/compile-fail/borrowck-move-by-capture.rs @@ -1,13 +1,13 @@ pub fn main() { let foo = ~3; let _pfoo = &foo; - let _f: @fn() -> int = || *foo + 5; + let _f: ~fn() -> int = || *foo + 5; //~^ ERROR cannot move `foo` // FIXME(#2202) - Due to the way that borrowck treats closures, // you get two error reports here. let bar = ~3; 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 }; } diff --git a/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs b/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs index b38cb895488..525f8f4a932 100644 --- a/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs +++ b/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs @@ -9,10 +9,10 @@ // except according to those terms. 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 } diff --git a/src/test/compile-fail/do2.rs b/src/test/compile-fail/do2.rs index 4466c07518f..1bffdaa682c 100644 --- a/src/test/compile-fail/do2.rs +++ b/src/test/compile-fail/do2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // 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() { assert!(do f() |i| { i == 10i } == 10i); diff --git a/src/test/compile-fail/fn-variance-2.rs b/src/test/compile-fail/fn-variance-2.rs deleted file mode 100644 index ab559190034..00000000000 --- a/src/test/compile-fail/fn-variance-2.rs +++ /dev/null @@ -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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn reproduce(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) -} diff --git a/src/test/compile-fail/fn-variance-3.rs b/src/test/compile-fail/fn-variance-3.rs deleted file mode 100644 index e42c6b658e4..00000000000 --- a/src/test/compile-fail/fn-variance-3.rs +++ /dev/null @@ -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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn mk_identity() -> @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; -} diff --git a/src/test/compile-fail/issue-1451.rs b/src/test/compile-fail/issue-1451.rs index a295e8eb7ed..0d8acaa4464 100644 --- a/src/test/compile-fail/issue-1451.rs +++ b/src/test/compile-fail/issue-1451.rs @@ -9,8 +9,8 @@ // except according to those terms. // xfail-test -struct T { f: @fn() }; -struct S { f: @fn() }; +struct T { f: extern "Rust" fn() }; +struct S { f: extern "Rust" fn() }; fn fooS(t: S) { } @@ -22,11 +22,11 @@ fn bar() { } fn main() { - let x: @fn() = bar; + let x: extern "Rust" fn() = bar; fooS(S {f: x}); fooS(S {f: bar}); - let x: @fn() = bar; + let x: extern "Rust" fn() = bar; fooT(T {f: x}); fooT(T {f: bar}); } diff --git a/src/test/compile-fail/issue-1896-1.rs b/src/test/compile-fail/issue-1896-1.rs deleted file mode 100644 index 4750f68d59b..00000000000 --- a/src/test/compile-fail/issue-1896-1.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// 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); -} diff --git a/src/test/compile-fail/issue-2074.rs b/src/test/compile-fail/issue-2074.rs index 40c2772f234..7815fca16c6 100644 --- a/src/test/compile-fail/issue-2074.rs +++ b/src/test/compile-fail/issue-2074.rs @@ -10,11 +10,11 @@ // xfail-test fn main() { - let one: @fn() -> uint = || { + let one: &fn() -> uint = || { enum r { a }; a as uint }; - let two = @fn() -> uint = || { + let two = &fn() -> uint = || { enum r { a }; a as uint }; diff --git a/src/test/compile-fail/issue-897.rs b/src/test/compile-fail/issue-897.rs index 103156175a3..8df73aef610 100644 --- a/src/test/compile-fail/issue-897.rs +++ b/src/test/compile-fail/issue-897.rs @@ -1,3 +1,5 @@ +// xfail-test + // 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. diff --git a/src/test/compile-fail/kindck-owned.rs b/src/test/compile-fail/kindck-owned.rs deleted file mode 100644 index 2dfdb2629f7..00000000000 --- a/src/test/compile-fail/kindck-owned.rs +++ /dev/null @@ -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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn copy1(t: T) -> @fn() -> T { - let result: @fn() -> T = || t.clone(); //~ ERROR does not fulfill `'static` - result -} - -fn copy2(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` -} diff --git a/src/test/compile-fail/lambda-mutate-nested.rs b/src/test/compile-fail/lambda-mutate-nested.rs deleted file mode 100644 index bfd1e12f3a6..00000000000 --- a/src/test/compile-fail/lambda-mutate-nested.rs +++ /dev/null @@ -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 or the MIT license -// , 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); -} diff --git a/src/test/compile-fail/lambda-mutate.rs b/src/test/compile-fail/lambda-mutate.rs deleted file mode 100644 index a848d8698a3..00000000000 --- a/src/test/compile-fail/lambda-mutate.rs +++ /dev/null @@ -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 or the MIT license -// , 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); -} diff --git a/src/test/compile-fail/liveness-init-in-called-fn-expr.rs b/src/test/compile-fail/liveness-init-in-called-fn-expr.rs index 1fddea80966..7054cb0d901 100644 --- a/src/test/compile-fail/liveness-init-in-called-fn-expr.rs +++ b/src/test/compile-fail/liveness-init-in-called-fn-expr.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let j: @fn() -> int = || { + let j: &fn() -> int = || { let i: int; i //~ ERROR use of possibly uninitialized variable: `i` }; 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 b7a715d2958..b6c7895235b 100644 --- a/src/test/compile-fail/liveness-init-in-fn-expr.rs +++ b/src/test/compile-fail/liveness-init-in-fn-expr.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let f: @fn() -> int = || { + let f: &fn() -> int = || { let i: int; i //~ ERROR use of possibly uninitialized variable: `i` }; diff --git a/src/test/compile-fail/regions-fn-subtyping.rs b/src/test/compile-fail/regions-fn-subtyping.rs index face9c74214..5928d31a668 100644 --- a/src/test/compile-fail/regions-fn-subtyping.rs +++ b/src/test/compile-fail/regions-fn-subtyping.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn of() -> @fn(T) { fail!(); } -fn subtype(x: @fn(T)) { fail!(); } +fn of() -> &fn(T) { fail!(); } +fn subtype(x: &fn(T)) { fail!(); } 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 @@ -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)>( 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() {} diff --git a/src/test/compile-fail/regions-fns.rs b/src/test/compile-fail/regions-fns.rs index 4f6cbdfdd65..715261d816a 100644 --- a/src/test/compile-fail/regions-fns.rs +++ b/src/test/compile-fail/regions-fns.rs @@ -12,7 +12,7 @@ // we reported errors in this case: 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 g(a); } diff --git a/src/test/compile-fail/regions-infer-at-fn-not-param.rs b/src/test/compile-fail/regions-infer-at-fn-not-param.rs index 488d1f3940d..3ddae976ce3 100644 --- a/src/test/compile-fail/regions-infer-at-fn-not-param.rs +++ b/src/test/compile-fail/regions-infer-at-fn-not-param.rs @@ -13,11 +13,11 @@ struct parameterized1<'self> { } struct not_parameterized1 { - g: @fn() + g: &'static fn() } struct not_parameterized2 { - g: @fn() + g: &'static fn() } fn take1(p: parameterized1) -> parameterized1 { p } 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 15f40a91735..3fcc5184b4a 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<'self> { - f: @fn() -> &'self int + f: &'static fn() -> &'self int } fn to_same_lifetime<'r>(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 c33ca2dab2e..4b26e6b6021 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<'self> { - f: @fn(x: &'self int) -> int + f: &'static fn(x: &'self int) -> int } fn to_same_lifetime<'r>(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 92447c1ef8d..6e322b170e8 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<'self> { - f: @fn(x: @mut &'self int) + f: &'static fn(x: @mut &'self int) } fn to_same_lifetime<'r>(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 61adba3aec1..380e9b27ff9 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<'self> { - f: @fn() -> @mut &'self int + f: &'static fn() -> @mut &'self int } fn to_same_lifetime<'r>(bi: invariant<'r>) { diff --git a/src/test/compile-fail/regions-infer-not-param.rs b/src/test/compile-fail/regions-infer-not-param.rs index fa853b82d9e..47c1f7a5757 100644 --- a/src/test/compile-fail/regions-infer-not-param.rs +++ b/src/test/compile-fail/regions-infer-not-param.rs @@ -14,12 +14,12 @@ struct direct<'self> { struct indirect1 { // Here the lifetime parameter of direct is bound by the fn() - g: @fn(direct) + g: &'static fn(direct) } struct indirect2<'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 diff --git a/src/test/compile-fail/sendfn-is-not-a-lambda.rs b/src/test/compile-fail/sendfn-is-not-a-lambda.rs deleted file mode 100644 index 609439d7b8e..00000000000 --- a/src/test/compile-fail/sendfn-is-not-a-lambda.rs +++ /dev/null @@ -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 or the MIT license -// , 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 -} diff --git a/src/test/debug-info/lexical-scope-in-managed-closure.rs b/src/test/debug-info/lexical-scope-in-managed-closure.rs deleted file mode 100644 index 96da78a9192..00000000000 --- a/src/test/debug-info/lexical-scope-in-managed-closure.rs +++ /dev/null @@ -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 or the MIT license -// , 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() {()} diff --git a/src/test/debug-info/var-captured-in-managed-closure.rs b/src/test/debug-info/var-captured-in-managed-closure.rs deleted file mode 100644 index b20f40378d3..00000000000 --- a/src/test/debug-info/var-captured-in-managed-closure.rs +++ /dev/null @@ -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 or the MIT license -// , 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() {()} diff --git a/src/test/pretty/block-arg-disambig.rs b/src/test/pretty/block-arg-disambig.rs deleted file mode 100644 index c0f173a1a0d..00000000000 --- a/src/test/pretty/block-arg-disambig.rs +++ /dev/null @@ -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 or the MIT license -// , 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"); })(); } diff --git a/src/test/pretty/do1.rs b/src/test/pretty/do1.rs index 6f9aa28f11a..751aedb39a3 100644 --- a/src/test/pretty/do1.rs +++ b/src/test/pretty/do1.rs @@ -10,6 +10,6 @@ // pp-exact -fn f(f: @fn(int)) { f(10) } +fn f(f: &fn(int)) { f(10) } fn main() { do f |i| { assert!(i == 10) } } diff --git a/src/test/pretty/fn-types.rs b/src/test/pretty/fn-types.rs index 0545e9ed166..b000c9f9137 100644 --- a/src/test/pretty/fn-types.rs +++ b/src/test/pretty/fn-types.rs @@ -12,6 +12,5 @@ fn from_foreign_fn(_x: extern "Rust" fn()) { } fn from_stack_closure(_x: &fn()) { } -fn from_box_closure(_x: @fn()) { } fn from_unique_closure(_x: ~fn()) { } fn main() { } diff --git a/src/test/run-fail/unwind-box-fn.rs b/src/test/run-fail/unwind-box-fn.rs deleted file mode 100644 index a94f904c492..00000000000 --- a/src/test/run-fail/unwind-box-fn.rs +++ /dev/null @@ -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 or the MIT license -// , 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); -} diff --git a/src/test/run-fail/unwind-closure.rs b/src/test/run-fail/unwind-closure.rs deleted file mode 100644 index 5ea71c94e14..00000000000 --- a/src/test/run-fail/unwind-closure.rs +++ /dev/null @@ -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 or the MIT license -// , 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(); -} diff --git a/src/test/run-fail/unwind-lambda.rs b/src/test/run-fail/unwind-lambda.rs index 74d6ab00802..65d9fce5ff5 100644 --- a/src/test/run-fail/unwind-lambda.rs +++ b/src/test/run-fail/unwind-lambda.rs @@ -14,7 +14,7 @@ fn main() { let cheese = ~"roquefort"; let carrots = @~"crunchy"; - let result: @fn(@~str, &fn(~str)) = (|tasties, macerate| { + let result: &'static fn(@~str, &fn(~str)) = (|tasties, macerate| { macerate((*tasties).clone()); }); result(carrots, |food| { diff --git a/src/test/run-pass/alignment-gep-tup-like-1.rs b/src/test/run-pass/alignment-gep-tup-like-1.rs index a821e4647c1..4352c139b62 100644 --- a/src/test/run-pass/alignment-gep-tup-like-1.rs +++ b/src/test/run-pass/alignment-gep-tup-like-1.rs @@ -12,13 +12,30 @@ struct pair { a: A, b: B } -fn f(a: A, b: u16) -> @fn() -> (A, u16) { - let result: @fn() -> (A, u16) = || (a.clone(), b); - result +trait Invokable { + fn f(&self) -> (A, u16); +} + +struct Invoker { + a: A, + b: u16, +} + +impl Invokable for Invoker { + fn f(&self) -> (A, u16) { + (self.a.clone(), self.b) + } +} + +fn f(a: A, b: u16) -> @Invokable { + @Invoker { + a: a, + b: b, + } as @Invokable } pub fn main() { - let (a, b) = f(22_u64, 44u16)(); + let (a, b) = f(22_u64, 44u16).f(); info!("a=%? b=%?", a, b); assert_eq!(a, 22u64); assert_eq!(b, 44u16); diff --git a/src/test/run-pass/alignment-gep-tup-like-2.rs b/src/test/run-pass/alignment-gep-tup-like-2.rs index e924c31bad6..9bf95968a9a 100644 --- a/src/test/run-pass/alignment-gep-tup-like-2.rs +++ b/src/test/run-pass/alignment-gep-tup-like-2.rs @@ -23,13 +23,30 @@ fn make_cycle(a: A) { g.rec = Some(g); } +struct Invoker { + a: A, + b: B, +} + +trait Invokable { + fn f(&self) -> (A, B); +} + +impl Invokable for Invoker { + fn f(&self) -> (A, B) { + (self.a.clone(), self.b.clone()) + } +} + fn f( a: A, b: B) - -> @fn() -> (A, B) { - let result: @fn() -> (A, B) = || (a.clone(), b.clone()); - result + -> @Invokable { + @Invoker { + a: a, + b: b, + } as @Invokable } pub fn main() { @@ -37,7 +54,7 @@ pub fn main() { let y = 44_u64; let z = f(~x, y); make_cycle(z); - let (a, b) = z(); + let (a, b) = z.f(); info!("a=%u b=%u", *a as uint, b as uint); assert_eq!(*a, x); assert_eq!(b, y); diff --git a/src/test/run-pass/block-arg-call-as.rs b/src/test/run-pass/block-arg-call-as.rs index d68b0be632e..6a59278982a 100644 --- a/src/test/run-pass/block-arg-call-as.rs +++ b/src/test/run-pass/block-arg-call-as.rs @@ -14,10 +14,6 @@ fn asSendfn( f : ~fn()->uint ) -> uint { return f(); } -fn asLambda( f : @fn()->uint ) -> uint { - return f(); -} - fn asBlock( f : &fn()->uint ) -> uint { return f(); } @@ -25,8 +21,6 @@ fn asBlock( f : &fn()->uint ) -> uint { pub fn main() { let x = asSendfn(|| 22u); assert_eq!(x, 22u); - let x = asLambda(|| 22u); - assert_eq!(x, 22u); let x = asBlock(|| 22u); assert_eq!(x, 22u); } diff --git a/src/test/run-pass/block-arg-used-as-lambda.rs b/src/test/run-pass/block-arg-used-as-lambda.rs deleted file mode 100644 index 34fa7e36d97..00000000000 --- a/src/test/run-pass/block-arg-used-as-lambda.rs +++ /dev/null @@ -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 or the MIT license -// , 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); -} diff --git a/src/test/run-pass/borrowck-move-by-capture-ok.rs b/src/test/run-pass/borrowck-move-by-capture-ok.rs index 095e2ba6fea..f6328c8c658 100644 --- a/src/test/run-pass/borrowck-move-by-capture-ok.rs +++ b/src/test/run-pass/borrowck-move-by-capture-ok.rs @@ -1,5 +1,5 @@ pub fn main() { let bar = ~3; - let h: @fn() -> int = || *bar; + let h: ~fn() -> int = || *bar; assert_eq!(h(), 3); } diff --git a/src/test/run-pass/call-closure-from-overloaded-op.rs b/src/test/run-pass/call-closure-from-overloaded-op.rs index cc8d8e96195..16728dffd19 100644 --- a/src/test/run-pass/call-closure-from-overloaded-op.rs +++ b/src/test/run-pass/call-closure-from-overloaded-op.rs @@ -11,7 +11,7 @@ fn foo() -> int { 22 } pub fn main() { - let mut x: ~[@fn() -> int] = ~[]; + let mut x: ~[extern "Rust" fn() -> int] = ~[]; x.push(foo); assert_eq!((x[0])(), 22); } diff --git a/src/test/run-pass/cap-clause-move.rs b/src/test/run-pass/cap-clause-move.rs index aadd6a72494..64be8dab6e7 100644 --- a/src/test/run-pass/cap-clause-move.rs +++ b/src/test/run-pass/cap-clause-move.rs @@ -11,16 +11,6 @@ use std::ptr; 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 y = ptr::to_unsafe_ptr(&(*x)) as uint; let snd_move: ~fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint; diff --git a/src/test/run-pass/close-over-big-then-small-data.rs b/src/test/run-pass/close-over-big-then-small-data.rs index 01c6442fa00..8b7967ac150 100644 --- a/src/test/run-pass/close-over-big-then-small-data.rs +++ b/src/test/run-pass/close-over-big-then-small-data.rs @@ -16,13 +16,30 @@ struct Pair { a: A, b: B } -fn f(a: A, b: u16) -> @fn() -> (A, u16) { - let result: @fn() -> (A, u16) = || (a.clone(), b); - result +struct Invoker { + a: A, + b: u16, +} + +trait Invokable { + fn f(&self) -> (A, u16); +} + +impl Invokable for Invoker { + fn f(&self) -> (A, u16) { + (self.a.clone(), self.b) + } +} + +fn f(a: A, b: u16) -> @Invokable { + @Invoker { + a: a, + b: b, + } as @Invokable } pub fn main() { - let (a, b) = f(22_u64, 44u16)(); + let (a, b) = f(22_u64, 44u16).f(); info!("a=%? b=%?", a, b); assert_eq!(a, 22u64); assert_eq!(b, 44u16); diff --git a/src/test/run-pass/cycle-collection2.rs b/src/test/run-pass/cycle-collection2.rs index cd148417f4c..46c0c52e0c7 100644 --- a/src/test/run-pass/cycle-collection2.rs +++ b/src/test/run-pass/cycle-collection2.rs @@ -8,13 +8,33 @@ // option. This file may not be copied, modified, or distributed // 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_foo(_x : @mut foo) { } pub fn main() { - let w = @mut foo{ z: || nop() }; - let x: @fn() = || nop_foo(w); - w.z = x; + let w = @mut foo { + z: None, + }; + let x = @Thing { + w: w, + } as @Invokable; + w.z = Some(x); } diff --git a/src/test/run-pass/cycle-collection4.rs b/src/test/run-pass/cycle-collection4.rs deleted file mode 100644 index 8b613093944..00000000000 --- a/src/test/run-pass/cycle-collection4.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -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; -} diff --git a/src/test/run-pass/cycle-collection5.rs b/src/test/run-pass/cycle-collection5.rs deleted file mode 100644 index f724a86555c..00000000000 --- a/src/test/run-pass/cycle-collection5.rs +++ /dev/null @@ -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 or the MIT license -// , 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; -} diff --git a/src/test/run-pass/do-no-args.rs b/src/test/run-pass/do-no-args.rs index 6aef1f5f9e5..1f725ffb357 100644 --- a/src/test/run-pass/do-no-args.rs +++ b/src/test/run-pass/do-no-args.rs @@ -10,9 +10,9 @@ // 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() { do d { } diff --git a/src/test/run-pass/do1.rs b/src/test/run-pass/do1.rs index 735621a19fe..0444b269cb3 100644 --- a/src/test/run-pass/do1.rs +++ b/src/test/run-pass/do1.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(f: @fn(int)) { f(10) } +fn f(f: &fn(int)) { f(10) } pub fn main() { do f() |i| { assert!(i == 10) } diff --git a/src/test/run-pass/do2.rs b/src/test/run-pass/do2.rs index 684a2c108eb..9feededc980 100644 --- a/src/test/run-pass/do2.rs +++ b/src/test/run-pass/do2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // 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() { assert_eq!(do f() |i| { i }, 10); diff --git a/src/test/run-pass/do3.rs b/src/test/run-pass/do3.rs index b0d49fd2bdd..eeb983b4557 100644 --- a/src/test/run-pass/do3.rs +++ b/src/test/run-pass/do3.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // 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() { assert_eq!(do f |i| { i }, 10); diff --git a/src/test/run-pass/expr-block-fn.rs b/src/test/run-pass/expr-block-fn.rs index dbb1ac1f649..63e5c7688d3 100644 --- a/src/test/run-pass/expr-block-fn.rs +++ b/src/test/run-pass/expr-block-fn.rs @@ -11,7 +11,7 @@ fn test_fn() { - type t = @fn() -> int; + type t = &'static fn() -> int; fn ten() -> int { return 10; } let rs: t = { ten }; assert!((rs() == 10)); diff --git a/src/test/run-pass/expr-block-generic-box1.rs b/src/test/run-pass/expr-block-generic-box1.rs index 2c902181810..12b387b7eae 100644 --- a/src/test/run-pass/expr-block-generic-box1.rs +++ b/src/test/run-pass/expr-block-generic-box1.rs @@ -12,7 +12,7 @@ // -*- rust -*- -type compare = @fn(@T, @T) -> bool; +type compare = &'static fn(@T, @T) -> bool; fn test_generic(expected: @T, eq: compare) { let actual: @T = { expected }; diff --git a/src/test/run-pass/expr-block-generic-box2.rs b/src/test/run-pass/expr-block-generic-box2.rs index 7d849bbff01..cfa59d68635 100644 --- a/src/test/run-pass/expr-block-generic-box2.rs +++ b/src/test/run-pass/expr-block-generic-box2.rs @@ -11,7 +11,7 @@ // xfail-fast -type compare = @fn(T, T) -> bool; +type compare<'self, T> = &'self fn(T, T) -> bool; fn test_generic(expected: T, eq: compare) { let actual: T = { expected.clone() }; diff --git a/src/test/run-pass/expr-block-generic-unique1.rs b/src/test/run-pass/expr-block-generic-unique1.rs index 0249820410c..3f9c101761f 100644 --- a/src/test/run-pass/expr-block-generic-unique1.rs +++ b/src/test/run-pass/expr-block-generic-unique1.rs @@ -11,7 +11,7 @@ // -*- rust -*- -type compare = @fn(~T, ~T) -> bool; +type compare<'self, T> = &'self fn(~T, ~T) -> bool; fn test_generic(expected: ~T, eq: compare) { let actual: ~T = { expected.clone() }; diff --git a/src/test/run-pass/expr-block-generic-unique2.rs b/src/test/run-pass/expr-block-generic-unique2.rs index 389a42ae7af..3484a4f7f5a 100644 --- a/src/test/run-pass/expr-block-generic-unique2.rs +++ b/src/test/run-pass/expr-block-generic-unique2.rs @@ -11,7 +11,7 @@ // xfail-fast // -*- rust -*- -type compare = @fn(T, T) -> bool; +type compare<'self, T> = &'self fn(T, T) -> bool; fn test_generic(expected: T, eq: compare) { let actual: T = { expected.clone() }; diff --git a/src/test/run-pass/expr-block-generic.rs b/src/test/run-pass/expr-block-generic.rs index 7091fceb771..2f379602c6b 100644 --- a/src/test/run-pass/expr-block-generic.rs +++ b/src/test/run-pass/expr-block-generic.rs @@ -13,7 +13,7 @@ // xfail-fast // Tests for standalone blocks as expressions with dynamic type sizes -type compare = @fn(T, T) -> bool; +type compare<'self, T> = &'self fn(T, T) -> bool; fn test_generic(expected: T, eq: compare) { let actual: T = { expected.clone() }; diff --git a/src/test/run-pass/expr-if-generic-box1.rs b/src/test/run-pass/expr-if-generic-box1.rs index def991adea8..8bf6e658408 100644 --- a/src/test/run-pass/expr-if-generic-box1.rs +++ b/src/test/run-pass/expr-if-generic-box1.rs @@ -12,7 +12,7 @@ // -*- rust -*- -type compare = @fn(@T, @T) -> bool; +type compare = &'static fn(@T, @T) -> bool; fn test_generic(expected: @T, not_expected: @T, eq: compare) { let actual: @T = if true { expected } else { not_expected }; diff --git a/src/test/run-pass/expr-if-generic-box2.rs b/src/test/run-pass/expr-if-generic-box2.rs index a2d28a2be04..2c4707a87d5 100644 --- a/src/test/run-pass/expr-if-generic-box2.rs +++ b/src/test/run-pass/expr-if-generic-box2.rs @@ -11,7 +11,7 @@ // xfail-fast // -*- rust -*- -type compare = @fn(T, T) -> bool; +type compare = &'static fn(T, T) -> bool; fn test_generic(expected: T, not_expected: T, eq: compare) { let actual: T = if true { expected.clone() } else { not_expected }; diff --git a/src/test/run-pass/expr-if-generic.rs b/src/test/run-pass/expr-if-generic.rs index f5b2a1a7986..1bbf3a537db 100644 --- a/src/test/run-pass/expr-if-generic.rs +++ b/src/test/run-pass/expr-if-generic.rs @@ -12,7 +12,7 @@ // -*- rust -*- // Tests for if as expressions with dynamic type sizes -type compare = @fn(T, T) -> bool; +type compare = &'static fn(T, T) -> bool; fn test_generic(expected: T, not_expected: T, eq: compare) { let actual: T = if true { expected.clone() } else { not_expected }; diff --git a/src/test/run-pass/expr-match-generic-box1.rs b/src/test/run-pass/expr-match-generic-box1.rs index 4ea2d0fba9b..064e3343620 100644 --- a/src/test/run-pass/expr-match-generic-box1.rs +++ b/src/test/run-pass/expr-match-generic-box1.rs @@ -12,7 +12,7 @@ // -*- rust -*- -type compare = @fn(@T, @T) -> bool; +type compare = &'static fn(@T, @T) -> bool; fn test_generic(expected: @T, eq: compare) { let actual: @T = match true { true => { expected }, _ => fail!() }; diff --git a/src/test/run-pass/expr-match-generic-box2.rs b/src/test/run-pass/expr-match-generic-box2.rs index a2ccf5c0fb9..bca06ebdbb5 100644 --- a/src/test/run-pass/expr-match-generic-box2.rs +++ b/src/test/run-pass/expr-match-generic-box2.rs @@ -11,7 +11,7 @@ // xfail-fast // -*- rust -*- -type compare = @fn(T, T) -> bool; +type compare = &'static fn(T, T) -> bool; fn test_generic(expected: T, eq: compare) { let actual: T = match true { true => { expected.clone() }, _ => fail!("wat") }; diff --git a/src/test/run-pass/expr-match-generic-unique1.rs b/src/test/run-pass/expr-match-generic-unique1.rs index 0f564e6a780..7371f8fd89b 100644 --- a/src/test/run-pass/expr-match-generic-unique1.rs +++ b/src/test/run-pass/expr-match-generic-unique1.rs @@ -11,7 +11,7 @@ // -*- rust -*- -type compare = @fn(~T, ~T) -> bool; +type compare = &'static fn(~T, ~T) -> bool; fn test_generic(expected: ~T, eq: compare) { let actual: ~T = match true { diff --git a/src/test/run-pass/expr-match-generic-unique2.rs b/src/test/run-pass/expr-match-generic-unique2.rs index ae88d48bc44..d07d40e6757 100644 --- a/src/test/run-pass/expr-match-generic-unique2.rs +++ b/src/test/run-pass/expr-match-generic-unique2.rs @@ -11,7 +11,7 @@ // xfail-fast // -*- rust -*- -type compare = @fn(T, T) -> bool; +type compare<'self, T> = &'self fn(T, T) -> bool; fn test_generic(expected: T, eq: compare) { let actual: T = match true { diff --git a/src/test/run-pass/expr-match-generic.rs b/src/test/run-pass/expr-match-generic.rs index 59f1ff14f59..b43085d346f 100644 --- a/src/test/run-pass/expr-match-generic.rs +++ b/src/test/run-pass/expr-match-generic.rs @@ -11,7 +11,7 @@ // xfail-fast // -*- rust -*- -type compare = @fn(T, T) -> bool; +type compare = extern "Rust" fn(T, T) -> bool; fn test_generic(expected: T, eq: compare) { let actual: T = match true { true => { expected.clone() }, _ => fail!("wat") }; diff --git a/src/test/run-pass/fixed-point-bind-box.rs b/src/test/run-pass/fixed-point-bind-box.rs deleted file mode 100644 index 4c28151224c..00000000000 --- a/src/test/run-pass/fixed-point-bind-box.rs +++ /dev/null @@ -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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// xfail-fast - -fn fix_help(f: extern fn(@fn(A) -> B, A) -> B, x: A) -> B { - return f( |a| fix_help(f, a), x); -} - -fn fix(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); -} diff --git a/src/test/run-pass/fixed-point-bind-unique.rs b/src/test/run-pass/fixed-point-bind-unique.rs deleted file mode 100644 index c7b64fde3fd..00000000000 --- a/src/test/run-pass/fixed-point-bind-unique.rs +++ /dev/null @@ -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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// xfail-fast - -fn fix_help(f: extern fn(@fn(A) -> B, A) -> B, x: A) -> B { - return f(|a| fix_help(f, a), x); -} - -fn fix(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); -} diff --git a/src/test/run-pass/fn-assign-managed-to-bare-1.rs b/src/test/run-pass/fn-assign-managed-to-bare-1.rs deleted file mode 100644 index dece77595bc..00000000000 --- a/src/test/run-pass/fn-assign-managed-to-bare-1.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn 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); -} diff --git a/src/test/run-pass/fn-assign-managed-to-bare-2.rs b/src/test/run-pass/fn-assign-managed-to-bare-2.rs deleted file mode 100644 index f8daacfa233..00000000000 --- a/src/test/run-pass/fn-assign-managed-to-bare-2.rs +++ /dev/null @@ -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 or the MIT license -// , 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); -} diff --git a/src/test/run-pass/fn-bare-coerce-to-shared.rs b/src/test/run-pass/fn-bare-coerce-to-shared.rs deleted file mode 100644 index 853b44ed76c..00000000000 --- a/src/test/run-pass/fn-bare-coerce-to-shared.rs +++ /dev/null @@ -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 or the MIT license -// , 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); -} diff --git a/src/test/run-pass/fn-coerce-field.rs b/src/test/run-pass/fn-coerce-field.rs index 22aab1aa661..ae2e353f913 100644 --- a/src/test/run-pass/fn-coerce-field.rs +++ b/src/test/run-pass/fn-coerce-field.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct r { - field: @fn() +struct r<'self> { + field: &'self fn() } pub fn main() { diff --git a/src/test/run-pass/fn-type-infer.rs b/src/test/run-pass/fn-type-infer.rs index bb9254589f7..09e7ababa6c 100644 --- a/src/test/run-pass/fn-type-infer.rs +++ b/src/test/run-pass/fn-type-infer.rs @@ -11,7 +11,7 @@ #[allow(unused_variable)]; 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 i = 10; }; diff --git a/src/test/run-pass/fun-call-variants.rs b/src/test/run-pass/fun-call-variants.rs index 52e6a4649a8..5011998f929 100644 --- a/src/test/run-pass/fun-call-variants.rs +++ b/src/test/run-pass/fun-call-variants.rs @@ -9,7 +9,7 @@ // option. This file may not be copied, modified, or distributed // 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; } diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index 7cd26dd84c4..15286a85c01 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -24,7 +24,7 @@ mod map_reduce { use std::str; use std::task; - pub type putter = @fn(~str, ~str); + pub type putter<'self> = &'self fn(~str, ~str); pub type mapper = extern fn(~str, putter); diff --git a/src/test/run-pass/infer-with-expected.rs b/src/test/run-pass/infer-with-expected.rs deleted file mode 100644 index 6f2fd54bc9c..00000000000 --- a/src/test/run-pass/infer-with-expected.rs +++ /dev/null @@ -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 or the MIT license -// , 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 }); -} diff --git a/src/test/run-pass/issue-1516.rs b/src/test/run-pass/issue-1516.rs index 2767ac6d69f..4b73d83595e 100644 --- a/src/test/run-pass/issue-1516.rs +++ b/src/test/run-pass/issue-1516.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn main() { - let early_error: @fn(&str) -> ! = |_msg| { fail!() }; + let early_error: &'static fn(&str) -> ! = |_msg| { fail!() }; } diff --git a/src/test/run-pass/issue-2185.rs b/src/test/run-pass/issue-2185.rs index c84386c722d..a1ea1b90809 100644 --- a/src/test/run-pass/issue-2185.rs +++ b/src/test/run-pass/issue-2185.rs @@ -18,11 +18,11 @@ // // Running /usr/local/bin/rustc: // issue-2185.rs:24:0: 26:1 error: conflicting implementations for a trait -// issue-2185.rs:24 impl iterable for @fn(&fn(uint)) { +// issue-2185.rs:24 impl iterable for &'static fn(&fn(uint)) { // issue-2185.rs:25 fn iter(&self, blk: &fn(v: uint)) { self( |i| blk(i) ) } // issue-2185.rs:26 } // issue-2185.rs:20:0: 22:1 note: note conflicting implementation here -// issue-2185.rs:20 impl iterable for @fn(&fn(A)) { +// issue-2185.rs:20 impl iterable for &'static fn(&fn(A)) { // issue-2185.rs:21 fn iter(&self, blk: &fn(A)) { self(blk); } // issue-2185.rs:22 } // @@ -42,15 +42,17 @@ trait iterable { fn iter(&self, blk: &fn(A)); } -impl iterable for @fn(&fn(A)) { +impl iterable for &'static fn(&fn(A)) { fn iter(&self, blk: &fn(A)) { self(blk); } } -impl iterable for @fn(&fn(uint)) { +impl iterable for &'static fn(&fn(uint)) { fn iter(&self, blk: &fn(v: uint)) { self( |i| blk(i) ) } } -fn filter>(self: IA, prd: @fn(A) -> bool, blk: &fn(A)) { +fn filter>(self: IA, + prd: &'static fn(A) -> bool, + blk: &fn(A)) { do self.iter |a| { if prd(a) { blk(a) } } @@ -73,8 +75,8 @@ fn range(lo: uint, hi: uint, it: &fn(uint)) { } pub fn main() { - let range: @fn(&fn(uint)) = |a| range(0u, 1000u, a); - let filt: @fn(&fn(v: uint)) = |a| filter( + let range: &'static fn(&fn(uint)) = |a| range(0u, 1000u, a); + let filt: &'static fn(&fn(v: uint)) = |a| filter( range, |&&n: uint| n % 3u != 0u && n % 5u != 0u, a); diff --git a/src/test/run-pass/issue-2633.rs b/src/test/run-pass/issue-2633.rs index e7da1286137..bde18d77b9a 100644 --- a/src/test/run-pass/issue-2633.rs +++ b/src/test/run-pass/issue-2633.rs @@ -9,12 +9,16 @@ // except according to those terms. struct cat { - meow: @fn(), + meow: extern "Rust" fn(), +} + +fn meow() { + error!("meow") } fn cat() -> cat { cat { - meow: || error!("meow") + meow: meow, } } diff --git a/src/test/run-pass/issue-3052.rs b/src/test/run-pass/issue-3052.rs index 852c6d995c6..cb1ffc38908 100644 --- a/src/test/run-pass/issue-3052.rs +++ b/src/test/run-pass/issue-3052.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -type Connection = @fn(~[u8]); +type Connection = &'static fn(~[u8]); fn f() -> Option { let mock_connection: Connection = |_| {}; diff --git a/src/test/run-pass/issue-3429.rs b/src/test/run-pass/issue-3429.rs index abea01cefd3..fc493485b79 100644 --- a/src/test/run-pass/issue-3429.rs +++ b/src/test/run-pass/issue-3429.rs @@ -10,6 +10,6 @@ pub fn main() { let x = 1; - let y: @fn() -> int = || x; + let y: &fn() -> int = || x; let _z = y(); } diff --git a/src/test/run-pass/issue-4929.rs b/src/test/run-pass/issue-4929.rs deleted file mode 100644 index 5803c3da6cc..00000000000 --- a/src/test/run-pass/issue-4929.rs +++ /dev/null @@ -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 or the MIT license -// , 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() { } diff --git a/src/test/run-pass/issue-5783.rs b/src/test/run-pass/issue-5783.rs deleted file mode 100644 index 7f988dc6489..00000000000 --- a/src/test/run-pass/issue-5783.rs +++ /dev/null @@ -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 or the MIT license -// , 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); -} diff --git a/src/test/run-pass/issue4516_ty_param.rs b/src/test/run-pass/issue4516_ty_param.rs deleted file mode 100644 index 35df47df036..00000000000 --- a/src/test/run-pass/issue4516_ty_param.rs +++ /dev/null @@ -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 or the MIT license -// , 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)(); -} diff --git a/src/test/run-pass/lambda-infer-unresolved.rs b/src/test/run-pass/lambda-infer-unresolved.rs index 9eecc788a69..d55150e448e 100644 --- a/src/test/run-pass/lambda-infer-unresolved.rs +++ b/src/test/run-pass/lambda-infer-unresolved.rs @@ -9,13 +9,13 @@ // except according to those terms. // 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 } pub fn main() { let e = @mut Refs{refs: ~[], n: 0}; - let _f: @fn() = || error!(e.n); + let _f: &fn() = || error!(e.n); e.refs.push(1); } diff --git a/src/test/run-pass/lambda-no-leak.rs b/src/test/run-pass/lambda-no-leak.rs deleted file mode 100644 index e19503240f0..00000000000 --- a/src/test/run-pass/lambda-no-leak.rs +++ /dev/null @@ -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 or the MIT license -// , 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)); -} 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 75c3008af8e..d014a3cf1a1 100644 --- a/src/test/run-pass/last-use-in-cap-clause.rs +++ b/src/test/run-pass/last-use-in-cap-clause.rs @@ -12,10 +12,10 @@ struct A { a: ~int } -fn foo() -> @fn() -> int { +fn foo() -> &'static fn() -> int { let k = ~22; let _u = A {a: k.clone()}; - let result: @fn() -> int = || 22; + let result: &'static 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 2c62b6894d0..079d2374a29 100644 --- a/src/test/run-pass/last-use-is-capture.rs +++ b/src/test/run-pass/last-use-is-capture.rs @@ -13,7 +13,7 @@ struct A { a: ~int } pub fn main() { - fn invoke(f: @fn()) { f(); } + fn invoke(f: &fn()) { f(); } let k = ~22; let _u = A {a: k.clone()}; invoke(|| error!(k.clone()) ) diff --git a/src/test/run-pass/monomorphize-trait-in-fn-at.rs b/src/test/run-pass/monomorphize-trait-in-fn-at.rs deleted file mode 100644 index 8e36b1138bd..00000000000 --- a/src/test/run-pass/monomorphize-trait-in-fn-at.rs +++ /dev/null @@ -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 or the MIT license -// , 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(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); -} diff --git a/src/test/run-pass/move-nullary-fn.rs b/src/test/run-pass/move-nullary-fn.rs index 464d915b2c4..87281c2fd22 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/newlambdas-ret-infer.rs b/src/test/run-pass/newlambdas-ret-infer.rs index 10ac45922aa..6d6757890ad 100644 --- a/src/test/run-pass/newlambdas-ret-infer.rs +++ b/src/test/run-pass/newlambdas-ret-infer.rs @@ -11,8 +11,6 @@ // Test that the lambda kind is inferred correctly as a return // expression -fn shared() -> @fn() { return || (); } - fn unique() -> ~fn() { return || (); } pub fn main() { diff --git a/src/test/run-pass/newlambdas-ret-infer2.rs b/src/test/run-pass/newlambdas-ret-infer2.rs index 4dfe3575eb5..17ff8ce94d9 100644 --- a/src/test/run-pass/newlambdas-ret-infer2.rs +++ b/src/test/run-pass/newlambdas-ret-infer2.rs @@ -11,8 +11,6 @@ // Test that the lambda kind is inferred correctly as a return // expression -fn shared() -> @fn() { || () } - fn unique() -> ~fn() { || () } pub fn main() { diff --git a/src/test/run-pass/newlambdas.rs b/src/test/run-pass/newlambdas.rs index 9c2a223174c..d9d0daa7138 100644 --- a/src/test/run-pass/newlambdas.rs +++ b/src/test/run-pass/newlambdas.rs @@ -14,16 +14,9 @@ fn f(i: int, f: &fn(int) -> int) -> int { f(i) } fn g(_g: &fn()) { } -fn ff() -> @fn(int) -> int { - return |x| x + 1; -} - pub fn main() { assert_eq!(f(10, |a| a), 10); g(||()); assert_eq!(do f(10) |a| { a }, 10); do g() { } - let _x: @fn() -> int = || 10; - let _y: @fn(int) -> int = |a| a; - assert_eq!(ff()(10), 11); } diff --git a/src/test/run-pass/propagate-expected-type-through-block.rs b/src/test/run-pass/propagate-expected-type-through-block.rs deleted file mode 100644 index f8f824cd596..00000000000 --- a/src/test/run-pass/propagate-expected-type-through-block.rs +++ /dev/null @@ -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); -} diff --git a/src/test/run-pass/reflect-visit-data.rs b/src/test/run-pass/reflect-visit-data.rs index 2d9f4a2ff6f..cf6f12a06e5 100644 --- a/src/test/run-pass/reflect-visit-data.rs +++ b/src/test/run-pass/reflect-visit-data.rs @@ -460,9 +460,9 @@ impl TyVisitor for ptr_visit_adaptor { } 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; } - self.bump_past::<@fn()>(); + self.bump_past::<(uint,uint)>(); true } } diff --git a/src/test/run-pass/regions-fn-subtyping.rs b/src/test/run-pass/regions-fn-subtyping.rs index a6b43df1f88..06c8aca4741 100644 --- a/src/test/run-pass/regions-fn-subtyping.rs +++ b/src/test/run-pass/regions-fn-subtyping.rs @@ -14,21 +14,21 @@ #[allow(unused_variable)]; // Should pass region checking. -fn ok(f: @fn(x: &uint)) { +fn ok(f: &fn(x: &uint)) { // Here, g is a function that can accept a uint pointer with // lifetime r, and f is a function that can accept a uint pointer // with any lifetime. The assignment g = f should be OK (i.e., // 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<'r>(y: &'r uint) = |x| { }; + let mut g: &fn<'r>(y: &'r uint) = |x| { }; g = f; } // This version is the same as above, except that here, g's type is // inferred. -fn ok_inferred(f: @fn(x: &uint)) { - let mut g: @fn<'r>(x: &'r uint) = |_| {}; +fn ok_inferred(f: &fn(x: &uint)) { + let mut g: &fn<'r>(x: &'r uint) = |_| {}; g = f; } diff --git a/src/test/run-pass/unused-move-capture.rs b/src/test/run-pass/unused-move-capture.rs index dd70b7daa70..662121a0993 100644 --- a/src/test/run-pass/unused-move-capture.rs +++ b/src/test/run-pass/unused-move-capture.rs @@ -10,6 +10,6 @@ pub fn main() { let _x = ~1; - let lam_move: @fn() = || {}; + let lam_move: &fn() = || {}; lam_move(); }