diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-11-30 11:24:16 -0800 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-11-30 12:45:10 -0800 |
| commit | daf28a421aece474dfcd4c5185709ca789fe29e3 (patch) | |
| tree | 4d7a357363dec4e51049ea989b2731161234c3b4 /src/libsyntax | |
| parent | f89d4ac8306dbe597f0bfef7cf92bea372eece1d (diff) | |
| download | rust-daf28a421aece474dfcd4c5185709ca789fe29e3.tar.gz rust-daf28a421aece474dfcd4c5185709ca789fe29e3.zip | |
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
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast_map.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 40 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 3251ea5d2e9..6e0069a649a 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -391,6 +391,16 @@ fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str { } } } + +fn node_item_query<Result>(items: map, id: node_id, + query: fn(@item) -> Result, + error_msg: ~str) -> Result { + match items.find(id) { + Some(node_item(it, _)) => query(it), + _ => fail(error_msg) + } +} + // Local Variables: // mode: rust // fill-column: 78; diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 0b066b57168..e4e29d1fb45 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -602,6 +602,46 @@ fn struct_def_is_tuple_like(struct_def: @ast::struct_def) -> bool { struct_def.ctor_id.is_some() } + +fn visibility_to_privacy(visibility: visibility, + legacy_exports: bool) -> Privacy { + if legacy_exports { + match visibility { + inherited | public => Public, + private => Private + } + } else { + match visibility { + public => Public, + inherited | private => Private + } + } +} + +enum Privacy { + Private, + Public +} + +impl Privacy : cmp::Eq { + pure fn eq(&self, other: &Privacy) -> bool { + ((*self) as uint) == ((*other) as uint) + } + pure fn ne(&self, other: &Privacy) -> bool { !(*self).eq(other) } +} + +fn has_legacy_export_attr(attrs: &[attribute]) -> bool { + for attrs.each |attribute| { + match attribute.node.value.node { + meta_word(w) if w == ~"legacy_exports" => { + return true; + } + _ => {} + } + } + return false; +} + // Local Variables: // mode: rust // fill-column: 78; |
