Skip to content

Use of Option<~T> (at least sometimes...) considered a copy #4821

@nikomatsakis

Description

@nikomatsakis

In this test case:

// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern mod std;
use core::cmp::Ord;
use core::option::swap_unwrap;

struct TreeNode<K> {
    key: K,
    left: Option<~TreeNode<K>>,
    right: Option<~TreeNode<K>>,
    level: uint
}

fn split<K: Ord>(node: ~TreeNode<K>) -> ~TreeNode<K> {
    match node.right {
      Some(right) => {
        match right.right {
          Some(right2) => {
            if right2.level != node.level {
                node
            } else { // double horizontal link
                let mut node = node;
                let mut save = swap_unwrap(&mut node.right);
                node.right <-> save.left; // save.left now None
                save.left = Some(node);
                save.level += 1;
                save
            }
          }
          None => node
        }
      }
      None => node
    }
}

fn main() {}

The match node.right seems to be considered a copy, not a move. This appears to be a bug in the kind code. I will dig more to be sure.

Hat tip: @thestinger

Metadata

Metadata

Assignees

Labels

A-type-systemArea: Type systemI-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions