about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2012-01-31 12:34:22 +0100
committerMarijn Haverbeke <marijnh@gmail.com>2012-01-31 13:02:46 +0100
commit25d60172d6a66b2a620a228ce6642640e9faa517 (patch)
tree49671182c1a0691704297adf0f46dc82ffd943a1 /src/comp
parentb9bb58f104400294d00cb821dfe15c19ed1b641d (diff)
downloadrust-25d60172d6a66b2a620a228ce6642640e9faa517.tar.gz
rust-25d60172d6a66b2a620a228ce6642640e9faa517.zip
Don't consider references to nullary tag variants lvals in kind.rs
This allows us to express option::map with noncopyable type
parameters, which makes sense, since the type params aren't being
copied (none doesn't contain any).
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/kind.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/comp/middle/kind.rs b/src/comp/middle/kind.rs
index 9c3796a7e01..c41b093225c 100644
--- a/src/comp/middle/kind.rs
+++ b/src/comp/middle/kind.rs
@@ -215,9 +215,24 @@ fn maybe_copy(cx: ctx, ex: @expr) {
     check_copy_ex(cx, ex, true);
 }
 
+fn is_nullary_variant(cx: ctx, ex: @expr) -> bool {
+    alt ex.node {
+      expr_path(_) {
+        alt cx.tcx.def_map.get(ex.id) {
+          def_variant(edid, vdid) {
+            vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u
+          }
+          _ { false }
+        }
+      }
+      _ { false }
+    }
+}
+
 fn check_copy_ex(cx: ctx, ex: @expr, _warn: bool) {
     if ty::expr_is_lval(cx.method_map, ex) &&
-       !cx.last_uses.contains_key(ex.id) {
+       !cx.last_uses.contains_key(ex.id) &&
+       !is_nullary_variant(cx, ex) {
         let ty = ty::expr_ty(cx.tcx, ex);
         check_copy(cx, ty, ex.span);
         // FIXME turn this on again once vector types are no longer unique.