From 74d11d26f4042ce04c56edfd6caafa003383147d Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Wed, 31 Dec 2014 17:24:42 +1300 Subject: [PATCH] Accept `self` in place of `mod` in use items [breaking-change] `mod` is still accepted, but gives a deprecated warning --- src/librustc_resolve/build_reduced_graph.rs | 11 ++++++----- src/librustc_resolve/lib.rs | 1 + src/libsyntax/parse/parser.rs | 4 ++++ src/libsyntax/print/pprust.rs | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 7dbcc810b571..efb9b636247d 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -681,9 +681,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { 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 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { }).collect::>(); 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 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { 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; } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 10756f21551a..11328bedcc49 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -971,6 +971,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } } + // Import resolution // // This is a fixed-point algorithm. We resolve imports until our efforts diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 457085f5cc84..f84ddcf360eb 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 02a03285d3b8..877b2c7b7d36 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") } } }));