Skip to content

Commit 7615e18

Browse files
committed
Auto merge of rust-lang#21605 - huonw:omg-muscle-memory, r=eddyb
I'm beginning to suspect it's impossible to avoid accidentally writing `#[deriving]` at least once in every program, and it results in non-intuitive error messages: "Foo doesn't have any method in scope `clone`" despite there being a `#[deriv...(Clone)]` attribute! Also, lots of documentation around the internet uses `#[deriving]` so providing this guidance is very helpful (lots of people ask in #rust about this error).
2 parents 9252525 + ae4e1a1 commit 7615e18

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/libsyntax/ext/base.rs

+2
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv {
467467
ext::log_syntax::expand_syntax_ext));
468468
syntax_expanders.insert(intern("derive"),
469469
Decorator(box ext::deriving::expand_meta_derive));
470+
syntax_expanders.insert(intern("deriving"),
471+
Decorator(box ext::deriving::expand_deprecated_deriving));
470472

471473
if ecfg.enable_quotes {
472474
// Quasi-quoting expanders

src/libsyntax/ext/deriving/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ pub mod totalord;
4040

4141
pub mod generic;
4242

43+
pub fn expand_deprecated_deriving(cx: &mut ExtCtxt,
44+
span: Span,
45+
_: &MetaItem,
46+
_: &Item,
47+
_: Box<FnMut(P<Item>)>) {
48+
cx.span_err(span, "`deriving` has been renamed to `derive`");
49+
}
50+
4351
pub fn expand_meta_derive(cx: &mut ExtCtxt,
4452
_span: Span,
4553
mitem: &MetaItem,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
#[deriving(Clone)] //~ ERROR `deriving` has been renamed to `derive`
13+
struct Foo;
14+
15+
fn main() {}

0 commit comments

Comments
 (0)