rust/src/test/compile-fail/pure-higher-order.rs
Brian Anderson 569467eb0d Merge remote-tracking branch 'Dretch/prettydocs'
Conflicts:
	src/compiletest/errors.rs
	src/libsyntax/parse/attr.rs
	src/libsyntax/parse/comments.rs
	src/test/compile-fail/ambig_impl_unify.rs
	src/test/compile-fail/assign-super.rs
	src/test/compile-fail/bad-for-loop.rs
	src/test/compile-fail/bad-var-env-capture-in-block-arg.rs
	src/test/compile-fail/block-arg-as-stmt-with-value.rs
	src/test/compile-fail/borrowck-assign-comp-idx.rs
	src/test/compile-fail/borrowck-lend-flow.rs
	src/test/compile-fail/borrowck-loan-blocks-move-cc.rs
	src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs
	src/test/compile-fail/borrowck-loan-rcvr.rs
	src/test/compile-fail/borrowck-loan-vec-content.rs
	src/test/compile-fail/borrowck-mut-vec-as-imm-slice-bad.rs
	src/test/compile-fail/cap-clause-with-stack-closure.rs
	src/test/compile-fail/do1.rs
	src/test/compile-fail/do2.rs
	src/test/compile-fail/empty-vec-trailing-comma.rs
	src/test/compile-fail/evec-subtyping.rs
	src/test/compile-fail/issue-1896.rs
	src/test/compile-fail/issue-2149.rs
	src/test/compile-fail/issue-2150.rs
	src/test/compile-fail/issue-2487-b.rs
	src/test/compile-fail/kindck-implicit-close-over-mut-var.rs
	src/test/compile-fail/liveness-issue-2163.rs
	src/test/compile-fail/liveness-use-in-index-lvalue.rs
	src/test/compile-fail/no-reuse-move-arc.rs
	src/test/compile-fail/no-send-res-ports.rs
	src/test/compile-fail/non-const.rs
	src/test/compile-fail/pure-higher-order.rs
	src/test/compile-fail/pure-loop-body.rs
	src/test/compile-fail/regions-addr-of-upvar-self.rs
	src/test/compile-fail/regions-escape-loop-via-vec.rs
	src/test/compile-fail/regions-scoping.rs
	src/test/compile-fail/seq-args.rs
	src/test/compile-fail/tstate-unsat-in-called-fn-expr.rs
	src/test/compile-fail/tstate-unsat-in-fn-expr.rs
	src/test/compile-fail/vec-add.rs
	src/test/compile-fail/vec-concat-bug.rs
	src/test/compile-fail/vector-no-ann.rs
2012-07-02 15:23:41 -07:00

48 lines
1.1 KiB
Rust

// Test rules governing higher-order pure fns.
pure fn range(from: uint, to: uint, f: fn(uint)) {
let mut i = from;
while i < to {
f(i); // Note: legal to call argument, even if it is not pure.
i += 1u;
}
}
pure fn range2(from: uint, to: uint, f: fn(uint)) {
do range(from, to) |i| {
f(i*2u);
}
}
pure fn range3(from: uint, to: uint, f: fn(uint)) {
range(from, to, f)
}
pure fn range4(from: uint, to: uint) {
range(from, to, print) //~ ERROR access to impure function prohibited in pure context
}
pure fn range5(from: uint, to: uint, x: {f: fn(uint)}) {
range(from, to, x.f) //~ ERROR access to impure function prohibited in pure context
}
pure fn range6(from: uint, to: uint, x: @{f: fn(uint)}) {
range(from, to, x.f) //~ ERROR access to impure function prohibited in pure context
}
pure fn range7(from: uint, to: uint) {
do range(from, to) |i| {
print(i); //~ ERROR access to impure function prohibited in pure context
}
}
pure fn range8(from: uint, to: uint) {
range(from, to, noop);
}
fn print(i: uint) { #error["i=%u", i]; }
pure fn noop(_i: uint) {}
fn main() {
}