Skip to content

Commit 97cf91a

Browse files
committed
Fix the opt-out-copy behavior so that values with dtor etc are considered affine
1 parent 07eebf6 commit 97cf91a

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

src/librustc/middle/traits/select.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12891289
// don't supply any form of builtin impl.
12901290
if !this.tcx().sess.features.borrow().opt_out_copy {
12911291
return Ok(ParameterBuiltin)
1292+
} else {
1293+
// Older, backwards compatibility behavior:
1294+
if
1295+
Some(def_id) == tcx.lang_items.no_copy_bound() ||
1296+
Some(def_id) == tcx.lang_items.managed_bound() ||
1297+
ty::has_dtor(tcx, def_id)
1298+
{
1299+
return Err(Unimplemented);
1300+
}
12921301
}
12931302
}
12941303

src/librustc_typeck/check/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ use {CrateCtxt, lookup_def_ccx, no_params, require_same_types};
104104
use TypeAndSubsts;
105105
use middle::lang_items::TypeIdLangItem;
106106
use lint;
107-
use util::common::ErrorReported;
108107
use util::common::{block_query, indenter, loop_query};
109108
use util::ppaux::{mod, UserString, Repr};
110109
use util::nodemap::{DefIdMap, FnvHashMap, NodeMap};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(opt_out_copy)]
12+
13+
// Test that when using the `opt-out-copy` feature we still consider
14+
// destructors to be non-movable
15+
16+
struct CantCopyThis;
17+
18+
impl Drop for CantCopyThis {
19+
fn drop(&mut self) { }
20+
}
21+
22+
struct IWantToCopyThis {
23+
but_i_cant: CantCopyThis,
24+
}
25+
26+
impl Copy for IWantToCopyThis {}
27+
//~^ ERROR the trait `Copy` may not be implemented for this type
28+
29+
enum CantCopyThisEither {
30+
A,
31+
B(::std::kinds::marker::NoCopy),
32+
}
33+
34+
enum IWantToCopyThisToo {
35+
ButICant(CantCopyThisEither),
36+
}
37+
38+
impl Copy for IWantToCopyThisToo {}
39+
//~^ ERROR the trait `Copy` may not be implemented for this type
40+
41+
fn main() {}
42+

0 commit comments

Comments
 (0)