Skip to content

Commit 7506fe5

Browse files
committed
Accept derive instead of deriving
[breaking-change] `deriving is still accepted, but gives a deprecation warning
1 parent f003b43 commit 7506fe5

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

src/librustc/lint/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ impl LintPass for BoxPointers {
551551
declare_lint! {
552552
RAW_POINTER_DERIVING,
553553
Warn,
554-
"uses of #[deriving] with raw pointers are rarely correct"
554+
"uses of #[derive] with raw pointers are rarely correct"
555555
}
556556

557557
struct RawPtrDerivingVisitor<'a, 'tcx: 'a> {
@@ -560,7 +560,7 @@ struct RawPtrDerivingVisitor<'a, 'tcx: 'a> {
560560

561561
impl<'a, 'tcx, 'v> Visitor<'v> for RawPtrDerivingVisitor<'a, 'tcx> {
562562
fn visit_ty(&mut self, ty: &ast::Ty) {
563-
static MSG: &'static str = "use of `#[deriving]` with a raw pointer";
563+
static MSG: &'static str = "use of `#[derive]` with a raw pointer";
564564
if let ast::TyPtr(..) = ty.node {
565565
self.cx.span_lint(RAW_POINTER_DERIVING, ty.span, MSG);
566566
}

src/libsyntax/ext/base.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv {
390390
syntax_expanders.insert(intern("log_syntax"),
391391
builtin_normal_expander(
392392
ext::log_syntax::expand_syntax_ext));
393+
syntax_expanders.insert(intern("derive"),
394+
Decorator(box ext::deriving::expand_meta_derive));
393395
syntax_expanders.insert(intern("deriving"),
394396
Decorator(box ext::deriving::expand_meta_deriving));
395397

src/libsyntax/ext/deriving/generic/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
//! Some code that abstracts away much of the boilerplate of writing
12-
//! `deriving` instances for traits. Among other things it manages getting
12+
//! `derive` instances for traits. Among other things it manages getting
1313
//! access to the fields of the 4 different sorts of structs and enum
1414
//! variants, as well as creating the method and impl ast instances.
1515
//!
@@ -26,7 +26,7 @@
2626
//! moment. (`TraitDef.additional_bounds`)
2727
//!
2828
//! Unsupported: FIXME #6257: calling methods on reference fields,
29-
//! e.g. deriving Eq/Ord/Clone don't work on `struct A(&int)`,
29+
//! e.g. derive Eq/Ord/Clone don't work on `struct A(&int)`,
3030
//! because of how the auto-dereferencing happens.
3131
//!
3232
//! The most important thing for implementers is the `Substructure` and
@@ -209,7 +209,7 @@ use self::ty::{LifetimeBounds, Path, Ptr, PtrTy, Self, Ty};
209209
pub mod ty;
210210

211211
pub struct TraitDef<'a> {
212-
/// The span for the current #[deriving(Foo)] header.
212+
/// The span for the current #[derive(Foo)] header.
213213
pub span: Span,
214214

215215
pub attributes: Vec<ast::Attribute>,
@@ -354,7 +354,7 @@ impl<'a> TraitDef<'a> {
354354
generics)
355355
}
356356
_ => {
357-
cx.span_err(mitem.span, "`deriving` may only be applied to structs and enums");
357+
cx.span_err(mitem.span, "`derive` may only be applied to structs and enums");
358358
return;
359359
}
360360
};
@@ -718,7 +718,7 @@ impl<'a> MethodDef<'a> {
718718
}
719719

