Skip to content

Change mod -> self in use items and deriving -> derive #20365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 2, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Accept self in place of mod in use items
[breaking-change]

`mod` is still accepted, but gives a deprecated warning
  • Loading branch information
nrc committed Jan 2, 2015
commit 74d11d26f4042ce04c56edfd6caafa003383147d
11 changes: 6 additions & 5 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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");
}
}

Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
}


// Import resolution
//
// This is a fixed-point algorithm. We resolve imports until our efforts
Expand Down
4 changes: 4 additions & 0 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2540,7 +2540,7 @@ impl<'a> State<'a> {
s.print_ident(name)
},
ast::PathListMod { .. } => {
word(&mut s.s, "mod")
word(&mut s.s, "self")
}
}
}));
Expand Down