Fix the opt-out-copy behavior so that values with dtor etc are considered affine

This commit is contained in:
Niko Matsakis 2014-12-09 20:25:09 -05:00
parent 07eebf6910
commit 97cf91aa30
3 changed files with 51 additions and 1 deletions

View File

@ -1289,6 +1289,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// don't supply any form of builtin impl.
if !this.tcx().sess.features.borrow().opt_out_copy {
return Ok(ParameterBuiltin)
} else {
// Older, backwards compatibility behavior:
if
Some(def_id) == tcx.lang_items.no_copy_bound() ||
Some(def_id) == tcx.lang_items.managed_bound() ||
ty::has_dtor(tcx, def_id)
{
return Err(Unimplemented);
}
}
}

View File

@ -104,7 +104,6 @@ use {CrateCtxt, lookup_def_ccx, no_params, require_same_types};
use TypeAndSubsts;
use middle::lang_items::TypeIdLangItem;
use lint;
use util::common::ErrorReported;
use util::common::{block_query, indenter, loop_query};
use util::ppaux::{mod, UserString, Repr};
use util::nodemap::{DefIdMap, FnvHashMap, NodeMap};

View File

@ -0,0 +1,42 @@
// Copyright 2014 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.
#![feature(opt_out_copy)]
// Test that when using the `opt-out-copy` feature we still consider
// destructors to be non-movable
struct CantCopyThis;
impl Drop for CantCopyThis {
fn drop(&mut self) { }
}
struct IWantToCopyThis {
but_i_cant: CantCopyThis,
}
impl Copy for IWantToCopyThis {}
//~^ ERROR the trait `Copy` may not be implemented for this type
enum CantCopyThisEither {
A,
B(::std::kinds::marker::NoCopy),
}
enum IWantToCopyThisToo {
ButICant(CantCopyThisEither),
}
impl Copy for IWantToCopyThisToo {}
//~^ ERROR the trait `Copy` may not be implemented for this type
fn main() {}