diff options
Diffstat (limited to 'src/test/compile-fail')
| -rw-r--r-- | src/test/compile-fail/borrowck/borrowck-union-borrow-nested.rs (renamed from src/test/compile-fail/union-borrow-nested.rs) | 0 | ||||
| -rw-r--r-- | src/test/compile-fail/borrowck/borrowck-union-borrow.rs (renamed from src/test/compile-fail/union-borrow.rs) | 0 | ||||
| -rw-r--r-- | src/test/compile-fail/borrowck/borrowck-union-move-assign.rs (renamed from src/test/compile-fail/union-move-assign.rs) | 0 | ||||
| -rw-r--r-- | src/test/compile-fail/borrowck/borrowck-union-move.rs (renamed from src/test/compile-fail/union-move.rs) | 0 | ||||
| -rw-r--r-- | src/test/compile-fail/borrowck/borrowck-union-uninitialized.rs (renamed from src/test/compile-fail/union-uninitialized.rs) | 0 | ||||
| -rw-r--r-- | src/test/compile-fail/privacy/union-field-privacy-1.rs | 30 | ||||
| -rw-r--r-- | src/test/compile-fail/privacy/union-field-privacy-2.rs | 28 | ||||
| -rw-r--r-- | src/test/compile-fail/union/union-const-eval.rs (renamed from src/test/compile-fail/union-const-eval.rs) | 0 | ||||
| -rw-r--r-- | src/test/compile-fail/union/union-const-pat.rs (renamed from src/test/compile-fail/union-const-pat.rs) | 0 | ||||
| -rw-r--r-- | src/test/compile-fail/union/union-copy.rs | 26 | ||||
| -rw-r--r-- | src/test/compile-fail/union/union-derive.rs (renamed from src/test/compile-fail/union-derive.rs) | 0 | ||||
| -rw-r--r-- | src/test/compile-fail/union/union-empty.rs (renamed from src/test/compile-fail/union-empty.rs) | 0 | ||||
| -rw-r--r-- | src/test/compile-fail/union/union-feature-gate.rs (renamed from src/test/compile-fail/union-field-privacy.rs) | 12 | ||||
| -rw-r--r-- | src/test/compile-fail/union/union-fields.rs (renamed from src/test/compile-fail/union-fields.rs) | 11 | ||||
| -rw-r--r-- | src/test/compile-fail/union/union-generic.rs | 24 | ||||
| -rw-r--r-- | src/test/compile-fail/union/union-nonrepresentable.rs (renamed from src/test/compile-fail/union-nonrepresentable.rs) | 0 | ||||
| -rw-r--r-- | src/test/compile-fail/union/union-repr-c.rs | 29 | ||||
| -rw-r--r-- | src/test/compile-fail/union/union-suggest-field.rs | 29 | ||||
| -rw-r--r-- | src/test/compile-fail/union/union-unsafe.rs (renamed from src/test/compile-fail/union-unsafe.rs) | 7 | ||||
| -rw-r--r-- | src/test/compile-fail/union/union-unsized.rs (renamed from src/test/compile-fail/union-unsized.rs) | 6 | ||||
| -rw-r--r-- | src/test/compile-fail/union/union-with-drop-fields-lint.rs (renamed from src/test/compile-fail/union-with-drop-fields-lint.rs) | 0 |
21 files changed, 185 insertions, 17 deletions
diff --git a/src/test/compile-fail/union-borrow-nested.rs b/src/test/compile-fail/borrowck/borrowck-union-borrow-nested.rs index 19975d79b60..19975d79b60 100644 --- a/src/test/compile-fail/union-borrow-nested.rs +++ b/src/test/compile-fail/borrowck/borrowck-union-borrow-nested.rs diff --git a/src/test/compile-fail/union-borrow.rs b/src/test/compile-fail/borrowck/borrowck-union-borrow.rs index e8989a3c2d4..e8989a3c2d4 100644 --- a/src/test/compile-fail/union-borrow.rs +++ b/src/test/compile-fail/borrowck/borrowck-union-borrow.rs diff --git a/src/test/compile-fail/union-move-assign.rs b/src/test/compile-fail/borrowck/borrowck-union-move-assign.rs index d4d7bc6b0f7..d4d7bc6b0f7 100644 --- a/src/test/compile-fail/union-move-assign.rs +++ b/src/test/compile-fail/borrowck/borrowck-union-move-assign.rs diff --git a/src/test/compile-fail/union-move.rs b/src/test/compile-fail/borrowck/borrowck-union-move.rs index 5320244cf43..5320244cf43 100644 --- a/src/test/compile-fail/union-move.rs +++ b/src/test/compile-fail/borrowck/borrowck-union-move.rs diff --git a/src/test/compile-fail/union-uninitialized.rs b/src/test/compile-fail/borrowck/borrowck-union-uninitialized.rs index 36e062f8464..36e062f8464 100644 --- a/src/test/compile-fail/union-uninitialized.rs +++ b/src/test/compile-fail/borrowck/borrowck-union-uninitialized.rs diff --git a/src/test/compile-fail/privacy/union-field-privacy-1.rs b/src/test/compile-fail/privacy/union-field-privacy-1.rs new file mode 100644 index 00000000000..4924fabafb0 --- /dev/null +++ b/src/test/compile-fail/privacy/union-field-privacy-1.rs @@ -0,0 +1,30 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-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(pub_restricted)] +#![feature(untagged_unions)] + +mod m { + pub union U { + pub a: u8, + pub(super) b: u8, + c: u8, + } +} + +fn main() { + let u = m::U { a: 0 }; // OK + let u = m::U { b: 0 }; // OK + let u = m::U { c: 0 }; //~ ERROR field `c` of union `m::U` is private + + let m::U { a } = u; // OK + let m::U { b } = u; // OK + let m::U { c } = u; //~ ERROR field `c` of union `m::U` is private +} diff --git a/src/test/compile-fail/privacy/union-field-privacy-2.rs b/src/test/compile-fail/privacy/union-field-privacy-2.rs new file mode 100644 index 00000000000..7151538f412 --- /dev/null +++ b/src/test/compile-fail/privacy/union-field-privacy-2.rs @@ -0,0 +1,28 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-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(pub_restricted)] +#![feature(untagged_unions)] + +mod m { + pub union U { + pub a: u8, + pub(super) b: u8, + c: u8, + } +} + +fn main() { + let u = m::U { a: 10 }; + + let a = u.a; // OK + let b = u.b; // OK + let c = u.c; //~ ERROR field `c` of struct `m::U` is private +} diff --git a/src/test/compile-fail/union-const-eval.rs b/src/test/compile-fail/union/union-const-eval.rs index b2bf173c59c..b2bf173c59c 100644 --- a/src/test/compile-fail/union-const-eval.rs +++ b/src/test/compile-fail/union/union-const-eval.rs diff --git a/src/test/compile-fail/union-const-pat.rs b/src/test/compile-fail/union/union-const-pat.rs index 3d168980ed2..3d168980ed2 100644 --- a/src/test/compile-fail/union-const-pat.rs +++ b/src/test/compile-fail/union/union-const-pat.rs diff --git a/src/test/compile-fail/union/union-copy.rs b/src/test/compile-fail/union/union-copy.rs new file mode 100644 index 00000000000..6e08ae0074d --- /dev/null +++ b/src/test/compile-fail/union/union-copy.rs @@ -0,0 +1,26 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-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(untagged_unions)] + +union U { + a: u8 +} + +union W { + a: String +} + +impl Clone for U { fn clone(&self) { panic!(); } } +impl Clone for W { fn clone(&self) { panic!(); } } +impl Copy for U {} // OK +impl Copy for W {} //~ ERROR the trait `Copy` may not be implemented for this type + +fn main() {} diff --git a/src/test/compile-fail/union-derive.rs b/src/test/compile-fail/union/union-derive.rs index 0f78e96f640..0f78e96f640 100644 --- a/src/test/compile-fail/union-derive.rs +++ b/src/test/compile-fail/union/union-derive.rs diff --git a/src/test/compile-fail/union-empty.rs b/src/test/compile-fail/union/union-empty.rs index ce5bbf60fee..ce5bbf60fee 100644 --- a/src/test/compile-fail/union-empty.rs +++ b/src/test/compile-fail/union/union-empty.rs diff --git a/src/test/compile-fail/union-field-privacy.rs b/src/test/compile-fail/union/union-feature-gate.rs index d1f2bbbc3d0..abfc4d90921 100644 --- a/src/test/compile-fail/union-field-privacy.rs +++ b/src/test/compile-fail/union/union-feature-gate.rs @@ -8,14 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(untagged_unions)] - -mod m { - pub union U { - a: u8 - } +union U { //~ ERROR unions are unstable and possibly buggy + a: u8, } -fn main() { - let u = m::U { a: 0 }; //~ ERROR field `a` of union `m::U` is private -} +fn main() {} diff --git a/src/test/compile-fail/union-fields.rs b/src/test/compile-fail/union/union-fields.rs index 2bd1b8a7b32..a1721dda7de 100644 --- a/src/test/compile-fail/union-fields.rs +++ b/src/test/compile-fail/union/union-fields.rs @@ -24,11 +24,12 @@ fn main() { let u = U { ..u }; //~ ERROR union expressions should have exactly one field //~^ ERROR functional record update syntax requires a struct - let U {} = u; //~ ERROR union patterns without `..` should have at least one field + let U {} = u; //~ ERROR union patterns should have exactly one field let U { a } = u; // OK - let U { a, b } = u; //~ ERROR union patterns can have at most one field - let U { a, b, c } = u; //~ ERROR union patterns can have at most one field + let U { a, b } = u; //~ ERROR union patterns should have exactly one field + let U { a, b, c } = u; //~ ERROR union patterns should have exactly one field //~^ ERROR union `U` does not have a field named `c` - let U { .. } = u; // OK - let U { a, .. } = u; // OK + let U { .. } = u; //~ ERROR union patterns should have exactly one field + //~^ ERROR `..` cannot be used in union patterns + let U { a, .. } = u; //~ ERROR `..` cannot be used in union patterns } diff --git a/src/test/compile-fail/union/union-generic.rs b/src/test/compile-fail/union/union-generic.rs new file mode 100644 index 00000000000..e6586b0fb7f --- /dev/null +++ b/src/test/compile-fail/union/union-generic.rs @@ -0,0 +1,24 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-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(untagged_unions)] + +use std::rc::Rc; + +union U<T: Copy> { + a: T +} + +fn main() { + let u = U { a: Rc::new(0u32) }; + //~^ ERROR the trait bound `std::rc::Rc<u32>: std::marker::Copy` is not satisfied + let u = U::<Rc<u32>> { a: Default::default() }; + //~^ ERROR the trait bound `std::rc::Rc<u32>: std::marker::Copy` is not satisfied +} diff --git a/src/test/compile-fail/union-nonrepresentable.rs b/src/test/compile-fail/union/union-nonrepresentable.rs index cb4683c2a0e..cb4683c2a0e 100644 --- a/src/test/compile-fail/union-nonrepresentable.rs +++ b/src/test/compile-fail/union/union-nonrepresentable.rs diff --git a/src/test/compile-fail/union/union-repr-c.rs b/src/test/compile-fail/union/union-repr-c.rs new file mode 100644 index 00000000000..d7dfb126c93 --- /dev/null +++ b/src/test/compile-fail/union/union-repr-c.rs @@ -0,0 +1,29 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-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(untagged_unions)] +#![allow(unused)] +#![deny(improper_ctypes)] + +#[repr(C)] +union U { + a: u8, +} + +union W { + a: u8, +} + +extern "C" { + static FOREIGN1: U; // OK + static FOREIGN2: W; //~ ERROR found union without foreign-function-safe representation +} + +fn main() {} diff --git a/src/test/compile-fail/union/union-suggest-field.rs b/src/test/compile-fail/union/union-suggest-field.rs new file mode 100644 index 00000000000..b05e9b6e273 --- /dev/null +++ b/src/test/compile-fail/union/union-suggest-field.rs @@ -0,0 +1,29 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-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(untagged_unions)] + +union U { + principal: u8, +} + +impl U { + fn calculate(&self) {} +} + +fn main() { + let u = U { principle: 0 }; //~ ERROR union `U` has no field named `principle` + //~^ HELP did you mean `principal`? + let w = u.principial; //~ ERROR attempted access of field `principial` on type `U` + //~^ HELP did you mean `principal`? + + let y = u.calculate; //~ ERROR attempted to take value of method `calculate` on type `U` + //~^ HELP maybe a `()` to call it is missing? +} diff --git a/src/test/compile-fail/union-unsafe.rs b/src/test/compile-fail/union/union-unsafe.rs index 762ac5d8751..97e1ec2cba8 100644 --- a/src/test/compile-fail/union-unsafe.rs +++ b/src/test/compile-fail/union/union-unsafe.rs @@ -15,9 +15,10 @@ union U { } fn main() { - let u = U { a: 10 }; // OK + let mut u = U { a: 10 }; // OK let a = u.a; //~ ERROR access to union field requires unsafe function or block + u.a = 11; //~ ERROR access to union field requires unsafe function or block let U { a } = u; //~ ERROR matching on union field requires unsafe function or block - if let U { a: 11 } = u {} //~ ERROR matching on union field requires unsafe function or block - let U { .. } = u; // OK + if let U { a: 12 } = u {} //~ ERROR matching on union field requires unsafe function or block + // let U { .. } = u; // OK } diff --git a/src/test/compile-fail/union-unsized.rs b/src/test/compile-fail/union/union-unsized.rs index 381122406d7..a238eaf0525 100644 --- a/src/test/compile-fail/union-unsized.rs +++ b/src/test/compile-fail/union/union-unsized.rs @@ -12,6 +12,12 @@ union U { a: str, //~ ERROR the trait bound `str: std::marker::Sized` is not satisfied + b: u8, +} + +union W { + a: u8, + b: str, //~ ERROR the trait bound `str: std::marker::Sized` is not satisfied } fn main() {} diff --git a/src/test/compile-fail/union-with-drop-fields-lint.rs b/src/test/compile-fail/union/union-with-drop-fields-lint.rs index 87a72efbe08..87a72efbe08 100644 --- a/src/test/compile-fail/union-with-drop-fields-lint.rs +++ b/src/test/compile-fail/union/union-with-drop-fields-lint.rs |
