Accept self
in place of mod
in use items
[breaking-change] `mod` is still accepted, but gives a deprecated warning
This commit is contained in:
parent
ee3c5957ea
commit
74d11d26f4
src
@ -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::<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 @@ 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;
|
||||
}
|
||||
|
@ -971,6 +971,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Import resolution
|
||||
//
|
||||
// This is a fixed-point algorithm. We resolve imports until our efforts
|
||||
|
@ -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();
|
||||
|
@ -2540,7 +2540,7 @@ impl<'a> State<'a> {
|
||||
s.print_ident(name)
|
||||
},
|
||||
ast::PathListMod { .. } => {
|
||||
word(&mut s.s, "mod")
|
||||
word(&mut s.s, "self")
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
Loading…
x
Reference in New Issue
Block a user