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:
Tim Chevalier 2012-11-30 11:24:16 -08:00
parent f89d4ac830
commit daf28a421a
13 changed files with 186 additions and 78 deletions

View file

@ -0,0 +1,5 @@
mod super_sekrit {
pub enum sooper_sekrit {
pub quux, priv baz
}
}

View 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
}

View 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
}