Disallow dereferencing enum types when the variant is private
If an enum type's only variant is private, disallow dereferencing values of its type. Due to #4082, this only applies to enums that are in the same crate. r=pcwalton Closes #818
This commit is contained in:
parent
f89d4ac830
commit
daf28a421a
13 changed files with 186 additions and 78 deletions
5
src/test/auxiliary/private_variant_1.rs
Normal file
5
src/test/auxiliary/private_variant_1.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
mod super_sekrit {
|
||||
pub enum sooper_sekrit {
|
||||
pub quux, priv baz
|
||||
}
|
||||
}
|
||||
14
src/test/compile-fail/issue-818.rs
Normal file
14
src/test/compile-fail/issue-818.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
mod ctr {
|
||||
|
||||
pub enum ctr { priv mkCtr(int) }
|
||||
|
||||
pub fn new(i: int) -> ctr { mkCtr(i) }
|
||||
pub fn inc(c: ctr) -> ctr { mkCtr(*c + 1) }
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let c = ctr::new(42);
|
||||
let c2 = ctr::inc(c);
|
||||
assert *c2 == 5; //~ ERROR can only dereference enums with a single, public variant
|
||||
}
|
||||
7
src/test/compile-fail/private_variant_2.rs
Normal file
7
src/test/compile-fail/private_variant_2.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// xfail-test
|
||||
// aux-build:private_variant_1.rs
|
||||
extern mod private_variant_1;
|
||||
|
||||
fn main() {
|
||||
let _x = private_variant_1::super_sekrit::baz; //~ ERROR baz is private
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue