rust/src/test/compile-fail/non-const.rs

56 lines
1.2 KiB
Rust
Raw Normal View History

// 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 various non const things are rejected.
fn foo<T: Const>(_x: T) { }
2012-08-15 20:46:55 -05:00
struct r {
2012-09-06 21:40:15 -05:00
x:int,
}
impl r : Drop {
fn finalize(&self) {}
2012-06-01 22:21:59 -05:00
}
2012-09-05 17:58:43 -05:00
fn r(x:int) -> r {
r {
x: x
}
}
2012-08-15 20:46:55 -05:00
struct r2 {
2012-09-06 21:40:15 -05:00
x:@mut int,
}
impl r2 : Drop {
fn finalize(&self) {}
2012-06-01 22:21:59 -05:00
}
2012-09-05 17:58:43 -05:00
fn r2(x:@mut int) -> r2 {
r2 {
x: x
}
}
fn main() {
foo({f: 3});
foo({mut f: 3}); //~ ERROR missing `const`
foo(~[1]);
Merge remote-tracking branch 'Dretch/prettydocs' Conflicts: src/compiletest/errors.rs src/libsyntax/parse/attr.rs src/libsyntax/parse/comments.rs src/test/compile-fail/ambig_impl_unify.rs src/test/compile-fail/assign-super.rs src/test/compile-fail/bad-for-loop.rs src/test/compile-fail/bad-var-env-capture-in-block-arg.rs src/test/compile-fail/block-arg-as-stmt-with-value.rs src/test/compile-fail/borrowck-assign-comp-idx.rs src/test/compile-fail/borrowck-lend-flow.rs src/test/compile-fail/borrowck-loan-blocks-move-cc.rs src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs src/test/compile-fail/borrowck-loan-rcvr.rs src/test/compile-fail/borrowck-loan-vec-content.rs src/test/compile-fail/borrowck-mut-vec-as-imm-slice-bad.rs src/test/compile-fail/cap-clause-with-stack-closure.rs src/test/compile-fail/do1.rs src/test/compile-fail/do2.rs src/test/compile-fail/empty-vec-trailing-comma.rs src/test/compile-fail/evec-subtyping.rs src/test/compile-fail/issue-1896.rs src/test/compile-fail/issue-2149.rs src/test/compile-fail/issue-2150.rs src/test/compile-fail/issue-2487-b.rs src/test/compile-fail/kindck-implicit-close-over-mut-var.rs src/test/compile-fail/liveness-issue-2163.rs src/test/compile-fail/liveness-use-in-index-lvalue.rs src/test/compile-fail/no-reuse-move-arc.rs src/test/compile-fail/no-send-res-ports.rs src/test/compile-fail/non-const.rs src/test/compile-fail/pure-higher-order.rs src/test/compile-fail/pure-loop-body.rs src/test/compile-fail/regions-addr-of-upvar-self.rs src/test/compile-fail/regions-escape-loop-via-vec.rs src/test/compile-fail/regions-scoping.rs src/test/compile-fail/seq-args.rs src/test/compile-fail/tstate-unsat-in-called-fn-expr.rs src/test/compile-fail/tstate-unsat-in-fn-expr.rs src/test/compile-fail/vec-add.rs src/test/compile-fail/vec-concat-bug.rs src/test/compile-fail/vector-no-ann.rs
2012-07-02 16:44:31 -05:00
foo(~[mut 1]); //~ ERROR missing `const`
foo(~1);
foo(~mut 1); //~ ERROR missing `const`
foo(@1);
foo(@mut 1); //~ ERROR missing `const`
foo(r(1)); // this is okay now.
foo(r2(@mut 1)); //~ ERROR missing `const`
foo({f: {mut f: 1}}); //~ ERROR missing `const`
}