Add a feature opt opt_out_copy that allows people to revert to the older

behavior temporarily. This feature will eventually transition to REJECTED.
This commit is contained in:
Niko Matsakis 2014-12-08 13:21:35 -05:00
parent 096a28607f
commit a16f60b117
3 changed files with 66 additions and 3 deletions

View File

@ -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 => {

View File

@ -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)
}

View File

@ -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>();
}