]> git.lizzy.rs Git - rust.git/commitdiff
Move the borrowck run-pass/compile-fail tests into their own directories
authorNiko Matsakis <niko@alum.mit.edu>
Thu, 18 Feb 2016 10:21:15 +0000 (05:21 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Wed, 24 Feb 2016 23:40:39 +0000 (18:40 -0500)
as a test.

320 files changed:
src/test/compile-fail/borrowck-and-init.rs [deleted file]
src/test/compile-fail/borrowck-anon-fields-struct.rs [deleted file]
src/test/compile-fail/borrowck-anon-fields-tuple.rs [deleted file]
src/test/compile-fail/borrowck-anon-fields-variant.rs [deleted file]
src/test/compile-fail/borrowck-argument.rs [deleted file]
src/test/compile-fail/borrowck-assign-comp-idx.rs [deleted file]
src/test/compile-fail/borrowck-assign-comp.rs [deleted file]
src/test/compile-fail/borrowck-assign-to-andmut-in-aliasable-loc.rs [deleted file]
src/test/compile-fail/borrowck-assign-to-andmut-in-borrowed-loc.rs [deleted file]
src/test/compile-fail/borrowck-assign-to-constants.rs [deleted file]
src/test/compile-fail/borrowck-auto-mut-ref-to-immut-var.rs [deleted file]
src/test/compile-fail/borrowck-autoref-3261.rs [deleted file]
src/test/compile-fail/borrowck-bad-nested-calls-free.rs [deleted file]
src/test/compile-fail/borrowck-bad-nested-calls-move.rs [deleted file]
src/test/compile-fail/borrowck-block-unint.rs [deleted file]
src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs [deleted file]
src/test/compile-fail/borrowck-borrow-from-stack-variable.rs [deleted file]
src/test/compile-fail/borrowck-borrow-from-temporary.rs [deleted file]
src/test/compile-fail/borrowck-borrow-immut-deref-of-box-as-mut.rs [deleted file]
src/test/compile-fail/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs [deleted file]
src/test/compile-fail/borrowck-borrow-mut-object-twice.rs [deleted file]
src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs [deleted file]
src/test/compile-fail/borrowck-borrow-overloaded-auto-deref.rs [deleted file]
src/test/compile-fail/borrowck-borrow-overloaded-deref-mut.rs [deleted file]
src/test/compile-fail/borrowck-borrow-overloaded-deref.rs [deleted file]
src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs [deleted file]
src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs [deleted file]
src/test/compile-fail/borrowck-box-insensitivity.rs [deleted file]
src/test/compile-fail/borrowck-break-uninit-2.rs [deleted file]
src/test/compile-fail/borrowck-break-uninit.rs [deleted file]
src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs [deleted file]
src/test/compile-fail/borrowck-call-method-from-mut-aliasable.rs [deleted file]
src/test/compile-fail/borrowck-closures-mut-and-imm.rs [deleted file]
src/test/compile-fail/borrowck-closures-mut-of-imm.rs [deleted file]
src/test/compile-fail/borrowck-closures-two-mut.rs [deleted file]
src/test/compile-fail/borrowck-closures-unique-imm.rs [deleted file]
src/test/compile-fail/borrowck-closures-unique.rs [deleted file]
src/test/compile-fail/borrowck-closures-use-after-free.rs [deleted file]
src/test/compile-fail/borrowck-consume-unsize-vec.rs [deleted file]
src/test/compile-fail/borrowck-consume-upcast-box.rs [deleted file]
src/test/compile-fail/borrowck-escaping-closure-error-1.rs [deleted file]
src/test/compile-fail/borrowck-escaping-closure-error-2.rs [deleted file]
src/test/compile-fail/borrowck-field-sensitivity.rs [deleted file]
src/test/compile-fail/borrowck-fn-in-const-a.rs [deleted file]
src/test/compile-fail/borrowck-fn-in-const-b.rs [deleted file]
src/test/compile-fail/borrowck-fn-in-const-c.rs [deleted file]
src/test/compile-fail/borrowck-for-loop-correct-cmt-for-pattern.rs [deleted file]
src/test/compile-fail/borrowck-for-loop-head-linkage.rs [deleted file]
src/test/compile-fail/borrowck-if-no-else.rs [deleted file]
src/test/compile-fail/borrowck-if-with-else.rs [deleted file]
src/test/compile-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162-c.rs [deleted file]
src/test/compile-fail/borrowck-in-static.rs [deleted file]
src/test/compile-fail/borrowck-init-in-called-fn-expr.rs [deleted file]
src/test/compile-fail/borrowck-init-in-fn-expr.rs [deleted file]
src/test/compile-fail/borrowck-init-in-fru.rs [deleted file]
src/test/compile-fail/borrowck-init-op-equal.rs [deleted file]
src/test/compile-fail/borrowck-init-plus-equal.rs [deleted file]
src/test/compile-fail/borrowck-insert-during-each.rs [deleted file]
src/test/compile-fail/borrowck-issue-14498.rs [deleted file]
src/test/compile-fail/borrowck-issue-2657-1.rs [deleted file]
src/test/compile-fail/borrowck-issue-2657-2.rs [deleted file]
src/test/compile-fail/borrowck-lend-flow-if.rs [deleted file]
src/test/compile-fail/borrowck-lend-flow-loop.rs [deleted file]
src/test/compile-fail/borrowck-lend-flow-match.rs [deleted file]
src/test/compile-fail/borrowck-lend-flow.rs [deleted file]
src/test/compile-fail/borrowck-let-suggestion-suffixes.rs [deleted file]
src/test/compile-fail/borrowck-let-suggestion.rs [deleted file]
src/test/compile-fail/borrowck-loan-blocks-move-cc.rs [deleted file]
src/test/compile-fail/borrowck-loan-blocks-move.rs [deleted file]
src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs [deleted file]
src/test/compile-fail/borrowck-loan-in-overloaded-op.rs [deleted file]
src/test/compile-fail/borrowck-loan-of-static-data-issue-27616.rs [deleted file]
src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs [deleted file]
src/test/compile-fail/borrowck-loan-rcvr.rs [deleted file]
src/test/compile-fail/borrowck-loan-vec-content.rs [deleted file]
src/test/compile-fail/borrowck-match-binding-is-assignment.rs [deleted file]
src/test/compile-fail/borrowck-move-by-capture.rs [deleted file]
src/test/compile-fail/borrowck-move-error-with-note.rs [deleted file]
src/test/compile-fail/borrowck-move-from-subpath-of-borrowed-path.rs [deleted file]
src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs [deleted file]
src/test/compile-fail/borrowck-move-in-irrefut-pat.rs [deleted file]
src/test/compile-fail/borrowck-move-moved-value-into-closure.rs [deleted file]
src/test/compile-fail/borrowck-move-mut-base-ptr.rs [deleted file]
src/test/compile-fail/borrowck-move-out-of-overloaded-auto-deref.rs [deleted file]
src/test/compile-fail/borrowck-move-out-of-overloaded-deref.rs [deleted file]
src/test/compile-fail/borrowck-move-out-of-static-item.rs [deleted file]
src/test/compile-fail/borrowck-move-out-of-struct-with-dtor.rs [deleted file]
src/test/compile-fail/borrowck-move-out-of-tuple-struct-with-dtor.rs [deleted file]
src/test/compile-fail/borrowck-move-out-of-vec-tail.rs [deleted file]
src/test/compile-fail/borrowck-move-subcomponent.rs [deleted file]
src/test/compile-fail/borrowck-multiple-captures.rs [deleted file]
src/test/compile-fail/borrowck-mut-addr-of-imm-var.rs [deleted file]
src/test/compile-fail/borrowck-mut-borrow-linear-errors.rs [deleted file]
src/test/compile-fail/borrowck-mut-borrow-of-mut-base-ptr.rs [deleted file]
src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs [deleted file]
src/test/compile-fail/borrowck-mutate-in-guard.rs [deleted file]
src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs [deleted file]
src/test/compile-fail/borrowck-object-lifetime.rs [deleted file]
src/test/compile-fail/borrowck-object-mutability.rs [deleted file]
src/test/compile-fail/borrowck-or-init.rs [deleted file]
src/test/compile-fail/borrowck-overloaded-call.rs [deleted file]
src/test/compile-fail/borrowck-overloaded-index-and-overloaded-deref.rs [deleted file]
src/test/compile-fail/borrowck-overloaded-index-autoderef.rs [deleted file]
src/test/compile-fail/borrowck-overloaded-index-move-from-vec.rs [deleted file]
src/test/compile-fail/borrowck-overloaded-index-move-index.rs [deleted file]
src/test/compile-fail/borrowck-overloaded-index-ref-index.rs [deleted file]
src/test/compile-fail/borrowck-partial-reinit-1.rs [deleted file]
src/test/compile-fail/borrowck-partial-reinit-2.rs [deleted file]
src/test/compile-fail/borrowck-partial-reinit-3.rs [deleted file]
src/test/compile-fail/borrowck-partial-reinit-4.rs [deleted file]
src/test/compile-fail/borrowck-pat-reassign-binding.rs [deleted file]
src/test/compile-fail/borrowck-reborrow-from-mut.rs [deleted file]
src/test/compile-fail/borrowck-reborrow-from-shorter-lived-andmut.rs [deleted file]
src/test/compile-fail/borrowck-ref-into-rvalue.rs [deleted file]
src/test/compile-fail/borrowck-ref-mut-of-imm.rs [deleted file]
src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs [deleted file]
src/test/compile-fail/borrowck-return-variable-on-stack-via-clone.rs [deleted file]
src/test/compile-fail/borrowck-return.rs [deleted file]
src/test/compile-fail/borrowck-struct-update-with-dtor.rs [deleted file]
src/test/compile-fail/borrowck-swap-mut-base-ptr.rs [deleted file]
src/test/compile-fail/borrowck-unary-move.rs [deleted file]
src/test/compile-fail/borrowck-unboxed-closures.rs [deleted file]
src/test/compile-fail/borrowck-uninit-after-item.rs [deleted file]
src/test/compile-fail/borrowck-uninit-in-assignop.rs [deleted file]
src/test/compile-fail/borrowck-uninit.rs [deleted file]
src/test/compile-fail/borrowck-uniq-via-lend.rs [deleted file]
src/test/compile-fail/borrowck-use-in-index-lvalue.rs [deleted file]
src/test/compile-fail/borrowck-use-mut-borrow.rs [deleted file]
src/test/compile-fail/borrowck-use-uninitialized-in-cast-trait.rs [deleted file]
src/test/compile-fail/borrowck-use-uninitialized-in-cast.rs [deleted file]
src/test/compile-fail/borrowck-vec-pattern-element-loan.rs [deleted file]
src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs [deleted file]
src/test/compile-fail/borrowck-vec-pattern-move-tail.rs [deleted file]
src/test/compile-fail/borrowck-vec-pattern-nesting.rs [deleted file]
src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs [deleted file]
src/test/compile-fail/borrowck-while-break.rs [deleted file]
src/test/compile-fail/borrowck-while-cond.rs [deleted file]
src/test/compile-fail/borrowck-while.rs [deleted file]
src/test/compile-fail/borrowck/borrowck-and-init.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-anon-fields-struct.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-anon-fields-tuple.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-anon-fields-variant.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-argument.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-assign-comp-idx.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-assign-comp.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-assign-to-andmut-in-borrowed-loc.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-assign-to-constants.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-auto-mut-ref-to-immut-var.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-autoref-3261.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-bad-nested-calls-free.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-bad-nested-calls-move.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-block-unint.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-borrow-from-owned-ptr.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-borrow-from-stack-variable.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-borrow-from-temporary.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-borrow-immut-deref-of-box-as-mut.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-borrow-mut-object-twice.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-borrow-overloaded-auto-deref-mut.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-borrow-overloaded-auto-deref.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-borrow-overloaded-deref-mut.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-borrow-overloaded-deref.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-borrowed-uniq-rvalue-2.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-borrowed-uniq-rvalue.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-box-insensitivity.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-break-uninit-2.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-break-uninit.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-call-is-borrow-issue-12224.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-call-method-from-mut-aliasable.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-closures-mut-and-imm.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-closures-mut-of-imm.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-closures-two-mut.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-closures-unique-imm.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-closures-unique.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-closures-use-after-free.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-consume-unsize-vec.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-consume-upcast-box.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-escaping-closure-error-1.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-escaping-closure-error-2.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-field-sensitivity.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-fn-in-const-a.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-fn-in-const-b.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-fn-in-const-c.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-for-loop-correct-cmt-for-pattern.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-for-loop-head-linkage.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-if-no-else.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-if-with-else.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-imm-ref-to-mut-rec-field-issue-3162-c.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-in-static.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-init-in-called-fn-expr.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-init-in-fn-expr.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-init-in-fru.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-init-op-equal.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-init-plus-equal.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-insert-during-each.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-issue-14498.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-issue-2657-1.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-issue-2657-2.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-lend-flow-if.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-lend-flow-loop.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-lend-flow-match.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-lend-flow.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-let-suggestion-suffixes.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-let-suggestion.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-loan-blocks-move-cc.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-loan-blocks-move.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-loan-blocks-mut-uniq.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-loan-in-overloaded-op.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-loan-of-static-data-issue-27616.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-loan-rcvr-overloaded-op.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-loan-rcvr.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-loan-vec-content.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-match-binding-is-assignment.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-move-by-capture.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-move-error-with-note.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-move-from-subpath-of-borrowed-path.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-move-from-unsafe-ptr.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-move-in-irrefut-pat.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-move-moved-value-into-closure.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-move-mut-base-ptr.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-move-out-of-overloaded-auto-deref.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-move-out-of-overloaded-deref.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-move-out-of-static-item.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-move-out-of-struct-with-dtor.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-move-out-of-vec-tail.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-move-subcomponent.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-multiple-captures.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-mut-addr-of-imm-var.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-mut-borrow-linear-errors.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-mut-borrow-of-mut-base-ptr.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-mut-slice-of-imm-vec.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-mutate-in-guard.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-no-cycle-in-exchange-heap.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-object-lifetime.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-object-mutability.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-or-init.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-overloaded-call.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-overloaded-index-and-overloaded-deref.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-overloaded-index-autoderef.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-overloaded-index-move-from-vec.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-overloaded-index-move-index.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-overloaded-index-ref-index.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-partial-reinit-1.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-partial-reinit-2.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-partial-reinit-3.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-partial-reinit-4.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-pat-reassign-binding.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-reborrow-from-mut.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-reborrow-from-shorter-lived-andmut.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-ref-into-rvalue.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-ref-mut-of-imm.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-report-with-custom-diagnostic.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-return-variable-on-stack-via-clone.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-return.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-struct-update-with-dtor.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-swap-mut-base-ptr.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-unary-move.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-unboxed-closures.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-uninit-after-item.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-uninit-in-assignop.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-uninit.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-uniq-via-lend.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-use-in-index-lvalue.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-use-mut-borrow.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-use-uninitialized-in-cast-trait.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-use-uninitialized-in-cast.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-vec-pattern-element-loan.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-vec-pattern-loan-from-mut.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-vec-pattern-move-tail.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-vec-pattern-nesting.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-vec-pattern-tail-element-loan.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-while-break.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-while-cond.rs [new file with mode: 0644]
src/test/compile-fail/borrowck/borrowck-while.rs [new file with mode: 0644]
src/test/run-pass/borrowck-assign-to-subfield.rs [deleted file]
src/test/run-pass/borrowck-binding-mutbl.rs [deleted file]
src/test/run-pass/borrowck-borrow-from-expr-block.rs [deleted file]
src/test/run-pass/borrowck-borrow-of-mut-base-ptr-safe.rs [deleted file]
src/test/run-pass/borrowck-closures-two-imm.rs [deleted file]
src/test/run-pass/borrowck-field-sensitivity.rs [deleted file]
src/test/run-pass/borrowck-fixed-length-vecs.rs [deleted file]
src/test/run-pass/borrowck-freeze-frozen-mut.rs [deleted file]
src/test/run-pass/borrowck-lend-args.rs [deleted file]
src/test/run-pass/borrowck-macro-interaction-issue-6304.rs [deleted file]
src/test/run-pass/borrowck-move-by-capture-ok.rs [deleted file]
src/test/run-pass/borrowck-mut-uniq.rs [deleted file]
src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs [deleted file]
src/test/run-pass/borrowck-pat-enum.rs [deleted file]
src/test/run-pass/borrowck-pat-reassign-no-binding.rs [deleted file]
src/test/run-pass/borrowck-rvalues-mutable.rs [deleted file]
src/test/run-pass/borrowck-scope-of-deref-issue-4666.rs [deleted file]
src/test/run-pass/borrowck-static-item-in-fn.rs [deleted file]
src/test/run-pass/borrowck-trait-lifetime.rs [deleted file]
src/test/run-pass/borrowck-uniq-via-ref.rs [deleted file]
src/test/run-pass/borrowck-univariant-enum.rs [deleted file]
src/test/run-pass/borrowck-use-mut-borrow.rs [deleted file]
src/test/run-pass/borrowck/borrowck-assign-to-subfield.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-binding-mutbl.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-borrow-from-expr-block.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-borrow-of-mut-base-ptr-safe.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-closures-two-imm.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-field-sensitivity.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-fixed-length-vecs.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-freeze-frozen-mut.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-lend-args.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-macro-interaction-issue-6304.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-move-by-capture-ok.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-mut-uniq.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-mut-vec-as-imm-slice.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-pat-enum.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-pat-reassign-no-binding.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-rvalues-mutable.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-scope-of-deref-issue-4666.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-static-item-in-fn.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-trait-lifetime.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-uniq-via-ref.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-univariant-enum.rs [new file with mode: 0644]
src/test/run-pass/borrowck/borrowck-use-mut-borrow.rs [new file with mode: 0644]

diff --git a/src/test/compile-fail/borrowck-and-init.rs b/src/test/compile-fail/borrowck-and-init.rs
deleted file mode 100644 (file)
index 92f16d8..0000000
+++ /dev/null
@@ -1,16 +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 main() {
-    let i: isize;
-
-    println!("{}", false && { i = 5; true });
-    println!("{}", i); //~ ERROR use of possibly uninitialized variable: `i`
-}
diff --git a/src/test/compile-fail/borrowck-anon-fields-struct.rs b/src/test/compile-fail/borrowck-anon-fields-struct.rs
deleted file mode 100644 (file)
index 5ee2b89..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2014 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 that we are able to distinguish when loans borrow different
-// anonymous fields of a tuple vs the same anonymous field.
-
-struct Y(usize, usize);
-
-fn distinct_variant() {
-    let mut y = Y(1, 2);
-
-    let a = match y {
-        Y(ref mut a, _) => a
-    };
-
-    let b = match y {
-        Y(_, ref mut b) => b
-    };
-
-    *a += 1;
-    *b += 1;
-}
-
-fn same_variant() {
-    let mut y = Y(1, 2);
-
-    let a = match y {
-        Y(ref mut a, _) => a
-    };
-
-    let b = match y {
-        Y(ref mut b, _) => b //~ ERROR cannot borrow
-    };
-
-    *a += 1;
-    *b += 1;
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-anon-fields-tuple.rs b/src/test/compile-fail/borrowck-anon-fields-tuple.rs
deleted file mode 100644 (file)
index ebaed01..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2014 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 that we are able to distinguish when loans borrow different
-// anonymous fields of a tuple vs the same anonymous field.
-
-fn distinct_variant() {
-    let mut y = (1, 2);
-
-    let a = match y {
-        (ref mut a, _) => a
-    };
-
-    let b = match y {
-        (_, ref mut b) => b
-    };
-
-    *a += 1;
-    *b += 1;
-}
-
-fn same_variant() {
-    let mut y = (1, 2);
-
-    let a = match y {
-        (ref mut a, _) => a
-    };
-
-    let b = match y {
-        (ref mut b, _) => b //~ ERROR cannot borrow
-    };
-
-    *a += 1;
-    *b += 1;
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-anon-fields-variant.rs b/src/test/compile-fail/borrowck-anon-fields-variant.rs
deleted file mode 100644 (file)
index 4e1b852..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2014 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 that we are able to distinguish when loans borrow different
-// anonymous fields of an enum variant vs the same anonymous field.
-
-enum Foo {
-    X, Y(usize, usize)
-}
-
-fn distinct_variant() {
-    let mut y = Foo::Y(1, 2);
-
-    let a = match y {
-      Foo::Y(ref mut a, _) => a,
-      Foo::X => panic!()
-    };
-
-    let b = match y {
-      Foo::Y(_, ref mut b) => b,
-      Foo::X => panic!()
-    };
-
-    *a += 1;
-    *b += 1;
-}
-
-fn same_variant() {
-    let mut y = Foo::Y(1, 2);
-
-    let a = match y {
-      Foo::Y(ref mut a, _) => a,
-      Foo::X => panic!()
-    };
-
-    let b = match y {
-      Foo::Y(ref mut b, _) => b, //~ ERROR cannot borrow
-      Foo::X => panic!()
-    };
-
-    *a += 1;
-    *b += 1;
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-argument.rs b/src/test/compile-fail/borrowck-argument.rs
deleted file mode 100644 (file)
index 3230689..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2015 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.
-
-#[derive(Copy, Clone)]
-struct S;
-
-impl S {
-    fn mutate(&mut self) {
-    }
-}
-
-fn func(arg: S) {
-    arg.mutate(); //~ ERROR: cannot borrow immutable argument
-}
-
-impl S {
-    fn method(&self, arg: S) {
-        arg.mutate(); //~ ERROR: cannot borrow immutable argument
-    }
-}
-
-trait T {
-    fn default(&self, arg: S) {
-        arg.mutate(); //~ ERROR: cannot borrow immutable argument
-    }
-}
-
-impl T for S {}
-
-fn main() {
-    let s = S;
-    func(s);
-    s.method(s);
-    s.default(s);
-    (|arg: S| { arg.mutate() })(s); //~ ERROR: cannot borrow immutable argument
-}
diff --git a/src/test/compile-fail/borrowck-assign-comp-idx.rs b/src/test/compile-fail/borrowck-assign-comp-idx.rs
deleted file mode 100644 (file)
index b18df7f..0000000
+++ /dev/null
@@ -1,49 +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 Point {
-    x: isize,
-    y: isize,
-}
-
-fn a() {
-    let mut p = vec!(1);
-
-    // Create an immutable pointer into p's contents:
-    let q: &isize = &p[0];
-
-    p[0] = 5; //~ ERROR cannot borrow
-
-    println!("{}", *q);
-}
-
-fn borrow<F>(_x: &[isize], _f: F) where F: FnOnce() {}
-
-fn b() {
-    // here we alias the mutable vector into an imm slice and try to
-    // modify the original:
-
-    let mut p = vec!(1);
-
-    borrow(
-        &p,
-        || p[0] = 5); //~ ERROR cannot borrow `p` as mutable
-}
-
-fn c() {
-    // Legal because the scope of the borrow does not include the
-    // modification:
-    let mut p = vec!(1);
-    borrow(&p, ||{});
-    p[0] = 5;
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-assign-comp.rs b/src/test/compile-fail/borrowck-assign-comp.rs
deleted file mode 100644 (file)
index 802b831..0000000
+++ /dev/null
@@ -1,46 +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 point { x: isize, y: isize }
-
-fn a() {
-    let mut p = point {x: 3, y: 4};
-    let q = &p;
-
-    // This assignment is illegal because the field x is not
-    // inherently mutable; since `p` was made immutable, `p.x` is now
-    // immutable.  Otherwise the type of &_q.x (&isize) would be wrong.
-    p.x = 5; //~ ERROR cannot assign to `p.x`
-    q.x;
-}
-
-fn c() {
-    // this is sort of the opposite.  We take a loan to the interior of `p`
-    // and then try to overwrite `p` as a whole.
-
-    let mut p = point {x: 3, y: 4};
-    let q = &p.y;
-    p = point {x: 5, y: 7};//~ ERROR cannot assign to `p`
-    p.x; // silence warning
-    *q; // stretch loan
-}
-
-fn d() {
-    // just for completeness's sake, the easy case, where we take the
-    // address of a subcomponent and then modify that subcomponent:
-
-    let mut p = point {x: 3, y: 4};
-    let q = &p.y;
-    p.y = 5; //~ ERROR cannot assign to `p.y`
-    *q;
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-assign-to-andmut-in-aliasable-loc.rs b/src/test/compile-fail/borrowck-assign-to-andmut-in-aliasable-loc.rs
deleted file mode 100644 (file)
index d66cdb9..0000000
+++ /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 <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 assignments to an `&mut` pointer which is found in a
-// borrowed (but otherwise non-aliasable) location is illegal.
-
-struct S<'a> {
-    pointer: &'a mut isize
-}
-
-fn a(s: &S) {
-    *s.pointer += 1; //~ ERROR cannot assign
-}
-
-fn b(s: &mut S) {
-    *s.pointer += 1;
-}
-
-fn c(s: & &mut S) {
-    *s.pointer += 1; //~ ERROR cannot assign
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-assign-to-andmut-in-borrowed-loc.rs b/src/test/compile-fail/borrowck-assign-to-andmut-in-borrowed-loc.rs
deleted file mode 100644 (file)
index 77aa57e..0000000
+++ /dev/null
@@ -1,31 +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 assignments to an `&mut` pointer which is found in a
-// borrowed (but otherwise non-aliasable) location is illegal.
-
-struct S<'a> {
-    pointer: &'a mut isize
-}
-
-fn copy_borrowed_ptr<'a>(p: &'a mut S<'a>) -> S<'a> {
-    S { pointer: &mut *p.pointer }
-}
-
-fn main() {
-    let mut x = 1;
-
-    {
-        let mut y = S { pointer: &mut x };
-        let z = copy_borrowed_ptr(&mut y);
-        *y.pointer += 1; //~ ERROR cannot assign
-        *z.pointer += 1;
-    }
-}
diff --git a/src/test/compile-fail/borrowck-assign-to-constants.rs b/src/test/compile-fail/borrowck-assign-to-constants.rs
deleted file mode 100644 (file)
index 1b5b189..0000000
+++ /dev/null
@@ -1,16 +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.
-
-static foo: isize = 5;
-
-fn main() {
-    // assigning to various global constants
-    foo = 6; //~ ERROR cannot assign to immutable static item
-}
diff --git a/src/test/compile-fail/borrowck-auto-mut-ref-to-immut-var.rs b/src/test/compile-fail/borrowck-auto-mut-ref-to-immut-var.rs
deleted file mode 100644 (file)
index ea020dc..0000000
+++ /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 <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 that auto-ref can't create mutable aliases to immutable memory.
-
-struct Foo {
-    x: isize
-}
-
-impl Foo {
-    pub fn printme(&mut self) {
-        println!("{}", self.x);
-    }
-}
-
-fn main() {
-    let x = Foo { x: 3 };
-    x.printme();    //~ ERROR cannot borrow
-}
diff --git a/src/test/compile-fail/borrowck-autoref-3261.rs b/src/test/compile-fail/borrowck-autoref-3261.rs
deleted file mode 100644 (file)
index d5f0930..0000000
+++ /dev/null
@@ -1,34 +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.
-
-enum Either<T, U> { Left(T), Right(U) }
-
-struct X(Either<(usize,usize), fn()>);
-
-impl X {
-    pub fn with<F>(&self, blk: F) where F: FnOnce(&Either<(usize, usize), fn()>) {
-        let X(ref e) = *self;
-        blk(e)
-    }
-}
-
-fn main() {
-    let mut x = X(Either::Right(main as fn()));
-    (&mut x).with(
-        |opt| { //~ ERROR cannot borrow `x` as mutable more than once at a time
-            match opt {
-                &Either::Right(ref f) => {
-                    x = X(Either::Left((0, 0)));
-                    (*f)()
-                },
-                _ => panic!()
-            }
-        })
-}
diff --git a/src/test/compile-fail/borrowck-bad-nested-calls-free.rs b/src/test/compile-fail/borrowck-bad-nested-calls-free.rs
deleted file mode 100644 (file)
index 7913f9a..0000000
+++ /dev/null
@@ -1,45 +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 detect nested calls that could free pointers evaluated
-// for earlier arguments.
-
-#![feature(box_syntax)]
-
-fn rewrite(v: &mut Box<usize>) -> usize {
-    *v = box 22;
-    **v
-}
-
-fn add(v: &usize, w: usize) -> usize {
-    *v + w
-}
-
-fn implicit() {
-    let mut a: Box<_> = box 1;
-
-    // Note the danger here:
-    //
-    //    the pointer for the first argument has already been
-    //    evaluated, but it gets freed when evaluating the second
-    //    argument!
-    add(
-        &*a,
-        rewrite(&mut a)); //~ ERROR cannot borrow
-}
-
-fn explicit() {
-    let mut a: Box<_> = box 1;
-    add(
-        &*a,
-        rewrite(&mut a)); //~ ERROR cannot borrow
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-bad-nested-calls-move.rs b/src/test/compile-fail/borrowck-bad-nested-calls-move.rs
deleted file mode 100644 (file)
index e24d4e8..0000000
+++ /dev/null
@@ -1,45 +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 detect nested calls that could free pointers evaluated
-// for earlier arguments.
-
-#![feature(box_syntax)]
-
-fn rewrite(v: &mut Box<usize>) -> usize {
-    *v = box 22;
-    **v
-}
-
-fn add(v: &usize, w: Box<usize>) -> usize {
-    *v + *w
-}
-
-fn implicit() {
-    let mut a: Box<_> = box 1;
-
-    // Note the danger here:
-    //
-    //    the pointer for the first argument has already been
-    //    evaluated, but it gets moved when evaluating the second
-    //    argument!
-    add(
-        &*a,
-        a); //~ ERROR cannot move
-}
-
-fn explicit() {
-    let mut a: Box<_> = box 1;
-    add(
-        &*a,
-        a); //~ ERROR cannot move
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-block-unint.rs b/src/test/compile-fail/borrowck-block-unint.rs
deleted file mode 100644 (file)
index a09ee43..0000000
+++ /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 <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 force<F>(f: F) where F: FnOnce() { f(); }
-fn main() {
-    let x: isize;
-    force(|| {  //~ ERROR capture of possibly uninitialized variable: `x`
-        println!("{}", x);
-    });
-}
diff --git a/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs b/src/test/compile-fail/borrowck-borrow-from-owned-ptr.rs
deleted file mode 100644 (file)
index e5091a9..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-// Copyright 2014 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.
-
-
-#[derive(Copy, Clone)]
-struct Foo {
-  bar1: Bar,
-  bar2: Bar
-}
-
-#[derive(Copy, Clone)]
-struct Bar {
-  int1: isize,
-  int2: isize,
-}
-
-fn make_foo() -> Box<Foo> { panic!() }
-
-fn borrow_same_field_twice_mut_mut() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1;
-    let _bar2 = &mut foo.bar1;  //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_same_field_twice_mut_imm() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1;
-    let _bar2 = &foo.bar1;  //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_same_field_twice_imm_mut() {
-    let mut foo = make_foo();
-    let bar1 = &foo.bar1;
-    let _bar2 = &mut foo.bar1;  //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_same_field_twice_imm_imm() {
-    let mut foo = make_foo();
-    let bar1 = &foo.bar1;
-    let _bar2 = &foo.bar1;
-    *bar1;
-}
-
-fn borrow_both_fields_mut() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1;
-    let _bar2 = &mut foo.bar2; //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_both_mut_pattern() {
-    let mut foo = make_foo();
-    match *foo {
-        Foo { bar1: ref mut _bar1, bar2: ref mut _bar2 } => {}
-        //~^ ERROR cannot borrow
-    }
-}
-
-fn borrow_var_and_pattern() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1;
-    match *foo {
-        Foo { bar1: ref mut _bar1, bar2: _ } => {}
-        //~^ ERROR cannot borrow
-    }
-    *bar1;
-}
-
-fn borrow_mut_and_base_imm() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1.int1;
-    let _foo1 = &foo.bar1; //~ ERROR cannot borrow
-    let _foo2 = &*foo; //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_mut_and_base_mut() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1.int1;
-    let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_mut_and_base_mut2() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1.int1;
-    let _foo2 = &mut *foo; //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_imm_and_base_mut() {
-    let mut foo = make_foo();
-    let bar1 = &foo.bar1.int1;
-    let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_imm_and_base_mut2() {
-    let mut foo = make_foo();
-    let bar1 = &foo.bar1.int1;
-    let _foo2 = &mut *foo; //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_imm_and_base_imm() {
-    let mut foo = make_foo();
-    let bar1 = &foo.bar1.int1;
-    let _foo1 = &foo.bar1;
-    let _foo2 = &*foo;
-    *bar1;
-}
-
-fn borrow_mut_and_imm() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1;
-    let _foo1 = &foo.bar2; //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_mut_from_imm() {
-    let foo = make_foo();
-    let bar1 = &mut foo.bar1; //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_long_path_both_mut() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1.int1;
-    let foo1 = &mut foo.bar2.int2; //~ ERROR cannot borrow
-    *bar1;
-    *foo1;
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs b/src/test/compile-fail/borrowck-borrow-from-stack-variable.rs
deleted file mode 100644 (file)
index 440be93..0000000
+++ /dev/null
@@ -1,141 +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.
-
-#[derive(Copy, Clone)]
-struct Foo {
-  bar1: Bar,
-  bar2: Bar
-}
-
-#[derive(Copy, Clone)]
-struct Bar {
-  int1: isize,
-  int2: isize,
-}
-
-fn make_foo() -> Foo { panic!() }
-
-fn borrow_same_field_twice_mut_mut() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1;
-    let _bar2 = &mut foo.bar1;  //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_same_field_twice_mut_imm() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1;
-    let _bar2 = &foo.bar1;  //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_same_field_twice_imm_mut() {
-    let mut foo = make_foo();
-    let bar1 = &foo.bar1;
-    let _bar2 = &mut foo.bar1;  //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_same_field_twice_imm_imm() {
-    let mut foo = make_foo();
-    let bar1 = &foo.bar1;
-    let _bar2 = &foo.bar1;
-    *bar1;
-}
-
-fn borrow_both_mut() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1;
-    let _bar2 = &mut foo.bar2;
-    *bar1;
-}
-
-fn borrow_both_mut_pattern() {
-    let mut foo = make_foo();
-    match foo {
-        Foo { bar1: ref mut _bar1, bar2: ref mut _bar2 } => {}
-    }
-}
-
-fn borrow_var_and_pattern() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1;
-    match foo {
-        Foo { bar1: ref mut _bar1, bar2: _ } => {} //
-        //~^ ERROR cannot borrow
-    }
-    *bar1;
-}
-
-fn borrow_mut_and_base_imm() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1.int1;
-    let _foo1 = &foo.bar1; //~ ERROR cannot borrow
-    let _foo2 = &foo; //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_mut_and_base_mut() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1.int1;
-    let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_mut_and_base_mut2() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1.int1;
-    let _foo2 = &mut foo; //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_imm_and_base_mut() {
-    let mut foo = make_foo();
-    let bar1 = &foo.bar1.int1;
-    let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_imm_and_base_mut2() {
-    let mut foo = make_foo();
-    let bar1 = &foo.bar1.int1;
-    let _foo2 = &mut foo; //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_imm_and_base_imm() {
-    let mut foo = make_foo();
-    let bar1 = &foo.bar1.int1;
-    let _foo1 = &foo.bar1;
-    let _foo2 = &foo;
-    *bar1;
-}
-
-fn borrow_mut_and_imm() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1;
-    let _foo1 = &foo.bar2;
-    *bar1;
-}
-
-fn borrow_mut_from_imm() {
-    let foo = make_foo();
-    let bar1 = &mut foo.bar1; //~ ERROR cannot borrow
-    *bar1;
-}
-
-fn borrow_long_path_both_mut() {
-    let mut foo = make_foo();
-    let bar1 = &mut foo.bar1.int1;
-    let _foo1 = &mut foo.bar2.int2;
-    *bar1;
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-borrow-from-temporary.rs b/src/test/compile-fail/borrowck-borrow-from-temporary.rs
deleted file mode 100644 (file)
index fbb3824..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2014 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 lifetimes are linked properly when we take reference
-// to interior.
-
-struct Foo(isize);
-
-fn foo<'a>() -> &'a isize {
-    let &Foo(ref x) = &Foo(3); //~ ERROR borrowed value does not live long enough
-    x
-}
-
-pub fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-borrow-immut-deref-of-box-as-mut.rs b/src/test/compile-fail/borrowck-borrow-immut-deref-of-box-as-mut.rs
deleted file mode 100644 (file)
index 3662e23..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2014 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.
-
-#![feature(box_syntax)]
-
-struct A;
-
-impl A {
-    fn foo(&mut self) {
-    }
-}
-
-pub fn main() {
-    let a: Box<_> = box A;
-    a.foo();
-    //~^ ERROR cannot borrow immutable `Box` content `*a` as mutable
-}
diff --git a/src/test/compile-fail/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs b/src/test/compile-fail/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs
deleted file mode 100644 (file)
index d60751e..0000000
+++ /dev/null
@@ -1,34 +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 attempt to reborrow an `&mut` pointer in an aliasable
-// location yields an error.
-//
-// Example from src/librustc_borrowck/borrowck/README.md
-
-fn foo(t0: & &mut isize) {
-    let t1 = t0;
-    let p: &isize = &**t0;
-    **t1 = 22; //~ ERROR cannot assign
-}
-
-fn foo3(t0: &mut &mut isize) {
-    let t1 = &mut *t0;
-    let p: &isize = &**t0; //~ ERROR cannot borrow
-    **t1 = 22;
-}
-
-fn foo4(t0: & &mut isize) {
-    let x:  &mut isize = &mut **t0; //~ ERROR cannot borrow
-    *x += 1;
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-borrow-mut-object-twice.rs b/src/test/compile-fail/borrowck-borrow-mut-object-twice.rs
deleted file mode 100644 (file)
index 7175194..0000000
+++ /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 <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.
-
-// Check that `&mut` objects cannot be borrowed twice, just like
-// other `&mut` pointers.
-
-trait Foo {
-    fn f1(&mut self) -> &();
-    fn f2(&mut self);
-}
-
-fn test(x: &mut Foo) {
-    let _y = x.f1();
-    x.f2(); //~ ERROR cannot borrow `*x` as mutable
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs b/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs
deleted file mode 100644 (file)
index 497b0e6..0000000
+++ /dev/null
@@ -1,150 +0,0 @@
-// Copyright 2014 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 how overloaded deref interacts with borrows when DerefMut
-// is implemented.
-
-use std::ops::{Deref, DerefMut};
-
-struct Own<T> {
-    value: *mut T
-}
-
-impl<T> Deref for Own<T> {
-    type Target = T;
-
-    fn deref(&self) -> &T {
-        unsafe { &*self.value }
-    }
-}
-
-impl<T> DerefMut for Own<T> {
-    fn deref_mut(&mut self) -> &mut T {
-        unsafe { &mut *self.value }
-    }
-}
-
-struct Point {
-    x: isize,
-    y: isize
-}
-
-impl Point {
-    fn get(&self) -> (isize, isize) {
-        (self.x, self.y)
-    }
-
-    fn set(&mut self, x: isize, y: isize) {
-        self.x = x;
-        self.y = y;
-    }
-
-    fn x_ref(&self) -> &isize {
-        &self.x
-    }
-
-    fn y_mut(&mut self) -> &mut isize {
-        &mut self.y
-    }
-}
-
-fn deref_imm_field(x: Own<Point>) {
-    let __isize = &x.y;
-}
-
-fn deref_mut_field1(x: Own<Point>) {
-    let __isize = &mut x.y; //~ ERROR cannot borrow
-}
-
-fn deref_mut_field2(mut x: Own<Point>) {
-    let __isize = &mut x.y;
-}
-
-fn deref_extend_field(x: &Own<Point>) -> &isize {
-    &x.y
-}
-
-fn deref_extend_mut_field1(x: &Own<Point>) -> &mut isize {
-    &mut x.y //~ ERROR cannot borrow
-}
-
-fn deref_extend_mut_field2(x: &mut Own<Point>) -> &mut isize {
-    &mut x.y
-}
-
-fn deref_extend_mut_field3(x: &mut Own<Point>) {
-    // Hmm, this is unfortunate, because with box it would work,
-    // but it's presently the expected outcome. See `deref_extend_mut_field4`
-    // for the workaround.
-
-    let _x = &mut x.x;
-    let _y = &mut x.y; //~ ERROR cannot borrow
-}
-
-fn deref_extend_mut_field4<'a>(x: &'a mut Own<Point>) {
-    let p = &mut **x;
-    let _x = &mut p.x;
-    let _y = &mut p.y;
-}
-
-fn assign_field1<'a>(x: Own<Point>) {
-    x.y = 3; //~ ERROR cannot borrow
-}
-
-fn assign_field2<'a>(x: &'a Own<Point>) {
-    x.y = 3; //~ ERROR cannot assign
-}
-
-fn assign_field3<'a>(x: &'a mut Own<Point>) {
-    x.y = 3;
-}
-
-fn assign_field4<'a>(x: &'a mut Own<Point>) {
-    let _p: &mut Point = &mut **x;
-    x.y = 3; //~ ERROR cannot borrow
-}
-
-fn deref_imm_method(x: Own<Point>) {
-    let __isize = x.get();
-}
-
-fn deref_mut_method1(x: Own<Point>) {
-    x.set(0, 0); //~ ERROR cannot borrow
-}
-
-fn deref_mut_method2(mut x: Own<Point>) {
-    x.set(0, 0);
-}
-
-fn deref_extend_method(x: &Own<Point>) -> &isize {
-    x.x_ref()
-}
-
-fn deref_extend_mut_method1(x: &Own<Point>) -> &mut isize {
-    x.y_mut() //~ ERROR cannot borrow
-}
-
-fn deref_extend_mut_method2(x: &mut Own<Point>) -> &mut isize {
-    x.y_mut()
-}
-
-fn assign_method1<'a>(x: Own<Point>) {
-    *x.y_mut() = 3; //~ ERROR cannot borrow
-}
-
-fn assign_method2<'a>(x: &'a Own<Point>) {
-    *x.y_mut() = 3; //~ ERROR cannot borrow
-}
-
-fn assign_method3<'a>(x: &'a mut Own<Point>) {
-    *x.y_mut() = 3;
-}
-
-pub fn main() {}
diff --git a/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref.rs b/src/test/compile-fail/borrowck-borrow-overloaded-auto-deref.rs
deleted file mode 100644 (file)
index 693ed29..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-// Copyright 2014 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 how overloaded deref interacts with borrows when only
-// Deref and not DerefMut is implemented.
-
-use std::ops::Deref;
-
-struct Rc<T> {
-    value: *const T
-}
-
-impl<T> Deref for Rc<T> {
-    type Target = T;
-
-    fn deref(&self) -> &T {
-        unsafe { &*self.value }
-    }
-}
-
-struct Point {
-    x: isize,
-    y: isize
-}
-
-impl Point {
-    fn get(&self) -> (isize, isize) {
-        (self.x, self.y)
-    }
-
-    fn set(&mut self, x: isize, y: isize) {
-        self.x = x;
-        self.y = y;
-    }
-
-    fn x_ref(&self) -> &isize {
-        &self.x
-    }
-
-    fn y_mut(&mut self) -> &mut isize {
-        &mut self.y
-    }
-}
-
-fn deref_imm_field(x: Rc<Point>) {
-    let __isize = &x.y;
-}
-
-fn deref_mut_field1(x: Rc<Point>) {
-    let __isize = &mut x.y; //~ ERROR cannot borrow
-}
-
-fn deref_mut_field2(mut x: Rc<Point>) {
-    let __isize = &mut x.y; //~ ERROR cannot borrow
-}
-
-fn deref_extend_field(x: &Rc<Point>) -> &isize {
-    &x.y
-}
-
-fn deref_extend_mut_field1(x: &Rc<Point>) -> &mut isize {
-    &mut x.y //~ ERROR cannot borrow
-}
-
-fn deref_extend_mut_field2(x: &mut Rc<Point>) -> &mut isize {
-    &mut x.y //~ ERROR cannot borrow
-}
-
-fn assign_field1<'a>(x: Rc<Point>) {
-    x.y = 3; //~ ERROR cannot assign
-}
-
-fn assign_field2<'a>(x: &'a Rc<Point>) {
-    x.y = 3; //~ ERROR cannot assign
-}
-
-fn assign_field3<'a>(x: &'a mut Rc<Point>) {
-    x.y = 3; //~ ERROR cannot assign
-}
-
-fn deref_imm_method(x: Rc<Point>) {
-    let __isize = x.get();
-}
-
-fn deref_mut_method1(x: Rc<Point>) {
-    x.set(0, 0); //~ ERROR cannot borrow
-}
-
-fn deref_mut_method2(mut x: Rc<Point>) {
-    x.set(0, 0); //~ ERROR cannot borrow
-}
-
-fn deref_extend_method(x: &Rc<Point>) -> &isize {
-    x.x_ref()
-}
-
-fn deref_extend_mut_method1(x: &Rc<Point>) -> &mut isize {
-    x.y_mut() //~ ERROR cannot borrow
-}
-
-fn deref_extend_mut_method2(x: &mut Rc<Point>) -> &mut isize {
-    x.y_mut() //~ ERROR cannot borrow
-}
-
-fn assign_method1<'a>(x: Rc<Point>) {
-    *x.y_mut() = 3; //~ ERROR cannot borrow
-}
-
-fn assign_method2<'a>(x: &'a Rc<Point>) {
-    *x.y_mut() = 3; //~ ERROR cannot borrow
-}
-
-fn assign_method3<'a>(x: &'a mut Rc<Point>) {
-    *x.y_mut() = 3; //~ ERROR cannot borrow
-}
-
-pub fn main() {}
diff --git a/src/test/compile-fail/borrowck-borrow-overloaded-deref-mut.rs b/src/test/compile-fail/borrowck-borrow-overloaded-deref-mut.rs
deleted file mode 100644 (file)
index 34b926a..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2014 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 how overloaded deref interacts with borrows when DerefMut
-// is implemented.
-
-use std::ops::{Deref, DerefMut};
-
-struct Own<T> {
-    value: *mut T
-}
-
-impl<T> Deref for Own<T> {
-    type Target = T;
-
-    fn deref<'a>(&'a self) -> &'a T {
-        unsafe { &*self.value }
-    }
-}
-
-impl<T> DerefMut for Own<T> {
-    fn deref_mut<'a>(&'a mut self) -> &'a mut T {
-        unsafe { &mut *self.value }
-    }
-}
-
-fn deref_imm(x: Own<isize>) {
-    let __isize = &*x;
-}
-
-fn deref_mut1(x: Own<isize>) {
-    let __isize = &mut *x; //~ ERROR cannot borrow
-}
-
-fn deref_mut2(mut x: Own<isize>) {
-    let __isize = &mut *x;
-}
-
-fn deref_extend<'a>(x: &'a Own<isize>) -> &'a isize {
-    &**x
-}
-
-fn deref_extend_mut1<'a>(x: &'a Own<isize>) -> &'a mut isize {
-    &mut **x //~ ERROR cannot borrow
-}
-
-fn deref_extend_mut2<'a>(x: &'a mut Own<isize>) -> &'a mut isize {
-    &mut **x
-}
-
-fn assign1<'a>(x: Own<isize>) {
-    *x = 3; //~ ERROR cannot borrow
-}
-
-fn assign2<'a>(x: &'a Own<isize>) {
-    **x = 3; //~ ERROR cannot borrow
-}
-
-fn assign3<'a>(x: &'a mut Own<isize>) {
-    **x = 3;
-}
-
-pub fn main() {}
diff --git a/src/test/compile-fail/borrowck-borrow-overloaded-deref.rs b/src/test/compile-fail/borrowck-borrow-overloaded-deref.rs
deleted file mode 100644 (file)
index 5b91624..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2014 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 how overloaded deref interacts with borrows when only
-// Deref and not DerefMut is implemented.
-
-use std::ops::Deref;
-
-struct Rc<T> {
-    value: *const T
-}
-
-impl<T> Deref for Rc<T> {
-    type Target = T;
-
-    fn deref<'a>(&'a self) -> &'a T {
-        unsafe { &*self.value }
-    }
-}
-
-fn deref_imm(x: Rc<isize>) {
-    let __isize = &*x;
-}
-
-fn deref_mut1(x: Rc<isize>) {
-    let __isize = &mut *x; //~ ERROR cannot borrow
-}
-
-fn deref_mut2(mut x: Rc<isize>) {
-    let __isize = &mut *x; //~ ERROR cannot borrow
-}
-
-fn deref_extend<'a>(x: &'a Rc<isize>) -> &'a isize {
-    &**x
-}
-
-fn deref_extend_mut1<'a>(x: &'a Rc<isize>) -> &'a mut isize {
-    &mut **x //~ ERROR cannot borrow
-}
-
-fn deref_extend_mut2<'a>(x: &'a mut Rc<isize>) -> &'a mut isize {
-    &mut **x //~ ERROR cannot borrow
-}
-
-fn assign1<'a>(x: Rc<isize>) {
-    *x = 3; //~ ERROR cannot assign
-}
-
-fn assign2<'a>(x: &'a Rc<isize>) {
-    **x = 3; //~ ERROR cannot assign
-}
-
-fn assign3<'a>(x: &'a mut Rc<isize>) {
-    **x = 3; //~ ERROR cannot assign
-}
-
-pub fn main() {}
diff --git a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs
deleted file mode 100644 (file)
index 309e286..0000000
+++ /dev/null
@@ -1,33 +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 defer<'a> {
-    x: &'a [&'a str],
-}
-
-impl<'a> Drop for defer<'a> {
-    fn drop(&mut self) {
-        unsafe {
-            println!("{:?}", self.x);
-        }
-    }
-}
-
-fn defer<'r>(x: &'r [&'r str]) -> defer<'r> {
-    defer {
-        x: x
-    }
-}
-
-fn main() {
-    let x = defer(&vec!("Goodbye", "world!"));
-    //~^ ERROR borrowed value does not live long enough
-    x.x[0];
-}
diff --git a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs
deleted file mode 100644 (file)
index 8bbecfd..0000000
+++ /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 <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.
-
-//buggy.rs
-
-#![feature(box_syntax)]
-
-extern crate collections;
-use std::collections::HashMap;
-
-fn main() {
-    let tmp: Box<_>;
-    let mut buggy_map: HashMap<usize, &usize> = HashMap::new();
-    // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
-    buggy_map.insert(42, &*Box::new(1)); //~ ERROR borrowed value does not live long enough
-
-    // but it is ok if we use a temporary
-    tmp = box 2;
-    buggy_map.insert(43, &*tmp);
-}
diff --git a/src/test/compile-fail/borrowck-box-insensitivity.rs b/src/test/compile-fail/borrowck-box-insensitivity.rs
deleted file mode 100644 (file)
index c980e77..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-// Copyright 2014 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.
-
-#![feature(box_syntax)]
-
-struct A {
-    x: Box<isize>,
-    y: isize,
-}
-
-struct B {
-    x: Box<isize>,
-    y: Box<isize>,
-}
-
-struct C {
-    x: Box<A>,
-    y: isize,
-}
-
-struct D {
-    x: Box<A>,
-    y: Box<isize>,
-}
-
-fn copy_after_move() {
-    let a: Box<_> = box A { x: box 0, y: 1 };
-    let _x = a.x;
-    let _y = a.y; //~ ERROR use of moved
-    //~^^ NOTE `a` moved here (through moving `a.x`)
-}
-
-fn move_after_move() {
-    let a: Box<_> = box B { x: box 0, y: box 1 };
-    let _x = a.x;
-    let _y = a.y; //~ ERROR use of moved
-    //~^^ NOTE `a` moved here (through moving `a.x`)
-}
-
-fn borrow_after_move() {
-    let a: Box<_> = box A { x: box 0, y: 1 };
-    let _x = a.x;
-    let _y = &a.y; //~ ERROR use of moved
-    //~^^ NOTE `a` moved here (through moving `a.x`)
-}
-
-fn move_after_borrow() {
-    let a: Box<_> = box B { x: box 0, y: box 1 };
-    let _x = &a.x;
-    let _y = a.y; //~ ERROR cannot move
-}
-
-fn copy_after_mut_borrow() {
-    let mut a: Box<_> = box A { x: box 0, y: 1 };
-    let _x = &mut a.x;
-    let _y = a.y; //~ ERROR cannot use
-}
-
-fn move_after_mut_borrow() {
-    let mut a: Box<_> = box B { x: box 0, y: box 1 };
-    let _x = &mut a.x;
-    let _y = a.y; //~ ERROR cannot move
-}
-
-fn borrow_after_mut_borrow() {
-    let mut a: Box<_> = box A { x: box 0, y: 1 };
-    let _x = &mut a.x;
-    let _y = &a.y; //~ ERROR cannot borrow
-}
-
-fn mut_borrow_after_borrow() {
-    let mut a: Box<_> = box A { x: box 0, y: 1 };
-    let _x = &a.x;
-    let _y = &mut a.y; //~ ERROR cannot borrow
-}
-
-fn copy_after_move_nested() {
-    let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
-    let _x = a.x.x;
-    let _y = a.y; //~ ERROR use of collaterally moved
-}
-
-fn move_after_move_nested() {
-    let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
-    let _x = a.x.x;
-    let _y = a.y; //~ ERROR use of collaterally moved
-}
-
-fn borrow_after_move_nested() {
-    let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
-    let _x = a.x.x;
-    let _y = &a.y; //~ ERROR use of collaterally moved
-}
-
-fn move_after_borrow_nested() {
-    let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
-    let _x = &a.x.x;
-    let _y = a.y; //~ ERROR cannot move
-}
-
-fn copy_after_mut_borrow_nested() {
-    let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
-    let _x = &mut a.x.x;
-    let _y = a.y; //~ ERROR cannot use
-}
-
-fn move_after_mut_borrow_nested() {
-    let mut a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
-    let _x = &mut a.x.x;
-    let _y = a.y; //~ ERROR cannot move
-}
-
-fn borrow_after_mut_borrow_nested() {
-    let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
-    let _x = &mut a.x.x;
-    let _y = &a.y; //~ ERROR cannot borrow
-}
-
-fn mut_borrow_after_borrow_nested() {
-    let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
-    let _x = &a.x.x;
-    let _y = &mut a.y; //~ ERROR cannot borrow
-}
-
-fn main() {
-    copy_after_move();
-    move_after_move();
-    borrow_after_move();
-
-    move_after_borrow();
-
-    copy_after_mut_borrow();
-    move_after_mut_borrow();
-    borrow_after_mut_borrow();
-    mut_borrow_after_borrow();
-
-    copy_after_move_nested();
-    move_after_move_nested();
-    borrow_after_move_nested();
-
-    move_after_borrow_nested();
-
-    copy_after_mut_borrow_nested();
-    move_after_mut_borrow_nested();
-    borrow_after_mut_borrow_nested();
-    mut_borrow_after_borrow_nested();
-}
diff --git a/src/test/compile-fail/borrowck-break-uninit-2.rs b/src/test/compile-fail/borrowck-break-uninit-2.rs
deleted file mode 100644 (file)
index 82a6c92..0000000
+++ /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 <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() -> isize {
-    let x: isize;
-
-    while 1 != 2  {
-        break;
-        x = 0;
-    }
-
-    println!("{}", x); //~ ERROR use of possibly uninitialized variable: `x`
-
-    return 17;
-}
-
-fn main() { println!("{}", foo()); }
diff --git a/src/test/compile-fail/borrowck-break-uninit.rs b/src/test/compile-fail/borrowck-break-uninit.rs
deleted file mode 100644 (file)
index 8a6a036..0000000
+++ /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 <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() -> isize {
-    let x: isize;
-
-    loop {
-        break;
-        x = 0;
-    }
-
-    println!("{}", x); //~ ERROR use of possibly uninitialized variable: `x`
-
-    return 17;
-}
-
-fn main() { println!("{}", foo()); }
diff --git a/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs b/src/test/compile-fail/borrowck-call-is-borrow-issue-12224.rs
deleted file mode 100644 (file)
index 7626f35..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright 2014 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.
-
-// Ensure that invoking a closure counts as a unique immutable borrow
-
-#![feature(unboxed_closures)]
-
-type Fn<'a> = Box<FnMut() + 'a>;
-
-struct Test<'a> {
-    f: Box<FnMut() + 'a>
-}
-
-// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
-fn call<F>(mut f: F) where F: FnMut(Fn) {
-    f(Box::new(|| {
-    //~^ ERROR: cannot borrow `f` as mutable more than once
-        f((Box::new(|| {})))
-    }));
-}
-
-fn test1() {
-    call(|mut a| {
-        a.call_mut(());
-    });
-}
-
-fn test2<F>(f: &F) where F: FnMut() {
-    (*f)(); //~ ERROR: cannot borrow immutable borrowed content `*f` as mutable
-}
-
-fn test3<F>(f: &mut F) where F: FnMut() {
-    (*f)();
-}
-
-fn test4(f: &Test) {
-    f.f.call_mut(()) //~ ERROR: cannot borrow immutable `Box` content `*f.f` as mutable
-}
-
-fn test5(f: &mut Test) {
-    f.f.call_mut(())
-}
-
-fn test6() {
-    let mut f = || {};
-    (|| {
-        f();
-    })();
-}
-
-fn test7() {
-    fn foo<F>(_: F) where F: FnMut(Box<FnMut(isize)>, isize) {}
-    let mut f = |g: Box<FnMut(isize)>, b: isize| {};
-    // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
-    f(Box::new(|a| {
-        foo(f);
-        //~^ ERROR cannot move `f` into closure because it is borrowed
-        //~| ERROR cannot move out of captured outer variable in an `FnMut` closure
-    }), 3);
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-call-method-from-mut-aliasable.rs b/src/test/compile-fail/borrowck-call-method-from-mut-aliasable.rs
deleted file mode 100644 (file)
index bc0b667..0000000
+++ /dev/null
@@ -1,31 +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 {
-    x: isize,
-}
-
-impl Foo {
-    pub fn f(&self) {}
-    pub fn h(&mut self) {}
-}
-
-fn a(x: &mut Foo) {
-    x.f();
-    x.h();
-}
-
-fn b(x: &Foo) {
-    x.f();
-    x.h(); //~ ERROR cannot borrow
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-closures-mut-and-imm.rs b/src/test/compile-fail/borrowck-closures-mut-and-imm.rs
deleted file mode 100644 (file)
index aaa0766..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2014 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 that two closures cannot simultaneously have mutable
-// and immutable access to the variable. Issue #6801.
-
-#![feature(box_syntax)]
-
-fn get(x: &isize) -> isize {
-    *x
-}
-
-fn set(x: &mut isize) {
-    *x = 4;
-}
-
-fn a() {
-    let mut x = 3;
-    let c1 = || x = 4;
-    let c2 = || x * 5; //~ ERROR cannot borrow `x`
-}
-
-fn b() {
-    let mut x = 3;
-    let c1 = || set(&mut x);
-    let c2 = || get(&x); //~ ERROR cannot borrow `x`
-}
-
-fn c() {
-    let mut x = 3;
-    let c1 = || set(&mut x);
-    let c2 = || x * 5; //~ ERROR cannot borrow `x`
-}
-
-fn d() {
-    let mut x = 3;
-    let c2 = || x * 5;
-    x = 5; //~ ERROR cannot assign
-}
-
-fn e() {
-    let mut x = 3;
-    let c1 = || get(&x);
-    x = 5; //~ ERROR cannot assign
-}
-
-fn f() {
-    let mut x: Box<_> = box 3;
-    let c1 = || get(&*x);
-    *x = 5; //~ ERROR cannot assign
-}
-
-fn g() {
-    struct Foo {
-        f: Box<isize>
-    }
-
-    let mut x: Box<_> = box Foo { f: box 3 };
-    let c1 = || get(&*x.f);
-    *x.f = 5; //~ ERROR cannot assign to `*x.f`
-}
-
-fn h() {
-    struct Foo {
-        f: Box<isize>
-    }
-
-    let mut x: Box<_> = box Foo { f: box 3 };
-    let c1 = || get(&*x.f);
-    let c2 = || *x.f = 5; //~ ERROR cannot borrow `x` as mutable
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-closures-mut-of-imm.rs b/src/test/compile-fail/borrowck-closures-mut-of-imm.rs
deleted file mode 100644 (file)
index 40f9be2..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2014 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 that two closures cannot simultaneously have mutable
-// and immutable access to the variable. Issue #6801.
-
-fn get(x: &isize) -> isize {
-    *x
-}
-
-fn set(x: &mut isize) {
-    *x = 4;
-}
-
-fn a(x: &isize) {
-    let c1 = || set(&mut *x);
-    //~^ ERROR cannot borrow
-    let c2 = || set(&mut *x);
-    //~^ ERROR cannot borrow
-    //~| ERROR closure requires unique access
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-closures-two-mut.rs b/src/test/compile-fail/borrowck-closures-two-mut.rs
deleted file mode 100644 (file)
index 29546ab..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2014 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 that two closures cannot simultaneously have mutable
-// access to the variable, whether that mutable access be used
-// for direct assignment or for taking mutable ref. Issue #6801.
-
-#![feature(box_syntax)]
-
-fn to_fn_mut<F: FnMut()>(f: F) -> F { f }
-
-fn a() {
-    let mut x = 3;
-    let c1 = to_fn_mut(|| x = 4);
-    let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable more than once
-}
-
-fn set(x: &mut isize) {
-    *x = 4;
-}
-
-fn b() {
-    let mut x = 3;
-    let c1 = to_fn_mut(|| set(&mut x));
-    let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as mutable more than once
-}
-
-fn c() {
-    let mut x = 3;
-    let c1 = to_fn_mut(|| x = 5);
-    let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as mutable more than once
-}
-
-fn d() {
-    let mut x = 3;
-    let c1 = to_fn_mut(|| x = 5);
-    let c2 = to_fn_mut(|| { let _y = to_fn_mut(|| set(&mut x)); }); // (nested closure)
-    //~^ ERROR cannot borrow `x` as mutable more than once
-}
-
-fn g() {
-    struct Foo {
-        f: Box<isize>
-    }
-
-    let mut x: Box<_> = box Foo { f: box 3 };
-    let c1 = to_fn_mut(|| set(&mut *x.f));
-    let c2 = to_fn_mut(|| set(&mut *x.f));
-    //~^ ERROR cannot borrow `x` as mutable more than once
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-closures-unique-imm.rs b/src/test/compile-fail/borrowck-closures-unique-imm.rs
deleted file mode 100644 (file)
index 247a4fe..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2014 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 {
-    x: isize,
-}
-
-pub fn main() {
-    let mut this = &mut Foo {
-        x: 1,
-    };
-    let mut r = || {
-        let p = &this.x;
-        &mut this.x; //~ ERROR cannot borrow
-    };
-    r()
-}
diff --git a/src/test/compile-fail/borrowck-closures-unique.rs b/src/test/compile-fail/borrowck-closures-unique.rs
deleted file mode 100644 (file)
index 3646a68..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2014 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 that a closure which requires mutable access to the referent
-// of an `&mut` requires a "unique" borrow -- that is, the variable to
-// be borrowed (here, `x`) will not be borrowed *mutably*, but
-//  may be *immutable*, but we cannot allow
-// multiple borrows.
-
-fn get(x: &isize) -> isize {
-    *x
-}
-
-fn set(x: &mut isize) -> isize {
-    *x
-}
-
-fn a(x: &mut isize) {
-    let c1 = || get(x);
-    let c2 = || get(x);
-}
-
-fn b(x: &mut isize) {
-    let c1 = || get(x);
-    let c2 = || set(x); //~ ERROR closure requires unique access to `x`
-}
-
-fn c(x: &mut isize) {
-    let c1 = || get(x);
-    let c2 = || { get(x); set(x); }; //~ ERROR closure requires unique access to `x`
-}
-
-fn d(x: &mut isize) {
-    let c1 = || set(x);
-    let c2 = || set(x); //~ ERROR closure requires unique access to `x`
-}
-
-fn e(x: &mut isize) {
-    let c1 = || x = panic!(); //~ ERROR closure cannot assign to immutable argument
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-closures-use-after-free.rs b/src/test/compile-fail/borrowck-closures-use-after-free.rs
deleted file mode 100644 (file)
index bb47434..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2014 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 that a closure which mutates a local variable
-// cannot also be supplied a borrowed version of that
-// variable's contents. Issue #11192.
-
-#![feature(box_syntax)]
-
-struct Foo {
-  x: isize
-}
-
-impl Drop for Foo {
-  fn drop(&mut self) {
-    println!("drop {}", self.x);
-  }
-}
-
-fn main() {
-  let mut ptr: Box<_> = box Foo { x: 0 };
-  let mut test = |foo: &Foo| {
-    ptr = box Foo { x: ptr.x + 1 };
-  };
-  test(&*ptr); //~ ERROR cannot borrow `*ptr`
-}
diff --git a/src/test/compile-fail/borrowck-consume-unsize-vec.rs b/src/test/compile-fail/borrowck-consume-unsize-vec.rs
deleted file mode 100644 (file)
index 32490e0..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2015 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.
-
-// Check that we report an error if an upcast box is moved twice.
-
-fn consume(_: Box<[i32]>) {
-}
-
-fn foo(b: Box<[i32;5]>) {
-    consume(b);
-    consume(b); //~ ERROR use of moved value
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-consume-upcast-box.rs b/src/test/compile-fail/borrowck-consume-upcast-box.rs
deleted file mode 100644 (file)
index 5bcafa6..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2015 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.
-
-// Check that we report an error if an upcast box is moved twice.
-
-trait Foo { fn dummy(&self); }
-
-fn consume(_: Box<Foo>) {
-}
-
-fn foo(b: Box<Foo+Send>) {
-    consume(b);
-    consume(b); //~ ERROR use of moved value
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-escaping-closure-error-1.rs b/src/test/compile-fail/borrowck-escaping-closure-error-1.rs
deleted file mode 100644 (file)
index 87e40df..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2015 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.
-
-use std::thread::spawn;
-
-// Test that we give a custom error (E0373) for the case where a
-// closure is escaping current frame, and offer a suggested code edit.
-// I refrained from including the precise message here, but the
-// original text as of the time of this writing is:
-//
-//    closure may outlive the current function, but it borrows `books`,
-//    which is owned by the current function
-
-fn main() {
-    let mut books = vec![1,2,3];
-    spawn(|| books.push(4));
-    //~^ ERROR E0373
-}
diff --git a/src/test/compile-fail/borrowck-escaping-closure-error-2.rs b/src/test/compile-fail/borrowck-escaping-closure-error-2.rs
deleted file mode 100644 (file)
index 67700be..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2015 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 give a custom error (E0373) for the case where a
-// closure is escaping current frame, and offer a suggested code edit.
-// I refrained from including the precise message here, but the
-// original text as of the time of this writing is:
-//
-//    closure may outlive the current function, but it borrows `books`,
-//    which is owned by the current function
-
-fn foo<'a>(x: &'a i32) -> Box<FnMut()+'a> {
-    let mut books = vec![1,2,3];
-    Box::new(|| books.push(4))
-    //~^ ERROR E0373
-}
-
-fn main() { }
diff --git a/src/test/compile-fail/borrowck-field-sensitivity.rs b/src/test/compile-fail/borrowck-field-sensitivity.rs
deleted file mode 100644 (file)
index 13fd5fc..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-// Copyright 2014 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.
-
-#![feature(box_syntax)]
-
-struct A { a: isize, b: Box<isize> }
-
-fn deref_after_move() {
-    let x = A { a: 1, b: box 2 };
-    drop(x.b);
-    drop(*x.b); //~ ERROR use of moved value: `*x.b`
-}
-
-fn deref_after_fu_move() {
-    let x = A { a: 1, b: box 2 };
-    let y = A { a: 3, .. x };
-    drop(*x.b); //~ ERROR use of moved value: `*x.b`
-}
-
-fn borrow_after_move() {
-    let x = A { a: 1, b: box 2 };
-    drop(x.b);
-    let p = &x.b; //~ ERROR use of moved value: `x.b`
-    drop(**p);
-}
-
-fn borrow_after_fu_move() {
-    let x = A { a: 1, b: box 2 };
-    let _y = A { a: 3, .. x };
-    let p = &x.b; //~ ERROR use of moved value: `x.b`
-    drop(**p);
-}
-
-fn move_after_borrow() {
-    let x = A { a: 1, b: box 2 };
-    let p = &x.b;
-    drop(x.b); //~ ERROR cannot move out of `x.b` because it is borrowed
-    drop(**p);
-}
-
-fn fu_move_after_borrow() {
-    let x = A { a: 1, b: box 2 };
-    let p = &x.b;
-    let _y = A { a: 3, .. x }; //~ ERROR cannot move out of `x.b` because it is borrowed
-    drop(**p);
-}
-
-fn mut_borrow_after_mut_borrow() {
-    let mut x = A { a: 1, b: box 2 };
-    let p = &mut x.a;
-    let q = &mut x.a; //~ ERROR cannot borrow `x.a` as mutable more than once at a time
-    drop(*p);
-    drop(*q);
-}
-
-fn move_after_move() {
-    let x = A { a: 1, b: box 2 };
-    drop(x.b);
-    drop(x.b);  //~ ERROR use of moved value: `x.b`
-}
-
-fn move_after_fu_move() {
-    let x = A { a: 1, b: box 2 };
-    let _y = A { a: 3, .. x };
-    drop(x.b);  //~ ERROR use of moved value: `x.b`
-}
-
-fn fu_move_after_move() {
-    let x = A { a: 1, b: box 2 };
-    drop(x.b);
-    let _z = A { a: 3, .. x };  //~ ERROR use of moved value: `x.b`
-}
-
-fn fu_move_after_fu_move() {
-    let x = A { a: 1, b: box 2 };
-    let _y = A { a: 3, .. x };
-    let _z = A { a: 4, .. x };  //~ ERROR use of moved value: `x.b`
-}
-
-// The following functions aren't yet accepted, but they should be.
-
-fn copy_after_field_assign_after_uninit() {
-    let mut x: A;
-    x.a = 1;
-    drop(x.a); //~ ERROR use of possibly uninitialized variable: `x.a`
-}
-
-fn borrow_after_field_assign_after_uninit() {
-    let mut x: A;
-    x.a = 1;
-    let p = &x.a; //~ ERROR use of possibly uninitialized variable: `x.a`
-    drop(*p);
-}
-
-fn move_after_field_assign_after_uninit() {
-    let mut x: A;
-    x.b = box 1;
-    drop(x.b); //~ ERROR use of possibly uninitialized variable: `x.b`
-}
-
-fn main() {
-    deref_after_move();
-    deref_after_fu_move();
-
-    borrow_after_move();
-    borrow_after_fu_move();
-    move_after_borrow();
-    fu_move_after_borrow();
-    mut_borrow_after_mut_borrow();
-
-    move_after_move();
-    move_after_fu_move();
-    fu_move_after_move();
-    fu_move_after_fu_move();
-
-    copy_after_field_assign_after_uninit();
-    borrow_after_field_assign_after_uninit();
-    move_after_field_assign_after_uninit();
-}
diff --git a/src/test/compile-fail/borrowck-fn-in-const-a.rs b/src/test/compile-fail/borrowck-fn-in-const-a.rs
deleted file mode 100644 (file)
index 3098807..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2014 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.
-
-// Check that we check fns appearing in constant declarations.
-// Issue #22382.
-
-const MOVE: fn(&String) -> String = {
-    fn broken(x: &String) -> String {
-        return *x //~ ERROR cannot move
-    }
-    broken
-};
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-fn-in-const-b.rs b/src/test/compile-fail/borrowck-fn-in-const-b.rs
deleted file mode 100644 (file)
index 7e29b2e..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2014 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.
-
-// Check that we check fns appearing in constant declarations.
-// Issue #22382.
-
-// How about mutating an immutable vector?
-const MUTATE: fn(&Vec<String>) = {
-    fn broken(x: &Vec<String>) {
-        x.push(format!("this is broken"));
-        //~^ ERROR cannot borrow
-    }
-    broken
-};
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-fn-in-const-c.rs b/src/test/compile-fail/borrowck-fn-in-const-c.rs
deleted file mode 100644 (file)
index e607397..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2014 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.
-
-// Check that we check fns appearing in constant declarations.
-// Issue #22382.
-
-// Returning local references?
-struct DropString {
-    inner: String
-}
-impl Drop for DropString {
-    fn drop(&mut self) {
-        self.inner.clear();
-        self.inner.push_str("dropped");
-    }
-}
-const LOCAL_REF: fn() -> &'static str = {
-    fn broken() -> &'static str {
-        let local = DropString { inner: format!("Some local string") };
-        return &local.inner; //~ ERROR does not live long enough
-    }
-    broken
-};
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-for-loop-correct-cmt-for-pattern.rs b/src/test/compile-fail/borrowck-for-loop-correct-cmt-for-pattern.rs
deleted file mode 100644 (file)
index 31ec5ae..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2014 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 #16205.
-
-#![feature(box_syntax)]
-
-struct Foo {
-    a: [Box<isize>; 3],
-}
-
-fn main() {
-    let mut y = 1;
-    let x = Some(&mut y);
-    for &a in x.iter() {    //~ ERROR cannot move out
-    }
-
-    let f = Foo {
-        a: [box 3, box 4, box 5],
-    };
-    for &a in &f.a {  //~ ERROR cannot move out
-    }
-
-    let x: Option<Box<_>> = Some(box 1);
-    for &a in x.iter() {    //~ ERROR cannot move out
-    }
-}
diff --git a/src/test/compile-fail/borrowck-for-loop-head-linkage.rs b/src/test/compile-fail/borrowck-for-loop-head-linkage.rs
deleted file mode 100644 (file)
index b79fc5b..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2014 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.
-
-use std::iter::repeat;
-
-fn main() {
-    let mut vector = vec![1, 2];
-    for &x in &vector {
-        let cap = vector.capacity();
-        vector.extend(repeat(0));      //~ ERROR cannot borrow
-        vector[1] = 5;   //~ ERROR cannot borrow
-    }
-}
diff --git a/src/test/compile-fail/borrowck-if-no-else.rs b/src/test/compile-fail/borrowck-if-no-else.rs
deleted file mode 100644 (file)
index 74b5428..0000000
+++ /dev/null
@@ -1,16 +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: isize) { println!("{}", x); }
-
-fn main() {
-    let x: isize; if 1 > 2 { x = 10; }
-    foo(x); //~ ERROR use of possibly uninitialized variable: `x`
-}
diff --git a/src/test/compile-fail/borrowck-if-with-else.rs b/src/test/compile-fail/borrowck-if-with-else.rs
deleted file mode 100644 (file)
index f3b02d1..0000000
+++ /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 <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: isize) { println!("{}", x); }
-
-fn main() {
-    let x: isize;
-    if 1 > 2 {
-        println!("whoops");
-    } else {
-        x = 10;
-    }
-    foo(x); //~ ERROR use of possibly uninitialized variable: `x`
-}
diff --git a/src/test/compile-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162-c.rs b/src/test/compile-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162-c.rs
deleted file mode 100644 (file)
index 8af1023..0000000
+++ /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 <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 main() {
-    let mut _a = 3;
-    let _b = &mut _a;
-    {
-        let _c = &*_b;
-        _a = 4; //~ ERROR cannot assign to `_a`
-    }
-}
diff --git a/src/test/compile-fail/borrowck-in-static.rs b/src/test/compile-fail/borrowck-in-static.rs
deleted file mode 100644 (file)
index 16b0e86..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2015 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.
-
-// check that borrowck looks inside consts/statics
-
-static FN : &'static (Fn() -> (Box<Fn()->Box<i32>>) + Sync) = &|| {
-    let x = Box::new(0);
-    Box::new(|| x) //~ ERROR cannot move out of captured outer variable
-};
-
-fn main() {
-    let f = (FN)();
-    f();
-    f();
-}
diff --git a/src/test/compile-fail/borrowck-init-in-called-fn-expr.rs b/src/test/compile-fail/borrowck-init-in-called-fn-expr.rs
deleted file mode 100644 (file)
index 5b32fd2..0000000
+++ /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 <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 main() {
-    let j = || -> isize {
-        let i: isize;
-        i //~ ERROR use of possibly uninitialized variable: `i`
-    };
-    j();
-}
diff --git a/src/test/compile-fail/borrowck-init-in-fn-expr.rs b/src/test/compile-fail/borrowck-init-in-fn-expr.rs
deleted file mode 100644 (file)
index 65f1a1f..0000000
+++ /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 <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 main() {
-    let f  = || -> isize {
-        let i: isize;
-        i //~ ERROR use of possibly uninitialized variable: `i`
-    };
-    println!("{}", f());
-}
diff --git a/src/test/compile-fail/borrowck-init-in-fru.rs b/src/test/compile-fail/borrowck-init-in-fru.rs
deleted file mode 100644 (file)
index 569ddb8..0000000
+++ /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 <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.
-
-#[derive(Clone)]
-struct point {
-    x: isize,
-    y: isize,
-}
-
-fn main() {
-    let mut origin: point;
-    origin = point {x: 10,.. origin}; //~ ERROR use of possibly uninitialized variable: `origin.y`
-    origin.clone();
-}
diff --git a/src/test/compile-fail/borrowck-init-op-equal.rs b/src/test/compile-fail/borrowck-init-op-equal.rs
deleted file mode 100644 (file)
index e0d93fd..0000000
+++ /dev/null
@@ -1,19 +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() {
-    let v: isize;
-    v += 1; //~ ERROR use of possibly uninitialized variable: `v`
-    v.clone();
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-init-plus-equal.rs b/src/test/compile-fail/borrowck-init-plus-equal.rs
deleted file mode 100644 (file)
index a036286..0000000
+++ /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 <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() {
-    let mut v: isize;
-    v = v + 1; //~ ERROR use of possibly uninitialized variable: `v`
-    v.clone();
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-insert-during-each.rs b/src/test/compile-fail/borrowck-insert-during-each.rs
deleted file mode 100644 (file)
index 2c63486..0000000
+++ /dev/null
@@ -1,36 +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.
-
-extern crate collections;
-use std::collections::HashSet;
-
-struct Foo {
-  n: HashSet<isize>,
-}
-
-impl Foo {
-    pub fn foo<F>(&mut self, mut fun: F) where F: FnMut(&isize) {
-        for f in &self.n {
-            fun(f);
-        }
-    }
-}
-
-fn bar(f: &mut Foo) {
-  f.foo(
-        |a| { //~ ERROR closure requires unique access to `f`
-            f.n.insert(*a);
-        })
-}
-
-fn main() {
-  let mut f = Foo { n: HashSet::new() };
-  bar(&mut f);
-}
diff --git a/src/test/compile-fail/borrowck-issue-14498.rs b/src/test/compile-fail/borrowck-issue-14498.rs
deleted file mode 100644 (file)
index 6403362..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-// Copyright 2014 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.
-
-// This tests that we can't modify Box<&mut T> contents while they
-// are borrowed (#14498).
-//
-// Also includes tests of the errors reported when the Box in question
-// is immutable (#14270).
-
-#![feature(box_syntax)]
-
-struct A { a: isize }
-struct B<'a> { a: Box<&'a mut isize> }
-
-fn indirect_write_to_imm_box() {
-    let mut x: isize = 1;
-    let y: Box<_> = box &mut x;
-    let p = &y;
-    ***p = 2; //~ ERROR cannot assign to data in an immutable container
-    drop(p);
-}
-
-fn borrow_in_var_from_var() {
-    let mut x: isize = 1;
-    let mut y: Box<_> = box &mut x;
-    let p = &y;
-    let q = &***p;
-    **y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
-    drop(p);
-    drop(q);
-}
-
-fn borrow_in_var_from_var_via_imm_box() {
-    let mut x: isize = 1;
-    let y: Box<_> = box &mut x;
-    let p = &y;
-    let q = &***p;
-    **y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
-    //~^         ERROR cannot assign to data in an immutable container
-    drop(p);
-    drop(q);
-}
-
-fn borrow_in_var_from_field() {
-    let mut x = A { a: 1 };
-    let mut y: Box<_> = box &mut x.a;
-    let p = &y;
-    let q = &***p;
-    **y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
-    drop(p);
-    drop(q);
-}
-
-fn borrow_in_var_from_field_via_imm_box() {
-    let mut x = A { a: 1 };
-    let y: Box<_> = box &mut x.a;
-    let p = &y;
-    let q = &***p;
-    **y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
-    //~^         ERROR cannot assign to data in an immutable container
-    drop(p);
-    drop(q);
-}
-
-fn borrow_in_field_from_var() {
-    let mut x: isize = 1;
-    let mut y = B { a: box &mut x };
-    let p = &y.a;
-    let q = &***p;
-    **y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
-    drop(p);
-    drop(q);
-}
-
-fn borrow_in_field_from_var_via_imm_box() {
-    let mut x: isize = 1;
-    let y = B { a: box &mut x };
-    let p = &y.a;
-    let q = &***p;
-    **y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
-    //~^           ERROR cannot assign to data in an immutable container
-    drop(p);
-    drop(q);
-}
-
-fn borrow_in_field_from_field() {
-    let mut x = A { a: 1 };
-    let mut y = B { a: box &mut x.a };
-    let p = &y.a;
-    let q = &***p;
-    **y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
-    drop(p);
-    drop(q);
-}
-
-fn borrow_in_field_from_field_via_imm_box() {
-    let mut x = A { a: 1 };
-    let y = B { a: box &mut x.a };
-    let p = &y.a;
-    let q = &***p;
-    **y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
-    //~^           ERROR cannot assign to data in an immutable container
-    drop(p);
-    drop(q);
-}
-
-fn main() {
-    indirect_write_to_imm_box();
-    borrow_in_var_from_var();
-    borrow_in_var_from_var_via_imm_box();
-    borrow_in_var_from_field();
-    borrow_in_var_from_field_via_imm_box();
-    borrow_in_field_from_var();
-    borrow_in_field_from_var_via_imm_box();
-    borrow_in_field_from_field();
-    borrow_in_field_from_field_via_imm_box();
-}
diff --git a/src/test/compile-fail/borrowck-issue-2657-1.rs b/src/test/compile-fail/borrowck-issue-2657-1.rs
deleted file mode 100644 (file)
index 0e17121..0000000
+++ /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 <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.
-
-#![feature(box_syntax)]
-
-fn main() {
-    let x: Option<Box<_>> = Some(box 1);
-    match x {
-      Some(ref _y) => {
-        let _a = x; //~ ERROR cannot move
-      }
-      _ => {}
-    }
-}
diff --git a/src/test/compile-fail/borrowck-issue-2657-2.rs b/src/test/compile-fail/borrowck-issue-2657-2.rs
deleted file mode 100644 (file)
index a389a4a..0000000
+++ /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 <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.
-
-#![feature(box_syntax)]
-
-fn main() {
-    let x: Option<Box<_>> = Some(box 1);
-    match x {
-      Some(ref y) => {
-        let _b = *y; //~ ERROR cannot move out
-      }
-      _ => {}
-    }
-}
diff --git a/src/test/compile-fail/borrowck-lend-flow-if.rs b/src/test/compile-fail/borrowck-lend-flow-if.rs
deleted file mode 100644 (file)
index a6ce36a..0000000
+++ /dev/null
@@ -1,54 +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.
-
-// Note: the borrowck analysis is currently flow-insensitive.
-// Therefore, some of these errors are marked as spurious and could be
-// corrected by a simple change to the analysis.  The others are
-// either genuine or would require more advanced changes.  The latter
-// cases are noted.
-
-#![feature(box_syntax)]
-
-fn borrow(_v: &isize) {}
-fn borrow_mut(_v: &mut isize) {}
-fn cond() -> bool { panic!() }
-fn for_func<F>(_f: F) where F: FnOnce() -> bool { panic!() }
-fn produce<T>() -> T { panic!(); }
-
-fn inc(v: &mut Box<isize>) {
-    *v = box (**v + 1);
-}
-
-fn pre_freeze_cond() {
-    // In this instance, the freeze is conditional and starts before
-    // the mut borrow.
-
-    let mut v: Box<_> = box 3;
-    let _w;
-    if cond() {
-        _w = &v;
-    }
-    borrow_mut(&mut *v); //~ ERROR cannot borrow
-}
-
-fn pre_freeze_else() {
-    // In this instance, the freeze and mut borrow are on separate sides
-    // of the if.
-
-    let mut v: Box<_> = box 3;
-    let _w;
-    if cond() {
-        _w = &v;
-    } else {
-        borrow_mut(&mut *v);
-    }
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-lend-flow-loop.rs b/src/test/compile-fail/borrowck-lend-flow-loop.rs
deleted file mode 100644 (file)
index f09e7ff..0000000
+++ /dev/null
@@ -1,150 +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.
-
-// Note: the borrowck analysis is currently flow-insensitive.
-// Therefore, some of these errors are marked as spurious and could be
-// corrected by a simple change to the analysis.  The others are
-// either genuine or would require more advanced changes.  The latter
-// cases are noted.
-
-#![feature(box_syntax)]
-
-fn borrow(_v: &isize) {}
-fn borrow_mut(_v: &mut isize) {}
-fn cond() -> bool { panic!() }
-fn produce<T>() -> T { panic!(); }
-
-fn inc(v: &mut Box<isize>) {
-    *v = box (**v + 1);
-}
-
-fn loop_overarching_alias_mut() {
-    // In this instance, the borrow encompasses the entire loop.
-
-    let mut v: Box<_> = box 3;
-    let mut x = &mut v;
-    **x += 1;
-    loop {
-        borrow(&*v); //~ ERROR cannot borrow
-    }
-}
-
-fn block_overarching_alias_mut() {
-    // In this instance, the borrow encompasses the entire closure call.
-
-    let mut v: Box<_> = box 3;
-    let mut x = &mut v;
-    for _ in 0..3 {
-        borrow(&*v); //~ ERROR cannot borrow
-    }
-    *x = box 5;
-}
-
-fn loop_aliased_mut() {
-    // In this instance, the borrow is carried through the loop.
-
-    let mut v: Box<_> = box 3;
-    let mut w: Box<_> = box 4;
-    let mut _x = &w;
-    loop {
-        borrow_mut(&mut *v); //~ ERROR cannot borrow
-        _x = &v;
-    }
-}
-
-fn while_aliased_mut() {
-    // In this instance, the borrow is carried through the loop.
-
-    let mut v: Box<_> = box 3;
-    let mut w: Box<_> = box 4;
-    let mut _x = &w;
-    while cond() {
-        borrow_mut(&mut *v); //~ ERROR cannot borrow
-        _x = &v;
-    }
-}
-
-
-fn loop_aliased_mut_break() {
-    // In this instance, the borrow is carried through the loop.
-
-    let mut v: Box<_> = box 3;
-    let mut w: Box<_> = box 4;
-    let mut _x = &w;
-    loop {
-        borrow_mut(&mut *v);
-        _x = &v;
-        break;
-    }
-    borrow_mut(&mut *v); //~ ERROR cannot borrow
-}
-
-fn while_aliased_mut_break() {
-    // In this instance, the borrow is carried through the loop.
-
-    let mut v: Box<_> = box 3;
-    let mut w: Box<_> = box 4;
-    let mut _x = &w;
-    while cond() {
-        borrow_mut(&mut *v);
-        _x = &v;
-        break;
-    }
-    borrow_mut(&mut *v); //~ ERROR cannot borrow
-}
-
-fn while_aliased_mut_cond(cond: bool, cond2: bool) {
-    let mut v: Box<_> = box 3;
-    let mut w: Box<_> = box 4;
-    let mut x = &mut w;
-    while cond {
-        **x += 1;
-        borrow(&*v); //~ ERROR cannot borrow
-        if cond2 {
-            x = &mut v; //~ ERROR cannot borrow
-        }
-    }
-}
-
-fn loop_break_pops_scopes<'r, F>(_v: &'r mut [usize], mut f: F) where
-    F: FnMut(&'r mut usize) -> bool,
-{
-    // Here we check that when you break out of an inner loop, the
-    // borrows that go out of scope as you exit the inner loop are
-    // removed from the bitset.
-
-    while cond() {
-        while cond() {
-            // this borrow is limited to the scope of `r`...
-            let r: &'r mut usize = produce();
-            if !f(&mut *r) {
-                break; // ...so it is not live as exit the `while` loop here
-            }
-        }
-    }
-}
-
-fn loop_loop_pops_scopes<'r, F>(_v: &'r mut [usize], mut f: F)
-    where F: FnMut(&'r mut usize) -> bool
-{
-    // Similar to `loop_break_pops_scopes` but for the `loop` keyword
-
-    while cond() {
-        while cond() {
-            // this borrow is limited to the scope of `r`...
-            let r: &'r mut usize = produce();
-            if !f(&mut *r) {
-                continue; // ...so it is not live as exit (and re-enter) the `while` loop here
-            }
-        }
-    }
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-lend-flow-match.rs b/src/test/compile-fail/borrowck-lend-flow-match.rs
deleted file mode 100644 (file)
index f24e82d..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2012-2014 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.
-
-#![allow(unused_variables)]
-#![allow(unused_assignments)]
-
-fn separate_arms() {
-    // Here both arms perform assignments, but only is illegal.
-
-    let mut x = None;
-    match x {
-        None => {
-            // It is ok to reassign x here, because there is in
-            // fact no outstanding loan of x!
-            x = Some(0);
-        }
-        Some(ref __isize) => {
-            x = Some(1); //~ ERROR cannot assign
-        }
-    }
-    x.clone(); // just to prevent liveness warnings
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-lend-flow.rs b/src/test/compile-fail/borrowck-lend-flow.rs
deleted file mode 100644 (file)
index 1ed779c..0000000
+++ /dev/null
@@ -1,45 +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.
-
-// Note: the borrowck analysis is currently flow-insensitive.
-// Therefore, some of these errors are marked as spurious and could be
-// corrected by a simple change to the analysis.  The others are
-// either genuine or would require more advanced changes.  The latter
-// cases are noted.
-
-#![feature(box_syntax)]
-
-fn borrow(_v: &isize) {}
-fn borrow_mut(_v: &mut isize) {}
-fn cond() -> bool { panic!() }
-fn for_func<F>(_f: F) where F: FnOnce() -> bool { panic!() }
-fn produce<T>() -> T { panic!(); }
-
-fn inc(v: &mut Box<isize>) {
-    *v = box (**v + 1);
-}
-
-fn pre_freeze() {
-    // In this instance, the freeze starts before the mut borrow.
-
-    let mut v: Box<_> = box 3;
-    let _w = &v;
-    borrow_mut(&mut *v); //~ ERROR cannot borrow
-}
-
-fn post_freeze() {
-    // In this instance, the const alias starts after the borrow.
-
-    let mut v: Box<_> = box 3;
-    borrow_mut(&mut *v);
-    let _w = &v;
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-let-suggestion-suffixes.rs b/src/test/compile-fail/borrowck-let-suggestion-suffixes.rs
deleted file mode 100644 (file)
index f551a2a..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2015 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 f() {
-    let old = ['o'];         // statement 0
-    let mut v1 = Vec::new(); // statement 1
-
-    let mut v2 = Vec::new(); // statement 2
-    //~^ NOTE reference must be valid for the block suffix following statement 2
-
-    let young = ['y'];       // statement 3
-    //~^ NOTE ...but borrowed value is only valid for the block suffix following statement 3
-
-    v2.push(&young[0]);      // statement 4
-    //~^ ERROR `young[..]` does not live long enough
-
-    let mut v3 = Vec::new(); // statement 5
-    //~^ NOTE reference must be valid for the block suffix following statement 5
-
-    v3.push(&'x');           // statement 6
-    //~^ ERROR borrowed value does not live long enough
-    //~| NOTE ...but borrowed value is only valid for the statement
-    //~| HELP consider using a `let` binding to increase its lifetime
-
-    {
-
-        let mut v4 = Vec::new(); // (sub) statement 0
-        //~^ NOTE reference must be valid for the block suffix following statement 0
-
-        v4.push(&'y');
-        //~^ ERROR borrowed value does not live long enough
-        //~| NOTE ...but borrowed value is only valid for the statement
-        //~| HELP consider using a `let` binding to increase its lifetime
-
-    }                       // (statement 7)
-
-    let mut v5 = Vec::new(); // statement 8
-    //~^ NOTE reference must be valid for the block suffix following statement 8
-
-    v5.push(&'z');
-    //~^ ERROR borrowed value does not live long enough
-    //~| NOTE ...but borrowed value is only valid for the statement
-    //~| HELP consider using a `let` binding to increase its lifetime
-
-    v1.push(&old[0]);
-}
-
-fn main() {
-    f();
-}
diff --git a/src/test/compile-fail/borrowck-let-suggestion.rs b/src/test/compile-fail/borrowck-let-suggestion.rs
deleted file mode 100644 (file)
index d760f3d..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2014 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 f() {
-    let x = [1].iter(); //~ ERROR borrowed value does not live long enough
-                         //~^ NOTE reference must be valid for the block suffix following statement
-                         //~^^ HELP consider using a `let` binding to increase its lifetime
-}
-
-fn main() {
-    f();
-}
diff --git a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs
deleted file mode 100644 (file)
index 57b584a..0000000
+++ /dev/null
@@ -1,38 +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.
-
-#![feature(box_syntax)]
-
-use std::thread;
-
-fn borrow<F>(v: &isize, f: F) where F: FnOnce(&isize) {
-    f(v);
-}
-
-fn box_imm() {
-    let v: Box<_> = box 3;
-    let _w = &v;
-    thread::spawn(move|| {
-        println!("v={}", *v);
-        //~^ ERROR cannot move `v` into closure
-    });
-}
-
-fn box_imm_explicit() {
-    let v: Box<_> = box 3;
-    let _w = &v;
-    thread::spawn(move|| {
-        println!("v={}", *v);
-        //~^ ERROR cannot move
-    });
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-loan-blocks-move.rs b/src/test/compile-fail/borrowck-loan-blocks-move.rs
deleted file mode 100644 (file)
index f3f1880..0000000
+++ /dev/null
@@ -1,23 +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.
-
-#![feature(box_syntax)]
-
-fn take(_v: Box<isize>) {
-}
-
-fn box_imm() {
-    let v = box 3;
-    let _w = &v;
-    take(v); //~ ERROR cannot move out of `v` because it is borrowed
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs b/src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs
deleted file mode 100644 (file)
index 32d8088..0000000
+++ /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 <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.
-
-#![feature(box_syntax)]
-
-fn borrow<F>(v: &isize, f: F) where F: FnOnce(&isize) {
-    f(v);
-}
-
-fn box_imm() {
-    let mut v: Box<_> = box 3;
-    borrow(&*v,
-           |w| { //~ ERROR cannot borrow `v` as mutable
-            v = box 4;
-            assert_eq!(*v, 3);
-            assert_eq!(*w, 4);
-        })
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs b/src/test/compile-fail/borrowck-loan-in-overloaded-op.rs
deleted file mode 100644 (file)
index a9079cf..0000000
+++ /dev/null
@@ -1,33 +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.
-
-#![feature(box_patterns)]
-#![feature(box_syntax)]
-
-use std::ops::Add;
-
-#[derive(Clone)]
-struct foo(Box<usize>);
-
-impl Add for foo {
-    type Output = foo;
-
-    fn add(self, f: foo) -> foo {
-        let foo(box i) = self;
-        let foo(box j) = f;
-        foo(box (i + j))
-    }
-}
-
-fn main() {
-    let x = foo(box 3);
-    let _y = {x} + x.clone(); // the `{x}` forces a move to occur
-    //~^ ERROR use of moved value: `x`
-}
diff --git a/src/test/compile-fail/borrowck-loan-of-static-data-issue-27616.rs b/src/test/compile-fail/borrowck-loan-of-static-data-issue-27616.rs
deleted file mode 100644 (file)
index 228e710..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2015 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.
-
-use std::mem;
-
-fn leak<T>(mut b: Box<T>) -> &'static mut T {
-    // isn't this supposed to be safe?
-    let inner = &mut *b as *mut _;
-    mem::forget(b);
-    unsafe { &mut *inner }
-}
-
-fn evil(mut s: &'static mut String)
-{
-    // create alias
-    let alias: &'static mut String = s;
-    let inner: &str = &alias;
-    // free value
-    *s = String::new(); //~ ERROR cannot assign
-    let _spray = "0wned".to_owned();
-    // ... and then use it
-    println!("{}", inner);
-}
-
-fn main() {
-    evil(leak(Box::new("hello".to_owned())));
-}
diff --git a/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs b/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs
deleted file mode 100644 (file)
index cce55b6..0000000
+++ /dev/null
@@ -1,56 +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.
-
-use std::ops::Add;
-
-#[derive(Copy, Clone)]
-struct Point {
-    x: isize,
-    y: isize,
-}
-
-impl Add<isize> for Point {
-    type Output = isize;
-
-    fn add(self, z: isize) -> isize {
-        self.x + self.y + z
-    }
-}
-
-impl Point {
-    pub fn times(&self, z: isize) -> isize {
-        self.x * self.y * z
-    }
-}
-
-fn a() {
-    let mut p = Point {x: 3, y: 4};
-
-    // ok (we can loan out rcvr)
-    p + 3;
-    p.times(3);
-}
-
-fn b() {
-    let mut p = Point {x: 3, y: 4};
-
-    // Here I create an outstanding loan and check that we get conflicts:
-
-    let q = &mut p;
-
-    p + 3;  //~ ERROR cannot use `p`
-    p.times(3); //~ ERROR cannot borrow `p`
-
-    *q + 3; // OK to use the new alias `q`
-    q.x += 1; // and OK to mutate it
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-loan-rcvr.rs b/src/test/compile-fail/borrowck-loan-rcvr.rs
deleted file mode 100644 (file)
index 014b27f..0000000
+++ /dev/null
@@ -1,51 +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 point { x: isize, y: isize }
-
-trait methods {
-    fn impurem(&self);
-    fn blockm<F>(&self, f: F) where F: FnOnce();
-}
-
-impl methods for point {
-    fn impurem(&self) {
-    }
-
-    fn blockm<F>(&self, f: F) where F: FnOnce() { f() }
-}
-
-fn a() {
-    let mut p = point {x: 3, y: 4};
-
-    // Here: it's ok to call even though receiver is mutable, because we
-    // can loan it out.
-    p.impurem();
-
-    // But in this case we do not honor the loan:
-    p.blockm(|| { //~ ERROR cannot borrow `p` as mutable
-        p.x = 10;
-    })
-}
-
-fn b() {
-    let mut p = point {x: 3, y: 4};
-
-    // Here I create an outstanding loan and check that we get conflicts:
-
-    let l = &mut p;
-    p.impurem(); //~ ERROR cannot borrow
-
-    l.x += 1;
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-loan-vec-content.rs b/src/test/compile-fail/borrowck-loan-vec-content.rs
deleted file mode 100644 (file)
index 21d9dea..0000000
+++ /dev/null
@@ -1,34 +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.
-
-// Here we check that it is allowed to lend out an element of a
-// (locally rooted) mutable, unique vector, and that we then prevent
-// modifications to the contents.
-
-fn takes_imm_elt<F>(_v: &isize, f: F) where F: FnOnce() {
-    f();
-}
-
-fn has_mut_vec_and_does_not_try_to_change_it() {
-    let mut v: Vec<isize> = vec!(1, 2, 3);
-    takes_imm_elt(&v[0], || {})
-}
-
-fn has_mut_vec_but_tries_to_change_it() {
-    let mut v: Vec<isize> = vec!(1, 2, 3);
-    takes_imm_elt(
-        &v[0],
-        || { //~ ERROR cannot borrow `v` as mutable
-            v[1] = 4;
-        })
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-match-binding-is-assignment.rs b/src/test/compile-fail/borrowck-match-binding-is-assignment.rs
deleted file mode 100644 (file)
index c219b7c..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2012-2014 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 immutable pattern bindings cannot be reassigned.
-
-#![feature(slice_patterns)]
-
-enum E {
-    Foo(isize)
-}
-
-struct S {
-    bar: isize,
-}
-
-pub fn main() {
-    match 1 {
-        x => {
-            x += 1; //~ ERROR re-assignment of immutable variable `x`
-        }
-    }
-
-    match E::Foo(1) {
-        E::Foo(x) => {
-            x += 1; //~ ERROR re-assignment of immutable variable `x`
-        }
-    }
-
-    match (S { bar: 1 }) {
-        S { bar: x } => {
-            x += 1; //~ ERROR re-assignment of immutable variable `x`
-        }
-    }
-
-    match (1,) {
-        (x,) => {
-            x += 1; //~ ERROR re-assignment of immutable variable `x`
-        }
-    }
-
-    match [1,2,3] {
-        [x,_,_] => {
-            x += 1; //~ ERROR re-assignment of immutable variable `x`
-        }
-    }
-}
diff --git a/src/test/compile-fail/borrowck-move-by-capture.rs b/src/test/compile-fail/borrowck-move-by-capture.rs
deleted file mode 100644 (file)
index bad5212..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2014 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.
-
-#![feature(box_syntax,unboxed_closures)]
-
-fn to_fn_mut<A,F:FnMut<A>>(f: F) -> F { f }
-fn to_fn_once<A,F:FnOnce<A>>(f: F) -> F { f }
-
-pub fn main() {
-    let bar: Box<_> = box 3;
-    let _g = to_fn_mut(|| {
-        let _h = to_fn_once(move || -> isize { *bar }); //~ ERROR cannot move out of
-    });
-}
diff --git a/src/test/compile-fail/borrowck-move-error-with-note.rs b/src/test/compile-fail/borrowck-move-error-with-note.rs
deleted file mode 100644 (file)
index e4b9fb2..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2014 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.
-
-#![feature(box_syntax)]
-
-enum Foo {
-    Foo1(Box<u32>, Box<u32>),
-    Foo2(Box<u32>),
-    Foo3,
-}
-
-fn blah() {
-    let f = &Foo::Foo1(box 1, box 2);
-    match *f {             //~ ERROR cannot move out of
-        Foo::Foo1(num1,         //~ NOTE attempting to move value to here
-                  num2) => (),  //~ NOTE and here
-        Foo::Foo2(num) => (),   //~ NOTE and here
-        Foo::Foo3 => ()
-    }
-}
-
-struct S {
-    f: String,
-    g: String
-}
-impl Drop for S {
-    fn drop(&mut self) { println!("{}", self.f); }
-}
-
-fn move_in_match() {
-    match (S {f: "foo".to_string(), g: "bar".to_string()}) {
-        S {         //~ ERROR cannot move out of type `S`, which defines the `Drop` trait
-            f: _s,  //~ NOTE attempting to move value to here
-            g: _t   //~ NOTE and here
-        } => {}
-    }
-}
-
-// from issue-8064
-struct A {
-    a: Box<isize>,
-}
-
-fn free<T>(_: T) {}
-
-fn blah2() {
-    let a = &A { a: box 1 };
-    match a.a {           //~ ERROR cannot move out of
-        n => {            //~ NOTE attempting to move value to here
-            free(n)
-        }
-    }
-    free(a)
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-move-from-subpath-of-borrowed-path.rs b/src/test/compile-fail/borrowck-move-from-subpath-of-borrowed-path.rs
deleted file mode 100644 (file)
index c02c6a7..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2014 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.
-
-// verify that an error is raised when trying to move out of a
-// borrowed path.
-
-#![feature(box_syntax)]
-
-fn main() {
-    let a: Box<Box<_>> = box box 2;
-    let b = &a;
-
-    let z = *a; //~ ERROR: cannot move out of `*a` because it is borrowed
-}
diff --git a/src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs b/src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs
deleted file mode 100644 (file)
index 7284fa7..0000000
+++ /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 <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: *const Box<isize>) -> Box<isize> {
-    let y = *x; //~ ERROR dereference of raw pointer requires unsafe function or block
-    return y;
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs
deleted file mode 100644 (file)
index ec505fa..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2014 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 with<F>(f: F) where F: FnOnce(&String) {}
-
-fn arg_item(&_x: &String) {}
-    //~^ ERROR cannot move out of borrowed content
-
-fn arg_closure() {
-    with(|&_x| ())
-    //~^ ERROR cannot move out of borrowed content
-}
-
-fn let_pat() {
-    let &_x = &"hi".to_string();
-    //~^ ERROR cannot move out of borrowed content
-}
-
-pub fn main() {}
diff --git a/src/test/compile-fail/borrowck-move-moved-value-into-closure.rs b/src/test/compile-fail/borrowck-move-moved-value-into-closure.rs
deleted file mode 100644 (file)
index c46bcbb..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2014 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.
-
-#![feature(box_syntax)]
-
-fn call_f<F:FnOnce() -> isize>(f: F) -> isize {
-    f()
-}
-
-fn main() {
-    let t: Box<_> = box 3;
-
-    call_f(move|| { *t + 1 });
-    call_f(move|| { *t + 1 }); //~ ERROR capture of moved value
-}
diff --git a/src/test/compile-fail/borrowck-move-mut-base-ptr.rs b/src/test/compile-fail/borrowck-move-mut-base-ptr.rs
deleted file mode 100644 (file)
index 2fb89e6..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2014 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 attempt to move `&mut` pointer while pointee is borrowed
-// yields an error.
-//
-// Example from src/librustc_borrowck/borrowck/README.md
-
-fn foo(t0: &mut isize) {
-    let p: &isize = &*t0; // Freezes `*t0`
-    let t1 = t0;        //~ ERROR cannot move out of `t0`
-    *t1 = 22;
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-move-out-of-overloaded-auto-deref.rs b/src/test/compile-fail/borrowck-move-out-of-overloaded-auto-deref.rs
deleted file mode 100644 (file)
index 27cef1f..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright 2014 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.
-
-use std::rc::Rc;
-
-pub fn main() {
-    let _x = Rc::new(vec!(1, 2)).into_iter();
-    //~^ ERROR cannot move out of borrowed content
-}
diff --git a/src/test/compile-fail/borrowck-move-out-of-overloaded-deref.rs b/src/test/compile-fail/borrowck-move-out-of-overloaded-deref.rs
deleted file mode 100644 (file)
index fffcf57..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright 2014 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.
-
-use std::rc::Rc;
-
-pub fn main() {
-    let _x = *Rc::new("hi".to_string());
-    //~^ ERROR cannot move out of borrowed content
-}
diff --git a/src/test/compile-fail/borrowck-move-out-of-static-item.rs b/src/test/compile-fail/borrowck-move-out-of-static-item.rs
deleted file mode 100644 (file)
index 8b83b94..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2014 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.
-
-// Ensure that moves out of static items is forbidden
-
-struct Foo {
-    foo: isize,
-}
-
-static BAR: Foo = Foo { foo: 5 };
-
-
-fn test(f: Foo) {
-    let _f = Foo{foo: 4, ..f};
-}
-
-fn main() {
-    test(BAR); //~ ERROR cannot move out of static item
-}
diff --git a/src/test/compile-fail/borrowck-move-out-of-struct-with-dtor.rs b/src/test/compile-fail/borrowck-move-out-of-struct-with-dtor.rs
deleted file mode 100644 (file)
index 3d13cbe..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2014 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 S {f:String}
-impl Drop for S {
-    fn drop(&mut self) { println!("{}", self.f); }
-}
-
-fn move_in_match() {
-    match (S {f:"foo".to_string()}) {
-        S {f:_s} => {}
-        //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
-    }
-}
-
-fn move_in_let() {
-    let S {f:_s} = S {f:"foo".to_string()};
-    //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
-}
-
-fn move_in_fn_arg(S {f:_s}: S) {
-    //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-move-out-of-tuple-struct-with-dtor.rs b/src/test/compile-fail/borrowck-move-out-of-tuple-struct-with-dtor.rs
deleted file mode 100644 (file)
index 625f718..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2014 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 S(String);
-impl Drop for S {
-    fn drop(&mut self) { }
-}
-
-fn move_in_match() {
-    match S("foo".to_string()) {
-        S(_s) => {}
-        //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
-    }
-}
-
-fn move_in_let() {
-    let S(_s) = S("foo".to_string());
-    //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
-}
-
-fn move_in_fn_arg(S(_s): S) {
-    //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs b/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs
deleted file mode 100644 (file)
index d9a2f89..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2014 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 do not permit moves from &[] matched by a vec pattern.
-
-#![feature(slice_patterns)]
-
-#[derive(Clone, Debug)]
-struct Foo {
-    string: String
-}
-
-pub fn main() {
-    let x = vec!(
-        Foo { string: "foo".to_string() },
-        Foo { string: "bar".to_string() },
-        Foo { string: "baz".to_string() }
-    );
-    let x: &[Foo] = &x;
-    match x {
-        [_, tail..] => {
-            match tail {
-                [Foo { string: a }, //~ ERROR cannot move out of borrowed content
-                 Foo { string: b }] => {
-                    //~^^ NOTE attempting to move value to here
-                    //~^^ NOTE and here
-                }
-                _ => {
-                    unreachable!();
-                }
-            }
-            let z = tail[0].clone();
-            println!("{:?}", z);
-        }
-        _ => {
-            unreachable!();
-        }
-    }
-}
diff --git a/src/test/compile-fail/borrowck-move-subcomponent.rs b/src/test/compile-fail/borrowck-move-subcomponent.rs
deleted file mode 100644 (file)
index 88871dd..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2012-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.
-
-// Tests that the borrow checker checks all components of a path when moving
-// out.
-
-#![feature(box_syntax)]
-
-struct S {
-  x : Box<isize>
-}
-
-fn f<T>(_: T) {}
-
-fn main() {
-  let a : S = S { x : box 1 };
-  let pb = &a;
-  let S { x: ax } = a;  //~ ERROR cannot move out
-  f(pb);
-}
diff --git a/src/test/compile-fail/borrowck-multiple-captures.rs b/src/test/compile-fail/borrowck-multiple-captures.rs
deleted file mode 100644 (file)
index 042b914..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2014 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.
-
-#![feature(box_syntax)]
-
-use std::thread;
-
-fn borrow<T>(_: &T) { }
-
-fn different_vars_after_borrows() {
-    let x1: Box<_> = box 1;
-    let p1 = &x1;
-    let x2: Box<_> = box 2;
-    let p2 = &x2;
-    thread::spawn(move|| {
-        drop(x1); //~ ERROR cannot move `x1` into closure because it is borrowed
-        drop(x2); //~ ERROR cannot move `x2` into closure because it is borrowed
-    });
-    borrow(&*p1);
-    borrow(&*p2);
-}
-
-fn different_vars_after_moves() {
-    let x1: Box<_> = box 1;
-    drop(x1);
-    let x2: Box<_> = box 2;
-    drop(x2);
-    thread::spawn(move|| {
-        drop(x1); //~ ERROR capture of moved value: `x1`
-        drop(x2); //~ ERROR capture of moved value: `x2`
-    });
-}
-
-fn same_var_after_borrow() {
-    let x: Box<_> = box 1;
-    let p = &x;
-    thread::spawn(move|| {
-        drop(x); //~ ERROR cannot move `x` into closure because it is borrowed
-        drop(x); //~ ERROR use of moved value: `x`
-    });
-    borrow(&*p);
-}
-
-fn same_var_after_move() {
-    let x: Box<_> = box 1;
-    drop(x);
-    thread::spawn(move|| {
-        drop(x); //~ ERROR capture of moved value: `x`
-        drop(x); //~ ERROR use of moved value: `x`
-    });
-}
-
-fn main() {
-    different_vars_after_borrows();
-    different_vars_after_moves();
-    same_var_after_borrow();
-    same_var_after_move();
-}
diff --git a/src/test/compile-fail/borrowck-mut-addr-of-imm-var.rs b/src/test/compile-fail/borrowck-mut-addr-of-imm-var.rs
deleted file mode 100644 (file)
index b6626a8..0000000
+++ /dev/null
@@ -1,16 +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 main() {
-    let x: isize = 3;
-    let y: &mut isize = &mut x; //~ ERROR cannot borrow
-    *y = 5;
-    println!("{}", *y);
-}
diff --git a/src/test/compile-fail/borrowck-mut-borrow-linear-errors.rs b/src/test/compile-fail/borrowck-mut-borrow-linear-errors.rs
deleted file mode 100644 (file)
index 38e0e27..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2015 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 to ensure we only report an error for the first issued loan that
-// conflicts with a new loan, as opposed to every issued loan.  This keeps us
-// down to O(n) errors (for n problem lines), instead of O(n^2) errors.
-
-fn main() {
-    let mut x = 1;
-    let mut addr;
-    loop {
-        match 1 {
-            1 => { addr = &mut x; }
-            //~^ ERROR cannot borrow `x` as mutable more than once at a time
-            2 => { addr = &mut x; }
-            //~^ ERROR cannot borrow `x` as mutable more than once at a time
-            _ => { addr = &mut x; }
-            //~^ ERROR cannot borrow `x` as mutable more than once at a time
-        }
-    }
-}
diff --git a/src/test/compile-fail/borrowck-mut-borrow-of-mut-base-ptr.rs b/src/test/compile-fail/borrowck-mut-borrow-of-mut-base-ptr.rs
deleted file mode 100644 (file)
index bdeb7ea..0000000
+++ /dev/null
@@ -1,31 +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.
-
-// Test that attempt to mutably borrow `&mut` pointer while pointee is
-// borrowed yields an error.
-//
-// Example from src/librustc_borrowck/borrowck/README.md
-
-fn foo<'a>(mut t0: &'a mut isize,
-           mut t1: &'a mut isize) {
-    let p: &isize = &*t0;     // Freezes `*t0`
-    let mut t2 = &mut t0;   //~ ERROR cannot borrow `t0`
-    **t2 += 1;              // Mutates `*t0`
-}
-
-fn bar<'a>(mut t0: &'a mut isize,
-           mut t1: &'a mut isize) {
-    let p: &mut isize = &mut *t0; // Claims `*t0`
-    let mut t2 = &mut t0;       //~ ERROR cannot borrow `t0`
-    **t2 += 1;                  // Mutates `*t0` but not through `*p`
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs b/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs
deleted file mode 100644 (file)
index 9341758..0000000
+++ /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 <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 write(v: &mut [isize]) {
-    v[0] += 1;
-}
-
-fn main() {
-    let v = vec!(1, 2, 3);
-    write(&mut v); //~ ERROR cannot borrow
-}
diff --git a/src/test/compile-fail/borrowck-mutate-in-guard.rs b/src/test/compile-fail/borrowck-mutate-in-guard.rs
deleted file mode 100644 (file)
index e35edca..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2014 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.
-
-enum Enum<'a> {
-    A(&'a isize),
-    B(bool),
-}
-
-fn foo() -> isize {
-    let mut n = 42;
-    let mut x = Enum::A(&mut n);
-    match x {
-        Enum::A(_) if { x = Enum::B(false); false } => 1,
-        //~^ ERROR cannot assign in a pattern guard
-        Enum::A(_) if { let y = &mut x; *y = Enum::B(false); false } => 1,
-        //~^ ERROR cannot mutably borrow in a pattern guard
-        //~^^ ERROR cannot assign in a pattern guard
-        Enum::A(p) => *p,
-        Enum::B(_) => 2,
-    }
-}
-
-fn main() {
-    foo();
-}
diff --git a/src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs b/src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs
deleted file mode 100644 (file)
index 8cb7423..0000000
+++ /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 <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.
-
-#![feature(box_syntax)]
-
-struct node_ {
-    a: Box<cycle>
-}
-
-enum cycle {
-    node(node_),
-    empty
-}
-fn main() {
-    let mut x: Box<_> = box cycle::node(node_ {a: box cycle::empty});
-    // Create a cycle!
-    match *x {
-      cycle::node(ref mut y) => {
-        y.a = x; //~ ERROR cannot move out of
-      }
-      cycle::empty => {}
-    };
-}
diff --git a/src/test/compile-fail/borrowck-object-lifetime.rs b/src/test/compile-fail/borrowck-object-lifetime.rs
deleted file mode 100644 (file)
index 021b3f3..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2014 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 borrows that occur due to calls to object methods
-// properly "claim" the object path.
-
-trait Foo {
-    fn borrowed(&self) -> &();
-    fn mut_borrowed(&mut self) -> &();
-}
-
-fn borrowed_receiver(x: &Foo) {
-    let _y = x.borrowed();
-    let _z = x.borrowed();
-}
-
-fn mut_borrowed_receiver(x: &mut Foo) {
-    let _y = x.borrowed();
-    let _z = x.mut_borrowed(); //~ ERROR cannot borrow
-}
-
-fn mut_owned_receiver(mut x: Box<Foo>) {
-    let _y = x.borrowed();
-    let _z = &mut x; //~ ERROR cannot borrow
-}
-
-fn imm_owned_receiver(mut x: Box<Foo>) {
-    let _y = x.borrowed();
-    let _z = &x;
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-object-mutability.rs b/src/test/compile-fail/borrowck-object-mutability.rs
deleted file mode 100644 (file)
index 1bdc32b..0000000
+++ /dev/null
@@ -1,37 +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.
-
-
-trait Foo {
-    fn borrowed(&self);
-    fn borrowed_mut(&mut self);
-}
-
-fn borrowed_receiver(x: &Foo) {
-    x.borrowed();
-    x.borrowed_mut(); //~ ERROR cannot borrow
-}
-
-fn borrowed_mut_receiver(x: &mut Foo) {
-    x.borrowed();
-    x.borrowed_mut();
-}
-
-fn owned_receiver(x: Box<Foo>) {
-    x.borrowed();
-    x.borrowed_mut(); //~ ERROR cannot borrow
-}
-
-fn mut_owned_receiver(mut x: Box<Foo>) {
-    x.borrowed();
-    x.borrowed_mut();
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-or-init.rs b/src/test/compile-fail/borrowck-or-init.rs
deleted file mode 100644 (file)
index 27871a6..0000000
+++ /dev/null
@@ -1,16 +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 main() {
-    let i: isize;
-
-    println!("{}", false || { i = 5; true });
-    println!("{}", i); //~ ERROR use of possibly uninitialized variable: `i`
-}
diff --git a/src/test/compile-fail/borrowck-overloaded-call.rs b/src/test/compile-fail/borrowck-overloaded-call.rs
deleted file mode 100644 (file)
index 93c3752..0000000
+++ /dev/null
@@ -1,89 +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.
-
-#![feature(unboxed_closures)]
-
-use std::ops::{Fn, FnMut, FnOnce};
-
-struct SFn {
-    x: isize,
-    y: isize,
-}
-
-impl Fn<(isize,)> for SFn {
-    extern "rust-call" fn call(&self, (z,): (isize,)) -> isize {
-        self.x * self.y * z
-    }
-}
-
-impl FnMut<(isize,)> for SFn {
-    extern "rust-call" fn call_mut(&mut self, args: (isize,)) -> isize { self.call(args) }
-}
-
-impl FnOnce<(isize,)> for SFn {
-    type Output = isize;
-    extern "rust-call" fn call_once(self, args: (isize,)) -> isize { self.call(args) }
-}
-
-struct SFnMut {
-    x: isize,
-    y: isize,
-}
-
-impl FnMut<(isize,)> for SFnMut {
-    extern "rust-call" fn call_mut(&mut self, (z,): (isize,)) -> isize {
-        self.x * self.y * z
-    }
-}
-
-impl FnOnce<(isize,)> for SFnMut {
-    type Output = isize;
-    extern "rust-call" fn call_once(mut self, args: (isize,)) -> isize { self.call_mut(args) }
-}
-
-struct SFnOnce {
-    x: String,
-}
-
-impl FnOnce<(String,)> for SFnOnce {
-    type Output = usize;
-
-    extern "rust-call" fn call_once(self, (z,): (String,)) -> usize {
-        self.x.len() + z.len()
-    }
-}
-
-fn f() {
-    let mut s = SFn {
-        x: 1,
-        y: 2,
-    };
-    let sp = &mut s;
-    s(3);   //~ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
-    //~^ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
-}
-
-fn g() {
-    let s = SFnMut {
-        x: 1,
-        y: 2,
-    };
-    s(3);   //~ ERROR cannot borrow immutable local variable `s` as mutable
-}
-
-fn h() {
-    let s = SFnOnce {
-        x: "hello".to_string(),
-    };
-    s(" world".to_string());
-    s(" world".to_string());    //~ ERROR use of moved value: `s`
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-overloaded-index-and-overloaded-deref.rs b/src/test/compile-fail/borrowck-overloaded-index-and-overloaded-deref.rs
deleted file mode 100644 (file)
index bee56c9..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2015 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.
-
-// Check that we properly record borrows when we are doing an
-// overloaded, autoderef of a value obtained via an overloaded index
-// operator. The accounting of the all the implicit things going on
-// here is rather subtle. Issue #20232.
-
-use std::ops::{Deref, Index};
-
-struct MyVec<T> { x: T }
-
-impl<T> Index<usize> for MyVec<T> {
-    type Output = T;
-    fn index(&self, _: usize) -> &T {
-        &self.x
-    }
-}
-
-struct MyPtr<T> { x: T }
-
-impl<T> Deref for MyPtr<T> {
-    type Target = T;
-    fn deref(&self) -> &T {
-        &self.x
-    }
-}
-
-struct Foo { f: usize }
-
-fn main() {
-    let mut v = MyVec { x: MyPtr { x: Foo { f: 22 } } };
-    let i = &v[0].f;
-    v = MyVec { x: MyPtr { x: Foo { f: 23 } } };
-    //~^ ERROR cannot assign to `v`
-    read(*i);
-}
-
-fn read(_: usize) { }
diff --git a/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs b/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs
deleted file mode 100644 (file)
index b726c46..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright 2014 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 still see borrowck errors of various kinds when using
-// indexing and autoderef in combination.
-
-use std::ops::{Index, IndexMut};
-
-struct Foo {
-    x: isize,
-    y: isize,
-}
-
-impl<'a> Index<&'a String> for Foo {
-    type Output = isize;
-
-    fn index(&self, z: &String) -> &isize {
-        if *z == "x" {
-            &self.x
-        } else {
-            &self.y
-        }
-    }
-}
-
-impl<'a> IndexMut<&'a String> for Foo {
-    fn index_mut(&mut self, z: &String) -> &mut isize {
-        if *z == "x" {
-            &mut self.x
-        } else {
-            &mut self.y
-        }
-    }
-}
-
-fn test1(mut f: Box<Foo>, s: String) {
-    let _p = &mut f[&s];
-    let _q = &f[&s]; //~ ERROR cannot borrow
-}
-
-fn test2(mut f: Box<Foo>, s: String) {
-    let _p = &mut f[&s];
-    let _q = &mut f[&s]; //~ ERROR cannot borrow
-}
-
-struct Bar {
-    foo: Foo
-}
-
-fn test3(mut f: Box<Bar>, s: String) {
-    let _p = &mut f.foo[&s];
-    let _q = &mut f.foo[&s]; //~ ERROR cannot borrow
-}
-
-fn test4(mut f: Box<Bar>, s: String) {
-    let _p = &f.foo[&s];
-    let _q = &f.foo[&s];
-}
-
-fn test5(mut f: Box<Bar>, s: String) {
-    let _p = &f.foo[&s];
-    let _q = &mut f.foo[&s]; //~ ERROR cannot borrow
-}
-
-fn test6(mut f: Box<Bar>, g: Foo, s: String) {
-    let _p = &f.foo[&s];
-    f.foo = g; //~ ERROR cannot assign
-}
-
-fn test7(mut f: Box<Bar>, g: Bar, s: String) {
-    let _p = &f.foo[&s];
-    *f = g; //~ ERROR cannot assign
-}
-
-fn test8(mut f: Box<Bar>, g: Foo, s: String) {
-    let _p = &mut f.foo[&s];
-    f.foo = g; //~ ERROR cannot assign
-}
-
-fn test9(mut f: Box<Bar>, g: Bar, s: String) {
-    let _p = &mut f.foo[&s];
-    *f = g; //~ ERROR cannot assign
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-overloaded-index-move-from-vec.rs b/src/test/compile-fail/borrowck-overloaded-index-move-from-vec.rs
deleted file mode 100644 (file)
index 1b62d9c..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2014 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.
-
-#![feature(box_syntax)]
-
-use std::ops::Index;
-
-struct MyVec<T> {
-    data: Vec<T>,
-}
-
-impl<T> Index<usize> for MyVec<T> {
-    type Output = T;
-
-    fn index(&self, i: usize) -> &T {
-        &self.data[i]
-    }
-}
-
-fn main() {
-    let v = MyVec::<Box<_>> { data: vec!(box 1, box 2, box 3) };
-    let good = &v[0]; // Shouldn't fail here
-    let bad = v[0];
-    //~^ ERROR cannot move out of indexed content
-}
diff --git a/src/test/compile-fail/borrowck-overloaded-index-move-index.rs b/src/test/compile-fail/borrowck-overloaded-index-move-index.rs
deleted file mode 100644 (file)
index d8615d1..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright 2014 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.
-
-use std::ops::{Index, IndexMut};
-
-struct Foo {
-    x: isize,
-    y: isize,
-}
-
-impl Index<String> for Foo {
-    type Output = isize;
-
-    fn index(&self, z: String) -> &isize {
-        if z == "x" {
-            &self.x
-        } else {
-            &self.y
-        }
-    }
-}
-
-impl IndexMut<String> for Foo {
-    fn index_mut(&mut self, z: String) -> &mut isize {
-        if z == "x" {
-            &mut self.x
-        } else {
-            &mut self.y
-        }
-    }
-}
-
-struct Bar {
-    x: isize,
-}
-
-impl Index<isize> for Bar {
-    type Output = isize;
-
-    fn index<'a>(&'a self, z: isize) -> &'a isize {
-        &self.x
-    }
-}
-
-fn main() {
-    let mut f = Foo {
-        x: 1,
-        y: 2,
-    };
-    let mut s = "hello".to_string();
-    let rs = &mut s;
-
-    println!("{}", f[s]);
-    //~^ ERROR cannot move out of `s` because it is borrowed
-
-    f[s] = 10;
-    //~^ ERROR cannot move out of `s` because it is borrowed
-    //~| ERROR use of moved value: `s`
-
-    let s = Bar {
-        x: 1,
-    };
-    let i = 2;
-    let _j = &i;
-    println!("{}", s[i]); // no error, i is copy
-    println!("{}", s[i]);
-}
diff --git a/src/test/compile-fail/borrowck-overloaded-index-ref-index.rs b/src/test/compile-fail/borrowck-overloaded-index-ref-index.rs
deleted file mode 100644 (file)
index 4c50caf..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright 2014 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.
-
-use std::ops::{Index, IndexMut};
-
-struct Foo {
-    x: isize,
-    y: isize,
-}
-
-impl<'a> Index<&'a String> for Foo {
-    type Output = isize;
-
-    fn index(&self, z: &String) -> &isize {
-        if *z == "x" {
-            &self.x
-        } else {
-            &self.y
-        }
-    }
-}
-
-impl<'a> IndexMut<&'a String> for Foo {
-    fn index_mut(&mut self, z: &String) -> &mut isize {
-        if *z == "x" {
-            &mut self.x
-        } else {
-            &mut self.y
-        }
-    }
-}
-
-struct Bar {
-    x: isize,
-}
-
-impl Index<isize> for Bar {
-    type Output = isize;
-
-    fn index<'a>(&'a self, z: isize) -> &'a isize {
-        &self.x
-    }
-}
-
-fn main() {
-    let mut f = Foo {
-        x: 1,
-        y: 2,
-    };
-    let mut s = "hello".to_string();
-    let rs = &mut s;
-    println!("{}", f[&s]);
-    //~^ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
-    f[&s] = 10;
-    //~^ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
-    let s = Bar {
-        x: 1,
-    };
-    s[2] = 20;
-    //~^ ERROR cannot assign to immutable indexed content
-}
diff --git a/src/test/compile-fail/borrowck-partial-reinit-1.rs b/src/test/compile-fail/borrowck-partial-reinit-1.rs
deleted file mode 100644 (file)
index 1ee040a..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2014-2015 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 Test;
-
-struct Test2 {
-    b: Option<Test>,
-}
-
-struct Test3(Option<Test>);
-
-impl Drop for Test {
-    fn drop(&mut self) {
-        println!("dropping!");
-    }
-}
-
-impl Drop for Test2 {
-    fn drop(&mut self) {}
-}
-
-impl Drop for Test3 {
-    fn drop(&mut self) {}
-}
-
-fn stuff() {
-    let mut t = Test2 { b: None };
-    let u = Test;
-    drop(t);
-    t.b = Some(u);
-    //~^ ERROR partial reinitialization of uninitialized structure `t`
-
-    let mut t = Test3(None);
-    let u = Test;
-    drop(t);
-    t.0 = Some(u);
-    //~^ ERROR partial reinitialization of uninitialized structure `t`
-}
-
-fn main() {
-    stuff()
-}
diff --git a/src/test/compile-fail/borrowck-partial-reinit-2.rs b/src/test/compile-fail/borrowck-partial-reinit-2.rs
deleted file mode 100644 (file)
index c9cdeff..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2014-2015 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 Test {
-    a: isize,
-    b: Option<Box<Test>>,
-}
-
-impl Drop for Test {
-    fn drop(&mut self) {
-        println!("Dropping {}", self.a);
-    }
-}
-
-fn stuff() {
-    let mut t = Test { a: 1, b: None};
-    let mut u = Test { a: 2, b: Some(Box::new(t))};
-    t.b = Some(Box::new(u));
-    //~^ ERROR partial reinitialization of uninitialized structure `t`
-    println!("done");
-}
-
-fn main() {
-    stuff();
-    println!("Hello, world!")
-}
diff --git a/src/test/compile-fail/borrowck-partial-reinit-3.rs b/src/test/compile-fail/borrowck-partial-reinit-3.rs
deleted file mode 100644 (file)
index 0aa7389..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2015 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.
-use std::mem;
-
-struct Test { f: usize }
-impl Drop for Test {
-    fn drop(&mut self) {}
-}
-
-fn main() {
-    let mut x = (Test { f: 2 }, Test { f: 4 });
-    mem::drop(x.0);
-    x.0.f = 3;
-    //~^ ERROR partial reinitialization of uninitialized structure `x.0`
-}
diff --git a/src/test/compile-fail/borrowck-partial-reinit-4.rs b/src/test/compile-fail/borrowck-partial-reinit-4.rs
deleted file mode 100644 (file)
index 774e04e..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2015 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 Test;
-
-struct Test2(Option<Test>);
-
-impl Drop for Test {
-    fn drop(&mut self) {
-        println!("dropping!");
-    }
-}
-
-impl Drop for Test2 {
-    fn drop(&mut self) {}
-}
-
-fn stuff() {
-    let mut x : (Test2, Test2);
-    (x.0).0 = Some(Test);
-    //~^ ERROR partial reinitialization of uninitialized structure `x.0`
-}
-
-fn main() {
-    stuff()
-}
diff --git a/src/test/compile-fail/borrowck-pat-reassign-binding.rs b/src/test/compile-fail/borrowck-pat-reassign-binding.rs
deleted file mode 100644 (file)
index d176245..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2012-2014 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 main() {
-    let mut x: Option<isize> = None;
-    match x {
-      None => {
-          // Note: on this branch, no borrow has occurred.
-          x = Some(0);
-      }
-      Some(ref i) => {
-          // But on this branch, `i` is an outstanding borrow
-          x = Some(*i+1); //~ ERROR cannot assign to `x`
-      }
-    }
-    x.clone(); // just to prevent liveness warnings
-}
diff --git a/src/test/compile-fail/borrowck-reborrow-from-mut.rs b/src/test/compile-fail/borrowck-reborrow-from-mut.rs
deleted file mode 100644 (file)
index 6f5dfa6..0000000
+++ /dev/null
@@ -1,106 +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 {
-  bar1: Bar,
-  bar2: Bar
-}
-
-struct Bar {
-  int1: isize,
-  int2: isize,
-}
-
-fn borrow_same_field_twice_mut_mut(foo: &mut Foo) {
-    let _bar1 = &mut foo.bar1;
-    let _bar2 = &mut foo.bar1;  //~ ERROR cannot borrow
-}
-
-fn borrow_same_field_twice_mut_imm(foo: &mut Foo) {
-    let _bar1 = &mut foo.bar1;
-    let _bar2 = &foo.bar1;  //~ ERROR cannot borrow
-}
-
-fn borrow_same_field_twice_imm_mut(foo: &mut Foo) {
-    let _bar1 = &foo.bar1;
-    let _bar2 = &mut foo.bar1;  //~ ERROR cannot borrow
-}
-
-fn borrow_same_field_twice_imm_imm(foo: &mut Foo) {
-    let _bar1 = &foo.bar1;
-    let _bar2 = &foo.bar1;
-}
-
-fn borrow_both_mut(foo: &mut Foo) {
-    let _bar1 = &mut foo.bar1;
-    let _bar2 = &mut foo.bar2;
-}
-
-fn borrow_both_mut_pattern(foo: &mut Foo) {
-    match *foo {
-        Foo { bar1: ref mut _bar1, bar2: ref mut _bar2 } => {}
-    }
-}
-
-fn borrow_var_and_pattern(foo: &mut Foo) {
-    let _bar1 = &mut foo.bar1;
-    match *foo {
-        Foo { bar1: ref mut _bar1, bar2: _ } => {}
-        //~^ ERROR cannot borrow
-    }
-}
-
-fn borrow_mut_and_base_imm(foo: &mut Foo) {
-    let _bar1 = &mut foo.bar1.int1;
-    let _foo1 = &foo.bar1; //~ ERROR cannot borrow
-    let _foo2 = &*foo; //~ ERROR cannot borrow
-}
-
-fn borrow_mut_and_base_mut(foo: &mut Foo) {
-    let _bar1 = &mut foo.bar1.int1;
-    let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
-}
-
-fn borrow_mut_and_base_mut2(foo: &mut Foo) {
-    let _bar1 = &mut foo.bar1.int1;
-    let _foo2 = &mut *foo; //~ ERROR cannot borrow
-}
-
-fn borrow_imm_and_base_mut(foo: &mut Foo) {
-    let _bar1 = &foo.bar1.int1;
-    let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
-}
-
-fn borrow_imm_and_base_mut2(foo: &mut Foo) {
-    let _bar1 = &foo.bar1.int1;
-    let _foo2 = &mut *foo; //~ ERROR cannot borrow
-}
-
-fn borrow_imm_and_base_imm(foo: &mut Foo) {
-    let _bar1 = &foo.bar1.int1;
-    let _foo1 = &foo.bar1;
-    let _foo2 = &*foo;
-}
-
-fn borrow_mut_and_imm(foo: &mut Foo) {
-    let _bar1 = &mut foo.bar1;
-    let _foo1 = &foo.bar2;
-}
-
-fn borrow_mut_from_imm(foo: &Foo) {
-    let _bar1 = &mut foo.bar1; //~ ERROR cannot borrow
-}
-
-fn borrow_long_path_both_mut(foo: &mut Foo) {
-    let _bar1 = &mut foo.bar1.int1;
-    let _foo1 = &mut foo.bar2.int2;
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-reborrow-from-shorter-lived-andmut.rs b/src/test/compile-fail/borrowck-reborrow-from-shorter-lived-andmut.rs
deleted file mode 100644 (file)
index eee4074..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2014 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 assignments to an `&mut` pointer which is found in a
-// borrowed (but otherwise non-aliasable) location is illegal.
-
-struct S<'a> {
-    pointer: &'a mut isize
-}
-
-fn copy_borrowed_ptr<'a,'b>(p: &'a mut S<'b>) -> S<'b> {
-    S { pointer: &mut *p.pointer }
-    //~^ ERROR cannot infer
-}
-
-fn main() {
-    let mut x = 1;
-
-    {
-        let mut y = S { pointer: &mut x };
-        let z = copy_borrowed_ptr(&mut y);
-        *y.pointer += 1;
-        *z.pointer += 1;
-    }
-}
diff --git a/src/test/compile-fail/borrowck-ref-into-rvalue.rs b/src/test/compile-fail/borrowck-ref-into-rvalue.rs
deleted file mode 100644 (file)
index 726d4bc..0000000
+++ /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 <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 main() {
-    let msg;
-    match Some("Hello".to_string()) {
-        Some(ref m) => { //~ ERROR borrowed value does not live long enough
-            msg = m;
-        },
-        None => { panic!() }
-    }
-    println!("{}", *msg);
-}
diff --git a/src/test/compile-fail/borrowck-ref-mut-of-imm.rs b/src/test/compile-fail/borrowck-ref-mut-of-imm.rs
deleted file mode 100644 (file)
index 1784b72..0000000
+++ /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 <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 destructure(x: Option<isize>) -> isize {
-    match x {
-      None => 0,
-      Some(ref mut v) => *v //~ ERROR cannot borrow
-    }
-}
-
-fn main() {
-    assert_eq!(destructure(Some(22)), 22);
-}
diff --git a/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs b/src/test/compile-fail/borrowck-report-with-custom-diagnostic.rs
deleted file mode 100644 (file)
index 61bf2c1..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2014 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.
-
-#![allow(dead_code)]
-fn main() {
-    // Original borrow ends at end of function
-    let mut x = 1;
-    let y = &mut x;
-    let z = &x; //~ ERROR cannot borrow
-}
-//~^ NOTE previous borrow ends here
-
-fn foo() {
-    match true {
-        true => {
-            // Original borrow ends at end of match arm
-            let mut x = 1;
-            let y = &x;
-            let z = &mut x; //~ ERROR cannot borrow
-        }
-     //~^ NOTE previous borrow ends here
-        false => ()
-    }
-}
-
-fn bar() {
-    // Original borrow ends at end of closure
-    || {
-        let mut x = 1;
-        let y = &mut x;
-        let z = &mut x; //~ ERROR cannot borrow
-    };
- //~^ NOTE previous borrow ends here
-}
diff --git a/src/test/compile-fail/borrowck-return-variable-on-stack-via-clone.rs b/src/test/compile-fail/borrowck-return-variable-on-stack-via-clone.rs
deleted file mode 100644 (file)
index 7529943..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2014 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.
-
-// Check that when we clone a `&T` pointer we properly relate the
-// lifetime of the pointer which results to the pointer being cloned.
-// Bugs in method resolution have sometimes broken this connection.
-// Issue #19261.
-
-fn leak<'a, T>(x: T) -> &'a T {
-    (&x).clone() //~ ERROR `x` does not live long enough
-}
-
-fn main() { }
diff --git a/src/test/compile-fail/borrowck-return.rs b/src/test/compile-fail/borrowck-return.rs
deleted file mode 100644 (file)
index 74d435b..0000000
+++ /dev/null
@@ -1,16 +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 f() -> isize {
-    let x: isize;
-    return x; //~ ERROR use of possibly uninitialized variable: `x`
-}
-
-fn main() { f(); }
diff --git a/src/test/compile-fail/borrowck-struct-update-with-dtor.rs b/src/test/compile-fail/borrowck-struct-update-with-dtor.rs
deleted file mode 100644 (file)
index bf14974..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2012-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 4691: Ensure that functional-struct-update can only copy, not
-// move, when the struct implements Drop.
-
-struct B;
-struct S { a: isize, b: B }
-impl Drop for S { fn drop(&mut self) { } }
-
-struct T { a: isize, mv: Box<isize> }
-impl Drop for T { fn drop(&mut self) { } }
-
-fn f(s0:S) {
-    let _s2 = S{a: 2, ..s0}; //~error: cannot move out of type `S`, which defines the `Drop` trait
-}
-
-fn g(s0:T) {
-    let _s2 = T{a: 2, ..s0}; //~error: cannot move out of type `T`, which defines the `Drop` trait
-}
-
-fn main() { }
diff --git a/src/test/compile-fail/borrowck-swap-mut-base-ptr.rs b/src/test/compile-fail/borrowck-swap-mut-base-ptr.rs
deleted file mode 100644 (file)
index 552fcec..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2014 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 attempt to swap `&mut` pointer while pointee is borrowed
-// yields an error.
-//
-// Example from src/librustc_borrowck/borrowck/README.md
-
-use std::mem::swap;
-
-fn foo<'a>(mut t0: &'a mut isize,
-           mut t1: &'a mut isize) {
-    let p: &isize = &*t0;     // Freezes `*t0`
-    swap(&mut t0, &mut t1); //~ ERROR cannot borrow `t0`
-    *t1 = 22;
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-unary-move.rs b/src/test/compile-fail/borrowck-unary-move.rs
deleted file mode 100644 (file)
index 5b5c5f4..0000000
+++ /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 <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: Box<isize>) -> isize {
-    let y = &*x;
-    free(x); //~ ERROR cannot move out of `x` because it is borrowed
-    *y
-}
-
-fn free(_x: Box<isize>) {
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-unboxed-closures.rs b/src/test/compile-fail/borrowck-unboxed-closures.rs
deleted file mode 100644 (file)
index 1c12ca9..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2014 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.
-
-#![feature(overloaded_calls, unboxed_closures)]
-
-fn a<F:Fn(isize, isize) -> isize>(mut f: F) {
-    let g = &mut f;
-    f(1, 2);    //~ ERROR cannot borrow `f` as immutable
-    //~^ ERROR cannot borrow `f` as immutable
-}
-
-fn b<F:FnMut(isize, isize) -> isize>(f: F) {
-    f(1, 2);    //~ ERROR cannot borrow immutable argument
-}
-
-fn c<F:FnOnce(isize, isize) -> isize>(f: F) {
-    f(1, 2);
-    f(1, 2);    //~ ERROR use of moved value
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-uninit-after-item.rs b/src/test/compile-fail/borrowck-uninit-after-item.rs
deleted file mode 100644 (file)
index acd827d..0000000
+++ /dev/null
@@ -1,15 +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 main() {
-    let bar;
-    fn baz(_x: isize) { }
-    baz(bar); //~ ERROR use of possibly uninitialized variable: `bar`
-}
diff --git a/src/test/compile-fail/borrowck-uninit-in-assignop.rs b/src/test/compile-fail/borrowck-uninit-in-assignop.rs
deleted file mode 100644 (file)
index e253ecc..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2012-2014 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 that the use of uninitialized variable in assignment operator
-// expression is detected.
-
-pub fn main() {
-    let x: isize;
-    x += 1; //~ ERROR use of possibly uninitialized variable: `x`
-
-    let x: isize;
-    x -= 1; //~ ERROR use of possibly uninitialized variable: `x`
-
-    let x: isize;
-    x *= 1; //~ ERROR use of possibly uninitialized variable: `x`
-
-    let x: isize;
-    x /= 1; //~ ERROR use of possibly uninitialized variable: `x`
-
-    let x: isize;
-    x %= 1; //~ ERROR use of possibly uninitialized variable: `x`
-
-    let x: isize;
-    x ^= 1; //~ ERROR use of possibly uninitialized variable: `x`
-
-    let x: isize;
-    x &= 1; //~ ERROR use of possibly uninitialized variable: `x`
-
-    let x: isize;
-    x |= 1; //~ ERROR use of possibly uninitialized variable: `x`
-
-    let x: isize;
-    x <<= 1;    //~ ERROR use of possibly uninitialized variable: `x`
-
-    let x: isize;
-    x >>= 1;    //~ ERROR use of possibly uninitialized variable: `x`
-}
diff --git a/src/test/compile-fail/borrowck-uninit.rs b/src/test/compile-fail/borrowck-uninit.rs
deleted file mode 100644 (file)
index f4b73bc..0000000
+++ /dev/null
@@ -1,16 +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: isize) { println!("{}", x); }
-
-fn main() {
-    let x: isize;
-    foo(x); //~ ERROR use of possibly uninitialized variable: `x`
-}
diff --git a/src/test/compile-fail/borrowck-uniq-via-lend.rs b/src/test/compile-fail/borrowck-uniq-via-lend.rs
deleted file mode 100644 (file)
index f36dc0c..0000000
+++ /dev/null
@@ -1,62 +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.
-
-#![feature(box_syntax)]
-
-fn borrow(_v: &isize) {}
-
-fn local() {
-    let mut v: Box<_> = box 3;
-    borrow(&*v);
-}
-
-fn local_rec() {
-    struct F { f: Box<isize> }
-    let mut v = F {f: box 3};
-    borrow(&*v.f);
-}
-
-fn local_recs() {
-    struct F { f: G }
-    struct G { g: H }
-    struct H { h: Box<isize> }
-    let mut v = F {f: G {g: H {h: box 3}}};
-    borrow(&*v.f.g.h);
-}
-
-fn aliased_imm() {
-    let mut v: Box<_> = box 3;
-    let _w = &v;
-    borrow(&*v);
-}
-
-fn aliased_mut() {
-    let mut v: Box<_> = box 3;
-    let _w = &mut v;
-    borrow(&*v); //~ ERROR cannot borrow `*v`
-}
-
-fn aliased_other() {
-    let mut v: Box<_> = box 3;
-    let mut w: Box<_> = box 4;
-    let _x = &mut w;
-    borrow(&*v);
-}
-
-fn aliased_other_reassign() {
-    let mut v: Box<_> = box 3;
-    let mut w: Box<_> = box 4;
-    let mut _x = &mut w;
-    _x = &mut v;
-    borrow(&*v); //~ ERROR cannot borrow `*v`
-}
-
-fn main() {
-}
diff --git a/src/test/compile-fail/borrowck-use-in-index-lvalue.rs b/src/test/compile-fail/borrowck-use-in-index-lvalue.rs
deleted file mode 100644 (file)
index 7291bcd..0000000
+++ /dev/null
@@ -1,19 +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() {
-    let w: &mut [isize];
-    w[5] = 0; //~ ERROR use of possibly uninitialized variable: `*w`
-
-    let mut w: &mut [isize];
-    w[5] = 0; //~ ERROR use of possibly uninitialized variable: `*w`
-}
-
-fn main() { test(); }
diff --git a/src/test/compile-fail/borrowck-use-mut-borrow.rs b/src/test/compile-fail/borrowck-use-mut-borrow.rs
deleted file mode 100644 (file)
index c11e586..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright 2014 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.
-
-#![feature(box_syntax)]
-
-#[derive(Copy, Clone)]
-struct A { a: isize, b: isize }
-
-struct B { a: isize, b: Box<isize> }
-
-fn var_copy_after_var_borrow() {
-    let mut x: isize = 1;
-    let p = &mut x;
-    drop(x); //~ ERROR cannot use `x` because it was mutably borrowed
-    *p = 2;
-}
-
-fn var_copy_after_field_borrow() {
-    let mut x = A { a: 1, b: 2 };
-    let p = &mut x.a;
-    drop(x); //~ ERROR cannot use `x` because it was mutably borrowed
-    *p = 3;
-}
-
-fn field_copy_after_var_borrow() {
-    let mut x = A { a: 1, b: 2 };
-    let p = &mut x;
-    drop(x.a); //~ ERROR cannot use `x.a` because it was mutably borrowed
-    p.a = 3;
-}
-
-fn field_copy_after_field_borrow() {
-    let mut x = A { a: 1, b: 2 };
-    let p = &mut x.a;
-    drop(x.a); //~ ERROR cannot use `x.a` because it was mutably borrowed
-    *p = 3;
-}
-
-fn fu_field_copy_after_var_borrow() {
-    let mut x = A { a: 1, b: 2 };
-    let p = &mut x;
-    let y = A { b: 3, .. x }; //~ ERROR cannot use `x.a` because it was mutably borrowed
-    drop(y);
-    p.a = 4;
-}
-
-fn fu_field_copy_after_field_borrow() {
-    let mut x = A { a: 1, b: 2 };
-    let p = &mut x.a;
-    let y = A { b: 3, .. x }; //~ ERROR cannot use `x.a` because it was mutably borrowed
-    drop(y);
-    *p = 4;
-}
-
-fn var_deref_after_var_borrow() {
-    let mut x: Box<isize> = box 1;
-    let p = &mut x;
-    drop(*x); //~ ERROR cannot use `*x` because it was mutably borrowed
-    **p = 2;
-}
-
-fn field_deref_after_var_borrow() {
-    let mut x = B { a: 1, b: box 2 };
-    let p = &mut x;
-    drop(*x.b); //~ ERROR cannot use `*x.b` because it was mutably borrowed
-    p.a = 3;
-}
-
-fn field_deref_after_field_borrow() {
-    let mut x = B { a: 1, b: box 2 };
-    let p = &mut x.b;
-    drop(*x.b); //~ ERROR cannot use `*x.b` because it was mutably borrowed
-    **p = 3;
-}
-
-fn main() {
-    var_copy_after_var_borrow();
-    var_copy_after_field_borrow();
-
-    field_copy_after_var_borrow();
-    field_copy_after_field_borrow();
-
-    fu_field_copy_after_var_borrow();
-    fu_field_copy_after_field_borrow();
-
-    var_deref_after_var_borrow();
-    field_deref_after_var_borrow();
-    field_deref_after_field_borrow();
-}
diff --git a/src/test/compile-fail/borrowck-use-uninitialized-in-cast-trait.rs b/src/test/compile-fail/borrowck-use-uninitialized-in-cast-trait.rs
deleted file mode 100644 (file)
index 796b455..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2015 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.
-
-// Variation on `borrowck-use-uninitialized-in-cast` in which we do a
-// trait cast from an uninitialized source. Issue #20791.
-
-trait Foo { fn dummy(&self) { } }
-impl Foo for i32 { }
-
-fn main() {
-    let x: &i32;
-    let y = x as *const Foo; //~ ERROR use of possibly uninitialized variable: `*x`
-}
diff --git a/src/test/compile-fail/borrowck-use-uninitialized-in-cast.rs b/src/test/compile-fail/borrowck-use-uninitialized-in-cast.rs
deleted file mode 100644 (file)
index a3d5af8..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2015 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.
-
-// Check that we detect unused values that are cast to other things.
-// The problem was specified to casting to `*`, as creating unsafe
-// pointers was not being fully checked. Issue #20791.
-
-// pretty-expanded FIXME #23616
-
-fn main() {
-    let x: &i32;
-    let y = x as *const i32; //~ ERROR use of possibly uninitialized variable: `*x`
-}
diff --git a/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs b/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs
deleted file mode 100644 (file)
index 98052ad..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2014 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.
-
-#![feature(advanced_slice_patterns)]
-#![feature(slice_patterns)]
-
-fn a<'a>() -> &'a [isize] {
-    let vec = vec!(1, 2, 3, 4);
-    let vec: &[isize] = &vec; //~ ERROR does not live long enough
-    let tail = match vec {
-        [_, tail..] => tail,
-        _ => panic!("a")
-    };
-    tail
-}
-
-fn b<'a>() -> &'a [isize] {
-    let vec = vec!(1, 2, 3, 4);
-    let vec: &[isize] = &vec; //~ ERROR does not live long enough
-    let init = match vec {
-        [init.., _] => init,
-        _ => panic!("b")
-    };
-    init
-}
-
-fn c<'a>() -> &'a [isize] {
-    let vec = vec!(1, 2, 3, 4);
-    let vec: &[isize] = &vec; //~ ERROR does not live long enough
-    let slice = match vec {
-        [_, slice.., _] => slice,
-        _ => panic!("c")
-    };
-    slice
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs b/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs
deleted file mode 100644 (file)
index db63589..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2014 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.
-
-#![feature(slice_patterns)]
-
-fn a() {
-    let mut v = vec!(1, 2, 3);
-    let vb: &mut [isize] = &mut v;
-    match vb {
-        [_a, tail..] => {
-            v.push(tail[0] + tail[1]); //~ ERROR cannot borrow
-        }
-        _ => {}
-    };
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs b/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs
deleted file mode 100644 (file)
index 97dcaeb..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2014 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.
-
-#![feature(slice_patterns)]
-
-fn main() {
-    let mut a = [1, 2, 3, 4];
-    let t = match a {
-        [1, 2, tail..] => tail,
-        _ => unreachable!()
-    };
-    println!("t[0]: {}", t[0]);
-    a[2] = 0; //~ ERROR cannot assign to `a[..]` because it is borrowed
-    println!("t[0]: {}", t[0]);
-    t[0];
-}
diff --git a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs
deleted file mode 100644 (file)
index a69ce0c..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2014 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.
-
-#![feature(advanced_slice_patterns)]
-#![feature(box_patterns)]
-#![feature(box_syntax)]
-#![feature(slice_patterns)]
-
-fn a() {
-    let mut vec = [box 1, box 2, box 3];
-    match vec {
-        [box ref _a, _, _] => {
-            vec[0] = box 4; //~ ERROR cannot assign
-        }
-    }
-}
-
-fn b() {
-    let mut vec = vec!(box 1, box 2, box 3);
-    let vec: &mut [Box<isize>] = &mut vec;
-    match vec {
-        [_b..] => {
-            vec[0] = box 4; //~ ERROR cannot assign
-        }
-    }
-}
-
-fn c() {
-    let mut vec = vec!(box 1, box 2, box 3);
-    let vec: &mut [Box<isize>] = &mut vec;
-    match vec {
-        [_a,         //~ ERROR cannot move out
-         _b..] => {  //~^ NOTE attempting to move value to here
-
-            // Note: `_a` is *moved* here, but `b` is borrowing,
-            // hence illegal.
-            //
-            // See comment in middle/borrowck/gather_loans/mod.rs
-            // in the case covering these sorts of vectors.
-        }
-        _ => {}
-    }
-    let a = vec[0]; //~ ERROR cannot move out
-}
-
-fn d() {
-    let mut vec = vec!(box 1, box 2, box 3);
-    let vec: &mut [Box<isize>] = &mut vec;
-    match vec {
-        [_a..,     //~ ERROR cannot move out
-         _b] => {} //~ NOTE attempting to move value to here
-        _ => {}
-    }
-    let a = vec[0]; //~ ERROR cannot move out
-}
-
-fn e() {
-    let mut vec = vec!(box 1, box 2, box 3);
-    let vec: &mut [Box<isize>] = &mut vec;
-    match vec {
-        [_a, _b, _c] => {}  //~ ERROR cannot move out
-        //~^ NOTE attempting to move value to here
-        //~^^ NOTE and here
-        //~^^^ NOTE and here
-        _ => {}
-    }
-    let a = vec[0]; //~ ERROR cannot move out
-    //~^ NOTE attempting to move value to here
-}
-
-fn main() {}
diff --git a/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs b/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs
deleted file mode 100644 (file)
index 82b3490..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2014 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.
-
-#![feature(slice_patterns)]
-
-fn a<'a>() -> &'a isize {
-    let vec = vec!(1, 2, 3, 4);
-    let vec: &[isize] = &vec; //~ ERROR `vec` does not live long enough
-    let tail = match vec {
-        [_a, tail..] => &tail[0],
-        _ => panic!("foo")
-    };
-    tail
-}
-
-fn main() {
-    let fifth = a();
-    println!("{}", *fifth);
-}
diff --git a/src/test/compile-fail/borrowck-while-break.rs b/src/test/compile-fail/borrowck-while-break.rs
deleted file mode 100644 (file)
index 8cdf1da..0000000
+++ /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 <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(cond: bool) {
-    let v;
-    while cond {
-        v = 3;
-        break;
-    }
-    println!("{}", v); //~ ERROR use of possibly uninitialized variable: `v`
-}
-
-fn main() {
-    test(true);
-}
diff --git a/src/test/compile-fail/borrowck-while-cond.rs b/src/test/compile-fail/borrowck-while-cond.rs
deleted file mode 100644 (file)
index 27d42d6..0000000
+++ /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 <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 main() {
-    let x: bool;
-    while x { } //~ ERROR use of possibly uninitialized variable: `x`
-}
diff --git a/src/test/compile-fail/borrowck-while.rs b/src/test/compile-fail/borrowck-while.rs
deleted file mode 100644 (file)
index e3566e9..0000000
+++ /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 <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 f() -> isize {
-    let mut x: isize;
-    while 1 == 1 { x = 10; }
-    return x; //~ ERROR use of possibly uninitialized variable: `x`
-}
-
-fn main() { f(); }
diff --git a/src/test/compile-fail/borrowck/borrowck-and-init.rs b/src/test/compile-fail/borrowck/borrowck-and-init.rs
new file mode 100644 (file)
index 0000000..92f16d8
--- /dev/null
@@ -0,0 +1,16 @@
+// 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 main() {
+    let i: isize;
+
+    println!("{}", false && { i = 5; true });
+    println!("{}", i); //~ ERROR use of possibly uninitialized variable: `i`
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-anon-fields-struct.rs b/src/test/compile-fail/borrowck/borrowck-anon-fields-struct.rs
new file mode 100644 (file)
index 0000000..5ee2b89
--- /dev/null
@@ -0,0 +1,47 @@
+// Copyright 2014 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 that we are able to distinguish when loans borrow different
+// anonymous fields of a tuple vs the same anonymous field.
+
+struct Y(usize, usize);
+
+fn distinct_variant() {
+    let mut y = Y(1, 2);
+
+    let a = match y {
+        Y(ref mut a, _) => a
+    };
+
+    let b = match y {
+        Y(_, ref mut b) => b
+    };
+
+    *a += 1;
+    *b += 1;
+}
+
+fn same_variant() {
+    let mut y = Y(1, 2);
+
+    let a = match y {
+        Y(ref mut a, _) => a
+    };
+
+    let b = match y {
+        Y(ref mut b, _) => b //~ ERROR cannot borrow
+    };
+
+    *a += 1;
+    *b += 1;
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-anon-fields-tuple.rs b/src/test/compile-fail/borrowck/borrowck-anon-fields-tuple.rs
new file mode 100644 (file)
index 0000000..ebaed01
--- /dev/null
@@ -0,0 +1,45 @@
+// Copyright 2014 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 that we are able to distinguish when loans borrow different
+// anonymous fields of a tuple vs the same anonymous field.
+
+fn distinct_variant() {
+    let mut y = (1, 2);
+
+    let a = match y {
+        (ref mut a, _) => a
+    };
+
+    let b = match y {
+        (_, ref mut b) => b
+    };
+
+    *a += 1;
+    *b += 1;
+}
+
+fn same_variant() {
+    let mut y = (1, 2);
+
+    let a = match y {
+        (ref mut a, _) => a
+    };
+
+    let b = match y {
+        (ref mut b, _) => b //~ ERROR cannot borrow
+    };
+
+    *a += 1;
+    *b += 1;
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-anon-fields-variant.rs b/src/test/compile-fail/borrowck/borrowck-anon-fields-variant.rs
new file mode 100644 (file)
index 0000000..4e1b852
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright 2014 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 that we are able to distinguish when loans borrow different
+// anonymous fields of an enum variant vs the same anonymous field.
+
+enum Foo {
+    X, Y(usize, usize)
+}
+
+fn distinct_variant() {
+    let mut y = Foo::Y(1, 2);
+
+    let a = match y {
+      Foo::Y(ref mut a, _) => a,
+      Foo::X => panic!()
+    };
+
+    let b = match y {
+      Foo::Y(_, ref mut b) => b,
+      Foo::X => panic!()
+    };
+
+    *a += 1;
+    *b += 1;
+}
+
+fn same_variant() {
+    let mut y = Foo::Y(1, 2);
+
+    let a = match y {
+      Foo::Y(ref mut a, _) => a,
+      Foo::X => panic!()
+    };
+
+    let b = match y {
+      Foo::Y(ref mut b, _) => b, //~ ERROR cannot borrow
+      Foo::X => panic!()
+    };
+
+    *a += 1;
+    *b += 1;
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-argument.rs b/src/test/compile-fail/borrowck/borrowck-argument.rs
new file mode 100644 (file)
index 0000000..3230689
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright 2015 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.
+
+#[derive(Copy, Clone)]
+struct S;
+
+impl S {
+    fn mutate(&mut self) {
+    }
+}
+
+fn func(arg: S) {
+    arg.mutate(); //~ ERROR: cannot borrow immutable argument
+}
+
+impl S {
+    fn method(&self, arg: S) {
+        arg.mutate(); //~ ERROR: cannot borrow immutable argument
+    }
+}
+
+trait T {
+    fn default(&self, arg: S) {
+        arg.mutate(); //~ ERROR: cannot borrow immutable argument
+    }
+}
+
+impl T for S {}
+
+fn main() {
+    let s = S;
+    func(s);
+    s.method(s);
+    s.default(s);
+    (|arg: S| { arg.mutate() })(s); //~ ERROR: cannot borrow immutable argument
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-assign-comp-idx.rs b/src/test/compile-fail/borrowck/borrowck-assign-comp-idx.rs
new file mode 100644 (file)
index 0000000..b18df7f
--- /dev/null
@@ -0,0 +1,49 @@
+// 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 Point {
+    x: isize,
+    y: isize,
+}
+
+fn a() {
+    let mut p = vec!(1);
+
+    // Create an immutable pointer into p's contents:
+    let q: &isize = &p[0];
+
+    p[0] = 5; //~ ERROR cannot borrow
+
+    println!("{}", *q);
+}
+
+fn borrow<F>(_x: &[isize], _f: F) where F: FnOnce() {}
+
+fn b() {
+    // here we alias the mutable vector into an imm slice and try to
+    // modify the original:
+
+    let mut p = vec!(1);
+
+    borrow(
+        &p,
+        || p[0] = 5); //~ ERROR cannot borrow `p` as mutable
+}
+
+fn c() {
+    // Legal because the scope of the borrow does not include the
+    // modification:
+    let mut p = vec!(1);
+    borrow(&p, ||{});
+    p[0] = 5;
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-assign-comp.rs b/src/test/compile-fail/borrowck/borrowck-assign-comp.rs
new file mode 100644 (file)
index 0000000..802b831
--- /dev/null
@@ -0,0 +1,46 @@
+// 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 point { x: isize, y: isize }
+
+fn a() {
+    let mut p = point {x: 3, y: 4};
+    let q = &p;
+
+    // This assignment is illegal because the field x is not
+    // inherently mutable; since `p` was made immutable, `p.x` is now
+    // immutable.  Otherwise the type of &_q.x (&isize) would be wrong.
+    p.x = 5; //~ ERROR cannot assign to `p.x`
+    q.x;
+}
+
+fn c() {
+    // this is sort of the opposite.  We take a loan to the interior of `p`
+    // and then try to overwrite `p` as a whole.
+
+    let mut p = point {x: 3, y: 4};
+    let q = &p.y;
+    p = point {x: 5, y: 7};//~ ERROR cannot assign to `p`
+    p.x; // silence warning
+    *q; // stretch loan
+}
+
+fn d() {
+    // just for completeness's sake, the easy case, where we take the
+    // address of a subcomponent and then modify that subcomponent:
+
+    let mut p = point {x: 3, y: 4};
+    let q = &p.y;
+    p.y = 5; //~ ERROR cannot assign to `p.y`
+    *q;
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.rs b/src/test/compile-fail/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.rs
new file mode 100644 (file)
index 0000000..d66cdb9
--- /dev/null
@@ -0,0 +1,30 @@
+// 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 assignments to an `&mut` pointer which is found in a
+// borrowed (but otherwise non-aliasable) location is illegal.
+
+struct S<'a> {
+    pointer: &'a mut isize
+}
+
+fn a(s: &S) {
+    *s.pointer += 1; //~ ERROR cannot assign
+}
+
+fn b(s: &mut S) {
+    *s.pointer += 1;
+}
+
+fn c(s: & &mut S) {
+    *s.pointer += 1; //~ ERROR cannot assign
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-assign-to-andmut-in-borrowed-loc.rs b/src/test/compile-fail/borrowck/borrowck-assign-to-andmut-in-borrowed-loc.rs
new file mode 100644 (file)
index 0000000..77aa57e
--- /dev/null
@@ -0,0 +1,31 @@
+// 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 assignments to an `&mut` pointer which is found in a
+// borrowed (but otherwise non-aliasable) location is illegal.
+
+struct S<'a> {
+    pointer: &'a mut isize
+}
+
+fn copy_borrowed_ptr<'a>(p: &'a mut S<'a>) -> S<'a> {
+    S { pointer: &mut *p.pointer }
+}
+
+fn main() {
+    let mut x = 1;
+
+    {
+        let mut y = S { pointer: &mut x };
+        let z = copy_borrowed_ptr(&mut y);
+        *y.pointer += 1; //~ ERROR cannot assign
+        *z.pointer += 1;
+    }
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-assign-to-constants.rs b/src/test/compile-fail/borrowck/borrowck-assign-to-constants.rs
new file mode 100644 (file)
index 0000000..1b5b189
--- /dev/null
@@ -0,0 +1,16 @@
+// 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.
+
+static foo: isize = 5;
+
+fn main() {
+    // assigning to various global constants
+    foo = 6; //~ ERROR cannot assign to immutable static item
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-auto-mut-ref-to-immut-var.rs b/src/test/compile-fail/borrowck/borrowck-auto-mut-ref-to-immut-var.rs
new file mode 100644 (file)
index 0000000..ea020dc
--- /dev/null
@@ -0,0 +1,26 @@
+// 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 that auto-ref can't create mutable aliases to immutable memory.
+
+struct Foo {
+    x: isize
+}
+
+impl Foo {
+    pub fn printme(&mut self) {
+        println!("{}", self.x);
+    }
+}
+
+fn main() {
+    let x = Foo { x: 3 };
+    x.printme();    //~ ERROR cannot borrow
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-autoref-3261.rs b/src/test/compile-fail/borrowck/borrowck-autoref-3261.rs
new file mode 100644 (file)
index 0000000..d5f0930
--- /dev/null
@@ -0,0 +1,34 @@
+// 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.
+
+enum Either<T, U> { Left(T), Right(U) }
+
+struct X(Either<(usize,usize), fn()>);
+
+impl X {
+    pub fn with<F>(&self, blk: F) where F: FnOnce(&Either<(usize, usize), fn()>) {
+        let X(ref e) = *self;
+        blk(e)
+    }
+}
+
+fn main() {
+    let mut x = X(Either::Right(main as fn()));
+    (&mut x).with(
+        |opt| { //~ ERROR cannot borrow `x` as mutable more than once at a time
+            match opt {
+                &Either::Right(ref f) => {
+                    x = X(Either::Left((0, 0)));
+                    (*f)()
+                },
+                _ => panic!()
+            }
+        })
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-bad-nested-calls-free.rs b/src/test/compile-fail/borrowck/borrowck-bad-nested-calls-free.rs
new file mode 100644 (file)
index 0000000..7913f9a
--- /dev/null
@@ -0,0 +1,45 @@
+// 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 detect nested calls that could free pointers evaluated
+// for earlier arguments.
+
+#![feature(box_syntax)]
+
+fn rewrite(v: &mut Box<usize>) -> usize {
+    *v = box 22;
+    **v
+}
+
+fn add(v: &usize, w: usize) -> usize {
+    *v + w
+}
+
+fn implicit() {
+    let mut a: Box<_> = box 1;
+
+    // Note the danger here:
+    //
+    //    the pointer for the first argument has already been
+    //    evaluated, but it gets freed when evaluating the second
+    //    argument!
+    add(
+        &*a,
+        rewrite(&mut a)); //~ ERROR cannot borrow
+}
+
+fn explicit() {
+    let mut a: Box<_> = box 1;
+    add(
+        &*a,
+        rewrite(&mut a)); //~ ERROR cannot borrow
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-bad-nested-calls-move.rs b/src/test/compile-fail/borrowck/borrowck-bad-nested-calls-move.rs
new file mode 100644 (file)
index 0000000..e24d4e8
--- /dev/null
@@ -0,0 +1,45 @@
+// 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 detect nested calls that could free pointers evaluated
+// for earlier arguments.
+
+#![feature(box_syntax)]
+
+fn rewrite(v: &mut Box<usize>) -> usize {
+    *v = box 22;
+    **v
+}
+
+fn add(v: &usize, w: Box<usize>) -> usize {
+    *v + *w
+}
+
+fn implicit() {
+    let mut a: Box<_> = box 1;
+
+    // Note the danger here:
+    //
+    //    the pointer for the first argument has already been
+    //    evaluated, but it gets moved when evaluating the second
+    //    argument!
+    add(
+        &*a,
+        a); //~ ERROR cannot move
+}
+
+fn explicit() {
+    let mut a: Box<_> = box 1;
+    add(
+        &*a,
+        a); //~ ERROR cannot move
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-block-unint.rs b/src/test/compile-fail/borrowck/borrowck-block-unint.rs
new file mode 100644 (file)
index 0000000..a09ee43
--- /dev/null
@@ -0,0 +1,17 @@
+// 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 force<F>(f: F) where F: FnOnce() { f(); }
+fn main() {
+    let x: isize;
+    force(|| {  //~ ERROR capture of possibly uninitialized variable: `x`
+        println!("{}", x);
+    });
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-borrow-from-owned-ptr.rs b/src/test/compile-fail/borrowck/borrowck-borrow-from-owned-ptr.rs
new file mode 100644 (file)
index 0000000..e5091a9
--- /dev/null
@@ -0,0 +1,144 @@
+// Copyright 2014 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.
+
+
+#[derive(Copy, Clone)]
+struct Foo {
+  bar1: Bar,
+  bar2: Bar
+}
+
+#[derive(Copy, Clone)]
+struct Bar {
+  int1: isize,
+  int2: isize,
+}
+
+fn make_foo() -> Box<Foo> { panic!() }
+
+fn borrow_same_field_twice_mut_mut() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1;
+    let _bar2 = &mut foo.bar1;  //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_same_field_twice_mut_imm() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1;
+    let _bar2 = &foo.bar1;  //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_same_field_twice_imm_mut() {
+    let mut foo = make_foo();
+    let bar1 = &foo.bar1;
+    let _bar2 = &mut foo.bar1;  //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_same_field_twice_imm_imm() {
+    let mut foo = make_foo();
+    let bar1 = &foo.bar1;
+    let _bar2 = &foo.bar1;
+    *bar1;
+}
+
+fn borrow_both_fields_mut() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1;
+    let _bar2 = &mut foo.bar2; //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_both_mut_pattern() {
+    let mut foo = make_foo();
+    match *foo {
+        Foo { bar1: ref mut _bar1, bar2: ref mut _bar2 } => {}
+        //~^ ERROR cannot borrow
+    }
+}
+
+fn borrow_var_and_pattern() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1;
+    match *foo {
+        Foo { bar1: ref mut _bar1, bar2: _ } => {}
+        //~^ ERROR cannot borrow
+    }
+    *bar1;
+}
+
+fn borrow_mut_and_base_imm() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1.int1;
+    let _foo1 = &foo.bar1; //~ ERROR cannot borrow
+    let _foo2 = &*foo; //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_mut_and_base_mut() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1.int1;
+    let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_mut_and_base_mut2() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1.int1;
+    let _foo2 = &mut *foo; //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_imm_and_base_mut() {
+    let mut foo = make_foo();
+    let bar1 = &foo.bar1.int1;
+    let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_imm_and_base_mut2() {
+    let mut foo = make_foo();
+    let bar1 = &foo.bar1.int1;
+    let _foo2 = &mut *foo; //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_imm_and_base_imm() {
+    let mut foo = make_foo();
+    let bar1 = &foo.bar1.int1;
+    let _foo1 = &foo.bar1;
+    let _foo2 = &*foo;
+    *bar1;
+}
+
+fn borrow_mut_and_imm() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1;
+    let _foo1 = &foo.bar2; //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_mut_from_imm() {
+    let foo = make_foo();
+    let bar1 = &mut foo.bar1; //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_long_path_both_mut() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1.int1;
+    let foo1 = &mut foo.bar2.int2; //~ ERROR cannot borrow
+    *bar1;
+    *foo1;
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-borrow-from-stack-variable.rs b/src/test/compile-fail/borrowck/borrowck-borrow-from-stack-variable.rs
new file mode 100644 (file)
index 0000000..440be93
--- /dev/null
@@ -0,0 +1,141 @@
+// 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.
+
+#[derive(Copy, Clone)]
+struct Foo {
+  bar1: Bar,
+  bar2: Bar
+}
+
+#[derive(Copy, Clone)]
+struct Bar {
+  int1: isize,
+  int2: isize,
+}
+
+fn make_foo() -> Foo { panic!() }
+
+fn borrow_same_field_twice_mut_mut() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1;
+    let _bar2 = &mut foo.bar1;  //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_same_field_twice_mut_imm() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1;
+    let _bar2 = &foo.bar1;  //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_same_field_twice_imm_mut() {
+    let mut foo = make_foo();
+    let bar1 = &foo.bar1;
+    let _bar2 = &mut foo.bar1;  //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_same_field_twice_imm_imm() {
+    let mut foo = make_foo();
+    let bar1 = &foo.bar1;
+    let _bar2 = &foo.bar1;
+    *bar1;
+}
+
+fn borrow_both_mut() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1;
+    let _bar2 = &mut foo.bar2;
+    *bar1;
+}
+
+fn borrow_both_mut_pattern() {
+    let mut foo = make_foo();
+    match foo {
+        Foo { bar1: ref mut _bar1, bar2: ref mut _bar2 } => {}
+    }
+}
+
+fn borrow_var_and_pattern() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1;
+    match foo {
+        Foo { bar1: ref mut _bar1, bar2: _ } => {} //
+        //~^ ERROR cannot borrow
+    }
+    *bar1;
+}
+
+fn borrow_mut_and_base_imm() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1.int1;
+    let _foo1 = &foo.bar1; //~ ERROR cannot borrow
+    let _foo2 = &foo; //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_mut_and_base_mut() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1.int1;
+    let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_mut_and_base_mut2() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1.int1;
+    let _foo2 = &mut foo; //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_imm_and_base_mut() {
+    let mut foo = make_foo();
+    let bar1 = &foo.bar1.int1;
+    let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_imm_and_base_mut2() {
+    let mut foo = make_foo();
+    let bar1 = &foo.bar1.int1;
+    let _foo2 = &mut foo; //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_imm_and_base_imm() {
+    let mut foo = make_foo();
+    let bar1 = &foo.bar1.int1;
+    let _foo1 = &foo.bar1;
+    let _foo2 = &foo;
+    *bar1;
+}
+
+fn borrow_mut_and_imm() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1;
+    let _foo1 = &foo.bar2;
+    *bar1;
+}
+
+fn borrow_mut_from_imm() {
+    let foo = make_foo();
+    let bar1 = &mut foo.bar1; //~ ERROR cannot borrow
+    *bar1;
+}
+
+fn borrow_long_path_both_mut() {
+    let mut foo = make_foo();
+    let bar1 = &mut foo.bar1.int1;
+    let _foo1 = &mut foo.bar2.int2;
+    *bar1;
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-borrow-from-temporary.rs b/src/test/compile-fail/borrowck/borrowck-borrow-from-temporary.rs
new file mode 100644 (file)
index 0000000..fbb3824
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2014 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 lifetimes are linked properly when we take reference
+// to interior.
+
+struct Foo(isize);
+
+fn foo<'a>() -> &'a isize {
+    let &Foo(ref x) = &Foo(3); //~ ERROR borrowed value does not live long enough
+    x
+}
+
+pub fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-borrow-immut-deref-of-box-as-mut.rs b/src/test/compile-fail/borrowck/borrowck-borrow-immut-deref-of-box-as-mut.rs
new file mode 100644 (file)
index 0000000..3662e23
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2014 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.
+
+#![feature(box_syntax)]
+
+struct A;
+
+impl A {
+    fn foo(&mut self) {
+    }
+}
+
+pub fn main() {
+    let a: Box<_> = box A;
+    a.foo();
+    //~^ ERROR cannot borrow immutable `Box` content `*a` as mutable
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs b/src/test/compile-fail/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs
new file mode 100644 (file)
index 0000000..d60751e
--- /dev/null
@@ -0,0 +1,34 @@
+// 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 attempt to reborrow an `&mut` pointer in an aliasable
+// location yields an error.
+//
+// Example from src/librustc_borrowck/borrowck/README.md
+
+fn foo(t0: & &mut isize) {
+    let t1 = t0;
+    let p: &isize = &**t0;
+    **t1 = 22; //~ ERROR cannot assign
+}
+
+fn foo3(t0: &mut &mut isize) {
+    let t1 = &mut *t0;
+    let p: &isize = &**t0; //~ ERROR cannot borrow
+    **t1 = 22;
+}
+
+fn foo4(t0: & &mut isize) {
+    let x:  &mut isize = &mut **t0; //~ ERROR cannot borrow
+    *x += 1;
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-borrow-mut-object-twice.rs b/src/test/compile-fail/borrowck/borrowck-borrow-mut-object-twice.rs
new file mode 100644 (file)
index 0000000..7175194
--- /dev/null
@@ -0,0 +1,24 @@
+// 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.
+
+// Check that `&mut` objects cannot be borrowed twice, just like
+// other `&mut` pointers.
+
+trait Foo {
+    fn f1(&mut self) -> &();
+    fn f2(&mut self);
+}
+
+fn test(x: &mut Foo) {
+    let _y = x.f1();
+    x.f2(); //~ ERROR cannot borrow `*x` as mutable
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-borrow-overloaded-auto-deref-mut.rs b/src/test/compile-fail/borrowck/borrowck-borrow-overloaded-auto-deref-mut.rs
new file mode 100644 (file)
index 0000000..497b0e6
--- /dev/null
@@ -0,0 +1,150 @@
+// Copyright 2014 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 how overloaded deref interacts with borrows when DerefMut
+// is implemented.
+
+use std::ops::{Deref, DerefMut};
+
+struct Own<T> {
+    value: *mut T
+}
+
+impl<T> Deref for Own<T> {
+    type Target = T;
+
+    fn deref(&self) -> &T {
+        unsafe { &*self.value }
+    }
+}
+
+impl<T> DerefMut for Own<T> {
+    fn deref_mut(&mut self) -> &mut T {
+        unsafe { &mut *self.value }
+    }
+}
+
+struct Point {
+    x: isize,
+    y: isize
+}
+
+impl Point {
+    fn get(&self) -> (isize, isize) {
+        (self.x, self.y)
+    }
+
+    fn set(&mut self, x: isize, y: isize) {
+        self.x = x;
+        self.y = y;
+    }
+
+    fn x_ref(&self) -> &isize {
+        &self.x
+    }
+
+    fn y_mut(&mut self) -> &mut isize {
+        &mut self.y
+    }
+}
+
+fn deref_imm_field(x: Own<Point>) {
+    let __isize = &x.y;
+}
+
+fn deref_mut_field1(x: Own<Point>) {
+    let __isize = &mut x.y; //~ ERROR cannot borrow
+}
+
+fn deref_mut_field2(mut x: Own<Point>) {
+    let __isize = &mut x.y;
+}
+
+fn deref_extend_field(x: &Own<Point>) -> &isize {
+    &x.y
+}
+
+fn deref_extend_mut_field1(x: &Own<Point>) -> &mut isize {
+    &mut x.y //~ ERROR cannot borrow
+}
+
+fn deref_extend_mut_field2(x: &mut Own<Point>) -> &mut isize {
+    &mut x.y
+}
+
+fn deref_extend_mut_field3(x: &mut Own<Point>) {
+    // Hmm, this is unfortunate, because with box it would work,
+    // but it's presently the expected outcome. See `deref_extend_mut_field4`
+    // for the workaround.
+
+    let _x = &mut x.x;
+    let _y = &mut x.y; //~ ERROR cannot borrow
+}
+
+fn deref_extend_mut_field4<'a>(x: &'a mut Own<Point>) {
+    let p = &mut **x;
+    let _x = &mut p.x;
+    let _y = &mut p.y;
+}
+
+fn assign_field1<'a>(x: Own<Point>) {
+    x.y = 3; //~ ERROR cannot borrow
+}
+
+fn assign_field2<'a>(x: &'a Own<Point>) {
+    x.y = 3; //~ ERROR cannot assign
+}
+
+fn assign_field3<'a>(x: &'a mut Own<Point>) {
+    x.y = 3;
+}
+
+fn assign_field4<'a>(x: &'a mut Own<Point>) {
+    let _p: &mut Point = &mut **x;
+    x.y = 3; //~ ERROR cannot borrow
+}
+
+fn deref_imm_method(x: Own<Point>) {
+    let __isize = x.get();
+}
+
+fn deref_mut_method1(x: Own<Point>) {
+    x.set(0, 0); //~ ERROR cannot borrow
+}
+
+fn deref_mut_method2(mut x: Own<Point>) {
+    x.set(0, 0);
+}
+
+fn deref_extend_method(x: &Own<Point>) -> &isize {
+    x.x_ref()
+}
+
+fn deref_extend_mut_method1(x: &Own<Point>) -> &mut isize {
+    x.y_mut() //~ ERROR cannot borrow
+}
+
+fn deref_extend_mut_method2(x: &mut Own<Point>) -> &mut isize {
+    x.y_mut()
+}
+
+fn assign_method1<'a>(x: Own<Point>) {
+    *x.y_mut() = 3; //~ ERROR cannot borrow
+}
+
+fn assign_method2<'a>(x: &'a Own<Point>) {
+    *x.y_mut() = 3; //~ ERROR cannot borrow
+}
+
+fn assign_method3<'a>(x: &'a mut Own<Point>) {
+    *x.y_mut() = 3;
+}
+
+pub fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-borrow-overloaded-auto-deref.rs b/src/test/compile-fail/borrowck/borrowck-borrow-overloaded-auto-deref.rs
new file mode 100644 (file)
index 0000000..693ed29
--- /dev/null
@@ -0,0 +1,124 @@
+// Copyright 2014 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 how overloaded deref interacts with borrows when only
+// Deref and not DerefMut is implemented.
+
+use std::ops::Deref;
+
+struct Rc<T> {
+    value: *const T
+}
+
+impl<T> Deref for Rc<T> {
+    type Target = T;
+
+    fn deref(&self) -> &T {
+        unsafe { &*self.value }
+    }
+}
+
+struct Point {
+    x: isize,
+    y: isize
+}
+
+impl Point {
+    fn get(&self) -> (isize, isize) {
+        (self.x, self.y)
+    }
+
+    fn set(&mut self, x: isize, y: isize) {
+        self.x = x;
+        self.y = y;
+    }
+
+    fn x_ref(&self) -> &isize {
+        &self.x
+    }
+
+    fn y_mut(&mut self) -> &mut isize {
+        &mut self.y
+    }
+}
+
+fn deref_imm_field(x: Rc<Point>) {
+    let __isize = &x.y;
+}
+
+fn deref_mut_field1(x: Rc<Point>) {
+    let __isize = &mut x.y; //~ ERROR cannot borrow
+}
+
+fn deref_mut_field2(mut x: Rc<Point>) {
+    let __isize = &mut x.y; //~ ERROR cannot borrow
+}
+
+fn deref_extend_field(x: &Rc<Point>) -> &isize {
+    &x.y
+}
+
+fn deref_extend_mut_field1(x: &Rc<Point>) -> &mut isize {
+    &mut x.y //~ ERROR cannot borrow
+}
+
+fn deref_extend_mut_field2(x: &mut Rc<Point>) -> &mut isize {
+    &mut x.y //~ ERROR cannot borrow
+}
+
+fn assign_field1<'a>(x: Rc<Point>) {
+    x.y = 3; //~ ERROR cannot assign
+}
+
+fn assign_field2<'a>(x: &'a Rc<Point>) {
+    x.y = 3; //~ ERROR cannot assign
+}
+
+fn assign_field3<'a>(x: &'a mut Rc<Point>) {
+    x.y = 3; //~ ERROR cannot assign
+}
+
+fn deref_imm_method(x: Rc<Point>) {
+    let __isize = x.get();
+}
+
+fn deref_mut_method1(x: Rc<Point>) {
+    x.set(0, 0); //~ ERROR cannot borrow
+}
+
+fn deref_mut_method2(mut x: Rc<Point>) {
+    x.set(0, 0); //~ ERROR cannot borrow
+}
+
+fn deref_extend_method(x: &Rc<Point>) -> &isize {
+    x.x_ref()
+}
+
+fn deref_extend_mut_method1(x: &Rc<Point>) -> &mut isize {
+    x.y_mut() //~ ERROR cannot borrow
+}
+
+fn deref_extend_mut_method2(x: &mut Rc<Point>) -> &mut isize {
+    x.y_mut() //~ ERROR cannot borrow
+}
+
+fn assign_method1<'a>(x: Rc<Point>) {
+    *x.y_mut() = 3; //~ ERROR cannot borrow
+}
+
+fn assign_method2<'a>(x: &'a Rc<Point>) {
+    *x.y_mut() = 3; //~ ERROR cannot borrow
+}
+
+fn assign_method3<'a>(x: &'a mut Rc<Point>) {
+    *x.y_mut() = 3; //~ ERROR cannot borrow
+}
+
+pub fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-borrow-overloaded-deref-mut.rs b/src/test/compile-fail/borrowck/borrowck-borrow-overloaded-deref-mut.rs
new file mode 100644 (file)
index 0000000..34b926a
--- /dev/null
@@ -0,0 +1,70 @@
+// Copyright 2014 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 how overloaded deref interacts with borrows when DerefMut
+// is implemented.
+
+use std::ops::{Deref, DerefMut};
+
+struct Own<T> {
+    value: *mut T
+}
+
+impl<T> Deref for Own<T> {
+    type Target = T;
+
+    fn deref<'a>(&'a self) -> &'a T {
+        unsafe { &*self.value }
+    }
+}
+
+impl<T> DerefMut for Own<T> {
+    fn deref_mut<'a>(&'a mut self) -> &'a mut T {
+        unsafe { &mut *self.value }
+    }
+}
+
+fn deref_imm(x: Own<isize>) {
+    let __isize = &*x;
+}
+
+fn deref_mut1(x: Own<isize>) {
+    let __isize = &mut *x; //~ ERROR cannot borrow
+}
+
+fn deref_mut2(mut x: Own<isize>) {
+    let __isize = &mut *x;
+}
+
+fn deref_extend<'a>(x: &'a Own<isize>) -> &'a isize {
+    &**x
+}
+
+fn deref_extend_mut1<'a>(x: &'a Own<isize>) -> &'a mut isize {
+    &mut **x //~ ERROR cannot borrow
+}
+
+fn deref_extend_mut2<'a>(x: &'a mut Own<isize>) -> &'a mut isize {
+    &mut **x
+}
+
+fn assign1<'a>(x: Own<isize>) {
+    *x = 3; //~ ERROR cannot borrow
+}
+
+fn assign2<'a>(x: &'a Own<isize>) {
+    **x = 3; //~ ERROR cannot borrow
+}
+
+fn assign3<'a>(x: &'a mut Own<isize>) {
+    **x = 3;
+}
+
+pub fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-borrow-overloaded-deref.rs b/src/test/compile-fail/borrowck/borrowck-borrow-overloaded-deref.rs
new file mode 100644 (file)
index 0000000..5b91624
--- /dev/null
@@ -0,0 +1,64 @@
+// Copyright 2014 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 how overloaded deref interacts with borrows when only
+// Deref and not DerefMut is implemented.
+
+use std::ops::Deref;
+
+struct Rc<T> {
+    value: *const T
+}
+
+impl<T> Deref for Rc<T> {
+    type Target = T;
+
+    fn deref<'a>(&'a self) -> &'a T {
+        unsafe { &*self.value }
+    }
+}
+
+fn deref_imm(x: Rc<isize>) {
+    let __isize = &*x;
+}
+
+fn deref_mut1(x: Rc<isize>) {
+    let __isize = &mut *x; //~ ERROR cannot borrow
+}
+
+fn deref_mut2(mut x: Rc<isize>) {
+    let __isize = &mut *x; //~ ERROR cannot borrow
+}
+
+fn deref_extend<'a>(x: &'a Rc<isize>) -> &'a isize {
+    &**x
+}
+
+fn deref_extend_mut1<'a>(x: &'a Rc<isize>) -> &'a mut isize {
+    &mut **x //~ ERROR cannot borrow
+}
+
+fn deref_extend_mut2<'a>(x: &'a mut Rc<isize>) -> &'a mut isize {
+    &mut **x //~ ERROR cannot borrow
+}
+
+fn assign1<'a>(x: Rc<isize>) {
+    *x = 3; //~ ERROR cannot assign
+}
+
+fn assign2<'a>(x: &'a Rc<isize>) {
+    **x = 3; //~ ERROR cannot assign
+}
+
+fn assign3<'a>(x: &'a mut Rc<isize>) {
+    **x = 3; //~ ERROR cannot assign
+}
+
+pub fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-borrowed-uniq-rvalue-2.rs b/src/test/compile-fail/borrowck/borrowck-borrowed-uniq-rvalue-2.rs
new file mode 100644 (file)
index 0000000..309e286
--- /dev/null
@@ -0,0 +1,33 @@
+// 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 defer<'a> {
+    x: &'a [&'a str],
+}
+
+impl<'a> Drop for defer<'a> {
+    fn drop(&mut self) {
+        unsafe {
+            println!("{:?}", self.x);
+        }
+    }
+}
+
+fn defer<'r>(x: &'r [&'r str]) -> defer<'r> {
+    defer {
+        x: x
+    }
+}
+
+fn main() {
+    let x = defer(&vec!("Goodbye", "world!"));
+    //~^ ERROR borrowed value does not live long enough
+    x.x[0];
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-borrowed-uniq-rvalue.rs b/src/test/compile-fail/borrowck/borrowck-borrowed-uniq-rvalue.rs
new file mode 100644 (file)
index 0000000..8bbecfd
--- /dev/null
@@ -0,0 +1,27 @@
+// 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.
+
+//buggy.rs
+
+#![feature(box_syntax)]
+
+extern crate collections;
+use std::collections::HashMap;
+
+fn main() {
+    let tmp: Box<_>;
+    let mut buggy_map: HashMap<usize, &usize> = HashMap::new();
+    // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
+    buggy_map.insert(42, &*Box::new(1)); //~ ERROR borrowed value does not live long enough
+
+    // but it is ok if we use a temporary
+    tmp = box 2;
+    buggy_map.insert(43, &*tmp);
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-box-insensitivity.rs b/src/test/compile-fail/borrowck/borrowck-box-insensitivity.rs
new file mode 100644 (file)
index 0000000..c980e77
--- /dev/null
@@ -0,0 +1,154 @@
+// Copyright 2014 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.
+
+#![feature(box_syntax)]
+
+struct A {
+    x: Box<isize>,
+    y: isize,
+}
+
+struct B {
+    x: Box<isize>,
+    y: Box<isize>,
+}
+
+struct C {
+    x: Box<A>,
+    y: isize,
+}
+
+struct D {
+    x: Box<A>,
+    y: Box<isize>,
+}
+
+fn copy_after_move() {
+    let a: Box<_> = box A { x: box 0, y: 1 };
+    let _x = a.x;
+    let _y = a.y; //~ ERROR use of moved
+    //~^^ NOTE `a` moved here (through moving `a.x`)
+}
+
+fn move_after_move() {
+    let a: Box<_> = box B { x: box 0, y: box 1 };
+    let _x = a.x;
+    let _y = a.y; //~ ERROR use of moved
+    //~^^ NOTE `a` moved here (through moving `a.x`)
+}
+
+fn borrow_after_move() {
+    let a: Box<_> = box A { x: box 0, y: 1 };
+    let _x = a.x;
+    let _y = &a.y; //~ ERROR use of moved
+    //~^^ NOTE `a` moved here (through moving `a.x`)
+}
+
+fn move_after_borrow() {
+    let a: Box<_> = box B { x: box 0, y: box 1 };
+    let _x = &a.x;
+    let _y = a.y; //~ ERROR cannot move
+}
+
+fn copy_after_mut_borrow() {
+    let mut a: Box<_> = box A { x: box 0, y: 1 };
+    let _x = &mut a.x;
+    let _y = a.y; //~ ERROR cannot use
+}
+
+fn move_after_mut_borrow() {
+    let mut a: Box<_> = box B { x: box 0, y: box 1 };
+    let _x = &mut a.x;
+    let _y = a.y; //~ ERROR cannot move
+}
+
+fn borrow_after_mut_borrow() {
+    let mut a: Box<_> = box A { x: box 0, y: 1 };
+    let _x = &mut a.x;
+    let _y = &a.y; //~ ERROR cannot borrow
+}
+
+fn mut_borrow_after_borrow() {
+    let mut a: Box<_> = box A { x: box 0, y: 1 };
+    let _x = &a.x;
+    let _y = &mut a.y; //~ ERROR cannot borrow
+}
+
+fn copy_after_move_nested() {
+    let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
+    let _x = a.x.x;
+    let _y = a.y; //~ ERROR use of collaterally moved
+}
+
+fn move_after_move_nested() {
+    let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
+    let _x = a.x.x;
+    let _y = a.y; //~ ERROR use of collaterally moved
+}
+
+fn borrow_after_move_nested() {
+    let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
+    let _x = a.x.x;
+    let _y = &a.y; //~ ERROR use of collaterally moved
+}
+
+fn move_after_borrow_nested() {
+    let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
+    let _x = &a.x.x;
+    let _y = a.y; //~ ERROR cannot move
+}
+
+fn copy_after_mut_borrow_nested() {
+    let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
+    let _x = &mut a.x.x;
+    let _y = a.y; //~ ERROR cannot use
+}
+
+fn move_after_mut_borrow_nested() {
+    let mut a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
+    let _x = &mut a.x.x;
+    let _y = a.y; //~ ERROR cannot move
+}
+
+fn borrow_after_mut_borrow_nested() {
+    let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
+    let _x = &mut a.x.x;
+    let _y = &a.y; //~ ERROR cannot borrow
+}
+
+fn mut_borrow_after_borrow_nested() {
+    let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
+    let _x = &a.x.x;
+    let _y = &mut a.y; //~ ERROR cannot borrow
+}
+
+fn main() {
+    copy_after_move();
+    move_after_move();
+    borrow_after_move();
+
+    move_after_borrow();
+
+    copy_after_mut_borrow();
+    move_after_mut_borrow();
+    borrow_after_mut_borrow();
+    mut_borrow_after_borrow();
+
+    copy_after_move_nested();
+    move_after_move_nested();
+    borrow_after_move_nested();
+
+    move_after_borrow_nested();
+
+    copy_after_mut_borrow_nested();
+    move_after_mut_borrow_nested();
+    borrow_after_mut_borrow_nested();
+    mut_borrow_after_borrow_nested();
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-break-uninit-2.rs b/src/test/compile-fail/borrowck/borrowck-break-uninit-2.rs
new file mode 100644 (file)
index 0000000..82a6c92
--- /dev/null
@@ -0,0 +1,24 @@
+// 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() -> isize {
+    let x: isize;
+
+    while 1 != 2  {
+        break;
+        x = 0;
+    }
+
+    println!("{}", x); //~ ERROR use of possibly uninitialized variable: `x`
+
+    return 17;
+}
+
+fn main() { println!("{}", foo()); }
diff --git a/src/test/compile-fail/borrowck/borrowck-break-uninit.rs b/src/test/compile-fail/borrowck/borrowck-break-uninit.rs
new file mode 100644 (file)
index 0000000..8a6a036
--- /dev/null
@@ -0,0 +1,24 @@
+// 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() -> isize {
+    let x: isize;
+
+    loop {
+        break;
+        x = 0;
+    }
+
+    println!("{}", x); //~ ERROR use of possibly uninitialized variable: `x`
+
+    return 17;
+}
+
+fn main() { println!("{}", foo()); }
diff --git a/src/test/compile-fail/borrowck/borrowck-call-is-borrow-issue-12224.rs b/src/test/compile-fail/borrowck/borrowck-call-is-borrow-issue-12224.rs
new file mode 100644 (file)
index 0000000..7626f35
--- /dev/null
@@ -0,0 +1,69 @@
+// Copyright 2014 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.
+
+// Ensure that invoking a closure counts as a unique immutable borrow
+
+#![feature(unboxed_closures)]
+
+type Fn<'a> = Box<FnMut() + 'a>;
+
+struct Test<'a> {
+    f: Box<FnMut() + 'a>
+}
+
+// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
+fn call<F>(mut f: F) where F: FnMut(Fn) {
+    f(Box::new(|| {
+    //~^ ERROR: cannot borrow `f` as mutable more than once
+        f((Box::new(|| {})))
+    }));
+}
+
+fn test1() {
+    call(|mut a| {
+        a.call_mut(());
+    });
+}
+
+fn test2<F>(f: &F) where F: FnMut() {
+    (*f)(); //~ ERROR: cannot borrow immutable borrowed content `*f` as mutable
+}
+
+fn test3<F>(f: &mut F) where F: FnMut() {
+    (*f)();
+}
+
+fn test4(f: &Test) {
+    f.f.call_mut(()) //~ ERROR: cannot borrow immutable `Box` content `*f.f` as mutable
+}
+
+fn test5(f: &mut Test) {
+    f.f.call_mut(())
+}
+
+fn test6() {
+    let mut f = || {};
+    (|| {
+        f();
+    })();
+}
+
+fn test7() {
+    fn foo<F>(_: F) where F: FnMut(Box<FnMut(isize)>, isize) {}
+    let mut f = |g: Box<FnMut(isize)>, b: isize| {};
+    // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
+    f(Box::new(|a| {
+        foo(f);
+        //~^ ERROR cannot move `f` into closure because it is borrowed
+        //~| ERROR cannot move out of captured outer variable in an `FnMut` closure
+    }), 3);
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-call-method-from-mut-aliasable.rs b/src/test/compile-fail/borrowck/borrowck-call-method-from-mut-aliasable.rs
new file mode 100644 (file)
index 0000000..bc0b667
--- /dev/null
@@ -0,0 +1,31 @@
+// 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 {
+    x: isize,
+}
+
+impl Foo {
+    pub fn f(&self) {}
+    pub fn h(&mut self) {}
+}
+
+fn a(x: &mut Foo) {
+    x.f();
+    x.h();
+}
+
+fn b(x: &Foo) {
+    x.f();
+    x.h(); //~ ERROR cannot borrow
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-closures-mut-and-imm.rs b/src/test/compile-fail/borrowck/borrowck-closures-mut-and-imm.rs
new file mode 100644 (file)
index 0000000..aaa0766
--- /dev/null
@@ -0,0 +1,81 @@
+// Copyright 2014 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 that two closures cannot simultaneously have mutable
+// and immutable access to the variable. Issue #6801.
+
+#![feature(box_syntax)]
+
+fn get(x: &isize) -> isize {
+    *x
+}
+
+fn set(x: &mut isize) {
+    *x = 4;
+}
+
+fn a() {
+    let mut x = 3;
+    let c1 = || x = 4;
+    let c2 = || x * 5; //~ ERROR cannot borrow `x`
+}
+
+fn b() {
+    let mut x = 3;
+    let c1 = || set(&mut x);
+    let c2 = || get(&x); //~ ERROR cannot borrow `x`
+}
+
+fn c() {
+    let mut x = 3;
+    let c1 = || set(&mut x);
+    let c2 = || x * 5; //~ ERROR cannot borrow `x`
+}
+
+fn d() {
+    let mut x = 3;
+    let c2 = || x * 5;
+    x = 5; //~ ERROR cannot assign
+}
+
+fn e() {
+    let mut x = 3;
+    let c1 = || get(&x);
+    x = 5; //~ ERROR cannot assign
+}
+
+fn f() {
+    let mut x: Box<_> = box 3;
+    let c1 = || get(&*x);
+    *x = 5; //~ ERROR cannot assign
+}
+
+fn g() {
+    struct Foo {
+        f: Box<isize>
+    }
+
+    let mut x: Box<_> = box Foo { f: box 3 };
+    let c1 = || get(&*x.f);
+    *x.f = 5; //~ ERROR cannot assign to `*x.f`
+}
+
+fn h() {
+    struct Foo {
+        f: Box<isize>
+    }
+
+    let mut x: Box<_> = box Foo { f: box 3 };
+    let c1 = || get(&*x.f);
+    let c2 = || *x.f = 5; //~ ERROR cannot borrow `x` as mutable
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-closures-mut-of-imm.rs b/src/test/compile-fail/borrowck/borrowck-closures-mut-of-imm.rs
new file mode 100644 (file)
index 0000000..40f9be2
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright 2014 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 that two closures cannot simultaneously have mutable
+// and immutable access to the variable. Issue #6801.
+
+fn get(x: &isize) -> isize {
+    *x
+}
+
+fn set(x: &mut isize) {
+    *x = 4;
+}
+
+fn a(x: &isize) {
+    let c1 = || set(&mut *x);
+    //~^ ERROR cannot borrow
+    let c2 = || set(&mut *x);
+    //~^ ERROR cannot borrow
+    //~| ERROR closure requires unique access
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-closures-two-mut.rs b/src/test/compile-fail/borrowck/borrowck-closures-two-mut.rs
new file mode 100644 (file)
index 0000000..29546ab
--- /dev/null
@@ -0,0 +1,60 @@
+// Copyright 2014 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 that two closures cannot simultaneously have mutable
+// access to the variable, whether that mutable access be used
+// for direct assignment or for taking mutable ref. Issue #6801.
+
+#![feature(box_syntax)]
+
+fn to_fn_mut<F: FnMut()>(f: F) -> F { f }
+
+fn a() {
+    let mut x = 3;
+    let c1 = to_fn_mut(|| x = 4);
+    let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable more than once
+}
+
+fn set(x: &mut isize) {
+    *x = 4;
+}
+
+fn b() {
+    let mut x = 3;
+    let c1 = to_fn_mut(|| set(&mut x));
+    let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as mutable more than once
+}
+
+fn c() {
+    let mut x = 3;
+    let c1 = to_fn_mut(|| x = 5);
+    let c2 = to_fn_mut(|| set(&mut x)); //~ ERROR cannot borrow `x` as mutable more than once
+}
+
+fn d() {
+    let mut x = 3;
+    let c1 = to_fn_mut(|| x = 5);
+    let c2 = to_fn_mut(|| { let _y = to_fn_mut(|| set(&mut x)); }); // (nested closure)
+    //~^ ERROR cannot borrow `x` as mutable more than once
+}
+
+fn g() {
+    struct Foo {
+        f: Box<isize>
+    }
+
+    let mut x: Box<_> = box Foo { f: box 3 };
+    let c1 = to_fn_mut(|| set(&mut *x.f));
+    let c2 = to_fn_mut(|| set(&mut *x.f));
+    //~^ ERROR cannot borrow `x` as mutable more than once
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-closures-unique-imm.rs b/src/test/compile-fail/borrowck/borrowck-closures-unique-imm.rs
new file mode 100644 (file)
index 0000000..247a4fe
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2014 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 {
+    x: isize,
+}
+
+pub fn main() {
+    let mut this = &mut Foo {
+        x: 1,
+    };
+    let mut r = || {
+        let p = &this.x;
+        &mut this.x; //~ ERROR cannot borrow
+    };
+    r()
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-closures-unique.rs b/src/test/compile-fail/borrowck/borrowck-closures-unique.rs
new file mode 100644 (file)
index 0000000..3646a68
--- /dev/null
@@ -0,0 +1,50 @@
+// Copyright 2014 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 that a closure which requires mutable access to the referent
+// of an `&mut` requires a "unique" borrow -- that is, the variable to
+// be borrowed (here, `x`) will not be borrowed *mutably*, but
+//  may be *immutable*, but we cannot allow
+// multiple borrows.
+
+fn get(x: &isize) -> isize {
+    *x
+}
+
+fn set(x: &mut isize) -> isize {
+    *x
+}
+
+fn a(x: &mut isize) {
+    let c1 = || get(x);
+    let c2 = || get(x);
+}
+
+fn b(x: &mut isize) {
+    let c1 = || get(x);
+    let c2 = || set(x); //~ ERROR closure requires unique access to `x`
+}
+
+fn c(x: &mut isize) {
+    let c1 = || get(x);
+    let c2 = || { get(x); set(x); }; //~ ERROR closure requires unique access to `x`
+}
+
+fn d(x: &mut isize) {
+    let c1 = || set(x);
+    let c2 = || set(x); //~ ERROR closure requires unique access to `x`
+}
+
+fn e(x: &mut isize) {
+    let c1 = || x = panic!(); //~ ERROR closure cannot assign to immutable argument
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-closures-use-after-free.rs b/src/test/compile-fail/borrowck/borrowck-closures-use-after-free.rs
new file mode 100644 (file)
index 0000000..bb47434
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright 2014 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 that a closure which mutates a local variable
+// cannot also be supplied a borrowed version of that
+// variable's contents. Issue #11192.
+
+#![feature(box_syntax)]
+
+struct Foo {
+  x: isize
+}
+
+impl Drop for Foo {
+  fn drop(&mut self) {
+    println!("drop {}", self.x);
+  }
+}
+
+fn main() {
+  let mut ptr: Box<_> = box Foo { x: 0 };
+  let mut test = |foo: &Foo| {
+    ptr = box Foo { x: ptr.x + 1 };
+  };
+  test(&*ptr); //~ ERROR cannot borrow `*ptr`
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-consume-unsize-vec.rs b/src/test/compile-fail/borrowck/borrowck-consume-unsize-vec.rs
new file mode 100644 (file)
index 0000000..32490e0
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2015 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.
+
+// Check that we report an error if an upcast box is moved twice.
+
+fn consume(_: Box<[i32]>) {
+}
+
+fn foo(b: Box<[i32;5]>) {
+    consume(b);
+    consume(b); //~ ERROR use of moved value
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-consume-upcast-box.rs b/src/test/compile-fail/borrowck/borrowck-consume-upcast-box.rs
new file mode 100644 (file)
index 0000000..5bcafa6
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2015 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.
+
+// Check that we report an error if an upcast box is moved twice.
+
+trait Foo { fn dummy(&self); }
+
+fn consume(_: Box<Foo>) {
+}
+
+fn foo(b: Box<Foo+Send>) {
+    consume(b);
+    consume(b); //~ ERROR use of moved value
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-escaping-closure-error-1.rs b/src/test/compile-fail/borrowck/borrowck-escaping-closure-error-1.rs
new file mode 100644 (file)
index 0000000..87e40df
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2015 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.
+
+use std::thread::spawn;
+
+// Test that we give a custom error (E0373) for the case where a
+// closure is escaping current frame, and offer a suggested code edit.
+// I refrained from including the precise message here, but the
+// original text as of the time of this writing is:
+//
+//    closure may outlive the current function, but it borrows `books`,
+//    which is owned by the current function
+
+fn main() {
+    let mut books = vec![1,2,3];
+    spawn(|| books.push(4));
+    //~^ ERROR E0373
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-escaping-closure-error-2.rs b/src/test/compile-fail/borrowck/borrowck-escaping-closure-error-2.rs
new file mode 100644 (file)
index 0000000..67700be
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2015 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 give a custom error (E0373) for the case where a
+// closure is escaping current frame, and offer a suggested code edit.
+// I refrained from including the precise message here, but the
+// original text as of the time of this writing is:
+//
+//    closure may outlive the current function, but it borrows `books`,
+//    which is owned by the current function
+
+fn foo<'a>(x: &'a i32) -> Box<FnMut()+'a> {
+    let mut books = vec![1,2,3];
+    Box::new(|| books.push(4))
+    //~^ ERROR E0373
+}
+
+fn main() { }
diff --git a/src/test/compile-fail/borrowck/borrowck-field-sensitivity.rs b/src/test/compile-fail/borrowck/borrowck-field-sensitivity.rs
new file mode 100644 (file)
index 0000000..13fd5fc
--- /dev/null
@@ -0,0 +1,126 @@
+// Copyright 2014 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.
+
+#![feature(box_syntax)]
+
+struct A { a: isize, b: Box<isize> }
+
+fn deref_after_move() {
+    let x = A { a: 1, b: box 2 };
+    drop(x.b);
+    drop(*x.b); //~ ERROR use of moved value: `*x.b`
+}
+
+fn deref_after_fu_move() {
+    let x = A { a: 1, b: box 2 };
+    let y = A { a: 3, .. x };
+    drop(*x.b); //~ ERROR use of moved value: `*x.b`
+}
+
+fn borrow_after_move() {
+    let x = A { a: 1, b: box 2 };
+    drop(x.b);
+    let p = &x.b; //~ ERROR use of moved value: `x.b`
+    drop(**p);
+}
+
+fn borrow_after_fu_move() {
+    let x = A { a: 1, b: box 2 };
+    let _y = A { a: 3, .. x };
+    let p = &x.b; //~ ERROR use of moved value: `x.b`
+    drop(**p);
+}
+
+fn move_after_borrow() {
+    let x = A { a: 1, b: box 2 };
+    let p = &x.b;
+    drop(x.b); //~ ERROR cannot move out of `x.b` because it is borrowed
+    drop(**p);
+}
+
+fn fu_move_after_borrow() {
+    let x = A { a: 1, b: box 2 };
+    let p = &x.b;
+    let _y = A { a: 3, .. x }; //~ ERROR cannot move out of `x.b` because it is borrowed
+    drop(**p);
+}
+
+fn mut_borrow_after_mut_borrow() {
+    let mut x = A { a: 1, b: box 2 };
+    let p = &mut x.a;
+    let q = &mut x.a; //~ ERROR cannot borrow `x.a` as mutable more than once at a time
+    drop(*p);
+    drop(*q);
+}
+
+fn move_after_move() {
+    let x = A { a: 1, b: box 2 };
+    drop(x.b);
+    drop(x.b);  //~ ERROR use of moved value: `x.b`
+}
+
+fn move_after_fu_move() {
+    let x = A { a: 1, b: box 2 };
+    let _y = A { a: 3, .. x };
+    drop(x.b);  //~ ERROR use of moved value: `x.b`
+}
+
+fn fu_move_after_move() {
+    let x = A { a: 1, b: box 2 };
+    drop(x.b);
+    let _z = A { a: 3, .. x };  //~ ERROR use of moved value: `x.b`
+}
+
+fn fu_move_after_fu_move() {
+    let x = A { a: 1, b: box 2 };
+    let _y = A { a: 3, .. x };
+    let _z = A { a: 4, .. x };  //~ ERROR use of moved value: `x.b`
+}
+
+// The following functions aren't yet accepted, but they should be.
+
+fn copy_after_field_assign_after_uninit() {
+    let mut x: A;
+    x.a = 1;
+    drop(x.a); //~ ERROR use of possibly uninitialized variable: `x.a`
+}
+
+fn borrow_after_field_assign_after_uninit() {
+    let mut x: A;
+    x.a = 1;
+    let p = &x.a; //~ ERROR use of possibly uninitialized variable: `x.a`
+    drop(*p);
+}
+
+fn move_after_field_assign_after_uninit() {
+    let mut x: A;
+    x.b = box 1;
+    drop(x.b); //~ ERROR use of possibly uninitialized variable: `x.b`
+}
+
+fn main() {
+    deref_after_move();
+    deref_after_fu_move();
+
+    borrow_after_move();
+    borrow_after_fu_move();
+    move_after_borrow();
+    fu_move_after_borrow();
+    mut_borrow_after_mut_borrow();
+
+    move_after_move();
+    move_after_fu_move();
+    fu_move_after_move();
+    fu_move_after_fu_move();
+
+    copy_after_field_assign_after_uninit();
+    borrow_after_field_assign_after_uninit();
+    move_after_field_assign_after_uninit();
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-fn-in-const-a.rs b/src/test/compile-fail/borrowck/borrowck-fn-in-const-a.rs
new file mode 100644 (file)
index 0000000..3098807
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2014 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.
+
+// Check that we check fns appearing in constant declarations.
+// Issue #22382.
+
+const MOVE: fn(&String) -> String = {
+    fn broken(x: &String) -> String {
+        return *x //~ ERROR cannot move
+    }
+    broken
+};
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-fn-in-const-b.rs b/src/test/compile-fail/borrowck/borrowck-fn-in-const-b.rs
new file mode 100644 (file)
index 0000000..7e29b2e
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2014 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.
+
+// Check that we check fns appearing in constant declarations.
+// Issue #22382.
+
+// How about mutating an immutable vector?
+const MUTATE: fn(&Vec<String>) = {
+    fn broken(x: &Vec<String>) {
+        x.push(format!("this is broken"));
+        //~^ ERROR cannot borrow
+    }
+    broken
+};
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-fn-in-const-c.rs b/src/test/compile-fail/borrowck/borrowck-fn-in-const-c.rs
new file mode 100644 (file)
index 0000000..e607397
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright 2014 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.
+
+// Check that we check fns appearing in constant declarations.
+// Issue #22382.
+
+// Returning local references?
+struct DropString {
+    inner: String
+}
+impl Drop for DropString {
+    fn drop(&mut self) {
+        self.inner.clear();
+        self.inner.push_str("dropped");
+    }
+}
+const LOCAL_REF: fn() -> &'static str = {
+    fn broken() -> &'static str {
+        let local = DropString { inner: format!("Some local string") };
+        return &local.inner; //~ ERROR does not live long enough
+    }
+    broken
+};
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-for-loop-correct-cmt-for-pattern.rs b/src/test/compile-fail/borrowck/borrowck-for-loop-correct-cmt-for-pattern.rs
new file mode 100644 (file)
index 0000000..31ec5ae
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright 2014 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 #16205.
+
+#![feature(box_syntax)]
+
+struct Foo {
+    a: [Box<isize>; 3],
+}
+
+fn main() {
+    let mut y = 1;
+    let x = Some(&mut y);
+    for &a in x.iter() {    //~ ERROR cannot move out
+    }
+
+    let f = Foo {
+        a: [box 3, box 4, box 5],
+    };
+    for &a in &f.a {  //~ ERROR cannot move out
+    }
+
+    let x: Option<Box<_>> = Some(box 1);
+    for &a in x.iter() {    //~ ERROR cannot move out
+    }
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-for-loop-head-linkage.rs b/src/test/compile-fail/borrowck/borrowck-for-loop-head-linkage.rs
new file mode 100644 (file)
index 0000000..b79fc5b
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2014 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.
+
+use std::iter::repeat;
+
+fn main() {
+    let mut vector = vec![1, 2];
+    for &x in &vector {
+        let cap = vector.capacity();
+        vector.extend(repeat(0));      //~ ERROR cannot borrow
+        vector[1] = 5;   //~ ERROR cannot borrow
+    }
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-if-no-else.rs b/src/test/compile-fail/borrowck/borrowck-if-no-else.rs
new file mode 100644 (file)
index 0000000..74b5428
--- /dev/null
@@ -0,0 +1,16 @@
+// 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: isize) { println!("{}", x); }
+
+fn main() {
+    let x: isize; if 1 > 2 { x = 10; }
+    foo(x); //~ ERROR use of possibly uninitialized variable: `x`
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-if-with-else.rs b/src/test/compile-fail/borrowck/borrowck-if-with-else.rs
new file mode 100644 (file)
index 0000000..f3b02d1
--- /dev/null
@@ -0,0 +1,21 @@
+// 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: isize) { println!("{}", x); }
+
+fn main() {
+    let x: isize;
+    if 1 > 2 {
+        println!("whoops");
+    } else {
+        x = 10;
+    }
+    foo(x); //~ ERROR use of possibly uninitialized variable: `x`
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-imm-ref-to-mut-rec-field-issue-3162-c.rs b/src/test/compile-fail/borrowck/borrowck-imm-ref-to-mut-rec-field-issue-3162-c.rs
new file mode 100644 (file)
index 0000000..8af1023
--- /dev/null
@@ -0,0 +1,18 @@
+// 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 main() {
+    let mut _a = 3;
+    let _b = &mut _a;
+    {
+        let _c = &*_b;
+        _a = 4; //~ ERROR cannot assign to `_a`
+    }
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-in-static.rs b/src/test/compile-fail/borrowck/borrowck-in-static.rs
new file mode 100644 (file)
index 0000000..16b0e86
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2015 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.
+
+// check that borrowck looks inside consts/statics
+
+static FN : &'static (Fn() -> (Box<Fn()->Box<i32>>) + Sync) = &|| {
+    let x = Box::new(0);
+    Box::new(|| x) //~ ERROR cannot move out of captured outer variable
+};
+
+fn main() {
+    let f = (FN)();
+    f();
+    f();
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-init-in-called-fn-expr.rs b/src/test/compile-fail/borrowck/borrowck-init-in-called-fn-expr.rs
new file mode 100644 (file)
index 0000000..5b32fd2
--- /dev/null
@@ -0,0 +1,17 @@
+// 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 main() {
+    let j = || -> isize {
+        let i: isize;
+        i //~ ERROR use of possibly uninitialized variable: `i`
+    };
+    j();
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-init-in-fn-expr.rs b/src/test/compile-fail/borrowck/borrowck-init-in-fn-expr.rs
new file mode 100644 (file)
index 0000000..65f1a1f
--- /dev/null
@@ -0,0 +1,17 @@
+// 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 main() {
+    let f  = || -> isize {
+        let i: isize;
+        i //~ ERROR use of possibly uninitialized variable: `i`
+    };
+    println!("{}", f());
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-init-in-fru.rs b/src/test/compile-fail/borrowck/borrowck-init-in-fru.rs
new file mode 100644 (file)
index 0000000..569ddb8
--- /dev/null
@@ -0,0 +1,21 @@
+// 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.
+
+#[derive(Clone)]
+struct point {
+    x: isize,
+    y: isize,
+}
+
+fn main() {
+    let mut origin: point;
+    origin = point {x: 10,.. origin}; //~ ERROR use of possibly uninitialized variable: `origin.y`
+    origin.clone();
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-init-op-equal.rs b/src/test/compile-fail/borrowck/borrowck-init-op-equal.rs
new file mode 100644 (file)
index 0000000..e0d93fd
--- /dev/null
@@ -0,0 +1,19 @@
+// 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() {
+    let v: isize;
+    v += 1; //~ ERROR use of possibly uninitialized variable: `v`
+    v.clone();
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-init-plus-equal.rs b/src/test/compile-fail/borrowck/borrowck-init-plus-equal.rs
new file mode 100644 (file)
index 0000000..a036286
--- /dev/null
@@ -0,0 +1,18 @@
+// 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() {
+    let mut v: isize;
+    v = v + 1; //~ ERROR use of possibly uninitialized variable: `v`
+    v.clone();
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-insert-during-each.rs b/src/test/compile-fail/borrowck/borrowck-insert-during-each.rs
new file mode 100644 (file)
index 0000000..2c63486
--- /dev/null
@@ -0,0 +1,36 @@
+// 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.
+
+extern crate collections;
+use std::collections::HashSet;
+
+struct Foo {
+  n: HashSet<isize>,
+}
+
+impl Foo {
+    pub fn foo<F>(&mut self, mut fun: F) where F: FnMut(&isize) {
+        for f in &self.n {
+            fun(f);
+        }
+    }
+}
+
+fn bar(f: &mut Foo) {
+  f.foo(
+        |a| { //~ ERROR closure requires unique access to `f`
+            f.n.insert(*a);
+        })
+}
+
+fn main() {
+  let mut f = Foo { n: HashSet::new() };
+  bar(&mut f);
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-issue-14498.rs b/src/test/compile-fail/borrowck/borrowck-issue-14498.rs
new file mode 100644 (file)
index 0000000..6403362
--- /dev/null
@@ -0,0 +1,124 @@
+// Copyright 2014 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.
+
+// This tests that we can't modify Box<&mut T> contents while they
+// are borrowed (#14498).
+//
+// Also includes tests of the errors reported when the Box in question
+// is immutable (#14270).
+
+#![feature(box_syntax)]
+
+struct A { a: isize }
+struct B<'a> { a: Box<&'a mut isize> }
+
+fn indirect_write_to_imm_box() {
+    let mut x: isize = 1;
+    let y: Box<_> = box &mut x;
+    let p = &y;
+    ***p = 2; //~ ERROR cannot assign to data in an immutable container
+    drop(p);
+}
+
+fn borrow_in_var_from_var() {
+    let mut x: isize = 1;
+    let mut y: Box<_> = box &mut x;
+    let p = &y;
+    let q = &***p;
+    **y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
+    drop(p);
+    drop(q);
+}
+
+fn borrow_in_var_from_var_via_imm_box() {
+    let mut x: isize = 1;
+    let y: Box<_> = box &mut x;
+    let p = &y;
+    let q = &***p;
+    **y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
+    //~^         ERROR cannot assign to data in an immutable container
+    drop(p);
+    drop(q);
+}
+
+fn borrow_in_var_from_field() {
+    let mut x = A { a: 1 };
+    let mut y: Box<_> = box &mut x.a;
+    let p = &y;
+    let q = &***p;
+    **y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
+    drop(p);
+    drop(q);
+}
+
+fn borrow_in_var_from_field_via_imm_box() {
+    let mut x = A { a: 1 };
+    let y: Box<_> = box &mut x.a;
+    let p = &y;
+    let q = &***p;
+    **y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
+    //~^         ERROR cannot assign to data in an immutable container
+    drop(p);
+    drop(q);
+}
+
+fn borrow_in_field_from_var() {
+    let mut x: isize = 1;
+    let mut y = B { a: box &mut x };
+    let p = &y.a;
+    let q = &***p;
+    **y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
+    drop(p);
+    drop(q);
+}
+
+fn borrow_in_field_from_var_via_imm_box() {
+    let mut x: isize = 1;
+    let y = B { a: box &mut x };
+    let p = &y.a;
+    let q = &***p;
+    **y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
+    //~^           ERROR cannot assign to data in an immutable container
+    drop(p);
+    drop(q);
+}
+
+fn borrow_in_field_from_field() {
+    let mut x = A { a: 1 };
+    let mut y = B { a: box &mut x.a };
+    let p = &y.a;
+    let q = &***p;
+    **y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
+    drop(p);
+    drop(q);
+}
+
+fn borrow_in_field_from_field_via_imm_box() {
+    let mut x = A { a: 1 };
+    let y = B { a: box &mut x.a };
+    let p = &y.a;
+    let q = &***p;
+    **y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
+    //~^           ERROR cannot assign to data in an immutable container
+    drop(p);
+    drop(q);
+}
+
+fn main() {
+    indirect_write_to_imm_box();
+    borrow_in_var_from_var();
+    borrow_in_var_from_var_via_imm_box();
+    borrow_in_var_from_field();
+    borrow_in_var_from_field_via_imm_box();
+    borrow_in_field_from_var();
+    borrow_in_field_from_var_via_imm_box();
+    borrow_in_field_from_field();
+    borrow_in_field_from_field_via_imm_box();
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-issue-2657-1.rs b/src/test/compile-fail/borrowck/borrowck-issue-2657-1.rs
new file mode 100644 (file)
index 0000000..0e17121
--- /dev/null
@@ -0,0 +1,21 @@
+// 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.
+
+#![feature(box_syntax)]
+
+fn main() {
+    let x: Option<Box<_>> = Some(box 1);
+    match x {
+      Some(ref _y) => {
+        let _a = x; //~ ERROR cannot move
+      }
+      _ => {}
+    }
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-issue-2657-2.rs b/src/test/compile-fail/borrowck/borrowck-issue-2657-2.rs
new file mode 100644 (file)
index 0000000..a389a4a
--- /dev/null
@@ -0,0 +1,21 @@
+// 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.
+
+#![feature(box_syntax)]
+
+fn main() {
+    let x: Option<Box<_>> = Some(box 1);
+    match x {
+      Some(ref y) => {
+        let _b = *y; //~ ERROR cannot move out
+      }
+      _ => {}
+    }
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-lend-flow-if.rs b/src/test/compile-fail/borrowck/borrowck-lend-flow-if.rs
new file mode 100644 (file)
index 0000000..a6ce36a
--- /dev/null
@@ -0,0 +1,54 @@
+// 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.
+
+// Note: the borrowck analysis is currently flow-insensitive.
+// Therefore, some of these errors are marked as spurious and could be
+// corrected by a simple change to the analysis.  The others are
+// either genuine or would require more advanced changes.  The latter
+// cases are noted.
+
+#![feature(box_syntax)]
+
+fn borrow(_v: &isize) {}
+fn borrow_mut(_v: &mut isize) {}
+fn cond() -> bool { panic!() }
+fn for_func<F>(_f: F) where F: FnOnce() -> bool { panic!() }
+fn produce<T>() -> T { panic!(); }
+
+fn inc(v: &mut Box<isize>) {
+    *v = box (**v + 1);
+}
+
+fn pre_freeze_cond() {
+    // In this instance, the freeze is conditional and starts before
+    // the mut borrow.
+
+    let mut v: Box<_> = box 3;
+    let _w;
+    if cond() {
+        _w = &v;
+    }
+    borrow_mut(&mut *v); //~ ERROR cannot borrow
+}
+
+fn pre_freeze_else() {
+    // In this instance, the freeze and mut borrow are on separate sides
+    // of the if.
+
+    let mut v: Box<_> = box 3;
+    let _w;
+    if cond() {
+        _w = &v;
+    } else {
+        borrow_mut(&mut *v);
+    }
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-lend-flow-loop.rs b/src/test/compile-fail/borrowck/borrowck-lend-flow-loop.rs
new file mode 100644 (file)
index 0000000..f09e7ff
--- /dev/null
@@ -0,0 +1,150 @@
+// 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.
+
+// Note: the borrowck analysis is currently flow-insensitive.
+// Therefore, some of these errors are marked as spurious and could be
+// corrected by a simple change to the analysis.  The others are
+// either genuine or would require more advanced changes.  The latter
+// cases are noted.
+
+#![feature(box_syntax)]
+
+fn borrow(_v: &isize) {}
+fn borrow_mut(_v: &mut isize) {}
+fn cond() -> bool { panic!() }
+fn produce<T>() -> T { panic!(); }
+
+fn inc(v: &mut Box<isize>) {
+    *v = box (**v + 1);
+}
+
+fn loop_overarching_alias_mut() {
+    // In this instance, the borrow encompasses the entire loop.
+
+    let mut v: Box<_> = box 3;
+    let mut x = &mut v;
+    **x += 1;
+    loop {
+        borrow(&*v); //~ ERROR cannot borrow
+    }
+}
+
+fn block_overarching_alias_mut() {
+    // In this instance, the borrow encompasses the entire closure call.
+
+    let mut v: Box<_> = box 3;
+    let mut x = &mut v;
+    for _ in 0..3 {
+        borrow(&*v); //~ ERROR cannot borrow
+    }
+    *x = box 5;
+}
+
+fn loop_aliased_mut() {
+    // In this instance, the borrow is carried through the loop.
+
+    let mut v: Box<_> = box 3;
+    let mut w: Box<_> = box 4;
+    let mut _x = &w;
+    loop {
+        borrow_mut(&mut *v); //~ ERROR cannot borrow
+        _x = &v;
+    }
+}
+
+fn while_aliased_mut() {
+    // In this instance, the borrow is carried through the loop.
+
+    let mut v: Box<_> = box 3;
+    let mut w: Box<_> = box 4;
+    let mut _x = &w;
+    while cond() {
+        borrow_mut(&mut *v); //~ ERROR cannot borrow
+        _x = &v;
+    }
+}
+
+
+fn loop_aliased_mut_break() {
+    // In this instance, the borrow is carried through the loop.
+
+    let mut v: Box<_> = box 3;
+    let mut w: Box<_> = box 4;
+    let mut _x = &w;
+    loop {
+        borrow_mut(&mut *v);
+        _x = &v;
+        break;
+    }
+    borrow_mut(&mut *v); //~ ERROR cannot borrow
+}
+
+fn while_aliased_mut_break() {
+    // In this instance, the borrow is carried through the loop.
+
+    let mut v: Box<_> = box 3;
+    let mut w: Box<_> = box 4;
+    let mut _x = &w;
+    while cond() {
+        borrow_mut(&mut *v);
+        _x = &v;
+        break;
+    }
+    borrow_mut(&mut *v); //~ ERROR cannot borrow
+}
+
+fn while_aliased_mut_cond(cond: bool, cond2: bool) {
+    let mut v: Box<_> = box 3;
+    let mut w: Box<_> = box 4;
+    let mut x = &mut w;
+    while cond {
+        **x += 1;
+        borrow(&*v); //~ ERROR cannot borrow
+        if cond2 {
+            x = &mut v; //~ ERROR cannot borrow
+        }
+    }
+}
+
+fn loop_break_pops_scopes<'r, F>(_v: &'r mut [usize], mut f: F) where
+    F: FnMut(&'r mut usize) -> bool,
+{
+    // Here we check that when you break out of an inner loop, the
+    // borrows that go out of scope as you exit the inner loop are
+    // removed from the bitset.
+
+    while cond() {
+        while cond() {
+            // this borrow is limited to the scope of `r`...
+            let r: &'r mut usize = produce();
+            if !f(&mut *r) {
+                break; // ...so it is not live as exit the `while` loop here
+            }
+        }
+    }
+}
+
+fn loop_loop_pops_scopes<'r, F>(_v: &'r mut [usize], mut f: F)
+    where F: FnMut(&'r mut usize) -> bool
+{
+    // Similar to `loop_break_pops_scopes` but for the `loop` keyword
+
+    while cond() {
+        while cond() {
+            // this borrow is limited to the scope of `r`...
+            let r: &'r mut usize = produce();
+            if !f(&mut *r) {
+                continue; // ...so it is not live as exit (and re-enter) the `while` loop here
+            }
+        }
+    }
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-lend-flow-match.rs b/src/test/compile-fail/borrowck/borrowck-lend-flow-match.rs
new file mode 100644 (file)
index 0000000..f24e82d
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright 2012-2014 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.
+
+#![allow(unused_variables)]
+#![allow(unused_assignments)]
+
+fn separate_arms() {
+    // Here both arms perform assignments, but only is illegal.
+
+    let mut x = None;
+    match x {
+        None => {
+            // It is ok to reassign x here, because there is in
+            // fact no outstanding loan of x!
+            x = Some(0);
+        }
+        Some(ref __isize) => {
+            x = Some(1); //~ ERROR cannot assign
+        }
+    }
+    x.clone(); // just to prevent liveness warnings
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-lend-flow.rs b/src/test/compile-fail/borrowck/borrowck-lend-flow.rs
new file mode 100644 (file)
index 0000000..1ed779c
--- /dev/null
@@ -0,0 +1,45 @@
+// 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.
+
+// Note: the borrowck analysis is currently flow-insensitive.
+// Therefore, some of these errors are marked as spurious and could be
+// corrected by a simple change to the analysis.  The others are
+// either genuine or would require more advanced changes.  The latter
+// cases are noted.
+
+#![feature(box_syntax)]
+
+fn borrow(_v: &isize) {}
+fn borrow_mut(_v: &mut isize) {}
+fn cond() -> bool { panic!() }
+fn for_func<F>(_f: F) where F: FnOnce() -> bool { panic!() }
+fn produce<T>() -> T { panic!(); }
+
+fn inc(v: &mut Box<isize>) {
+    *v = box (**v + 1);
+}
+
+fn pre_freeze() {
+    // In this instance, the freeze starts before the mut borrow.
+
+    let mut v: Box<_> = box 3;
+    let _w = &v;
+    borrow_mut(&mut *v); //~ ERROR cannot borrow
+}
+
+fn post_freeze() {
+    // In this instance, the const alias starts after the borrow.
+
+    let mut v: Box<_> = box 3;
+    borrow_mut(&mut *v);
+    let _w = &v;
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-let-suggestion-suffixes.rs b/src/test/compile-fail/borrowck/borrowck-let-suggestion-suffixes.rs
new file mode 100644 (file)
index 0000000..f551a2a
--- /dev/null
@@ -0,0 +1,57 @@
+// Copyright 2015 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 f() {
+    let old = ['o'];         // statement 0
+    let mut v1 = Vec::new(); // statement 1
+
+    let mut v2 = Vec::new(); // statement 2
+    //~^ NOTE reference must be valid for the block suffix following statement 2
+
+    let young = ['y'];       // statement 3
+    //~^ NOTE ...but borrowed value is only valid for the block suffix following statement 3
+
+    v2.push(&young[0]);      // statement 4
+    //~^ ERROR `young[..]` does not live long enough
+
+    let mut v3 = Vec::new(); // statement 5
+    //~^ NOTE reference must be valid for the block suffix following statement 5
+
+    v3.push(&'x');           // statement 6
+    //~^ ERROR borrowed value does not live long enough
+    //~| NOTE ...but borrowed value is only valid for the statement
+    //~| HELP consider using a `let` binding to increase its lifetime
+
+    {
+
+        let mut v4 = Vec::new(); // (sub) statement 0
+        //~^ NOTE reference must be valid for the block suffix following statement 0
+
+        v4.push(&'y');
+        //~^ ERROR borrowed value does not live long enough
+        //~| NOTE ...but borrowed value is only valid for the statement
+        //~| HELP consider using a `let` binding to increase its lifetime
+
+    }                       // (statement 7)
+
+    let mut v5 = Vec::new(); // statement 8
+    //~^ NOTE reference must be valid for the block suffix following statement 8
+
+    v5.push(&'z');
+    //~^ ERROR borrowed value does not live long enough
+    //~| NOTE ...but borrowed value is only valid for the statement
+    //~| HELP consider using a `let` binding to increase its lifetime
+
+    v1.push(&old[0]);
+}
+
+fn main() {
+    f();
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-let-suggestion.rs b/src/test/compile-fail/borrowck/borrowck-let-suggestion.rs
new file mode 100644 (file)
index 0000000..d760f3d
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2014 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 f() {
+    let x = [1].iter(); //~ ERROR borrowed value does not live long enough
+                         //~^ NOTE reference must be valid for the block suffix following statement
+                         //~^^ HELP consider using a `let` binding to increase its lifetime
+}
+
+fn main() {
+    f();
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-loan-blocks-move-cc.rs b/src/test/compile-fail/borrowck/borrowck-loan-blocks-move-cc.rs
new file mode 100644 (file)
index 0000000..57b584a
--- /dev/null
@@ -0,0 +1,38 @@
+// 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.
+
+#![feature(box_syntax)]
+
+use std::thread;
+
+fn borrow<F>(v: &isize, f: F) where F: FnOnce(&isize) {
+    f(v);
+}
+
+fn box_imm() {
+    let v: Box<_> = box 3;
+    let _w = &v;
+    thread::spawn(move|| {
+        println!("v={}", *v);
+        //~^ ERROR cannot move `v` into closure
+    });
+}
+
+fn box_imm_explicit() {
+    let v: Box<_> = box 3;
+    let _w = &v;
+    thread::spawn(move|| {
+        println!("v={}", *v);
+        //~^ ERROR cannot move
+    });
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-loan-blocks-move.rs b/src/test/compile-fail/borrowck/borrowck-loan-blocks-move.rs
new file mode 100644 (file)
index 0000000..f3f1880
--- /dev/null
@@ -0,0 +1,23 @@
+// 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.
+
+#![feature(box_syntax)]
+
+fn take(_v: Box<isize>) {
+}
+
+fn box_imm() {
+    let v = box 3;
+    let _w = &v;
+    take(v); //~ ERROR cannot move out of `v` because it is borrowed
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-loan-blocks-mut-uniq.rs b/src/test/compile-fail/borrowck/borrowck-loan-blocks-mut-uniq.rs
new file mode 100644 (file)
index 0000000..32d8088
--- /dev/null
@@ -0,0 +1,28 @@
+// 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.
+
+#![feature(box_syntax)]
+
+fn borrow<F>(v: &isize, f: F) where F: FnOnce(&isize) {
+    f(v);
+}
+
+fn box_imm() {
+    let mut v: Box<_> = box 3;
+    borrow(&*v,
+           |w| { //~ ERROR cannot borrow `v` as mutable
+            v = box 4;
+            assert_eq!(*v, 3);
+            assert_eq!(*w, 4);
+        })
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-loan-in-overloaded-op.rs b/src/test/compile-fail/borrowck/borrowck-loan-in-overloaded-op.rs
new file mode 100644 (file)
index 0000000..a9079cf
--- /dev/null
@@ -0,0 +1,33 @@
+// 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.
+
+#![feature(box_patterns)]
+#![feature(box_syntax)]
+
+use std::ops::Add;
+
+#[derive(Clone)]
+struct foo(Box<usize>);
+
+impl Add for foo {
+    type Output = foo;
+
+    fn add(self, f: foo) -> foo {
+        let foo(box i) = self;
+        let foo(box j) = f;
+        foo(box (i + j))
+    }
+}
+
+fn main() {
+    let x = foo(box 3);
+    let _y = {x} + x.clone(); // the `{x}` forces a move to occur
+    //~^ ERROR use of moved value: `x`
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-loan-of-static-data-issue-27616.rs b/src/test/compile-fail/borrowck/borrowck-loan-of-static-data-issue-27616.rs
new file mode 100644 (file)
index 0000000..228e710
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright 2015 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.
+
+use std::mem;
+
+fn leak<T>(mut b: Box<T>) -> &'static mut T {
+    // isn't this supposed to be safe?
+    let inner = &mut *b as *mut _;
+    mem::forget(b);
+    unsafe { &mut *inner }
+}
+
+fn evil(mut s: &'static mut String)
+{
+    // create alias
+    let alias: &'static mut String = s;
+    let inner: &str = &alias;
+    // free value
+    *s = String::new(); //~ ERROR cannot assign
+    let _spray = "0wned".to_owned();
+    // ... and then use it
+    println!("{}", inner);
+}
+
+fn main() {
+    evil(leak(Box::new("hello".to_owned())));
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-loan-rcvr-overloaded-op.rs b/src/test/compile-fail/borrowck/borrowck-loan-rcvr-overloaded-op.rs
new file mode 100644 (file)
index 0000000..cce55b6
--- /dev/null
@@ -0,0 +1,56 @@
+// 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.
+
+use std::ops::Add;
+
+#[derive(Copy, Clone)]
+struct Point {
+    x: isize,
+    y: isize,
+}
+
+impl Add<isize> for Point {
+    type Output = isize;
+
+    fn add(self, z: isize) -> isize {
+        self.x + self.y + z
+    }
+}
+
+impl Point {
+    pub fn times(&self, z: isize) -> isize {
+        self.x * self.y * z
+    }
+}
+
+fn a() {
+    let mut p = Point {x: 3, y: 4};
+
+    // ok (we can loan out rcvr)
+    p + 3;
+    p.times(3);
+}
+
+fn b() {
+    let mut p = Point {x: 3, y: 4};
+
+    // Here I create an outstanding loan and check that we get conflicts:
+
+    let q = &mut p;
+
+    p + 3;  //~ ERROR cannot use `p`
+    p.times(3); //~ ERROR cannot borrow `p`
+
+    *q + 3; // OK to use the new alias `q`
+    q.x += 1; // and OK to mutate it
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-loan-rcvr.rs b/src/test/compile-fail/borrowck/borrowck-loan-rcvr.rs
new file mode 100644 (file)
index 0000000..014b27f
--- /dev/null
@@ -0,0 +1,51 @@
+// 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 point { x: isize, y: isize }
+
+trait methods {
+    fn impurem(&self);
+    fn blockm<F>(&self, f: F) where F: FnOnce();
+}
+
+impl methods for point {
+    fn impurem(&self) {
+    }
+
+    fn blockm<F>(&self, f: F) where F: FnOnce() { f() }
+}
+
+fn a() {
+    let mut p = point {x: 3, y: 4};
+
+    // Here: it's ok to call even though receiver is mutable, because we
+    // can loan it out.
+    p.impurem();
+
+    // But in this case we do not honor the loan:
+    p.blockm(|| { //~ ERROR cannot borrow `p` as mutable
+        p.x = 10;
+    })
+}
+
+fn b() {
+    let mut p = point {x: 3, y: 4};
+
+    // Here I create an outstanding loan and check that we get conflicts:
+
+    let l = &mut p;
+    p.impurem(); //~ ERROR cannot borrow
+
+    l.x += 1;
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-loan-vec-content.rs b/src/test/compile-fail/borrowck/borrowck-loan-vec-content.rs
new file mode 100644 (file)
index 0000000..21d9dea
--- /dev/null
@@ -0,0 +1,34 @@
+// 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.
+
+// Here we check that it is allowed to lend out an element of a
+// (locally rooted) mutable, unique vector, and that we then prevent
+// modifications to the contents.
+
+fn takes_imm_elt<F>(_v: &isize, f: F) where F: FnOnce() {
+    f();
+}
+
+fn has_mut_vec_and_does_not_try_to_change_it() {
+    let mut v: Vec<isize> = vec!(1, 2, 3);
+    takes_imm_elt(&v[0], || {})
+}
+
+fn has_mut_vec_but_tries_to_change_it() {
+    let mut v: Vec<isize> = vec!(1, 2, 3);
+    takes_imm_elt(
+        &v[0],
+        || { //~ ERROR cannot borrow `v` as mutable
+            v[1] = 4;
+        })
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-match-binding-is-assignment.rs b/src/test/compile-fail/borrowck/borrowck-match-binding-is-assignment.rs
new file mode 100644 (file)
index 0000000..c219b7c
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright 2012-2014 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 immutable pattern bindings cannot be reassigned.
+
+#![feature(slice_patterns)]
+
+enum E {
+    Foo(isize)
+}
+
+struct S {
+    bar: isize,
+}
+
+pub fn main() {
+    match 1 {
+        x => {
+            x += 1; //~ ERROR re-assignment of immutable variable `x`
+        }
+    }
+
+    match E::Foo(1) {
+        E::Foo(x) => {
+            x += 1; //~ ERROR re-assignment of immutable variable `x`
+        }
+    }
+
+    match (S { bar: 1 }) {
+        S { bar: x } => {
+            x += 1; //~ ERROR re-assignment of immutable variable `x`
+        }
+    }
+
+    match (1,) {
+        (x,) => {
+            x += 1; //~ ERROR re-assignment of immutable variable `x`
+        }
+    }
+
+    match [1,2,3] {
+        [x,_,_] => {
+            x += 1; //~ ERROR re-assignment of immutable variable `x`
+        }
+    }
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-move-by-capture.rs b/src/test/compile-fail/borrowck/borrowck-move-by-capture.rs
new file mode 100644 (file)
index 0000000..bad5212
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright 2014 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.
+
+#![feature(box_syntax,unboxed_closures)]
+
+fn to_fn_mut<A,F:FnMut<A>>(f: F) -> F { f }
+fn to_fn_once<A,F:FnOnce<A>>(f: F) -> F { f }
+
+pub fn main() {
+    let bar: Box<_> = box 3;
+    let _g = to_fn_mut(|| {
+        let _h = to_fn_once(move || -> isize { *bar }); //~ ERROR cannot move out of
+    });
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-move-error-with-note.rs b/src/test/compile-fail/borrowck/borrowck-move-error-with-note.rs
new file mode 100644 (file)
index 0000000..e4b9fb2
--- /dev/null
@@ -0,0 +1,63 @@
+// Copyright 2014 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.
+
+#![feature(box_syntax)]
+
+enum Foo {
+    Foo1(Box<u32>, Box<u32>),
+    Foo2(Box<u32>),
+    Foo3,
+}
+
+fn blah() {
+    let f = &Foo::Foo1(box 1, box 2);
+    match *f {             //~ ERROR cannot move out of
+        Foo::Foo1(num1,         //~ NOTE attempting to move value to here
+                  num2) => (),  //~ NOTE and here
+        Foo::Foo2(num) => (),   //~ NOTE and here
+        Foo::Foo3 => ()
+    }
+}
+
+struct S {
+    f: String,
+    g: String
+}
+impl Drop for S {
+    fn drop(&mut self) { println!("{}", self.f); }
+}
+
+fn move_in_match() {
+    match (S {f: "foo".to_string(), g: "bar".to_string()}) {
+        S {         //~ ERROR cannot move out of type `S`, which defines the `Drop` trait
+            f: _s,  //~ NOTE attempting to move value to here
+            g: _t   //~ NOTE and here
+        } => {}
+    }
+}
+
+// from issue-8064
+struct A {
+    a: Box<isize>,
+}
+
+fn free<T>(_: T) {}
+
+fn blah2() {
+    let a = &A { a: box 1 };
+    match a.a {           //~ ERROR cannot move out of
+        n => {            //~ NOTE attempting to move value to here
+            free(n)
+        }
+    }
+    free(a)
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-move-from-subpath-of-borrowed-path.rs b/src/test/compile-fail/borrowck/borrowck-move-from-subpath-of-borrowed-path.rs
new file mode 100644 (file)
index 0000000..c02c6a7
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright 2014 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.
+
+// verify that an error is raised when trying to move out of a
+// borrowed path.
+
+#![feature(box_syntax)]
+
+fn main() {
+    let a: Box<Box<_>> = box box 2;
+    let b = &a;
+
+    let z = *a; //~ ERROR: cannot move out of `*a` because it is borrowed
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-move-from-unsafe-ptr.rs b/src/test/compile-fail/borrowck/borrowck-move-from-unsafe-ptr.rs
new file mode 100644 (file)
index 0000000..7284fa7
--- /dev/null
@@ -0,0 +1,18 @@
+// 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: *const Box<isize>) -> Box<isize> {
+    let y = *x; //~ ERROR dereference of raw pointer requires unsafe function or block
+    return y;
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-move-in-irrefut-pat.rs b/src/test/compile-fail/borrowck/borrowck-move-in-irrefut-pat.rs
new file mode 100644 (file)
index 0000000..ec505fa
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright 2014 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 with<F>(f: F) where F: FnOnce(&String) {}
+
+fn arg_item(&_x: &String) {}
+    //~^ ERROR cannot move out of borrowed content
+
+fn arg_closure() {
+    with(|&_x| ())
+    //~^ ERROR cannot move out of borrowed content
+}
+
+fn let_pat() {
+    let &_x = &"hi".to_string();
+    //~^ ERROR cannot move out of borrowed content
+}
+
+pub fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-move-moved-value-into-closure.rs b/src/test/compile-fail/borrowck/borrowck-move-moved-value-into-closure.rs
new file mode 100644 (file)
index 0000000..c46bcbb
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2014 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.
+
+#![feature(box_syntax)]
+
+fn call_f<F:FnOnce() -> isize>(f: F) -> isize {
+    f()
+}
+
+fn main() {
+    let t: Box<_> = box 3;
+
+    call_f(move|| { *t + 1 });
+    call_f(move|| { *t + 1 }); //~ ERROR capture of moved value
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-move-mut-base-ptr.rs b/src/test/compile-fail/borrowck/borrowck-move-mut-base-ptr.rs
new file mode 100644 (file)
index 0000000..2fb89e6
--- /dev/null
@@ -0,0 +1,23 @@
+// Copyright 2014 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 attempt to move `&mut` pointer while pointee is borrowed
+// yields an error.
+//
+// Example from src/librustc_borrowck/borrowck/README.md
+
+fn foo(t0: &mut isize) {
+    let p: &isize = &*t0; // Freezes `*t0`
+    let t1 = t0;        //~ ERROR cannot move out of `t0`
+    *t1 = 22;
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-move-out-of-overloaded-auto-deref.rs b/src/test/compile-fail/borrowck/borrowck-move-out-of-overloaded-auto-deref.rs
new file mode 100644 (file)
index 0000000..27cef1f
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright 2014 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.
+
+use std::rc::Rc;
+
+pub fn main() {
+    let _x = Rc::new(vec!(1, 2)).into_iter();
+    //~^ ERROR cannot move out of borrowed content
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-move-out-of-overloaded-deref.rs b/src/test/compile-fail/borrowck/borrowck-move-out-of-overloaded-deref.rs
new file mode 100644 (file)
index 0000000..fffcf57
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright 2014 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.
+
+use std::rc::Rc;
+
+pub fn main() {
+    let _x = *Rc::new("hi".to_string());
+    //~^ ERROR cannot move out of borrowed content
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-move-out-of-static-item.rs b/src/test/compile-fail/borrowck/borrowck-move-out-of-static-item.rs
new file mode 100644 (file)
index 0000000..8b83b94
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright 2014 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.
+
+// Ensure that moves out of static items is forbidden
+
+struct Foo {
+    foo: isize,
+}
+
+static BAR: Foo = Foo { foo: 5 };
+
+
+fn test(f: Foo) {
+    let _f = Foo{foo: 4, ..f};
+}
+
+fn main() {
+    test(BAR); //~ ERROR cannot move out of static item
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-move-out-of-struct-with-dtor.rs b/src/test/compile-fail/borrowck/borrowck-move-out-of-struct-with-dtor.rs
new file mode 100644 (file)
index 0000000..3d13cbe
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright 2014 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 S {f:String}
+impl Drop for S {
+    fn drop(&mut self) { println!("{}", self.f); }
+}
+
+fn move_in_match() {
+    match (S {f:"foo".to_string()}) {
+        S {f:_s} => {}
+        //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
+    }
+}
+
+fn move_in_let() {
+    let S {f:_s} = S {f:"foo".to_string()};
+    //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
+}
+
+fn move_in_fn_arg(S {f:_s}: S) {
+    //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.rs b/src/test/compile-fail/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.rs
new file mode 100644 (file)
index 0000000..625f718
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright 2014 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 S(String);
+impl Drop for S {
+    fn drop(&mut self) { }
+}
+
+fn move_in_match() {
+    match S("foo".to_string()) {
+        S(_s) => {}
+        //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
+    }
+}
+
+fn move_in_let() {
+    let S(_s) = S("foo".to_string());
+    //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
+}
+
+fn move_in_fn_arg(S(_s): S) {
+    //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-move-out-of-vec-tail.rs b/src/test/compile-fail/borrowck/borrowck-move-out-of-vec-tail.rs
new file mode 100644 (file)
index 0000000..d9a2f89
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright 2014 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 do not permit moves from &[] matched by a vec pattern.
+
+#![feature(slice_patterns)]
+
+#[derive(Clone, Debug)]
+struct Foo {
+    string: String
+}
+
+pub fn main() {
+    let x = vec!(
+        Foo { string: "foo".to_string() },
+        Foo { string: "bar".to_string() },
+        Foo { string: "baz".to_string() }
+    );
+    let x: &[Foo] = &x;
+    match x {
+        [_, tail..] => {
+            match tail {
+                [Foo { string: a }, //~ ERROR cannot move out of borrowed content
+                 Foo { string: b }] => {
+                    //~^^ NOTE attempting to move value to here
+                    //~^^ NOTE and here
+                }
+                _ => {
+                    unreachable!();
+                }
+            }
+            let z = tail[0].clone();
+            println!("{:?}", z);
+        }
+        _ => {
+            unreachable!();
+        }
+    }
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-move-subcomponent.rs b/src/test/compile-fail/borrowck/borrowck-move-subcomponent.rs
new file mode 100644 (file)
index 0000000..88871dd
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright 2012-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.
+
+// Tests that the borrow checker checks all components of a path when moving
+// out.
+
+#![feature(box_syntax)]
+
+struct S {
+  x : Box<isize>
+}
+
+fn f<T>(_: T) {}
+
+fn main() {
+  let a : S = S { x : box 1 };
+  let pb = &a;
+  let S { x: ax } = a;  //~ ERROR cannot move out
+  f(pb);
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-multiple-captures.rs b/src/test/compile-fail/borrowck/borrowck-multiple-captures.rs
new file mode 100644 (file)
index 0000000..042b914
--- /dev/null
@@ -0,0 +1,65 @@
+// Copyright 2014 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.
+
+#![feature(box_syntax)]
+
+use std::thread;
+
+fn borrow<T>(_: &T) { }
+
+fn different_vars_after_borrows() {
+    let x1: Box<_> = box 1;
+    let p1 = &x1;
+    let x2: Box<_> = box 2;
+    let p2 = &x2;
+    thread::spawn(move|| {
+        drop(x1); //~ ERROR cannot move `x1` into closure because it is borrowed
+        drop(x2); //~ ERROR cannot move `x2` into closure because it is borrowed
+    });
+    borrow(&*p1);
+    borrow(&*p2);
+}
+
+fn different_vars_after_moves() {
+    let x1: Box<_> = box 1;
+    drop(x1);
+    let x2: Box<_> = box 2;
+    drop(x2);
+    thread::spawn(move|| {
+        drop(x1); //~ ERROR capture of moved value: `x1`
+        drop(x2); //~ ERROR capture of moved value: `x2`
+    });
+}
+
+fn same_var_after_borrow() {
+    let x: Box<_> = box 1;
+    let p = &x;
+    thread::spawn(move|| {
+        drop(x); //~ ERROR cannot move `x` into closure because it is borrowed
+        drop(x); //~ ERROR use of moved value: `x`
+    });
+    borrow(&*p);
+}
+
+fn same_var_after_move() {
+    let x: Box<_> = box 1;
+    drop(x);
+    thread::spawn(move|| {
+        drop(x); //~ ERROR capture of moved value: `x`
+        drop(x); //~ ERROR use of moved value: `x`
+    });
+}
+
+fn main() {
+    different_vars_after_borrows();
+    different_vars_after_moves();
+    same_var_after_borrow();
+    same_var_after_move();
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-mut-addr-of-imm-var.rs b/src/test/compile-fail/borrowck/borrowck-mut-addr-of-imm-var.rs
new file mode 100644 (file)
index 0000000..b6626a8
--- /dev/null
@@ -0,0 +1,16 @@
+// 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 main() {
+    let x: isize = 3;
+    let y: &mut isize = &mut x; //~ ERROR cannot borrow
+    *y = 5;
+    println!("{}", *y);
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-mut-borrow-linear-errors.rs b/src/test/compile-fail/borrowck/borrowck-mut-borrow-linear-errors.rs
new file mode 100644 (file)
index 0000000..38e0e27
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright 2015 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 to ensure we only report an error for the first issued loan that
+// conflicts with a new loan, as opposed to every issued loan.  This keeps us
+// down to O(n) errors (for n problem lines), instead of O(n^2) errors.
+
+fn main() {
+    let mut x = 1;
+    let mut addr;
+    loop {
+        match 1 {
+            1 => { addr = &mut x; }
+            //~^ ERROR cannot borrow `x` as mutable more than once at a time
+            2 => { addr = &mut x; }
+            //~^ ERROR cannot borrow `x` as mutable more than once at a time
+            _ => { addr = &mut x; }
+            //~^ ERROR cannot borrow `x` as mutable more than once at a time
+        }
+    }
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-mut-borrow-of-mut-base-ptr.rs b/src/test/compile-fail/borrowck/borrowck-mut-borrow-of-mut-base-ptr.rs
new file mode 100644 (file)
index 0000000..bdeb7ea
--- /dev/null
@@ -0,0 +1,31 @@
+// 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.
+
+// Test that attempt to mutably borrow `&mut` pointer while pointee is
+// borrowed yields an error.
+//
+// Example from src/librustc_borrowck/borrowck/README.md
+
+fn foo<'a>(mut t0: &'a mut isize,
+           mut t1: &'a mut isize) {
+    let p: &isize = &*t0;     // Freezes `*t0`
+    let mut t2 = &mut t0;   //~ ERROR cannot borrow `t0`
+    **t2 += 1;              // Mutates `*t0`
+}
+
+fn bar<'a>(mut t0: &'a mut isize,
+           mut t1: &'a mut isize) {
+    let p: &mut isize = &mut *t0; // Claims `*t0`
+    let mut t2 = &mut t0;       //~ ERROR cannot borrow `t0`
+    **t2 += 1;                  // Mutates `*t0` but not through `*p`
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-mut-slice-of-imm-vec.rs b/src/test/compile-fail/borrowck/borrowck-mut-slice-of-imm-vec.rs
new file mode 100644 (file)
index 0000000..9341758
--- /dev/null
@@ -0,0 +1,18 @@
+// 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 write(v: &mut [isize]) {
+    v[0] += 1;
+}
+
+fn main() {
+    let v = vec!(1, 2, 3);
+    write(&mut v); //~ ERROR cannot borrow
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-mutate-in-guard.rs b/src/test/compile-fail/borrowck/borrowck-mutate-in-guard.rs
new file mode 100644 (file)
index 0000000..e35edca
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright 2014 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.
+
+enum Enum<'a> {
+    A(&'a isize),
+    B(bool),
+}
+
+fn foo() -> isize {
+    let mut n = 42;
+    let mut x = Enum::A(&mut n);
+    match x {
+        Enum::A(_) if { x = Enum::B(false); false } => 1,
+        //~^ ERROR cannot assign in a pattern guard
+        Enum::A(_) if { let y = &mut x; *y = Enum::B(false); false } => 1,
+        //~^ ERROR cannot mutably borrow in a pattern guard
+        //~^^ ERROR cannot assign in a pattern guard
+        Enum::A(p) => *p,
+        Enum::B(_) => 2,
+    }
+}
+
+fn main() {
+    foo();
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-no-cycle-in-exchange-heap.rs b/src/test/compile-fail/borrowck/borrowck-no-cycle-in-exchange-heap.rs
new file mode 100644 (file)
index 0000000..8cb7423
--- /dev/null
@@ -0,0 +1,30 @@
+// 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.
+
+#![feature(box_syntax)]
+
+struct node_ {
+    a: Box<cycle>
+}
+
+enum cycle {
+    node(node_),
+    empty
+}
+fn main() {
+    let mut x: Box<_> = box cycle::node(node_ {a: box cycle::empty});
+    // Create a cycle!
+    match *x {
+      cycle::node(ref mut y) => {
+        y.a = x; //~ ERROR cannot move out of
+      }
+      cycle::empty => {}
+    };
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-object-lifetime.rs b/src/test/compile-fail/borrowck/borrowck-object-lifetime.rs
new file mode 100644 (file)
index 0000000..021b3f3
--- /dev/null
@@ -0,0 +1,39 @@
+// Copyright 2014 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 borrows that occur due to calls to object methods
+// properly "claim" the object path.
+
+trait Foo {
+    fn borrowed(&self) -> &();
+    fn mut_borrowed(&mut self) -> &();
+}
+
+fn borrowed_receiver(x: &Foo) {
+    let _y = x.borrowed();
+    let _z = x.borrowed();
+}
+
+fn mut_borrowed_receiver(x: &mut Foo) {
+    let _y = x.borrowed();
+    let _z = x.mut_borrowed(); //~ ERROR cannot borrow
+}
+
+fn mut_owned_receiver(mut x: Box<Foo>) {
+    let _y = x.borrowed();
+    let _z = &mut x; //~ ERROR cannot borrow
+}
+
+fn imm_owned_receiver(mut x: Box<Foo>) {
+    let _y = x.borrowed();
+    let _z = &x;
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-object-mutability.rs b/src/test/compile-fail/borrowck/borrowck-object-mutability.rs
new file mode 100644 (file)
index 0000000..1bdc32b
--- /dev/null
@@ -0,0 +1,37 @@
+// 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.
+
+
+trait Foo {
+    fn borrowed(&self);
+    fn borrowed_mut(&mut self);
+}
+
+fn borrowed_receiver(x: &Foo) {
+    x.borrowed();
+    x.borrowed_mut(); //~ ERROR cannot borrow
+}
+
+fn borrowed_mut_receiver(x: &mut Foo) {
+    x.borrowed();
+    x.borrowed_mut();
+}
+
+fn owned_receiver(x: Box<Foo>) {
+    x.borrowed();
+    x.borrowed_mut(); //~ ERROR cannot borrow
+}
+
+fn mut_owned_receiver(mut x: Box<Foo>) {
+    x.borrowed();
+    x.borrowed_mut();
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-or-init.rs b/src/test/compile-fail/borrowck/borrowck-or-init.rs
new file mode 100644 (file)
index 0000000..27871a6
--- /dev/null
@@ -0,0 +1,16 @@
+// 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 main() {
+    let i: isize;
+
+    println!("{}", false || { i = 5; true });
+    println!("{}", i); //~ ERROR use of possibly uninitialized variable: `i`
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-overloaded-call.rs b/src/test/compile-fail/borrowck/borrowck-overloaded-call.rs
new file mode 100644 (file)
index 0000000..93c3752
--- /dev/null
@@ -0,0 +1,89 @@
+// 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.
+
+#![feature(unboxed_closures)]
+
+use std::ops::{Fn, FnMut, FnOnce};
+
+struct SFn {
+    x: isize,
+    y: isize,
+}
+
+impl Fn<(isize,)> for SFn {
+    extern "rust-call" fn call(&self, (z,): (isize,)) -> isize {
+        self.x * self.y * z
+    }
+}
+
+impl FnMut<(isize,)> for SFn {
+    extern "rust-call" fn call_mut(&mut self, args: (isize,)) -> isize { self.call(args) }
+}
+
+impl FnOnce<(isize,)> for SFn {
+    type Output = isize;
+    extern "rust-call" fn call_once(self, args: (isize,)) -> isize { self.call(args) }
+}
+
+struct SFnMut {
+    x: isize,
+    y: isize,
+}
+
+impl FnMut<(isize,)> for SFnMut {
+    extern "rust-call" fn call_mut(&mut self, (z,): (isize,)) -> isize {
+        self.x * self.y * z
+    }
+}
+
+impl FnOnce<(isize,)> for SFnMut {
+    type Output = isize;
+    extern "rust-call" fn call_once(mut self, args: (isize,)) -> isize { self.call_mut(args) }
+}
+
+struct SFnOnce {
+    x: String,
+}
+
+impl FnOnce<(String,)> for SFnOnce {
+    type Output = usize;
+
+    extern "rust-call" fn call_once(self, (z,): (String,)) -> usize {
+        self.x.len() + z.len()
+    }
+}
+
+fn f() {
+    let mut s = SFn {
+        x: 1,
+        y: 2,
+    };
+    let sp = &mut s;
+    s(3);   //~ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
+    //~^ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
+}
+
+fn g() {
+    let s = SFnMut {
+        x: 1,
+        y: 2,
+    };
+    s(3);   //~ ERROR cannot borrow immutable local variable `s` as mutable
+}
+
+fn h() {
+    let s = SFnOnce {
+        x: "hello".to_string(),
+    };
+    s(" world".to_string());
+    s(" world".to_string());    //~ ERROR use of moved value: `s`
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-overloaded-index-and-overloaded-deref.rs b/src/test/compile-fail/borrowck/borrowck-overloaded-index-and-overloaded-deref.rs
new file mode 100644 (file)
index 0000000..bee56c9
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright 2015 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.
+
+// Check that we properly record borrows when we are doing an
+// overloaded, autoderef of a value obtained via an overloaded index
+// operator. The accounting of the all the implicit things going on
+// here is rather subtle. Issue #20232.
+
+use std::ops::{Deref, Index};
+
+struct MyVec<T> { x: T }
+
+impl<T> Index<usize> for MyVec<T> {
+    type Output = T;
+    fn index(&self, _: usize) -> &T {
+        &self.x
+    }
+}
+
+struct MyPtr<T> { x: T }
+
+impl<T> Deref for MyPtr<T> {
+    type Target = T;
+    fn deref(&self) -> &T {
+        &self.x
+    }
+}
+
+struct Foo { f: usize }
+
+fn main() {
+    let mut v = MyVec { x: MyPtr { x: Foo { f: 22 } } };
+    let i = &v[0].f;
+    v = MyVec { x: MyPtr { x: Foo { f: 23 } } };
+    //~^ ERROR cannot assign to `v`
+    read(*i);
+}
+
+fn read(_: usize) { }
diff --git a/src/test/compile-fail/borrowck/borrowck-overloaded-index-autoderef.rs b/src/test/compile-fail/borrowck/borrowck-overloaded-index-autoderef.rs
new file mode 100644 (file)
index 0000000..b726c46
--- /dev/null
@@ -0,0 +1,93 @@
+// Copyright 2014 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 still see borrowck errors of various kinds when using
+// indexing and autoderef in combination.
+
+use std::ops::{Index, IndexMut};
+
+struct Foo {
+    x: isize,
+    y: isize,
+}
+
+impl<'a> Index<&'a String> for Foo {
+    type Output = isize;
+
+    fn index(&self, z: &String) -> &isize {
+        if *z == "x" {
+            &self.x
+        } else {
+            &self.y
+        }
+    }
+}
+
+impl<'a> IndexMut<&'a String> for Foo {
+    fn index_mut(&mut self, z: &String) -> &mut isize {
+        if *z == "x" {
+            &mut self.x
+        } else {
+            &mut self.y
+        }
+    }
+}
+
+fn test1(mut f: Box<Foo>, s: String) {
+    let _p = &mut f[&s];
+    let _q = &f[&s]; //~ ERROR cannot borrow
+}
+
+fn test2(mut f: Box<Foo>, s: String) {
+    let _p = &mut f[&s];
+    let _q = &mut f[&s]; //~ ERROR cannot borrow
+}
+
+struct Bar {
+    foo: Foo
+}
+
+fn test3(mut f: Box<Bar>, s: String) {
+    let _p = &mut f.foo[&s];
+    let _q = &mut f.foo[&s]; //~ ERROR cannot borrow
+}
+
+fn test4(mut f: Box<Bar>, s: String) {
+    let _p = &f.foo[&s];
+    let _q = &f.foo[&s];
+}
+
+fn test5(mut f: Box<Bar>, s: String) {
+    let _p = &f.foo[&s];
+    let _q = &mut f.foo[&s]; //~ ERROR cannot borrow
+}
+
+fn test6(mut f: Box<Bar>, g: Foo, s: String) {
+    let _p = &f.foo[&s];
+    f.foo = g; //~ ERROR cannot assign
+}
+
+fn test7(mut f: Box<Bar>, g: Bar, s: String) {
+    let _p = &f.foo[&s];
+    *f = g; //~ ERROR cannot assign
+}
+
+fn test8(mut f: Box<Bar>, g: Foo, s: String) {
+    let _p = &mut f.foo[&s];
+    f.foo = g; //~ ERROR cannot assign
+}
+
+fn test9(mut f: Box<Bar>, g: Bar, s: String) {
+    let _p = &mut f.foo[&s];
+    *f = g; //~ ERROR cannot assign
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-overloaded-index-move-from-vec.rs b/src/test/compile-fail/borrowck/borrowck-overloaded-index-move-from-vec.rs
new file mode 100644 (file)
index 0000000..1b62d9c
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright 2014 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.
+
+#![feature(box_syntax)]
+
+use std::ops::Index;
+
+struct MyVec<T> {
+    data: Vec<T>,
+}
+
+impl<T> Index<usize> for MyVec<T> {
+    type Output = T;
+
+    fn index(&self, i: usize) -> &T {
+        &self.data[i]
+    }
+}
+
+fn main() {
+    let v = MyVec::<Box<_>> { data: vec!(box 1, box 2, box 3) };
+    let good = &v[0]; // Shouldn't fail here
+    let bad = v[0];
+    //~^ ERROR cannot move out of indexed content
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-overloaded-index-move-index.rs b/src/test/compile-fail/borrowck/borrowck-overloaded-index-move-index.rs
new file mode 100644 (file)
index 0000000..d8615d1
--- /dev/null
@@ -0,0 +1,74 @@
+// Copyright 2014 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.
+
+use std::ops::{Index, IndexMut};
+
+struct Foo {
+    x: isize,
+    y: isize,
+}
+
+impl Index<String> for Foo {
+    type Output = isize;
+
+    fn index(&self, z: String) -> &isize {
+        if z == "x" {
+            &self.x
+        } else {
+            &self.y
+        }
+    }
+}
+
+impl IndexMut<String> for Foo {
+    fn index_mut(&mut self, z: String) -> &mut isize {
+        if z == "x" {
+            &mut self.x
+        } else {
+            &mut self.y
+        }
+    }
+}
+
+struct Bar {
+    x: isize,
+}
+
+impl Index<isize> for Bar {
+    type Output = isize;
+
+    fn index<'a>(&'a self, z: isize) -> &'a isize {
+        &self.x
+    }
+}
+
+fn main() {
+    let mut f = Foo {
+        x: 1,
+        y: 2,
+    };
+    let mut s = "hello".to_string();
+    let rs = &mut s;
+
+    println!("{}", f[s]);
+    //~^ ERROR cannot move out of `s` because it is borrowed
+
+    f[s] = 10;
+    //~^ ERROR cannot move out of `s` because it is borrowed
+    //~| ERROR use of moved value: `s`
+
+    let s = Bar {
+        x: 1,
+    };
+    let i = 2;
+    let _j = &i;
+    println!("{}", s[i]); // no error, i is copy
+    println!("{}", s[i]);
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-overloaded-index-ref-index.rs b/src/test/compile-fail/borrowck/borrowck-overloaded-index-ref-index.rs
new file mode 100644 (file)
index 0000000..4c50caf
--- /dev/null
@@ -0,0 +1,68 @@
+// Copyright 2014 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.
+
+use std::ops::{Index, IndexMut};
+
+struct Foo {
+    x: isize,
+    y: isize,
+}
+
+impl<'a> Index<&'a String> for Foo {
+    type Output = isize;
+
+    fn index(&self, z: &String) -> &isize {
+        if *z == "x" {
+            &self.x
+        } else {
+            &self.y
+        }
+    }
+}
+
+impl<'a> IndexMut<&'a String> for Foo {
+    fn index_mut(&mut self, z: &String) -> &mut isize {
+        if *z == "x" {
+            &mut self.x
+        } else {
+            &mut self.y
+        }
+    }
+}
+
+struct Bar {
+    x: isize,
+}
+
+impl Index<isize> for Bar {
+    type Output = isize;
+
+    fn index<'a>(&'a self, z: isize) -> &'a isize {
+        &self.x
+    }
+}
+
+fn main() {
+    let mut f = Foo {
+        x: 1,
+        y: 2,
+    };
+    let mut s = "hello".to_string();
+    let rs = &mut s;
+    println!("{}", f[&s]);
+    //~^ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
+    f[&s] = 10;
+    //~^ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
+    let s = Bar {
+        x: 1,
+    };
+    s[2] = 20;
+    //~^ ERROR cannot assign to immutable indexed content
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-partial-reinit-1.rs b/src/test/compile-fail/borrowck/borrowck-partial-reinit-1.rs
new file mode 100644 (file)
index 0000000..1ee040a
--- /dev/null
@@ -0,0 +1,49 @@
+// Copyright 2014-2015 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 Test;
+
+struct Test2 {
+    b: Option<Test>,
+}
+
+struct Test3(Option<Test>);
+
+impl Drop for Test {
+    fn drop(&mut self) {
+        println!("dropping!");
+    }
+}
+
+impl Drop for Test2 {
+    fn drop(&mut self) {}
+}
+
+impl Drop for Test3 {
+    fn drop(&mut self) {}
+}
+
+fn stuff() {
+    let mut t = Test2 { b: None };
+    let u = Test;
+    drop(t);
+    t.b = Some(u);
+    //~^ ERROR partial reinitialization of uninitialized structure `t`
+
+    let mut t = Test3(None);
+    let u = Test;
+    drop(t);
+    t.0 = Some(u);
+    //~^ ERROR partial reinitialization of uninitialized structure `t`
+}
+
+fn main() {
+    stuff()
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-partial-reinit-2.rs b/src/test/compile-fail/borrowck/borrowck-partial-reinit-2.rs
new file mode 100644 (file)
index 0000000..c9cdeff
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright 2014-2015 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 Test {
+    a: isize,
+    b: Option<Box<Test>>,
+}
+
+impl Drop for Test {
+    fn drop(&mut self) {
+        println!("Dropping {}", self.a);
+    }
+}
+
+fn stuff() {
+    let mut t = Test { a: 1, b: None};
+    let mut u = Test { a: 2, b: Some(Box::new(t))};
+    t.b = Some(Box::new(u));
+    //~^ ERROR partial reinitialization of uninitialized structure `t`
+    println!("done");
+}
+
+fn main() {
+    stuff();
+    println!("Hello, world!")
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-partial-reinit-3.rs b/src/test/compile-fail/borrowck/borrowck-partial-reinit-3.rs
new file mode 100644 (file)
index 0000000..0aa7389
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2015 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.
+use std::mem;
+
+struct Test { f: usize }
+impl Drop for Test {
+    fn drop(&mut self) {}
+}
+
+fn main() {
+    let mut x = (Test { f: 2 }, Test { f: 4 });
+    mem::drop(x.0);
+    x.0.f = 3;
+    //~^ ERROR partial reinitialization of uninitialized structure `x.0`
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-partial-reinit-4.rs b/src/test/compile-fail/borrowck/borrowck-partial-reinit-4.rs
new file mode 100644 (file)
index 0000000..774e04e
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright 2015 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 Test;
+
+struct Test2(Option<Test>);
+
+impl Drop for Test {
+    fn drop(&mut self) {
+        println!("dropping!");
+    }
+}
+
+impl Drop for Test2 {
+    fn drop(&mut self) {}
+}
+
+fn stuff() {
+    let mut x : (Test2, Test2);
+    (x.0).0 = Some(Test);
+    //~^ ERROR partial reinitialization of uninitialized structure `x.0`
+}
+
+fn main() {
+    stuff()
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-pat-reassign-binding.rs b/src/test/compile-fail/borrowck/borrowck-pat-reassign-binding.rs
new file mode 100644 (file)
index 0000000..d176245
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2012-2014 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 main() {
+    let mut x: Option<isize> = None;
+    match x {
+      None => {
+          // Note: on this branch, no borrow has occurred.
+          x = Some(0);
+      }
+      Some(ref i) => {
+          // But on this branch, `i` is an outstanding borrow
+          x = Some(*i+1); //~ ERROR cannot assign to `x`
+      }
+    }
+    x.clone(); // just to prevent liveness warnings
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-reborrow-from-mut.rs b/src/test/compile-fail/borrowck/borrowck-reborrow-from-mut.rs
new file mode 100644 (file)
index 0000000..6f5dfa6
--- /dev/null
@@ -0,0 +1,106 @@
+// 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 {
+  bar1: Bar,
+  bar2: Bar
+}
+
+struct Bar {
+  int1: isize,
+  int2: isize,
+}
+
+fn borrow_same_field_twice_mut_mut(foo: &mut Foo) {
+    let _bar1 = &mut foo.bar1;
+    let _bar2 = &mut foo.bar1;  //~ ERROR cannot borrow
+}
+
+fn borrow_same_field_twice_mut_imm(foo: &mut Foo) {
+    let _bar1 = &mut foo.bar1;
+    let _bar2 = &foo.bar1;  //~ ERROR cannot borrow
+}
+
+fn borrow_same_field_twice_imm_mut(foo: &mut Foo) {
+    let _bar1 = &foo.bar1;
+    let _bar2 = &mut foo.bar1;  //~ ERROR cannot borrow
+}
+
+fn borrow_same_field_twice_imm_imm(foo: &mut Foo) {
+    let _bar1 = &foo.bar1;
+    let _bar2 = &foo.bar1;
+}
+
+fn borrow_both_mut(foo: &mut Foo) {
+    let _bar1 = &mut foo.bar1;
+    let _bar2 = &mut foo.bar2;
+}
+
+fn borrow_both_mut_pattern(foo: &mut Foo) {
+    match *foo {
+        Foo { bar1: ref mut _bar1, bar2: ref mut _bar2 } => {}
+    }
+}
+
+fn borrow_var_and_pattern(foo: &mut Foo) {
+    let _bar1 = &mut foo.bar1;
+    match *foo {
+        Foo { bar1: ref mut _bar1, bar2: _ } => {}
+        //~^ ERROR cannot borrow
+    }
+}
+
+fn borrow_mut_and_base_imm(foo: &mut Foo) {
+    let _bar1 = &mut foo.bar1.int1;
+    let _foo1 = &foo.bar1; //~ ERROR cannot borrow
+    let _foo2 = &*foo; //~ ERROR cannot borrow
+}
+
+fn borrow_mut_and_base_mut(foo: &mut Foo) {
+    let _bar1 = &mut foo.bar1.int1;
+    let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
+}
+
+fn borrow_mut_and_base_mut2(foo: &mut Foo) {
+    let _bar1 = &mut foo.bar1.int1;
+    let _foo2 = &mut *foo; //~ ERROR cannot borrow
+}
+
+fn borrow_imm_and_base_mut(foo: &mut Foo) {
+    let _bar1 = &foo.bar1.int1;
+    let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow
+}
+
+fn borrow_imm_and_base_mut2(foo: &mut Foo) {
+    let _bar1 = &foo.bar1.int1;
+    let _foo2 = &mut *foo; //~ ERROR cannot borrow
+}
+
+fn borrow_imm_and_base_imm(foo: &mut Foo) {
+    let _bar1 = &foo.bar1.int1;
+    let _foo1 = &foo.bar1;
+    let _foo2 = &*foo;
+}
+
+fn borrow_mut_and_imm(foo: &mut Foo) {
+    let _bar1 = &mut foo.bar1;
+    let _foo1 = &foo.bar2;
+}
+
+fn borrow_mut_from_imm(foo: &Foo) {
+    let _bar1 = &mut foo.bar1; //~ ERROR cannot borrow
+}
+
+fn borrow_long_path_both_mut(foo: &mut Foo) {
+    let _bar1 = &mut foo.bar1.int1;
+    let _foo1 = &mut foo.bar2.int2;
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-reborrow-from-shorter-lived-andmut.rs b/src/test/compile-fail/borrowck/borrowck-reborrow-from-shorter-lived-andmut.rs
new file mode 100644 (file)
index 0000000..eee4074
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright 2014 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 assignments to an `&mut` pointer which is found in a
+// borrowed (but otherwise non-aliasable) location is illegal.
+
+struct S<'a> {
+    pointer: &'a mut isize
+}
+
+fn copy_borrowed_ptr<'a,'b>(p: &'a mut S<'b>) -> S<'b> {
+    S { pointer: &mut *p.pointer }
+    //~^ ERROR cannot infer
+}
+
+fn main() {
+    let mut x = 1;
+
+    {
+        let mut y = S { pointer: &mut x };
+        let z = copy_borrowed_ptr(&mut y);
+        *y.pointer += 1;
+        *z.pointer += 1;
+    }
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-ref-into-rvalue.rs b/src/test/compile-fail/borrowck/borrowck-ref-into-rvalue.rs
new file mode 100644 (file)
index 0000000..726d4bc
--- /dev/null
@@ -0,0 +1,20 @@
+// 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 main() {
+    let msg;
+    match Some("Hello".to_string()) {
+        Some(ref m) => { //~ ERROR borrowed value does not live long enough
+            msg = m;
+        },
+        None => { panic!() }
+    }
+    println!("{}", *msg);
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-ref-mut-of-imm.rs b/src/test/compile-fail/borrowck/borrowck-ref-mut-of-imm.rs
new file mode 100644 (file)
index 0000000..1784b72
--- /dev/null
@@ -0,0 +1,20 @@
+// 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 destructure(x: Option<isize>) -> isize {
+    match x {
+      None => 0,
+      Some(ref mut v) => *v //~ ERROR cannot borrow
+    }
+}
+
+fn main() {
+    assert_eq!(destructure(Some(22)), 22);
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-report-with-custom-diagnostic.rs b/src/test/compile-fail/borrowck/borrowck-report-with-custom-diagnostic.rs
new file mode 100644 (file)
index 0000000..61bf2c1
--- /dev/null
@@ -0,0 +1,41 @@
+// Copyright 2014 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.
+
+#![allow(dead_code)]
+fn main() {
+    // Original borrow ends at end of function
+    let mut x = 1;
+    let y = &mut x;
+    let z = &x; //~ ERROR cannot borrow
+}
+//~^ NOTE previous borrow ends here
+
+fn foo() {
+    match true {
+        true => {
+            // Original borrow ends at end of match arm
+            let mut x = 1;
+            let y = &x;
+            let z = &mut x; //~ ERROR cannot borrow
+        }
+     //~^ NOTE previous borrow ends here
+        false => ()
+    }
+}
+
+fn bar() {
+    // Original borrow ends at end of closure
+    || {
+        let mut x = 1;
+        let y = &mut x;
+        let z = &mut x; //~ ERROR cannot borrow
+    };
+ //~^ NOTE previous borrow ends here
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-return-variable-on-stack-via-clone.rs b/src/test/compile-fail/borrowck/borrowck-return-variable-on-stack-via-clone.rs
new file mode 100644 (file)
index 0000000..7529943
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2014 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.
+
+// Check that when we clone a `&T` pointer we properly relate the
+// lifetime of the pointer which results to the pointer being cloned.
+// Bugs in method resolution have sometimes broken this connection.
+// Issue #19261.
+
+fn leak<'a, T>(x: T) -> &'a T {
+    (&x).clone() //~ ERROR `x` does not live long enough
+}
+
+fn main() { }
diff --git a/src/test/compile-fail/borrowck/borrowck-return.rs b/src/test/compile-fail/borrowck/borrowck-return.rs
new file mode 100644 (file)
index 0000000..74d435b
--- /dev/null
@@ -0,0 +1,16 @@
+// 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 f() -> isize {
+    let x: isize;
+    return x; //~ ERROR use of possibly uninitialized variable: `x`
+}
+
+fn main() { f(); }
diff --git a/src/test/compile-fail/borrowck/borrowck-struct-update-with-dtor.rs b/src/test/compile-fail/borrowck/borrowck-struct-update-with-dtor.rs
new file mode 100644 (file)
index 0000000..bf14974
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright 2012-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 4691: Ensure that functional-struct-update can only copy, not
+// move, when the struct implements Drop.
+
+struct B;
+struct S { a: isize, b: B }
+impl Drop for S { fn drop(&mut self) { } }
+
+struct T { a: isize, mv: Box<isize> }
+impl Drop for T { fn drop(&mut self) { } }
+
+fn f(s0:S) {
+    let _s2 = S{a: 2, ..s0}; //~error: cannot move out of type `S`, which defines the `Drop` trait
+}
+
+fn g(s0:T) {
+    let _s2 = T{a: 2, ..s0}; //~error: cannot move out of type `T`, which defines the `Drop` trait
+}
+
+fn main() { }
diff --git a/src/test/compile-fail/borrowck/borrowck-swap-mut-base-ptr.rs b/src/test/compile-fail/borrowck/borrowck-swap-mut-base-ptr.rs
new file mode 100644 (file)
index 0000000..552fcec
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright 2014 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 attempt to swap `&mut` pointer while pointee is borrowed
+// yields an error.
+//
+// Example from src/librustc_borrowck/borrowck/README.md
+
+use std::mem::swap;
+
+fn foo<'a>(mut t0: &'a mut isize,
+           mut t1: &'a mut isize) {
+    let p: &isize = &*t0;     // Freezes `*t0`
+    swap(&mut t0, &mut t1); //~ ERROR cannot borrow `t0`
+    *t1 = 22;
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-unary-move.rs b/src/test/compile-fail/borrowck/borrowck-unary-move.rs
new file mode 100644 (file)
index 0000000..5b5c5f4
--- /dev/null
@@ -0,0 +1,22 @@
+// 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: Box<isize>) -> isize {
+    let y = &*x;
+    free(x); //~ ERROR cannot move out of `x` because it is borrowed
+    *y
+}
+
+fn free(_x: Box<isize>) {
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-unboxed-closures.rs b/src/test/compile-fail/borrowck/borrowck-unboxed-closures.rs
new file mode 100644 (file)
index 0000000..1c12ca9
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright 2014 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.
+
+#![feature(overloaded_calls, unboxed_closures)]
+
+fn a<F:Fn(isize, isize) -> isize>(mut f: F) {
+    let g = &mut f;
+    f(1, 2);    //~ ERROR cannot borrow `f` as immutable
+    //~^ ERROR cannot borrow `f` as immutable
+}
+
+fn b<F:FnMut(isize, isize) -> isize>(f: F) {
+    f(1, 2);    //~ ERROR cannot borrow immutable argument
+}
+
+fn c<F:FnOnce(isize, isize) -> isize>(f: F) {
+    f(1, 2);
+    f(1, 2);    //~ ERROR use of moved value
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-uninit-after-item.rs b/src/test/compile-fail/borrowck/borrowck-uninit-after-item.rs
new file mode 100644 (file)
index 0000000..acd827d
--- /dev/null
@@ -0,0 +1,15 @@
+// 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 main() {
+    let bar;
+    fn baz(_x: isize) { }
+    baz(bar); //~ ERROR use of possibly uninitialized variable: `bar`
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-uninit-in-assignop.rs b/src/test/compile-fail/borrowck/borrowck-uninit-in-assignop.rs
new file mode 100644 (file)
index 0000000..e253ecc
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright 2012-2014 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 that the use of uninitialized variable in assignment operator
+// expression is detected.
+
+pub fn main() {
+    let x: isize;
+    x += 1; //~ ERROR use of possibly uninitialized variable: `x`
+
+    let x: isize;
+    x -= 1; //~ ERROR use of possibly uninitialized variable: `x`
+
+    let x: isize;
+    x *= 1; //~ ERROR use of possibly uninitialized variable: `x`
+
+    let x: isize;
+    x /= 1; //~ ERROR use of possibly uninitialized variable: `x`
+
+    let x: isize;
+    x %= 1; //~ ERROR use of possibly uninitialized variable: `x`
+
+    let x: isize;
+    x ^= 1; //~ ERROR use of possibly uninitialized variable: `x`
+
+    let x: isize;
+    x &= 1; //~ ERROR use of possibly uninitialized variable: `x`
+
+    let x: isize;
+    x |= 1; //~ ERROR use of possibly uninitialized variable: `x`
+
+    let x: isize;
+    x <<= 1;    //~ ERROR use of possibly uninitialized variable: `x`
+
+    let x: isize;
+    x >>= 1;    //~ ERROR use of possibly uninitialized variable: `x`
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-uninit.rs b/src/test/compile-fail/borrowck/borrowck-uninit.rs
new file mode 100644 (file)
index 0000000..f4b73bc
--- /dev/null
@@ -0,0 +1,16 @@
+// 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: isize) { println!("{}", x); }
+
+fn main() {
+    let x: isize;
+    foo(x); //~ ERROR use of possibly uninitialized variable: `x`
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-uniq-via-lend.rs b/src/test/compile-fail/borrowck/borrowck-uniq-via-lend.rs
new file mode 100644 (file)
index 0000000..f36dc0c
--- /dev/null
@@ -0,0 +1,62 @@
+// 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.
+
+#![feature(box_syntax)]
+
+fn borrow(_v: &isize) {}
+
+fn local() {
+    let mut v: Box<_> = box 3;
+    borrow(&*v);
+}
+
+fn local_rec() {
+    struct F { f: Box<isize> }
+    let mut v = F {f: box 3};
+    borrow(&*v.f);
+}
+
+fn local_recs() {
+    struct F { f: G }
+    struct G { g: H }
+    struct H { h: Box<isize> }
+    let mut v = F {f: G {g: H {h: box 3}}};
+    borrow(&*v.f.g.h);
+}
+
+fn aliased_imm() {
+    let mut v: Box<_> = box 3;
+    let _w = &v;
+    borrow(&*v);
+}
+
+fn aliased_mut() {
+    let mut v: Box<_> = box 3;
+    let _w = &mut v;
+    borrow(&*v); //~ ERROR cannot borrow `*v`
+}
+
+fn aliased_other() {
+    let mut v: Box<_> = box 3;
+    let mut w: Box<_> = box 4;
+    let _x = &mut w;
+    borrow(&*v);
+}
+
+fn aliased_other_reassign() {
+    let mut v: Box<_> = box 3;
+    let mut w: Box<_> = box 4;
+    let mut _x = &mut w;
+    _x = &mut v;
+    borrow(&*v); //~ ERROR cannot borrow `*v`
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-use-in-index-lvalue.rs b/src/test/compile-fail/borrowck/borrowck-use-in-index-lvalue.rs
new file mode 100644 (file)
index 0000000..7291bcd
--- /dev/null
@@ -0,0 +1,19 @@
+// 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() {
+    let w: &mut [isize];
+    w[5] = 0; //~ ERROR use of possibly uninitialized variable: `*w`
+
+    let mut w: &mut [isize];
+    w[5] = 0; //~ ERROR use of possibly uninitialized variable: `*w`
+}
+
+fn main() { test(); }
diff --git a/src/test/compile-fail/borrowck/borrowck-use-mut-borrow.rs b/src/test/compile-fail/borrowck/borrowck-use-mut-borrow.rs
new file mode 100644 (file)
index 0000000..c11e586
--- /dev/null
@@ -0,0 +1,96 @@
+// Copyright 2014 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.
+
+#![feature(box_syntax)]
+
+#[derive(Copy, Clone)]
+struct A { a: isize, b: isize }
+
+struct B { a: isize, b: Box<isize> }
+
+fn var_copy_after_var_borrow() {
+    let mut x: isize = 1;
+    let p = &mut x;
+    drop(x); //~ ERROR cannot use `x` because it was mutably borrowed
+    *p = 2;
+}
+
+fn var_copy_after_field_borrow() {
+    let mut x = A { a: 1, b: 2 };
+    let p = &mut x.a;
+    drop(x); //~ ERROR cannot use `x` because it was mutably borrowed
+    *p = 3;
+}
+
+fn field_copy_after_var_borrow() {
+    let mut x = A { a: 1, b: 2 };
+    let p = &mut x;
+    drop(x.a); //~ ERROR cannot use `x.a` because it was mutably borrowed
+    p.a = 3;
+}
+
+fn field_copy_after_field_borrow() {
+    let mut x = A { a: 1, b: 2 };
+    let p = &mut x.a;
+    drop(x.a); //~ ERROR cannot use `x.a` because it was mutably borrowed
+    *p = 3;
+}
+
+fn fu_field_copy_after_var_borrow() {
+    let mut x = A { a: 1, b: 2 };
+    let p = &mut x;
+    let y = A { b: 3, .. x }; //~ ERROR cannot use `x.a` because it was mutably borrowed
+    drop(y);
+    p.a = 4;
+}
+
+fn fu_field_copy_after_field_borrow() {
+    let mut x = A { a: 1, b: 2 };
+    let p = &mut x.a;
+    let y = A { b: 3, .. x }; //~ ERROR cannot use `x.a` because it was mutably borrowed
+    drop(y);
+    *p = 4;
+}
+
+fn var_deref_after_var_borrow() {
+    let mut x: Box<isize> = box 1;
+    let p = &mut x;
+    drop(*x); //~ ERROR cannot use `*x` because it was mutably borrowed
+    **p = 2;
+}
+
+fn field_deref_after_var_borrow() {
+    let mut x = B { a: 1, b: box 2 };
+    let p = &mut x;
+    drop(*x.b); //~ ERROR cannot use `*x.b` because it was mutably borrowed
+    p.a = 3;
+}
+
+fn field_deref_after_field_borrow() {
+    let mut x = B { a: 1, b: box 2 };
+    let p = &mut x.b;
+    drop(*x.b); //~ ERROR cannot use `*x.b` because it was mutably borrowed
+    **p = 3;
+}
+
+fn main() {
+    var_copy_after_var_borrow();
+    var_copy_after_field_borrow();
+
+    field_copy_after_var_borrow();
+    field_copy_after_field_borrow();
+
+    fu_field_copy_after_var_borrow();
+    fu_field_copy_after_field_borrow();
+
+    var_deref_after_var_borrow();
+    field_deref_after_var_borrow();
+    field_deref_after_field_borrow();
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-use-uninitialized-in-cast-trait.rs b/src/test/compile-fail/borrowck/borrowck-use-uninitialized-in-cast-trait.rs
new file mode 100644 (file)
index 0000000..796b455
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2015 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.
+
+// Variation on `borrowck-use-uninitialized-in-cast` in which we do a
+// trait cast from an uninitialized source. Issue #20791.
+
+trait Foo { fn dummy(&self) { } }
+impl Foo for i32 { }
+
+fn main() {
+    let x: &i32;
+    let y = x as *const Foo; //~ ERROR use of possibly uninitialized variable: `*x`
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-use-uninitialized-in-cast.rs b/src/test/compile-fail/borrowck/borrowck-use-uninitialized-in-cast.rs
new file mode 100644 (file)
index 0000000..a3d5af8
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2015 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.
+
+// Check that we detect unused values that are cast to other things.
+// The problem was specified to casting to `*`, as creating unsafe
+// pointers was not being fully checked. Issue #20791.
+
+// pretty-expanded FIXME #23616
+
+fn main() {
+    let x: &i32;
+    let y = x as *const i32; //~ ERROR use of possibly uninitialized variable: `*x`
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-vec-pattern-element-loan.rs b/src/test/compile-fail/borrowck/borrowck-vec-pattern-element-loan.rs
new file mode 100644 (file)
index 0000000..98052ad
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright 2014 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.
+
+#![feature(advanced_slice_patterns)]
+#![feature(slice_patterns)]
+
+fn a<'a>() -> &'a [isize] {
+    let vec = vec!(1, 2, 3, 4);
+    let vec: &[isize] = &vec; //~ ERROR does not live long enough
+    let tail = match vec {
+        [_, tail..] => tail,
+        _ => panic!("a")
+    };
+    tail
+}
+
+fn b<'a>() -> &'a [isize] {
+    let vec = vec!(1, 2, 3, 4);
+    let vec: &[isize] = &vec; //~ ERROR does not live long enough
+    let init = match vec {
+        [init.., _] => init,
+        _ => panic!("b")
+    };
+    init
+}
+
+fn c<'a>() -> &'a [isize] {
+    let vec = vec!(1, 2, 3, 4);
+    let vec: &[isize] = &vec; //~ ERROR does not live long enough
+    let slice = match vec {
+        [_, slice.., _] => slice,
+        _ => panic!("c")
+    };
+    slice
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-vec-pattern-loan-from-mut.rs b/src/test/compile-fail/borrowck/borrowck-vec-pattern-loan-from-mut.rs
new file mode 100644 (file)
index 0000000..db63589
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2014 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.
+
+#![feature(slice_patterns)]
+
+fn a() {
+    let mut v = vec!(1, 2, 3);
+    let vb: &mut [isize] = &mut v;
+    match vb {
+        [_a, tail..] => {
+            v.push(tail[0] + tail[1]); //~ ERROR cannot borrow
+        }
+        _ => {}
+    };
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-vec-pattern-move-tail.rs b/src/test/compile-fail/borrowck/borrowck-vec-pattern-move-tail.rs
new file mode 100644 (file)
index 0000000..97dcaeb
--- /dev/null
@@ -0,0 +1,23 @@
+// Copyright 2014 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.
+
+#![feature(slice_patterns)]
+
+fn main() {
+    let mut a = [1, 2, 3, 4];
+    let t = match a {
+        [1, 2, tail..] => tail,
+        _ => unreachable!()
+    };
+    println!("t[0]: {}", t[0]);
+    a[2] = 0; //~ ERROR cannot assign to `a[..]` because it is borrowed
+    println!("t[0]: {}", t[0]);
+    t[0];
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-vec-pattern-nesting.rs b/src/test/compile-fail/borrowck/borrowck-vec-pattern-nesting.rs
new file mode 100644 (file)
index 0000000..a69ce0c
--- /dev/null
@@ -0,0 +1,78 @@
+// Copyright 2014 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.
+
+#![feature(advanced_slice_patterns)]
+#![feature(box_patterns)]
+#![feature(box_syntax)]
+#![feature(slice_patterns)]
+
+fn a() {
+    let mut vec = [box 1, box 2, box 3];
+    match vec {
+        [box ref _a, _, _] => {
+            vec[0] = box 4; //~ ERROR cannot assign
+        }
+    }
+}
+
+fn b() {
+    let mut vec = vec!(box 1, box 2, box 3);
+    let vec: &mut [Box<isize>] = &mut vec;
+    match vec {
+        [_b..] => {
+            vec[0] = box 4; //~ ERROR cannot assign
+        }
+    }
+}
+
+fn c() {
+    let mut vec = vec!(box 1, box 2, box 3);
+    let vec: &mut [Box<isize>] = &mut vec;
+    match vec {
+        [_a,         //~ ERROR cannot move out
+         _b..] => {  //~^ NOTE attempting to move value to here
+
+            // Note: `_a` is *moved* here, but `b` is borrowing,
+            // hence illegal.
+            //
+            // See comment in middle/borrowck/gather_loans/mod.rs
+            // in the case covering these sorts of vectors.
+        }
+        _ => {}
+    }
+    let a = vec[0]; //~ ERROR cannot move out
+}
+
+fn d() {
+    let mut vec = vec!(box 1, box 2, box 3);
+    let vec: &mut [Box<isize>] = &mut vec;
+    match vec {
+        [_a..,     //~ ERROR cannot move out
+         _b] => {} //~ NOTE attempting to move value to here
+        _ => {}
+    }
+    let a = vec[0]; //~ ERROR cannot move out
+}
+
+fn e() {
+    let mut vec = vec!(box 1, box 2, box 3);
+    let vec: &mut [Box<isize>] = &mut vec;
+    match vec {
+        [_a, _b, _c] => {}  //~ ERROR cannot move out
+        //~^ NOTE attempting to move value to here
+        //~^^ NOTE and here
+        //~^^^ NOTE and here
+        _ => {}
+    }
+    let a = vec[0]; //~ ERROR cannot move out
+    //~^ NOTE attempting to move value to here
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/borrowck/borrowck-vec-pattern-tail-element-loan.rs b/src/test/compile-fail/borrowck/borrowck-vec-pattern-tail-element-loan.rs
new file mode 100644 (file)
index 0000000..82b3490
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright 2014 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.
+
+#![feature(slice_patterns)]
+
+fn a<'a>() -> &'a isize {
+    let vec = vec!(1, 2, 3, 4);
+    let vec: &[isize] = &vec; //~ ERROR `vec` does not live long enough
+    let tail = match vec {
+        [_a, tail..] => &tail[0],
+        _ => panic!("foo")
+    };
+    tail
+}
+
+fn main() {
+    let fifth = a();
+    println!("{}", *fifth);
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-while-break.rs b/src/test/compile-fail/borrowck/borrowck-while-break.rs
new file mode 100644 (file)
index 0000000..8cdf1da
--- /dev/null
@@ -0,0 +1,22 @@
+// 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(cond: bool) {
+    let v;
+    while cond {
+        v = 3;
+        break;
+    }
+    println!("{}", v); //~ ERROR use of possibly uninitialized variable: `v`
+}
+
+fn main() {
+    test(true);
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-while-cond.rs b/src/test/compile-fail/borrowck/borrowck-while-cond.rs
new file mode 100644 (file)
index 0000000..27d42d6
--- /dev/null
@@ -0,0 +1,14 @@
+// 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 main() {
+    let x: bool;
+    while x { } //~ ERROR use of possibly uninitialized variable: `x`
+}
diff --git a/src/test/compile-fail/borrowck/borrowck-while.rs b/src/test/compile-fail/borrowck/borrowck-while.rs
new file mode 100644 (file)
index 0000000..e3566e9
--- /dev/null
@@ -0,0 +1,17 @@
+// 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 f() -> isize {
+    let mut x: isize;
+    while 1 == 1 { x = 10; }
+    return x; //~ ERROR use of possibly uninitialized variable: `x`
+}
+
+fn main() { f(); }
diff --git a/src/test/run-pass/borrowck-assign-to-subfield.rs b/src/test/run-pass/borrowck-assign-to-subfield.rs
deleted file mode 100644 (file)
index ee74a05..0000000
+++ /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 <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.
-
-// pretty-expanded FIXME #23616
-
-pub fn main() {
-    struct A {
-        a: isize,
-        w: B,
-    }
-    struct B {
-        a: isize
-    }
-    let mut p = A {
-        a: 1,
-        w: B {a: 1},
-    };
-
-    // even though `x` is not declared as a mutable field,
-    // `p` as a whole is mutable, so it can be modified.
-    p.a = 2;
-
-    // this is true for an interior field too
-    p.w.a = 2;
-}
diff --git a/src/test/run-pass/borrowck-binding-mutbl.rs b/src/test/run-pass/borrowck-binding-mutbl.rs
deleted file mode 100644 (file)
index 10e9a1b..0000000
+++ /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 <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.
-
-
-// pretty-expanded FIXME #23616
-
-struct F { f: Vec<isize> }
-
-fn impure(_v: &[isize]) {
-}
-
-pub fn main() {
-    let mut x = F {f: vec!(3)};
-
-    match x {
-      F {f: ref mut v} => {
-        impure(v);
-      }
-    }
-}
diff --git a/src/test/run-pass/borrowck-borrow-from-expr-block.rs b/src/test/run-pass/borrowck-borrow-from-expr-block.rs
deleted file mode 100644 (file)
index 7fdc65a..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2014 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.
-
-
-#![allow(unknown_features)]
-#![feature(box_syntax)]
-
-fn borrow<F>(x: &isize, f: F) where F: FnOnce(&isize) {
-    f(x)
-}
-
-fn test1(x: &Box<isize>) {
-    borrow(&*(*x).clone(), |p| {
-        let x_a = &**x as *const isize;
-        assert!((x_a as usize) != (p as *const isize as usize));
-        assert_eq!(unsafe{*x_a}, *p);
-    })
-}
-
-pub fn main() {
-    test1(&box 22);
-}
diff --git a/src/test/run-pass/borrowck-borrow-of-mut-base-ptr-safe.rs b/src/test/run-pass/borrowck-borrow-of-mut-base-ptr-safe.rs
deleted file mode 100644 (file)
index b716a1a..0000000
+++ /dev/null
@@ -1,27 +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.
-
-// Test that freezing an `&mut` pointer while referent is
-// frozen is legal.
-//
-// Example from src/librustc_borrowck/borrowck/README.md
-
-// pretty-expanded FIXME #23616
-
-fn foo<'a>(mut t0: &'a mut isize,
-           mut t1: &'a mut isize) {
-    let p: &isize = &*t0; // Freezes `*t0`
-    let mut t2 = &t0;
-    let q: &isize = &**t2; // Freezes `*t0`, but that's ok...
-    let r: &isize = &*t0; // ...after all, could do same thing directly.
-}
-
-pub fn main() {
-}
diff --git a/src/test/run-pass/borrowck-closures-two-imm.rs b/src/test/run-pass/borrowck-closures-two-imm.rs
deleted file mode 100644 (file)
index 5b15c8f..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2014 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 that two closures can simultaneously have immutable
-// access to the variable, whether that immutable access be used
-// for direct reads or for taking immutable ref. Also check
-// that the main function can read the variable too while
-// the closures are in scope. Issue #6801.
-
-
-fn a() -> i32 {
-    let mut x = 3;
-    x += 1;
-    let c1 = || x * 4;
-    let c2 = || x * 5;
-    c1() * c2() * x
-}
-
-fn get(x: &i32) -> i32 {
-    *x * 4
-}
-
-fn b() -> i32 {
-    let mut x = 3;
-    x += 1;
-    let c1 = || get(&x);
-    let c2 = || get(&x);
-    c1() * c2() * x
-}
-
-fn c() -> i32 {
-    let mut x = 3;
-    x += 1;
-    let c1 = || x * 5;
-    let c2 = || get(&x);
-    c1() * c2() * x
-}
-
-pub fn main() {
-    assert_eq!(a(), 1280);
-    assert_eq!(b(), 1024);
-    assert_eq!(c(), 1280);
-}
diff --git a/src/test/run-pass/borrowck-field-sensitivity.rs b/src/test/run-pass/borrowck-field-sensitivity.rs
deleted file mode 100644 (file)
index d97564a..0000000
+++ /dev/null
@@ -1,274 +0,0 @@
-// Copyright 2014 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.
-
-// pretty-expanded FIXME #23616
-
-#![allow(unknown_features)]
-#![feature(box_syntax)]
-
-struct A { a: isize, b: Box<isize> }
-struct B { a: Box<isize>, b: Box<isize> }
-
-fn move_after_copy() {
-    let x = A { a: 1, b: box 2 };
-    drop(x.a);
-    drop(x.b);
-}
-
-fn move_after_fu_copy() {
-    let x = A { a: 1, b: box 2 };
-    let _y = A { b: box 3, .. x };
-    drop(x.b);
-}
-
-fn fu_move_after_copy() {
-    let x = A { a: 1, b: box 2 };
-    drop(x.a);
-    let _y = A { a: 3, .. x };
-}
-
-fn fu_move_after_fu_copy() {
-    let x = A { a: 1, b: box 2 };
-    let _y = A { b: box 3, .. x };
-    let _z = A { a: 4, .. x };
-}
-
-fn copy_after_move() {
-    let x = A { a: 1, b: box 2 };
-    drop(x.b);
-    drop(x.a);
-}
-
-fn copy_after_fu_move() {
-    let x = A { a: 1, b: box 2 };
-    let y = A { a: 3, .. x };
-    drop(x.a);
-}
-
-fn fu_copy_after_move() {
-    let x = A { a: 1, b: box 2 };
-    drop(x.b);
-    let _y = A { b: box 3, .. x };
-}
-
-fn fu_copy_after_fu_move() {
-    let x = A { a: 1, b: box 2 };
-    let _y = A { a: 3, .. x };
-    let _z = A { b: box 3, .. x };
-}
-
-fn borrow_after_move() {
-    let x = A { a: 1, b: box 2 };
-    drop(x.b);
-    let p = &x.a;
-    drop(*p);
-}
-
-fn borrow_after_fu_move() {
-    let x = A { a: 1, b: box 2 };
-    let _y = A { a: 3, .. x };
-    let p = &x.a;
-    drop(*p);
-}
-
-fn move_after_borrow() {
-    let x = A { a: 1, b: box 2 };
-    let p = &x.a;
-    drop(x.b);
-    drop(*p);
-}
-
-fn fu_move_after_borrow() {
-    let x = A { a: 1, b: box 2 };
-    let p = &x.a;
-    let _y = A { a: 3, .. x };
-    drop(*p);
-}
-
-fn mut_borrow_after_mut_borrow() {
-    let mut x = A { a: 1, b: box 2 };
-    let p = &mut x.a;
-    let q = &mut x.b;
-    drop(*p);
-    drop(**q);
-}
-
-fn move_after_move() {
-    let x = B { a: box 1, b: box 2 };
-    drop(x.a);
-    drop(x.b);
-}
-
-fn move_after_fu_move() {
-    let x = B { a: box 1, b: box 2 };
-    let y = B { a: box 3, .. x };
-    drop(x.a);
-}
-
-fn fu_move_after_move() {
-    let x = B { a: box 1, b: box 2 };
-    drop(x.a);
-    let z = B { a: box 3, .. x };
-    drop(z.b);
-}
-
-fn fu_move_after_fu_move() {
-    let x = B { a: box 1, b: box 2 };
-    let _y = B { b: box 3, .. x };
-    let _z = B { a: box 4, .. x };
-}
-
-fn copy_after_assign_after_move() {
-    let mut x = A { a: 1, b: box 2 };
-    drop(x.b);
-    x = A { a: 3, b: box 4 };
-    drop(*x.b);
-}
-
-fn copy_after_assign_after_fu_move() {
-    let mut x = A { a: 1, b: box 2 };
-    let _y = A { a: 3, .. x };
-    x = A { a: 3, b: box 4 };
-    drop(*x.b);
-}
-
-fn copy_after_field_assign_after_move() {
-    let mut x = A { a: 1, b: box 2 };
-    drop(x.b);
-    x.b = box 3;
-    drop(*x.b);
-}
-
-fn copy_after_field_assign_after_fu_move() {
-    let mut x = A { a: 1, b: box 2 };
-    let _y = A { a: 3, .. x };
-    x.b = box 3;
-    drop(*x.b);
-}
-
-fn borrow_after_assign_after_move() {
-    let mut x = A { a: 1, b: box 2 };
-    drop(x.b);
-    x = A { a: 3, b: box 4 };
-    let p = &x.b;
-    drop(**p);
-}
-
-fn borrow_after_assign_after_fu_move() {
-    let mut x = A { a: 1, b: box 2 };
-    let _y = A { a: 3, .. x };
-    x = A { a: 3, b: box 4 };
-    let p = &x.b;
-    drop(**p);
-}
-
-fn borrow_after_field_assign_after_move() {
-    let mut x = A { a: 1, b: box 2 };
-    drop(x.b);
-    x.b = box 3;
-    let p = &x.b;
-    drop(**p);
-}
-
-fn borrow_after_field_assign_after_fu_move() {
-    let mut x = A { a: 1, b: box 2 };
-    let _y = A { a: 3, .. x };
-    x.b = box 3;
-    let p = &x.b;
-    drop(**p);
-}
-
-fn move_after_assign_after_move() {
-    let mut x = A { a: 1, b: box 2 };
-    let _y = x.b;
-    x = A { a: 3, b: box 4 };
-    drop(x.b);
-}
-
-fn move_after_assign_after_fu_move() {
-    let mut x = A { a: 1, b: box 2 };
-    let _y = A { a: 3, .. x };
-    x = A { a: 3, b: box 4 };
-    drop(x.b);
-}
-
-fn move_after_field_assign_after_move() {
-    let mut x = A { a: 1, b: box 2 };
-    drop(x.b);
-    x.b = box 3;
-    drop(x.b);
-}
-
-fn move_after_field_assign_after_fu_move() {
-    let mut x = A { a: 1, b: box 2 };
-    let _y = A { a: 3, .. x };
-    x.b = box 3;
-    drop(x.b);
-}
-
-fn copy_after_assign_after_uninit() {
-    let mut x: A;
-    x = A { a: 1, b: box 2 };
-    drop(x.a);
-}
-
-fn borrow_after_assign_after_uninit() {
-    let mut x: A;
-    x = A { a: 1, b: box 2 };
-    let p = &x.a;
-    drop(*p);
-}
-
-fn move_after_assign_after_uninit() {
-    let mut x: A;
-    x = A { a: 1, b: box 2 };
-    drop(x.b);
-}
-
-fn main() {
-    move_after_copy();
-    move_after_fu_copy();
-    fu_move_after_copy();
-    fu_move_after_fu_copy();
-    copy_after_move();
-    copy_after_fu_move();
-    fu_copy_after_move();
-    fu_copy_after_fu_move();
-
-    borrow_after_move();
-    borrow_after_fu_move();
-    move_after_borrow();
-    fu_move_after_borrow();
-    mut_borrow_after_mut_borrow();
-
-    move_after_move();
-    move_after_fu_move();
-    fu_move_after_move();
-    fu_move_after_fu_move();
-
-    copy_after_assign_after_move();
-    copy_after_assign_after_fu_move();
-    copy_after_field_assign_after_move();
-    copy_after_field_assign_after_fu_move();
-
-    borrow_after_assign_after_move();
-    borrow_after_assign_after_fu_move();
-    borrow_after_field_assign_after_move();
-    borrow_after_field_assign_after_fu_move();
-
-    move_after_assign_after_move();
-    move_after_assign_after_fu_move();
-    move_after_field_assign_after_move();
-    move_after_field_assign_after_fu_move();
-
-    copy_after_assign_after_uninit();
-    borrow_after_assign_after_uninit();
-    move_after_assign_after_uninit();
-}
diff --git a/src/test/run-pass/borrowck-fixed-length-vecs.rs b/src/test/run-pass/borrowck-fixed-length-vecs.rs
deleted file mode 100644 (file)
index 0e33351..0000000
+++ /dev/null
@@ -1,16 +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 main() {
-    let x = [22];
-    let y = &x[0];
-    assert_eq!(*y, 22);
-}
diff --git a/src/test/run-pass/borrowck-freeze-frozen-mut.rs b/src/test/run-pass/borrowck-freeze-frozen-mut.rs
deleted file mode 100644 (file)
index 380bd39..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2012-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.
-
-// Test that a `&mut` inside of an `&` is freezable.
-
-
-struct MutSlice<'a, T:'a> {
-    data: &'a mut [T]
-}
-
-fn get<'a, T>(ms: &'a MutSlice<'a, T>, index: usize) -> &'a T {
-    &ms.data[index]
-}
-
-pub fn main() {
-    let mut data = [1, 2, 3];
-    {
-        let slice = MutSlice { data: &mut data };
-        slice.data[0] += 4;
-        let index0 = get(&slice, 0);
-        let index1 = get(&slice, 1);
-        let index2 = get(&slice, 2);
-        assert_eq!(*index0, 5);
-        assert_eq!(*index1, 2);
-        assert_eq!(*index2, 3);
-    }
-    assert_eq!(data[0], 5);
-    assert_eq!(data[1], 2);
-    assert_eq!(data[2], 3);
-}
diff --git a/src/test/run-pass/borrowck-lend-args.rs b/src/test/run-pass/borrowck-lend-args.rs
deleted file mode 100644 (file)
index f1f0274..0000000
+++ /dev/null
@@ -1,29 +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.
-
-
-// pretty-expanded FIXME #23616
-
-fn borrow(_v: &isize) {}
-
-fn borrow_from_arg_imm_ref(v: Box<isize>) {
-    borrow(&*v);
-}
-
-fn borrow_from_arg_mut_ref(v: &mut Box<isize>) {
-    borrow(&**v);
-}
-
-fn borrow_from_arg_copy(v: Box<isize>) {
-    borrow(&*v);
-}
-
-pub fn main() {
-}
diff --git a/src/test/run-pass/borrowck-macro-interaction-issue-6304.rs b/src/test/run-pass/borrowck-macro-interaction-issue-6304.rs
deleted file mode 100644 (file)
index fb30c85..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2014 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.
-
-// Check that we do not ICE when compiling this
-// macro, which reuses the expression `$id`
-
-
-#![feature(box_patterns)]
-#![feature(box_syntax)]
-
-struct Foo {
-  a: isize
-}
-
-pub enum Bar {
-  Bar1, Bar2(isize, Box<Bar>),
-}
-
-impl Foo {
-  fn elaborate_stm(&mut self, s: Box<Bar>) -> Box<Bar> {
-    macro_rules! declare {
-      ($id:expr, $rest:expr) => ({
-        self.check_id($id);
-        box Bar::Bar2($id, $rest)
-      })
-    }
-    match s {
-      box Bar::Bar2(id, rest) => declare!(id, self.elaborate_stm(rest)),
-      _ => panic!()
-    }
-  }
-
-  fn check_id(&mut self, s: isize) { panic!() }
-}
-
-pub fn main() { }
diff --git a/src/test/run-pass/borrowck-move-by-capture-ok.rs b/src/test/run-pass/borrowck-move-by-capture-ok.rs
deleted file mode 100644 (file)
index bbc668f..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2014 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.
-
-
-#![allow(unknown_features)]
-#![feature(box_syntax)]
-#![feature(unboxed_closures)]
-
-pub fn main() {
-    let bar: Box<_> = box 3;
-    let h = || -> isize { *bar };
-    assert_eq!(h(), 3);
-}
diff --git a/src/test/run-pass/borrowck-mut-uniq.rs b/src/test/run-pass/borrowck-mut-uniq.rs
deleted file mode 100644 (file)
index f535c5f..0000000
+++ /dev/null
@@ -1,43 +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.
-
-#![allow(unknown_features)]
-#![feature(box_syntax)]
-
-use std::mem::swap;
-
-#[derive(Debug)]
-struct Ints {sum: Box<isize>, values: Vec<isize> }
-
-fn add_int(x: &mut Ints, v: isize) {
-    *x.sum += v;
-    let mut values = Vec::new();
-    swap(&mut values, &mut x.values);
-    values.push(v);
-    swap(&mut values, &mut x.values);
-}
-
-fn iter_ints<F>(x: &Ints, mut f: F) -> bool where F: FnMut(&isize) -> bool {
-    let l = x.values.len();
-    (0..l).all(|i| f(&x.values[i]))
-}
-
-pub fn main() {
-    let mut ints: Box<_> = box Ints {sum: box 0, values: Vec::new()};
-    add_int(&mut *ints, 22);
-    add_int(&mut *ints, 44);
-
-    iter_ints(&*ints, |i| {
-        println!("isize = {:?}", *i);
-        true
-    });
-
-    println!("ints={:?}", ints);
-}
diff --git a/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs b/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs
deleted file mode 100644 (file)
index d55517c..0000000
+++ /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 <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 want_slice(v: &[isize]) -> isize {
-    let mut sum = 0;
-    for i in v { sum += *i; }
-    sum
-}
-
-fn has_mut_vec(v: Vec<isize> ) -> isize {
-    want_slice(&v)
-}
-
-pub fn main() {
-    assert_eq!(has_mut_vec(vec!(1, 2, 3)), 6);
-}
diff --git a/src/test/run-pass/borrowck-pat-enum.rs b/src/test/run-pass/borrowck-pat-enum.rs
deleted file mode 100644 (file)
index b29cb63..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2012-2014 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.
-
-// ignore-pretty
-
-fn match_ref(v: Option<isize>) -> isize {
-    match v {
-      Some(ref i) => {
-        *i
-      }
-      None => {0}
-    }
-}
-
-fn match_ref_unused(v: Option<isize>) {
-    match v {
-      Some(_) => {}
-      None => {}
-    }
-}
-
-fn impure(_i: isize) {
-}
-
-fn match_imm_reg(v: &Option<isize>) {
-    match *v {
-      Some(ref i) => {impure(*i)} // OK because immutable
-      None => {}
-    }
-}
-
-fn match_mut_reg(v: &mut Option<isize>) {
-    match *v {
-      Some(ref i) => {impure(*i)} // OK, frozen
-      None => {}
-    }
-}
-
-pub fn main() {
-}
diff --git a/src/test/run-pass/borrowck-pat-reassign-no-binding.rs b/src/test/run-pass/borrowck-pat-reassign-no-binding.rs
deleted file mode 100644 (file)
index e0a5db6..0000000
+++ /dev/null
@@ -1,23 +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 main() {
-    let mut x = None;
-    match x {
-      None => {
-        // It is ok to reassign x here, because there is in
-        // fact no outstanding loan of x!
-        x = Some(0);
-      }
-      Some(_) => { }
-    }
-    assert_eq!(x, Some(0));
-}
diff --git a/src/test/run-pass/borrowck-rvalues-mutable.rs b/src/test/run-pass/borrowck-rvalues-mutable.rs
deleted file mode 100644 (file)
index 93cb0cb..0000000
+++ /dev/null
@@ -1,43 +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 Counter {
-    value: usize
-}
-
-impl Counter {
-    fn new(v: usize) -> Counter {
-        Counter {value: v}
-    }
-
-    fn inc<'a>(&'a mut self) -> &'a mut Counter {
-        self.value += 1;
-        self
-    }
-
-    fn get(&self) -> usize {
-        self.value
-    }
-
-    fn get_and_inc(&mut self) -> usize {
-        let v = self.value;
-        self.value += 1;
-        v
-    }
-}
-
-pub fn main() {
-    let v = Counter::new(22).get_and_inc();
-    assert_eq!(v, 22);
-
-    let v = Counter::new(22).inc().inc().get();
-    assert_eq!(v, 24);
-}
diff --git a/src/test/run-pass/borrowck-scope-of-deref-issue-4666.rs b/src/test/run-pass/borrowck-scope-of-deref-issue-4666.rs
deleted file mode 100644 (file)
index 59a5fea..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2012-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.
-
-// Tests that the scope of the pointer returned from `get()` is
-// limited to the deref operation itself, and does not infect the
-// block as a whole.
-
-
-struct Box {
-    x: usize
-}
-
-impl Box {
-    fn get(&self) -> &usize {
-        &self.x
-    }
-    fn set(&mut self, x: usize) {
-        self.x = x;
-    }
-}
-
-fn fun1() {
-    // in the past, borrow checker behaved differently when
-    // init and decl of `v` were distinct
-    let v;
-    let mut a_box = Box {x: 0};
-    a_box.set(22);
-    v = *a_box.get();
-    a_box.set(v+1);
-    assert_eq!(23, *a_box.get());
-}
-
-fn fun2() {
-    let mut a_box = Box {x: 0};
-    a_box.set(22);
-    let v = *a_box.get();
-    a_box.set(v+1);
-    assert_eq!(23, *a_box.get());
-}
-
-pub fn main() {
-    fun1();
-    fun2();
-}
diff --git a/src/test/run-pass/borrowck-static-item-in-fn.rs b/src/test/run-pass/borrowck-static-item-in-fn.rs
deleted file mode 100644 (file)
index d51d0b1..0000000
+++ /dev/null
@@ -1,17 +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.
-
-// Regression test for issue #7740
-
-// pretty-expanded FIXME #23616
-
-pub fn main() {
-    static A: &'static char = &'A';
-}
diff --git a/src/test/run-pass/borrowck-trait-lifetime.rs b/src/test/run-pass/borrowck-trait-lifetime.rs
deleted file mode 100644 (file)
index 0bfa8f4..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2014 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.
-
-// This test verifies that casting from the same lifetime on a value
-// to the same lifetime on a trait succeeds. See issue #10766.
-
-// pretty-expanded FIXME #23616
-
-#![allow(dead_code)]
-
-use std::marker;
-
-fn main() {
-    trait T { fn foo(&self) {} }
-
-    fn f<'a, V: T>(v: &'a V) -> &'a T {
-        v as &'a T
-    }
-}
diff --git a/src/test/run-pass/borrowck-uniq-via-ref.rs b/src/test/run-pass/borrowck-uniq-via-ref.rs
deleted file mode 100644 (file)
index 0ec8759..0000000
+++ /dev/null
@@ -1,57 +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.
-
-
-// pretty-expanded FIXME #23616
-
-struct Rec {
-    f: Box<isize>,
-}
-
-struct Outer {
-    f: Inner
-}
-
-struct Inner {
-    g: Innermost
-}
-
-struct Innermost {
-    h: Box<isize>,
-}
-
-fn borrow(_v: &isize) {}
-
-fn box_mut(v: &mut Box<isize>) {
-    borrow(&**v); // OK: &mut -> &imm
-}
-
-fn box_mut_rec(v: &mut Rec) {
-    borrow(&*v.f); // OK: &mut -> &imm
-}
-
-fn box_mut_recs(v: &mut Outer) {
-    borrow(&*v.f.g.h); // OK: &mut -> &imm
-}
-
-fn box_imm(v: &Box<isize>) {
-    borrow(&**v); // OK
-}
-
-fn box_imm_rec(v: &Rec) {
-    borrow(&*v.f); // OK
-}
-
-fn box_imm_recs(v: &Outer) {
-    borrow(&*v.f.g.h); // OK
-}
-
-pub fn main() {
-}
diff --git a/src/test/run-pass/borrowck-univariant-enum.rs b/src/test/run-pass/borrowck-univariant-enum.rs
deleted file mode 100644 (file)
index 2e8ddb0..0000000
+++ /dev/null
@@ -1,34 +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.
-
-
-
-use std::cell::Cell;
-
-#[derive(Copy, Clone)]
-enum newtype {
-    newvar(isize)
-}
-
-pub fn main() {
-
-    // Test that borrowck treats enums with a single variant
-    // specially.
-
-    let x = &Cell::new(5);
-    let y = &Cell::new(newtype::newvar(3));
-    let z = match y.get() {
-      newtype::newvar(b) => {
-        x.set(x.get() + 1);
-        x.get() * b
-      }
-    };
-    assert_eq!(z, 18);
-}
diff --git a/src/test/run-pass/borrowck-use-mut-borrow.rs b/src/test/run-pass/borrowck-use-mut-borrow.rs
deleted file mode 100644 (file)
index 7ad81b6..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2014 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.
-
-// pretty-expanded FIXME #23616
-
-#![allow(unknown_features)]
-#![feature(box_syntax)]
-
-struct A { a: isize, b: Box<isize> }
-
-fn field_copy_after_field_borrow() {
-    let mut x = A { a: 1, b: box 2 };
-    let p = &mut x.b;
-    drop(x.a);
-    **p = 3;
-}
-
-fn fu_field_copy_after_field_borrow() {
-    let mut x = A { a: 1, b: box 2 };
-    let p = &mut x.b;
-    let y = A { b: box 3, .. x };
-    drop(y);
-    **p = 4;
-}
-
-fn field_deref_after_field_borrow() {
-    let mut x = A { a: 1, b: box 2 };
-    let p = &mut x.a;
-    drop(*x.b);
-    *p = 3;
-}
-
-fn field_move_after_field_borrow() {
-    let mut x = A { a: 1, b: box 2 };
-    let p = &mut x.a;
-    drop(x.b);
-    *p = 3;
-}
-
-fn fu_field_move_after_field_borrow() {
-    let mut x = A { a: 1, b: box 2 };
-    let p = &mut x.a;
-    let y = A { a: 3, .. x };
-    drop(y);
-    *p = 4;
-}
-
-fn main() {
-    field_copy_after_field_borrow();
-    fu_field_copy_after_field_borrow();
-    field_deref_after_field_borrow();
-    field_move_after_field_borrow();
-    fu_field_move_after_field_borrow();
-}
diff --git a/src/test/run-pass/borrowck/borrowck-assign-to-subfield.rs b/src/test/run-pass/borrowck/borrowck-assign-to-subfield.rs
new file mode 100644 (file)
index 0000000..ee74a05
--- /dev/null
@@ -0,0 +1,32 @@
+// 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.
+
+// pretty-expanded FIXME #23616
+
+pub fn main() {
+    struct A {
+        a: isize,
+        w: B,
+    }
+    struct B {
+        a: isize
+    }
+    let mut p = A {
+        a: 1,
+        w: B {a: 1},
+    };
+
+    // even though `x` is not declared as a mutable field,
+    // `p` as a whole is mutable, so it can be modified.
+    p.a = 2;
+
+    // this is true for an interior field too
+    p.w.a = 2;
+}
diff --git a/src/test/run-pass/borrowck/borrowck-binding-mutbl.rs b/src/test/run-pass/borrowck/borrowck-binding-mutbl.rs
new file mode 100644 (file)
index 0000000..10e9a1b
--- /dev/null
@@ -0,0 +1,27 @@
+// 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.
+
+
+// pretty-expanded FIXME #23616
+
+struct F { f: Vec<isize> }
+
+fn impure(_v: &[isize]) {
+}
+
+pub fn main() {
+    let mut x = F {f: vec!(3)};
+
+    match x {
+      F {f: ref mut v} => {
+        impure(v);
+      }
+    }
+}
diff --git a/src/test/run-pass/borrowck/borrowck-borrow-from-expr-block.rs b/src/test/run-pass/borrowck/borrowck-borrow-from-expr-block.rs
new file mode 100644 (file)
index 0000000..7fdc65a
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright 2014 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.
+
+
+#![allow(unknown_features)]
+#![feature(box_syntax)]
+
+fn borrow<F>(x: &isize, f: F) where F: FnOnce(&isize) {
+    f(x)
+}
+
+fn test1(x: &Box<isize>) {
+    borrow(&*(*x).clone(), |p| {
+        let x_a = &**x as *const isize;
+        assert!((x_a as usize) != (p as *const isize as usize));
+        assert_eq!(unsafe{*x_a}, *p);
+    })
+}
+
+pub fn main() {
+    test1(&box 22);
+}
diff --git a/src/test/run-pass/borrowck/borrowck-borrow-of-mut-base-ptr-safe.rs b/src/test/run-pass/borrowck/borrowck-borrow-of-mut-base-ptr-safe.rs
new file mode 100644 (file)
index 0000000..b716a1a
--- /dev/null
@@ -0,0 +1,27 @@
+// 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.
+
+// Test that freezing an `&mut` pointer while referent is
+// frozen is legal.
+//
+// Example from src/librustc_borrowck/borrowck/README.md
+
+// pretty-expanded FIXME #23616
+
+fn foo<'a>(mut t0: &'a mut isize,
+           mut t1: &'a mut isize) {
+    let p: &isize = &*t0; // Freezes `*t0`
+    let mut t2 = &t0;
+    let q: &isize = &**t2; // Freezes `*t0`, but that's ok...
+    let r: &isize = &*t0; // ...after all, could do same thing directly.
+}
+
+pub fn main() {
+}
diff --git a/src/test/run-pass/borrowck/borrowck-closures-two-imm.rs b/src/test/run-pass/borrowck/borrowck-closures-two-imm.rs
new file mode 100644 (file)
index 0000000..5b15c8f
--- /dev/null
@@ -0,0 +1,50 @@
+// Copyright 2014 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 that two closures can simultaneously have immutable
+// access to the variable, whether that immutable access be used
+// for direct reads or for taking immutable ref. Also check
+// that the main function can read the variable too while
+// the closures are in scope. Issue #6801.
+
+
+fn a() -> i32 {
+    let mut x = 3;
+    x += 1;
+    let c1 = || x * 4;
+    let c2 = || x * 5;
+    c1() * c2() * x
+}
+
+fn get(x: &i32) -> i32 {
+    *x * 4
+}
+
+fn b() -> i32 {
+    let mut x = 3;
+    x += 1;
+    let c1 = || get(&x);
+    let c2 = || get(&x);
+    c1() * c2() * x
+}
+
+fn c() -> i32 {
+    let mut x = 3;
+    x += 1;
+    let c1 = || x * 5;
+    let c2 = || get(&x);
+    c1() * c2() * x
+}
+
+pub fn main() {
+    assert_eq!(a(), 1280);
+    assert_eq!(b(), 1024);
+    assert_eq!(c(), 1280);
+}
diff --git a/src/test/run-pass/borrowck/borrowck-field-sensitivity.rs b/src/test/run-pass/borrowck/borrowck-field-sensitivity.rs
new file mode 100644 (file)
index 0000000..d97564a
--- /dev/null
@@ -0,0 +1,274 @@
+// Copyright 2014 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.
+
+// pretty-expanded FIXME #23616
+
+#![allow(unknown_features)]
+#![feature(box_syntax)]
+
+struct A { a: isize, b: Box<isize> }
+struct B { a: Box<isize>, b: Box<isize> }
+
+fn move_after_copy() {
+    let x = A { a: 1, b: box 2 };
+    drop(x.a);
+    drop(x.b);
+}
+
+fn move_after_fu_copy() {
+    let x = A { a: 1, b: box 2 };
+    let _y = A { b: box 3, .. x };
+    drop(x.b);
+}
+
+fn fu_move_after_copy() {
+    let x = A { a: 1, b: box 2 };
+    drop(x.a);
+    let _y = A { a: 3, .. x };
+}
+
+fn fu_move_after_fu_copy() {
+    let x = A { a: 1, b: box 2 };
+    let _y = A { b: box 3, .. x };
+    let _z = A { a: 4, .. x };
+}
+
+fn copy_after_move() {
+    let x = A { a: 1, b: box 2 };
+    drop(x.b);
+    drop(x.a);
+}
+
+fn copy_after_fu_move() {
+    let x = A { a: 1, b: box 2 };
+    let y = A { a: 3, .. x };
+    drop(x.a);
+}
+
+fn fu_copy_after_move() {
+    let x = A { a: 1, b: box 2 };
+    drop(x.b);
+    let _y = A { b: box 3, .. x };
+}
+
+fn fu_copy_after_fu_move() {
+    let x = A { a: 1, b: box 2 };
+    let _y = A { a: 3, .. x };
+    let _z = A { b: box 3, .. x };
+}
+
+fn borrow_after_move() {
+    let x = A { a: 1, b: box 2 };
+    drop(x.b);
+    let p = &x.a;
+    drop(*p);
+}
+
+fn borrow_after_fu_move() {
+    let x = A { a: 1, b: box 2 };
+    let _y = A { a: 3, .. x };
+    let p = &x.a;
+    drop(*p);
+}
+
+fn move_after_borrow() {
+    let x = A { a: 1, b: box 2 };
+    let p = &x.a;
+    drop(x.b);
+    drop(*p);
+}
+
+fn fu_move_after_borrow() {
+    let x = A { a: 1, b: box 2 };
+    let p = &x.a;
+    let _y = A { a: 3, .. x };
+    drop(*p);
+}
+
+fn mut_borrow_after_mut_borrow() {
+    let mut x = A { a: 1, b: box 2 };
+    let p = &mut x.a;
+    let q = &mut x.b;
+    drop(*p);
+    drop(**q);
+}
+
+fn move_after_move() {
+    let x = B { a: box 1, b: box 2 };
+    drop(x.a);
+    drop(x.b);
+}
+
+fn move_after_fu_move() {
+    let x = B { a: box 1, b: box 2 };
+    let y = B { a: box 3, .. x };
+    drop(x.a);
+}
+
+fn fu_move_after_move() {
+    let x = B { a: box 1, b: box 2 };
+    drop(x.a);
+    let z = B { a: box 3, .. x };
+    drop(z.b);
+}
+
+fn fu_move_after_fu_move() {
+    let x = B { a: box 1, b: box 2 };
+    let _y = B { b: box 3, .. x };
+    let _z = B { a: box 4, .. x };
+}
+
+fn copy_after_assign_after_move() {
+    let mut x = A { a: 1, b: box 2 };
+    drop(x.b);
+    x = A { a: 3, b: box 4 };
+    drop(*x.b);
+}
+
+fn copy_after_assign_after_fu_move() {
+    let mut x = A { a: 1, b: box 2 };
+    let _y = A { a: 3, .. x };
+    x = A { a: 3, b: box 4 };
+    drop(*x.b);
+}
+
+fn copy_after_field_assign_after_move() {
+    let mut x = A { a: 1, b: box 2 };
+    drop(x.b);
+    x.b = box 3;
+    drop(*x.b);
+}
+
+fn copy_after_field_assign_after_fu_move() {
+    let mut x = A { a: 1, b: box 2 };
+    let _y = A { a: 3, .. x };
+    x.b = box 3;
+    drop(*x.b);
+}
+
+fn borrow_after_assign_after_move() {
+    let mut x = A { a: 1, b: box 2 };
+    drop(x.b);
+    x = A { a: 3, b: box 4 };
+    let p = &x.b;
+    drop(**p);
+}
+
+fn borrow_after_assign_after_fu_move() {
+    let mut x = A { a: 1, b: box 2 };
+    let _y = A { a: 3, .. x };
+    x = A { a: 3, b: box 4 };
+    let p = &x.b;
+    drop(**p);
+}
+
+fn borrow_after_field_assign_after_move() {
+    let mut x = A { a: 1, b: box 2 };
+    drop(x.b);
+    x.b = box 3;
+    let p = &x.b;
+    drop(**p);
+}
+
+fn borrow_after_field_assign_after_fu_move() {
+    let mut x = A { a: 1, b: box 2 };
+    let _y = A { a: 3, .. x };
+    x.b = box 3;
+    let p = &x.b;
+    drop(**p);
+}
+
+fn move_after_assign_after_move() {
+    let mut x = A { a: 1, b: box 2 };
+    let _y = x.b;
+    x = A { a: 3, b: box 4 };
+    drop(x.b);
+}
+
+fn move_after_assign_after_fu_move() {
+    let mut x = A { a: 1, b: box 2 };
+    let _y = A { a: 3, .. x };
+    x = A { a: 3, b: box 4 };
+    drop(x.b);
+}
+
+fn move_after_field_assign_after_move() {
+    let mut x = A { a: 1, b: box 2 };
+    drop(x.b);
+    x.b = box 3;
+    drop(x.b);
+}
+
+fn move_after_field_assign_after_fu_move() {
+    let mut x = A { a: 1, b: box 2 };
+    let _y = A { a: 3, .. x };
+    x.b = box 3;
+    drop(x.b);
+}
+
+fn copy_after_assign_after_uninit() {
+    let mut x: A;
+    x = A { a: 1, b: box 2 };
+    drop(x.a);
+}
+
+fn borrow_after_assign_after_uninit() {
+    let mut x: A;
+    x = A { a: 1, b: box 2 };
+    let p = &x.a;
+    drop(*p);
+}
+
+fn move_after_assign_after_uninit() {
+    let mut x: A;
+    x = A { a: 1, b: box 2 };
+    drop(x.b);
+}
+
+fn main() {
+    move_after_copy();
+    move_after_fu_copy();
+    fu_move_after_copy();
+    fu_move_after_fu_copy();
+    copy_after_move();
+    copy_after_fu_move();
+    fu_copy_after_move();
+    fu_copy_after_fu_move();
+
+    borrow_after_move();
+    borrow_after_fu_move();
+    move_after_borrow();
+    fu_move_after_borrow();
+    mut_borrow_after_mut_borrow();
+
+    move_after_move();
+    move_after_fu_move();
+    fu_move_after_move();
+    fu_move_after_fu_move();
+
+    copy_after_assign_after_move();
+    copy_after_assign_after_fu_move();
+    copy_after_field_assign_after_move();
+    copy_after_field_assign_after_fu_move();
+
+    borrow_after_assign_after_move();
+    borrow_after_assign_after_fu_move();
+    borrow_after_field_assign_after_move();
+    borrow_after_field_assign_after_fu_move();
+
+    move_after_assign_after_move();
+    move_after_assign_after_fu_move();
+    move_after_field_assign_after_move();
+    move_after_field_assign_after_fu_move();
+
+    copy_after_assign_after_uninit();
+    borrow_after_assign_after_uninit();
+    move_after_assign_after_uninit();
+}
diff --git a/src/test/run-pass/borrowck/borrowck-fixed-length-vecs.rs b/src/test/run-pass/borrowck/borrowck-fixed-length-vecs.rs
new file mode 100644 (file)
index 0000000..0e33351
--- /dev/null
@@ -0,0 +1,16 @@
+// 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 main() {
+    let x = [22];
+    let y = &x[0];
+    assert_eq!(*y, 22);
+}
diff --git a/src/test/run-pass/borrowck/borrowck-freeze-frozen-mut.rs b/src/test/run-pass/borrowck/borrowck-freeze-frozen-mut.rs
new file mode 100644 (file)
index 0000000..380bd39
--- /dev/null
@@ -0,0 +1,37 @@
+// Copyright 2012-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.
+
+// Test that a `&mut` inside of an `&` is freezable.
+
+
+struct MutSlice<'a, T:'a> {
+    data: &'a mut [T]
+}
+
+fn get<'a, T>(ms: &'a MutSlice<'a, T>, index: usize) -> &'a T {
+    &ms.data[index]
+}
+
+pub fn main() {
+    let mut data = [1, 2, 3];
+    {
+        let slice = MutSlice { data: &mut data };
+        slice.data[0] += 4;
+        let index0 = get(&slice, 0);
+        let index1 = get(&slice, 1);
+        let index2 = get(&slice, 2);
+        assert_eq!(*index0, 5);
+        assert_eq!(*index1, 2);
+        assert_eq!(*index2, 3);
+    }
+    assert_eq!(data[0], 5);
+    assert_eq!(data[1], 2);
+    assert_eq!(data[2], 3);
+}
diff --git a/src/test/run-pass/borrowck/borrowck-lend-args.rs b/src/test/run-pass/borrowck/borrowck-lend-args.rs
new file mode 100644 (file)
index 0000000..f1f0274
--- /dev/null
@@ -0,0 +1,29 @@
+// 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.
+
+
+// pretty-expanded FIXME #23616
+
+fn borrow(_v: &isize) {}
+
+fn borrow_from_arg_imm_ref(v: Box<isize>) {
+    borrow(&*v);
+}
+
+fn borrow_from_arg_mut_ref(v: &mut Box<isize>) {
+    borrow(&**v);
+}
+
+fn borrow_from_arg_copy(v: Box<isize>) {
+    borrow(&*v);
+}
+
+pub fn main() {
+}
diff --git a/src/test/run-pass/borrowck/borrowck-macro-interaction-issue-6304.rs b/src/test/run-pass/borrowck/borrowck-macro-interaction-issue-6304.rs
new file mode 100644 (file)
index 0000000..fb30c85
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright 2014 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.
+
+// Check that we do not ICE when compiling this
+// macro, which reuses the expression `$id`
+
+
+#![feature(box_patterns)]
+#![feature(box_syntax)]
+
+struct Foo {
+  a: isize
+}
+
+pub enum Bar {
+  Bar1, Bar2(isize, Box<Bar>),
+}
+
+impl Foo {
+  fn elaborate_stm(&mut self, s: Box<Bar>) -> Box<Bar> {
+    macro_rules! declare {
+      ($id:expr, $rest:expr) => ({
+        self.check_id($id);
+        box Bar::Bar2($id, $rest)
+      })
+    }
+    match s {
+      box Bar::Bar2(id, rest) => declare!(id, self.elaborate_stm(rest)),
+      _ => panic!()
+    }
+  }
+
+  fn check_id(&mut self, s: isize) { panic!() }
+}
+
+pub fn main() { }
diff --git a/src/test/run-pass/borrowck/borrowck-move-by-capture-ok.rs b/src/test/run-pass/borrowck/borrowck-move-by-capture-ok.rs
new file mode 100644 (file)
index 0000000..bbc668f
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2014 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.
+
+
+#![allow(unknown_features)]
+#![feature(box_syntax)]
+#![feature(unboxed_closures)]
+
+pub fn main() {
+    let bar: Box<_> = box 3;
+    let h = || -> isize { *bar };
+    assert_eq!(h(), 3);
+}
diff --git a/src/test/run-pass/borrowck/borrowck-mut-uniq.rs b/src/test/run-pass/borrowck/borrowck-mut-uniq.rs
new file mode 100644 (file)
index 0000000..f535c5f
--- /dev/null
@@ -0,0 +1,43 @@
+// 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.
+
+#![allow(unknown_features)]
+#![feature(box_syntax)]
+
+use std::mem::swap;
+
+#[derive(Debug)]
+struct Ints {sum: Box<isize>, values: Vec<isize> }
+
+fn add_int(x: &mut Ints, v: isize) {
+    *x.sum += v;
+    let mut values = Vec::new();
+    swap(&mut values, &mut x.values);
+    values.push(v);
+    swap(&mut values, &mut x.values);
+}
+
+fn iter_ints<F>(x: &Ints, mut f: F) -> bool where F: FnMut(&isize) -> bool {
+    let l = x.values.len();
+    (0..l).all(|i| f(&x.values[i]))
+}
+
+pub fn main() {
+    let mut ints: Box<_> = box Ints {sum: box 0, values: Vec::new()};
+    add_int(&mut *ints, 22);
+    add_int(&mut *ints, 44);
+
+    iter_ints(&*ints, |i| {
+        println!("isize = {:?}", *i);
+        true
+    });
+
+    println!("ints={:?}", ints);
+}
diff --git a/src/test/run-pass/borrowck/borrowck-mut-vec-as-imm-slice.rs b/src/test/run-pass/borrowck/borrowck-mut-vec-as-imm-slice.rs
new file mode 100644 (file)
index 0000000..d55517c
--- /dev/null
@@ -0,0 +1,25 @@
+// 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 want_slice(v: &[isize]) -> isize {
+    let mut sum = 0;
+    for i in v { sum += *i; }
+    sum
+}
+
+fn has_mut_vec(v: Vec<isize> ) -> isize {
+    want_slice(&v)
+}
+
+pub fn main() {
+    assert_eq!(has_mut_vec(vec!(1, 2, 3)), 6);
+}
diff --git a/src/test/run-pass/borrowck/borrowck-pat-enum.rs b/src/test/run-pass/borrowck/borrowck-pat-enum.rs
new file mode 100644 (file)
index 0000000..b29cb63
--- /dev/null
@@ -0,0 +1,47 @@
+// Copyright 2012-2014 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.
+
+// ignore-pretty
+
+fn match_ref(v: Option<isize>) -> isize {
+    match v {
+      Some(ref i) => {
+        *i
+      }
+      None => {0}
+    }
+}
+
+fn match_ref_unused(v: Option<isize>) {
+    match v {
+      Some(_) => {}
+      None => {}
+    }
+}
+
+fn impure(_i: isize) {
+}
+
+fn match_imm_reg(v: &Option<isize>) {
+    match *v {
+      Some(ref i) => {impure(*i)} // OK because immutable
+      None => {}
+    }
+}
+
+fn match_mut_reg(v: &mut Option<isize>) {
+    match *v {
+      Some(ref i) => {impure(*i)} // OK, frozen
+      None => {}
+    }
+}
+
+pub fn main() {
+}
diff --git a/src/test/run-pass/borrowck/borrowck-pat-reassign-no-binding.rs b/src/test/run-pass/borrowck/borrowck-pat-reassign-no-binding.rs
new file mode 100644 (file)
index 0000000..e0a5db6
--- /dev/null
@@ -0,0 +1,23 @@
+// 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 main() {
+    let mut x = None;
+    match x {
+      None => {
+        // It is ok to reassign x here, because there is in
+        // fact no outstanding loan of x!
+        x = Some(0);
+      }
+      Some(_) => { }
+    }
+    assert_eq!(x, Some(0));
+}
diff --git a/src/test/run-pass/borrowck/borrowck-rvalues-mutable.rs b/src/test/run-pass/borrowck/borrowck-rvalues-mutable.rs
new file mode 100644 (file)
index 0000000..93cb0cb
--- /dev/null
@@ -0,0 +1,43 @@
+// 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 Counter {
+    value: usize
+}
+
+impl Counter {
+    fn new(v: usize) -> Counter {
+        Counter {value: v}
+    }
+
+    fn inc<'a>(&'a mut self) -> &'a mut Counter {
+        self.value += 1;
+        self
+    }
+
+    fn get(&self) -> usize {
+        self.value
+    }
+
+    fn get_and_inc(&mut self) -> usize {
+        let v = self.value;
+        self.value += 1;
+        v
+    }
+}
+
+pub fn main() {
+    let v = Counter::new(22).get_and_inc();
+    assert_eq!(v, 22);
+
+    let v = Counter::new(22).inc().inc().get();
+    assert_eq!(v, 24);
+}
diff --git a/src/test/run-pass/borrowck/borrowck-scope-of-deref-issue-4666.rs b/src/test/run-pass/borrowck/borrowck-scope-of-deref-issue-4666.rs
new file mode 100644 (file)
index 0000000..59a5fea
--- /dev/null
@@ -0,0 +1,51 @@
+// Copyright 2012-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.
+
+// Tests that the scope of the pointer returned from `get()` is
+// limited to the deref operation itself, and does not infect the
+// block as a whole.
+
+
+struct Box {
+    x: usize
+}
+
+impl Box {
+    fn get(&self) -> &usize {
+        &self.x
+    }
+    fn set(&mut self, x: usize) {
+        self.x = x;
+    }
+}
+
+fn fun1() {
+    // in the past, borrow checker behaved differently when
+    // init and decl of `v` were distinct
+    let v;
+    let mut a_box = Box {x: 0};
+    a_box.set(22);
+    v = *a_box.get();
+    a_box.set(v+1);
+    assert_eq!(23, *a_box.get());
+}
+
+fn fun2() {
+    let mut a_box = Box {x: 0};
+    a_box.set(22);
+    let v = *a_box.get();
+    a_box.set(v+1);
+    assert_eq!(23, *a_box.get());
+}
+
+pub fn main() {
+    fun1();
+    fun2();
+}
diff --git a/src/test/run-pass/borrowck/borrowck-static-item-in-fn.rs b/src/test/run-pass/borrowck/borrowck-static-item-in-fn.rs
new file mode 100644 (file)
index 0000000..d51d0b1
--- /dev/null
@@ -0,0 +1,17 @@
+// 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.
+
+// Regression test for issue #7740
+
+// pretty-expanded FIXME #23616
+
+pub fn main() {
+    static A: &'static char = &'A';
+}
diff --git a/src/test/run-pass/borrowck/borrowck-trait-lifetime.rs b/src/test/run-pass/borrowck/borrowck-trait-lifetime.rs
new file mode 100644 (file)
index 0000000..0bfa8f4
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright 2014 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.
+
+// This test verifies that casting from the same lifetime on a value
+// to the same lifetime on a trait succeeds. See issue #10766.
+
+// pretty-expanded FIXME #23616
+
+#![allow(dead_code)]
+
+use std::marker;
+
+fn main() {
+    trait T { fn foo(&self) {} }
+
+    fn f<'a, V: T>(v: &'a V) -> &'a T {
+        v as &'a T
+    }
+}
diff --git a/src/test/run-pass/borrowck/borrowck-uniq-via-ref.rs b/src/test/run-pass/borrowck/borrowck-uniq-via-ref.rs
new file mode 100644 (file)
index 0000000..0ec8759
--- /dev/null
@@ -0,0 +1,57 @@
+// 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.
+
+
+// pretty-expanded FIXME #23616
+
+struct Rec {
+    f: Box<isize>,
+}
+
+struct Outer {
+    f: Inner
+}
+
+struct Inner {
+    g: Innermost
+}
+
+struct Innermost {
+    h: Box<isize>,
+}
+
+fn borrow(_v: &isize) {}
+
+fn box_mut(v: &mut Box<isize>) {
+    borrow(&**v); // OK: &mut -> &imm
+}
+
+fn box_mut_rec(v: &mut Rec) {
+    borrow(&*v.f); // OK: &mut -> &imm
+}
+
+fn box_mut_recs(v: &mut Outer) {
+    borrow(&*v.f.g.h); // OK: &mut -> &imm
+}
+
+fn box_imm(v: &Box<isize>) {
+    borrow(&**v); // OK
+}
+
+fn box_imm_rec(v: &Rec) {
+    borrow(&*v.f); // OK
+}
+
+fn box_imm_recs(v: &Outer) {
+    borrow(&*v.f.g.h); // OK
+}
+
+pub fn main() {
+}
diff --git a/src/test/run-pass/borrowck/borrowck-univariant-enum.rs b/src/test/run-pass/borrowck/borrowck-univariant-enum.rs
new file mode 100644 (file)
index 0000000..2e8ddb0
--- /dev/null
@@ -0,0 +1,34 @@
+// 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.
+
+
+
+use std::cell::Cell;
+
+#[derive(Copy, Clone)]
+enum newtype {
+    newvar(isize)
+}
+
+pub fn main() {
+
+    // Test that borrowck treats enums with a single variant
+    // specially.
+
+    let x = &Cell::new(5);
+    let y = &Cell::new(newtype::newvar(3));
+    let z = match y.get() {
+      newtype::newvar(b) => {
+        x.set(x.get() + 1);
+        x.get() * b
+      }
+    };
+    assert_eq!(z, 18);
+}
diff --git a/src/test/run-pass/borrowck/borrowck-use-mut-borrow.rs b/src/test/run-pass/borrowck/borrowck-use-mut-borrow.rs
new file mode 100644 (file)
index 0000000..7ad81b6
--- /dev/null
@@ -0,0 +1,61 @@
+// Copyright 2014 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.
+
+// pretty-expanded FIXME #23616
+
+#![allow(unknown_features)]
+#![feature(box_syntax)]
+
+struct A { a: isize, b: Box<isize> }
+
+fn field_copy_after_field_borrow() {
+    let mut x = A { a: 1, b: box 2 };
+    let p = &mut x.b;
+    drop(x.a);
+    **p = 3;
+}
+
+fn fu_field_copy_after_field_borrow() {
+    let mut x = A { a: 1, b: box 2 };
+    let p = &mut x.b;
+    let y = A { b: box 3, .. x };
+    drop(y);
+    **p = 4;
+}
+
+fn field_deref_after_field_borrow() {
+    let mut x = A { a: 1, b: box 2 };
+    let p = &mut x.a;
+    drop(*x.b);
+    *p = 3;
+}
+
+fn field_move_after_field_borrow() {
+    let mut x = A { a: 1, b: box 2 };
+    let p = &mut x.a;
+    drop(x.b);
+    *p = 3;
+}
+
+fn fu_field_move_after_field_borrow() {
+    let mut x = A { a: 1, b: box 2 };
+    let p = &mut x.a;
+    let y = A { a: 3, .. x };
+    drop(y);
+    *p = 4;
+}
+
+fn main() {
+    field_copy_after_field_borrow();
+    fu_field_copy_after_field_borrow();
+    field_deref_after_field_borrow();
+    field_move_after_field_borrow();
+    fu_field_move_after_field_borrow();
+}