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
4 changed files with 12 additions and 6 deletions
|
@ -681,9 +681,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||||
ViewPathSimple(binding, ref full_path, id) => {
|
ViewPathSimple(binding, ref full_path, id) => {
|
||||||
let source_name =
|
let source_name =
|
||||||
full_path.segments.last().unwrap().identifier.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,
|
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,
|
let subclass = SingleImport(binding.name,
|
||||||
|
@ -704,10 +705,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||||
}).collect::<Vec<Span>>();
|
}).collect::<Vec<Span>>();
|
||||||
if mod_spans.len() > 1 {
|
if mod_spans.len() > 1 {
|
||||||
self.resolve_error(mod_spans[0],
|
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) {
|
for other_span in mod_spans.iter().skip(1) {
|
||||||
self.session.span_note(*other_span,
|
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,
|
Some(name) => *name,
|
||||||
None => {
|
None => {
|
||||||
self.resolve_error(source_item.span,
|
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");
|
with a non-empty prefix");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -971,6 +971,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Import resolution
|
// Import resolution
|
||||||
//
|
//
|
||||||
// This is a fixed-point algorithm. We resolve imports until our efforts
|
// 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 {
|
pub fn parse_path_list_item(&mut self) -> ast::PathListItem {
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
let node = if self.eat_keyword(keywords::Mod) {
|
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 }
|
ast::PathListMod { id: ast::DUMMY_NODE_ID }
|
||||||
} else {
|
} else {
|
||||||
let ident = self.parse_ident();
|
let ident = self.parse_ident();
|
||||||
|
|
|
@ -2540,7 +2540,7 @@ impl<'a> State<'a> {
|
||||||
s.print_ident(name)
|
s.print_ident(name)
|
||||||
},
|
},
|
||||||
ast::PathListMod { .. } => {
|
ast::PathListMod { .. } => {
|
||||||
word(&mut s.s, "mod")
|
word(&mut s.s, "self")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Reference in a new issue