Skip to content

Commit a16f60b

Browse files
committed
Add a feature opt opt_out_copy that allows people to revert to the older
behavior temporarily. This feature will eventually transition to REJECTED.
1 parent 096a286 commit a16f60b

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

src/librustc/middle/traits/select.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
924924
Some(ty::BoundCopy) => {
925925
debug!("obligation self ty is {}",
926926
obligation.self_ty().repr(self.tcx()));
927-
try!(self.assemble_candidates_from_impls(obligation, &mut candidates));
927+
928+
// If the user has asked for the older, compatibility
929+
// behavior, ignore user-defined impls here. This will
930+
// go away by the time 1.0 is released.
931+
if !self.tcx().sess.features.borrow().opt_out_copy {
932+
try!(self.assemble_candidates_from_impls(obligation, &mut candidates));
933+
}
934+
928935
try!(self.assemble_builtin_bound_candidates(ty::BoundCopy,
929936
stack,
930937
&mut candidates));
@@ -1533,8 +1540,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15331540
}
15341541

15351542
ty::BoundCopy => {
1536-
// This is an Opt-In Built-In Trait.
1537-
return Ok(ParameterBuiltin)
1543+
// This is an Opt-In Built-In Trait. So, unless
1544+
// the user is asking for the old behavior, we
1545+
// don't supply any form of builtin impl.
1546+
if !this.tcx().sess.features.borrow().opt_out_copy {
1547+
return Ok(ParameterBuiltin)
1548+
}
15381549
}
15391550

15401551
ty::BoundSync => {

src/libsyntax/feature_gate.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
7575
// to bootstrap fix for #5723.
7676
("issue_5723_bootstrap", Accepted),
7777

78+
// A way to temporary opt out of opt in copy. This will *never* be accepted.
79+
("opt_out_copy", Active),
80+
7881
// These are used to test this portion of the compiler, they don't actually
7982
// mean anything
8083
("test_accepted_feature", Accepted),
@@ -101,6 +104,7 @@ pub struct Features {
101104
pub import_shadowing: bool,
102105
pub visible_private_types: bool,
103106
pub quote: bool,
107+
pub opt_out_copy: bool,
104108
}
105109

106110
impl Copy for Features {}
@@ -114,6 +118,7 @@ impl Features {
114118
import_shadowing: false,
115119
visible_private_types: false,
116120
quote: false,
121+
opt_out_copy: false,
117122
}
118123
}
119124
}
@@ -441,6 +446,7 @@ pub fn check_crate(span_handler: &SpanHandler, krate: &ast::Crate) -> (Features,
441446
import_shadowing: cx.has_feature("import_shadowing"),
442447
visible_private_types: cx.has_feature("visible_private_types"),
443448
quote: cx.has_feature("quote"),
449+
opt_out_copy: cx.has_feature("opt_out_copy"),
444450
},
445451
unknown_features)
446452
}

src/test/run-pass/opt-out-copy.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 the opt-out-copy feature guard. This is the same as the
14+
// "opt-in-copy.rs" test from compile-fail, except that it is using
15+
// the feature guard, and hence the structureds in this file are
16+
// implicitly copyable, and hence we get no errors. This test can be
17+
// safely removed once the opt-out-copy "feature" is rejected.
18+
19+
struct CantCopyThis;
20+
21+
struct IWantToCopyThis {
22+
but_i_cant: CantCopyThis,
23+
}
24+
25+
impl Copy for IWantToCopyThis {}
26+
27+
enum CantCopyThisEither {
28+
A,
29+
B,
30+
}
31+
32+
enum IWantToCopyThisToo {
33+
ButICant(CantCopyThisEither),
34+
}
35+
36+
impl Copy for IWantToCopyThisToo {}
37+
38+
fn is_copy<T:Copy>() { }
39+
40+
fn main() {
41+
is_copy::<CantCopyThis>();
42+
is_copy::<CantCopyThisEither>();
43+
is_copy::<IWantToCopyThis>();
44+
is_copy::<IWantToCopyThisToo>();
45+
}
46+

0 commit comments

Comments
 (0)