about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-01-02 16:31:26 +0000
committerbors <bors@rust-lang.org>2015-01-02 16:31:26 +0000
commit4b40bc85cbc1d072179c92ce01655db0272aa598 (patch)
treee9ea8c89e3dbde74c6e87899e440a0ec0649887c /src/libsyntax
parent71b46b18a274edc7f7fb60b490e5ebbb9c911462 (diff)
parentdc53461a983ec4f5bc50291e71bfc67fd3d2d815 (diff)
downloadrust-4b40bc85cbc1d072179c92ce01655db0272aa598.tar.gz
rust-4b40bc85cbc1d072179c92ce01655db0272aa598.zip
auto merge of #20365 : nick29581/rust/mod, r=huonw
Part of #20361 and #20362
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/base.rs2
-rw-r--r--src/libsyntax/ext/deriving/generic/mod.rs24
-rw-r--r--src/libsyntax/ext/deriving/mod.rs30
-rw-r--r--src/libsyntax/parse/parser.rs4
-rw-r--r--src/libsyntax/print/pprust.rs2
5 files changed, 39 insertions, 23 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index 5134897893f..efb4867a016 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -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));
 
diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs
index 9149c20ce1b..acfb020fab6 100644
--- a/src/libsyntax/ext/deriving/generic/mod.rs
+++ b/src/libsyntax/ext/deriving/generic/mod.rs
@@ -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`")
         }
     }
 }
diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs
index 75f763b5c38..57d66f0e355 100644
--- a/src/libsyntax/ext/deriving/mod.rs
+++ b/src/libsyntax/ext/deriving/mod.rs
@@ -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)[]);
                             }
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 457085f5cc8..f84ddcf360e 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -546,6 +546,10 @@ impl<'a> Parser<'a> {
     pub fn parse_path_list_item(&mut self) -> ast::PathListItem {
         let lo = self.span.lo;
         let node = if self.eat_keyword(keywords::Mod) {
+            let span = self.last_span;
+            self.span_warn(span, "deprecated syntax; use the `self` keyword now");
+            ast::PathListMod { id: ast::DUMMY_NODE_ID }
+        } else if self.eat_keyword(keywords::Self) {
             ast::PathListMod { id: ast::DUMMY_NODE_ID }
         } else {
             let ident = self.parse_ident();
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 02a03285d3b..877b2c7b7d3 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -2540,7 +2540,7 @@ impl<'a> State<'a> {
                             s.print_ident(name)
                         },
                         ast::PathListMod { .. } => {
-                            word(&mut s.s, "mod")
+                            word(&mut s.s, "self")
                         }
                     }
                 }));