]> git.lizzy.rs Git - rust.git/commitdiff
Accept `self` in place of `mod` in use items
authorNick Cameron <ncameron@mozilla.com>
Wed, 31 Dec 2014 04:24:42 +0000 (17:24 +1300)
committerNick Cameron <ncameron@mozilla.com>
Fri, 2 Jan 2015 10:05:22 +0000 (23:05 +1300)
[breaking-change]

`mod` is still accepted, but gives a deprecated warning

src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/lib.rs
src/libsyntax/parse/parser.rs
src/libsyntax/print/pprust.rs

index 7dbcc810b571b521a0b1435ea109eef9df387e25..efb9b636247da964337fa9ad1aaf090c7433038c 100644 (file)
@@ -681,9 +681,10 @@ fn build_reduced_graph_for_view_item(&mut self, view_item: &ViewItem, parent: &R
                     ViewPathSimple(binding, ref full_path, id) => {
                         let source_name =
                             full_path.segments.last().unwrap().identifier.name;
-                        if token::get_name(source_name).get() == "mod" {
+                        if token::get_name(source_name).get() == "mod" ||
+                           token::get_name(source_name).get() == "self" {
                             self.resolve_error(view_path.span,
-                                "`mod` imports are only allowed within a { } list");
+                                "`self` imports are only allowed within a { } list");
                         }
 
                         let subclass = SingleImport(binding.name,
@@ -704,10 +705,10 @@ fn build_reduced_graph_for_view_item(&mut self, view_item: &ViewItem, parent: &R
                         }).collect::<Vec<Span>>();
                         if mod_spans.len() > 1 {
                             self.resolve_error(mod_spans[0],
-                                "`mod` import can only appear once in the list");
+                                "`self` import can only appear once in the list");
                             for other_span in mod_spans.iter().skip(1) {
                                 self.session.span_note(*other_span,
-                                    "another `mod` import appears here");
+                                    "another `self` import appears here");
                             }
                         }
 
@@ -720,7 +721,7 @@ fn build_reduced_graph_for_view_item(&mut self, view_item: &ViewItem, parent: &R
                                         Some(name) => *name,
                                         None => {
                                             self.resolve_error(source_item.span,
-                                                "`mod` import can only appear in an import list \
+                                                "`self` import can only appear in an import list \
                                                  with a non-empty prefix");
                                             continue;
                                         }
index 10756f21551a021b2e3dcc149802a82ac6759b7b..11328bedcc4938e977ee14649c045b13b61e1089 100644 (file)
@@ -971,6 +971,7 @@ fn new(session: &'a Session,
         }
     }
 
+
     // Import resolution
     //
     // This is a fixed-point algorithm. We resolve imports until our efforts
index 457085f5cc84878c61d935fe0ba8af1d5a83b6b4..f84ddcf360ebe4adde54e1a78309066105a027db 100644 (file)
@@ -546,6 +546,10 @@ pub fn parse_ident(&mut self) -> ast::Ident {
     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();
index 02a03285d3b86df9e5a7d8909d77edf40688bef6..877b2c7b7d366905330749d53d528c87391f441a 100644 (file)
@@ -2540,7 +2540,7 @@ pub fn print_view_path(&mut self, vp: &ast::ViewPath) -> IoResult<()> {
                             s.print_ident(name)
                         },
                         ast::PathListMod { .. } => {
-                            word(&mut s.s, "mod")
+                            word(&mut s.s, "self")
                         }
                     }
                 }));