Skip to content

Commit 74d11d2

Browse files
committed
Accept self in place of mod in use items
[breaking-change] `mod` is still accepted, but gives a deprecated warning
1 parent ee3c595 commit 74d11d2

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
681681
ViewPathSimple(binding, ref full_path, id) => {
682682
let source_name =
683683
full_path.segments.last().unwrap().identifier.name;
684-
if token::get_name(source_name).get() == "mod" {
684+
if token::get_name(source_name).get() == "mod" ||
685+
token::get_name(source_name).get() == "self" {
685686
self.resolve_error(view_path.span,
686-
"`mod` imports are only allowed within a { } list");
687+
"`self` imports are only allowed within a { } list");
687688
}
688689

689690
let subclass = SingleImport(binding.name,
@@ -704,10 +705,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
704705
}).collect::<Vec<Span>>();
705706
if mod_spans.len() > 1 {
706707
self.resolve_error(mod_spans[0],
707-
"`mod` import can only appear once in the list");
708+
"`self` import can only appear once in the list");
708709
for other_span in mod_spans.iter().skip(1) {
709710
self.session.span_note(*other_span,
710-
"another `mod` import appears here");
711+
"another `self` import appears here");
711712
}
712713
}
713714

@@ -720,7 +721,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
720721
Some(name) => *name,
721722
None => {
722723
self.resolve_error(source_item.span,
723-
"`mod` import can only appear in an import list \
724+
"`self` import can only appear in an import list \
724725
with a non-empty prefix");
725726
continue;
726727
}

src/librustc_resolve/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
971971
}
972972
}
973973

974+
974975
// Import resolution
975976
//
976977
// This is a fixed-point algorithm. We resolve imports until our efforts

src/libsyntax/parse/parser.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@ impl<'a> Parser<'a> {
546546
pub fn parse_path_list_item(&mut self) -> ast::PathListItem {
547547
let lo = self.span.lo;
548548
let node = if self.eat_keyword(keywords::Mod) {
549+
let span = self.last_span;
550+
self.span_warn(span, "deprecated syntax; use the `self` keyword now");
551+
ast::PathListMod { id: ast::DUMMY_NODE_ID }
552+
} else if self.eat_keyword(keywords::Self) {
549553
ast::PathListMod { id: ast::DUMMY_NODE_ID }
550554
} else {
551555
let ident = self.parse_ident();

src/libsyntax/print/pprust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2540,7 +2540,7 @@ impl<'a> State<'a> {
25402540
s.print_ident(name)
25412541
},
25422542
ast::PathListMod { .. } => {
2543-
word(&mut s.s, "mod")
2543+
word(&mut s.s, "self")
25442544
}
25452545
}
25462546
}));

0 commit comments

Comments
 (0)