提交 757f106b 编写于 作者: B bors

auto merge of #13868 : FlaPer87/rust/opt-in-phase1, r=alexcrichton

This is a first patch towards an opt-in built-in trait world. This patch removes the restriction on built-in traits and allows such traits to be derived.

[RFC#3]

cc #13231

@nikomatsakis r?
......@@ -631,14 +631,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) {
parent_visibility);
for trait_ref in opt_trait_ref.iter() {
let trait_ref = instantiate_trait_ref(ccx, trait_ref, selfty);
// Prevent the builtin kind traits from being manually implemented.
if tcx.lang_items.to_builtin_kind(trait_ref.def_id).is_some() {
tcx.sess.span_err(it.span,
"cannot provide an explicit implementation \
for a builtin kind");
}
instantiate_trait_ref(ccx, trait_ref, selfty);
}
},
ast::ItemTrait(ref generics, _, _, ref trait_methods) => {
......
// 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.
use ast::{MetaItem, MetaWord, Item};
use codemap::Span;
use ext::base::ExtCtxt;
use ext::deriving::generic::*;
pub fn expand_deriving_bound(cx: &mut ExtCtxt,
span: Span,
mitem: @MetaItem,
item: @Item,
push: |@Item|) {
let name = match mitem.node {
MetaWord(ref tname) => {
match tname.get() {
"Copy" => "Copy",
"Send" => "Send",
"Share" => "Share",
ref tname => cx.span_bug(span,
format!("expected built-in trait name but found {}",
*tname))
}
},
_ => return cx.span_err(span, "unexpected value in deriving, expected a trait")
};
let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
path: Path::new(vec!("std", "kinds", name)),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
methods: vec!()
};
trait_def.expand(cx, mitem, item, push)
}
......@@ -22,6 +22,7 @@
use ext::base::ExtCtxt;
use codemap::Span;
pub mod bounds;
pub mod clone;
pub mod encodable;
pub mod decodable;
......@@ -90,6 +91,10 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt,
"FromPrimitive" => expand!(primitive::expand_deriving_from_primitive),
"Send" => expand!(bounds::expand_deriving_bound),
"Share" => expand!(bounds::expand_deriving_bound),
"Copy" => expand!(bounds::expand_deriving_bound),
ref tname => {
cx.span_err(titem.span, format!("unknown \
`deriving` trait: `{}`", *tname));
......
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// 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.
//
......@@ -8,12 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// See issue #8517 for why this should be illegal.
//NOTE: Remove in the next snapshot
#[cfg(not(stage0))]
#[deriving(Share(Bad),Send,Copy)]
//~^ ERROR unexpected value in deriving, expected a trait
struct Test;
struct X<T>(T);
impl <T> Send for X<T> { } //~ ERROR cannot provide an explicit implementation for a builtin kind
impl <T> Sized for X<T> { } //~ ERROR cannot provide an explicit implementation for a builtin kind
impl <T> Share for X<T> { } //~ ERROR cannot provide an explicit implementation for a builtin kind
fn main() { }
pub fn main() {}
// 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.
//NOTE: Remove in the next snapshot
#[cfg(not(stage0))]
#[deriving(Share,Send,Copy)]
struct Test;
pub fn main() {}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册