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).
This commit is contained in:
Marijn Haverbeke 2012-01-31 12:34:22 +01:00
parent b9bb58f104
commit 25d60172d6
1 changed files with 16 additions and 1 deletions

View File

@ -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.