diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2014-12-08 13:21:35 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2014-12-08 13:47:45 -0500 |
| commit | a16f60b1173fae1b971b41780288e2dbe005569d (patch) | |
| tree | 54234f214f914bfae06e9e9a12bc705c029e25b1 | |
| parent | 096a28607fb80c91e6e2ca64d9ef44c4e550e96c (diff) | |
Add a feature opt `opt_out_copy` that allows people to revert to the older
behavior temporarily. This feature will eventually transition to REJECTED.
| -rw-r--r-- | src/librustc/middle/traits/select.rs | 17 | ||||
| -rw-r--r-- | src/libsyntax/feature_gate.rs | 6 | ||||
| -rw-r--r-- | src/test/run-pass/opt-out-copy.rs | 46 |
3 files changed, 66 insertions, 3 deletions
diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index 5ad0d17ad13..302834f3eac 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -924,7 +924,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { Some(ty::BoundCopy) => { debug!("obligation self ty is {}", obligation.self_ty().repr(self.tcx())); - try!(self.assemble_candidates_from_impls(obligation, &mut candidates)); + + // If the user has asked for the older, compatibility + // behavior, ignore user-defined impls here. This will + // go away by the time 1.0 is released. + if !self.tcx().sess.features.borrow().opt_out_copy { + try!(self.assemble_candidates_from_impls(obligation, &mut candidates)); + } + try!(self.assemble_builtin_bound_candidates(ty::BoundCopy, stack, &mut candidates)); @@ -1533,8 +1540,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } ty::BoundCopy => { - // This is an Opt-In Built-In Trait. - return Ok(ParameterBuiltin) + // This is an Opt-In Built-In Trait. So, unless + // the user is asking for the old behavior, we + // don't supply any form of builtin impl. + if !this.tcx().sess.features.borrow().opt_out_copy { + return Ok(ParameterBuiltin) + } } ty::BoundSync => { diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index ac36e508f3b..b8f60e77601 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -75,6 +75,9 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[ // to bootstrap fix for #5723. ("issue_5723_bootstrap", Accepted), + // A way to temporary opt out of opt in copy. This will *never* be accepted. + ("opt_out_copy", Active), + // These are used to test this portion of the compiler, they don't actually // mean anything ("test_accepted_feature", Accepted), @@ -101,6 +104,7 @@ pub struct Features { pub import_shadowing: bool, pub visible_private_types: bool, pub quote: bool, + pub opt_out_copy: bool, } impl Copy for Features {} @@ -114,6 +118,7 @@ impl Features { import_shadowing: false, visible_private_types: false, quote: false, + opt_out_copy: false, } } } @@ -441,6 +446,7 @@ pub fn check_crate(span_handler: &SpanHandler, krate: &ast::Crate) -> (Features, import_shadowing: cx.has_feature("import_shadowing"), visible_private_types: cx.has_feature("visible_private_types"), quote: cx.has_feature("quote"), + opt_out_copy: cx.has_feature("opt_out_copy"), }, unknown_features) } diff --git a/src/test/run-pass/opt-out-copy.rs b/src/test/run-pass/opt-out-copy.rs new file mode 100644 index 00000000000..8c7072cfdf5 --- /dev/null +++ b/src/test/run-pass/opt-out-copy.rs @@ -0,0 +1,46 @@ +// 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 the opt-out-copy feature guard. This is the same as the +// "opt-in-copy.rs" test from compile-fail, except that it is using +// the feature guard, and hence the structureds in this file are +// implicitly copyable, and hence we get no errors. This test can be +// safely removed once the opt-out-copy "feature" is rejected. + +struct CantCopyThis; + +struct IWantToCopyThis { + but_i_cant: CantCopyThis, +} + +impl Copy for IWantToCopyThis {} + +enum CantCopyThisEither { + A, + B, +} + +enum IWantToCopyThisToo { + ButICant(CantCopyThisEither), +} + +impl Copy for IWantToCopyThisToo {} + +fn is_copy<T:Copy>() { } + +fn main() { + is_copy::<CantCopyThis>(); + is_copy::<CantCopyThisEither>(); + is_copy::<IWantToCopyThis>(); + is_copy::<IWantToCopyThisToo>(); +} + |