720720
/// ```
721-
/// #[deriving(PartialEq)]
721+
/// #[derive(PartialEq)]
722722
/// struct A { x: int, y: int }
723723
///
724724
/// // equivalent to:
@@ -782,7 +782,7 @@ impl<'a> MethodDef<'a> {
782782
} else {
783783
cx.span_bug(trait_.span,
784784
"no self arguments to non-static method in generic \
785-
`deriving`")
785+
`derive`")
786786
};
787787

788788
// body of the inner most destructuring match
@@ -822,7 +822,7 @@ impl<'a> MethodDef<'a> {
822822
}
823823

824824
/// ```
825-
/// #[deriving(PartialEq)]
825+
/// #[derive(PartialEq)]
826826
/// enum A {
827827
/// A1,
828828
/// A2(int)
@@ -1185,7 +1185,7 @@ impl<'a> TraitDef<'a> {
11851185
cx: &mut ExtCtxt,
11861186
mut to_set: Span) -> Span {
11871187
let trait_name = match self.path.path.last() {
1188-
None => cx.span_bug(self.span, "trait with empty path in generic `deriving`"),
1188+
None => cx.span_bug(self.span, "trait with empty path in generic `derive`"),
11891189
Some(name) => *name
11901190
};
11911191
to_set.expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
@@ -1215,7 +1215,7 @@ impl<'a> TraitDef<'a> {
12151215
match (just_spans.is_empty(), named_idents.is_empty()) {
12161216
(false, false) => cx.span_bug(self.span,
12171217
"a struct with named and unnamed \
1218-
fields in generic `deriving`"),
1218+
fields in generic `derive`"),
12191219
// named fields
12201220
(_, false) => Named(named_idents),
12211221
// tuple structs (includes empty structs)
@@ -1263,7 +1263,7 @@ impl<'a> TraitDef<'a> {
12631263
None
12641264
}
12651265
_ => {
1266-
cx.span_bug(sp, "a struct with named and unnamed fields in `deriving`");
1266+
cx.span_bug(sp, "a struct with named and unnamed fields in `derive`");
12671267
}
12681268
};
12691269
let ident = cx.ident_of(format!("{}_{}", prefix, i)[]);
@@ -1371,7 +1371,7 @@ pub fn cs_fold<F>(use_foldl: bool,
13711371
enum_nonmatch_f(cx, trait_span, (all_args[], tuple),
13721372
substructure.nonself_args),
13731373
StaticEnum(..) | StaticStruct(..) => {
1374-
cx.span_bug(trait_span, "static function in `deriving`")
1374+
cx.span_bug(trait_span, "static function in `derive`")
13751375
}
13761376
}
13771377
}
@@ -1411,7 +1411,7 @@ pub fn cs_same_method<F>(f: F,
14111411
enum_nonmatch_f(cx, trait_span, (all_self_args[], tuple),
14121412
substructure.nonself_args),
14131413
StaticEnum(..) | StaticStruct(..) => {
1414-
cx.span_bug(trait_span, "static function in `deriving`")
1414+
cx.span_bug(trait_span, "static function in `derive`")
14151415
}
14161416
}
14171417
}

src/libsyntax/ext/deriving/mod.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! The compiler code necessary to implement the `#[deriving]` extensions.
11+
//! The compiler code necessary to implement the `#[derive]` extensions.
1212
//!
1313
//! FIXME (#2810): hygiene. Search for "__" strings (in other files too). We also assume "extra" is
1414
//! the standard library, and "std" is the core library.
@@ -45,16 +45,26 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt,
4545
_span: Span,
4646
mitem: &MetaItem,
4747
item: &Item,
48-
mut push: Box<FnMut(P<Item>)>) {
48+
push: Box<FnMut(P<Item>)>) {
49+
cx.span_warn(mitem.span, "`deriving` is deprecated; use `derive`");
50+
51+
expand_meta_derive(cx, _span, mitem, item, push)
52+
}
53+
54+
pub fn expand_meta_derive(cx: &mut ExtCtxt,
55+
_span: Span,
56+
mitem: &MetaItem,
57+
item: &Item,
58+
mut push: Box<FnMut(P<Item>)>) {
4959
match mitem.node {
5060
MetaNameValue(_, ref l) => {
51-
cx.span_err(l.span, "unexpected value in `deriving`");
61+
cx.span_err(l.span, "unexpected value in `derive`");
5262
}
5363
MetaWord(_) => {
54-
cx.span_warn(mitem.span, "empty trait list in `deriving`");
64+
cx.span_warn(mitem.span, "empty trait list in `derive`");
5565
}
5666
MetaList(_, ref titems) if titems.len() == 0 => {
57-
cx.span_warn(mitem.span, "empty trait list in `deriving`");
67+
cx.span_warn(mitem.span, "empty trait list in `derive`");
5868
}
5969
MetaList(_, ref titems) => {
6070
for titem in titems.iter().rev() {
@@ -78,15 +88,15 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt,
7888
}
7989
"Encodable" => {
8090
cx.span_warn(titem.span,
81-
"deriving(Encodable) is deprecated \
82-
in favor of deriving(RustcEncodable)");
91+
"derive(Encodable) is deprecated \
92+
in favor of derive(RustcEncodable)");
8393

8494
expand!(encodable::expand_deriving_encodable)
8595
}
8696
"Decodable" => {
8797
cx.span_warn(titem.span,
88-
"deriving(Decodable) is deprecated \
89-
in favor of deriving(RustcDecodable)");
98+
"derive(Decodable) is deprecated \
99+
in favor of derive(RustcDecodable)");
90100

91101
expand!(decodable::expand_deriving_decodable)
92102
}
@@ -111,7 +121,7 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt,
111121

112122
ref tname => {
113123
cx.span_err(titem.span,
114-
format!("unknown `deriving` \
124+
format!("unknown `derive` \
115125
trait: `{}`",
116126
*tname)[]);
117127
}

0 commit comments

Comments
 (0)