From 25d60172d6a66b2a620a228ce6642640e9faa517 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Tue, 31 Jan 2012 12:34:22 +0100 Subject: [PATCH] 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). --- src/comp/middle/kind.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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.