Accept derive
instead of deriving
[breaking-change] `deriving is still accepted, but gives a deprecation warning
This commit is contained in:
parent
f003b43823
commit
7506fe5269
src
@ -551,7 +551,7 @@ impl LintPass for BoxPointers {
|
||||
declare_lint! {
|
||||
RAW_POINTER_DERIVING,
|
||||
Warn,
|
||||
"uses of #[deriving] with raw pointers are rarely correct"
|
||||
"uses of #[derive] with raw pointers are rarely correct"
|
||||
}
|
||||
|
||||
struct RawPtrDerivingVisitor<'a, 'tcx: 'a> {
|
||||
@ -560,7 +560,7 @@ struct RawPtrDerivingVisitor<'a, 'tcx: 'a> {
|
||||
|
||||
impl<'a, 'tcx, 'v> Visitor<'v> for RawPtrDerivingVisitor<'a, 'tcx> {
|
||||
fn visit_ty(&mut self, ty: &ast::Ty) {
|
||||
static MSG: &'static str = "use of `#[deriving]` with a raw pointer";
|
||||
static MSG: &'static str = "use of `#[derive]` with a raw pointer";
|
||||
if let ast::TyPtr(..) = ty.node {
|
||||
self.cx.span_lint(RAW_POINTER_DERIVING, ty.span, MSG);
|
||||
}
|
||||
|
@ -390,6 +390,8 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv {
|
||||
syntax_expanders.insert(intern("log_syntax"),
|
||||
builtin_normal_expander(
|
||||
ext::log_syntax::expand_syntax_ext));
|
||||
syntax_expanders.insert(intern("derive"),
|
||||
Decorator(box ext::deriving::expand_meta_derive));
|
||||
syntax_expanders.insert(intern("deriving"),
|
||||
Decorator(box ext::deriving::expand_meta_deriving));
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
//! Some code that abstracts away much of the boilerplate of writing
|
||||
//! `deriving` instances for traits. Among other things it manages getting
|
||||
//! `derive` instances for traits. Among other things it manages getting
|
||||
//! access to the fields of the 4 different sorts of structs and enum
|
||||
//! variants, as well as creating the method and impl ast instances.
|
||||
//!
|
||||
@ -26,7 +26,7 @@
|
||||
//! moment. (`TraitDef.additional_bounds`)
|
||||
//!
|
||||
//! Unsupported: FIXME #6257: calling methods on reference fields,
|
||||
//! e.g. deriving Eq/Ord/Clone don't work on `struct A(&int)`,
|
||||
//! e.g. derive Eq/Ord/Clone don't work on `struct A(&int)`,
|
||||
//! because of how the auto-dereferencing happens.
|
||||
//!
|
||||
//! The most important thing for implementers is the `Substructure` and
|
||||
@ -209,7 +209,7 @@ use self::ty::{LifetimeBounds, Path, Ptr, PtrTy, Self, Ty};
|
||||
pub mod ty;
|
||||
|
||||
pub struct TraitDef<'a> {
|
||||
/// The span for the current #[deriving(Foo)] header.
|
||||
/// The span for the current #[derive(Foo)] header.
|
||||
pub span: Span,
|
||||
|
||||
pub attributes: Vec<ast::Attribute>,
|
||||
@ -354,7 +354,7 @@ impl<'a> TraitDef<'a> {
|
||||
generics)
|
||||
}
|
||||
_ => {
|
||||
cx.span_err(mitem.span, "`deriving` may only be applied to structs and enums");
|
||||
cx.span_err(mitem.span, "`derive` may only be applied to structs and enums");
|
||||
return;
|
||||
}
|
||||
};
|
||||
@ -718,7 +718,7 @@ impl<'a> MethodDef<'a> {
|
||||
}
|
||||
|
||||
/// ```
|
||||
/// #[deriving(PartialEq)]
|
||||
/// #[derive(PartialEq)]
|
||||
/// struct A { x: int, y: int }
|
||||
///
|
||||
/// // equivalent to:
|
||||
@ -782,7 +782,7 @@ impl<'a> MethodDef<'a> {
|
||||
} else {
|
||||
cx.span_bug(trait_.span,
|
||||
"no self arguments to non-static method in generic \
|
||||
`deriving`")
|
||||
`derive`")
|
||||
};
|
||||
|
||||
// body of the inner most destructuring match
|
||||
@ -822,7 +822,7 @@ impl<'a> MethodDef<'a> {
|
||||
}
|
||||
|
||||
/// ```
|
||||
/// #[deriving(PartialEq)]
|
||||
/// #[derive(PartialEq)]
|
||||
/// enum A {
|
||||
/// A1,
|
||||
/// A2(int)
|
||||
@ -1185,7 +1185,7 @@ impl<'a> TraitDef<'a> {
|
||||
cx: &mut ExtCtxt,
|
||||
mut to_set: Span) -> Span {
|
||||
let trait_name = match self.path.path.last() {
|
||||
None => cx.span_bug(self.span, "trait with empty path in generic `deriving`"),
|
||||
None => cx.span_bug(self.span, "trait with empty path in generic `derive`"),
|
||||
Some(name) => *name
|
||||
};
|
||||
to_set.expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
|
||||
@ -1215,7 +1215,7 @@ impl<'a> TraitDef<'a> {
|
||||
match (just_spans.is_empty(), named_idents.is_empty()) {
|
||||
(false, false) => cx.span_bug(self.span,
|
||||
"a struct with named and unnamed \
|
||||
fields in generic `deriving`"),
|
||||
fields in generic `derive`"),
|
||||
// named fields
|
||||
(_, false) => Named(named_idents),
|
||||
// tuple structs (includes empty structs)
|
||||
@ -1263,7 +1263,7 @@ impl<'a> TraitDef<'a> {
|
||||
None
|
||||
}
|
||||
_ => {
|
||||
cx.span_bug(sp, "a struct with named and unnamed fields in `deriving`");
|
||||
cx.span_bug(sp, "a struct with named and unnamed fields in `derive`");
|
||||
}
|
||||
};
|
||||
let ident = cx.ident_of(format!("{}_{}", prefix, i)[]);
|
||||
@ -1371,7 +1371,7 @@ pub fn cs_fold<F>(use_foldl: bool,
|
||||
enum_nonmatch_f(cx, trait_span, (all_args[], tuple),
|
||||
substructure.nonself_args),
|
||||
StaticEnum(..) | StaticStruct(..) => {
|
||||
cx.span_bug(trait_span, "static function in `deriving`")
|
||||
cx.span_bug(trait_span, "static function in `derive`")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1411,7 +1411,7 @@ pub fn cs_same_method<F>(f: F,
|
||||
enum_nonmatch_f(cx, trait_span, (all_self_args[], tuple),
|
||||
substructure.nonself_args),
|
||||
StaticEnum(..) | StaticStruct(..) => {
|
||||
cx.span_bug(trait_span, "static function in `deriving`")
|
||||
cx.span_bug(trait_span, "static function in `derive`")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! The compiler code necessary to implement the `#[deriving]` extensions.
|
||||
//! The compiler code necessary to implement the `#[derive]` extensions.
|
||||
//!
|
||||
//! FIXME (#2810): hygiene. Search for "__" strings (in other files too). We also assume "extra" is
|
||||
//! the standard library, and "std" is the core library.
|
||||
@ -45,16 +45,26 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt,
|
||||
_span: Span,
|
||||
mitem: &MetaItem,
|
||||
item: &Item,
|
||||
mut push: Box<FnMut(P<Item>)>) {
|
||||
push: Box<FnMut(P<Item>)>) {
|
||||
cx.span_warn(mitem.span, "`deriving` is deprecated; use `derive`");
|
||||
|
||||
expand_meta_derive(cx, _span, mitem, item, push)
|
||||
}
|
||||
|
||||
pub fn expand_meta_derive(cx: &mut ExtCtxt,
|
||||
_span: Span,
|
||||
mitem: &MetaItem,
|
||||
item: &Item,
|
||||
mut push: Box<FnMut(P<Item>)>) {
|
||||
match mitem.node {
|
||||
MetaNameValue(_, ref l) => {
|
||||
cx.span_err(l.span, "unexpected value in `deriving`");
|
||||
cx.span_err(l.span, "unexpected value in `derive`");
|
||||
}
|
||||
MetaWord(_) => {
|
||||
cx.span_warn(mitem.span, "empty trait list in `deriving`");
|
||||
cx.span_warn(mitem.span, "empty trait list in `derive`");
|
||||
}
|
||||
MetaList(_, ref titems) if titems.len() == 0 => {
|
||||
cx.span_warn(mitem.span, "empty trait list in `deriving`");
|
||||
cx.span_warn(mitem.span, "empty trait list in `derive`");
|
||||
}
|
||||
MetaList(_, ref titems) => {
|
||||
for titem in titems.iter().rev() {
|
||||
@ -78,15 +88,15 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt,
|
||||
}
|
||||
"Encodable" => {
|
||||
cx.span_warn(titem.span,
|
||||
"deriving(Encodable) is deprecated \
|
||||
in favor of deriving(RustcEncodable)");
|
||||
"derive(Encodable) is deprecated \
|
||||
in favor of derive(RustcEncodable)");
|
||||
|
||||
expand!(encodable::expand_deriving_encodable)
|
||||
}
|
||||
"Decodable" => {
|
||||
cx.span_warn(titem.span,
|
||||
"deriving(Decodable) is deprecated \
|
||||
in favor of deriving(RustcDecodable)");
|
||||
"derive(Decodable) is deprecated \
|
||||
in favor of derive(RustcDecodable)");
|
||||
|
||||
expand!(decodable::expand_deriving_decodable)
|
||||
}
|
||||
@ -111,7 +121,7 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt,
|
||||
|
||||
ref tname => {
|
||||
cx.span_err(titem.span,
|
||||
format!("unknown `deriving` \
|
||||
format!("unknown `derive` \
|
||||
trait: `{}`",
|
||||
*tname)[]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user