Skip to content

libsyntax: update view_item_use/import to reflect actual usage #4722

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/libcargo/cargo.rc
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ pub fn load_crate(filename: &Path) -> Option<Crate> {
fn goto_view_item(ps: syntax::parse::parse_sess, e: @Env,
i: @ast::view_item) {
match i.node {
ast::view_item_use(ident, metas, _) => {
ast::view_item_extern_mod(ident, metas, _) => {
let name_items =
attr::find_meta_items_by_name(metas, ~"name");
let m = if name_items.is_empty() {
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/front/core_inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ fn inject_libcore_ref(sess: Session,
fold_crate: |crate, span, fld| {
let n1 = sess.next_node_id();
let vi1 = @ast::view_item {
node: ast::view_item_use(sess.ident_of(~"core"), ~[], n1),
node: ast::view_item_extern_mod(
sess.ident_of(~"core"), ~[], n1),
attrs: ~[
spanned(ast::attribute_ {
style: ast::attr_inner,
Expand Down Expand Up @@ -85,7 +86,7 @@ fn inject_libcore_ref(sess: Session,
};

let vp = @spanned(ast::view_path_glob(prelude_path, n2));
let vi2 = @ast::view_item { node: ast::view_item_import(~[vp]),
let vi2 = @ast::view_item { node: ast::view_item_use(~[vp]),
attrs: ~[],
vis: ast::private,
span: dummy_sp() };
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,10 @@ fn mk_std(cx: test_ctxt) -> @ast::view_item {
let vers = nospan(vers);
let mi = ast::meta_name_value(~"vers", vers);
let mi = nospan(mi);
let vi = ast::view_item_use(cx.sess.ident_of(~"std"),
~[@mi],
cx.sess.next_node_id());
let vi = ast::view_item_extern_mod(
cx.sess.ident_of(~"std"),
~[@mi],
cx.sess.next_node_id());
let vi = ast::view_item {
node: vi,
attrs: ~[],
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ type env = @{diag: span_handler,

fn visit_view_item(e: env, i: @ast::view_item) {
match /*bad*/copy i.node {
ast::view_item_use(ident, meta_items, id) => {
debug!("resolving use stmt. ident: %?, meta: %?", ident, meta_items);
ast::view_item_extern_mod(ident, meta_items, id) => {
debug!("resolving extern mod stmt. ident: %?, meta: %?", ident, meta_items);
let cnum = resolve_crate(e, ident, meta_items, ~"", i.span);
cstore::add_use_stmt_cnum(e.cstore, id, cnum);
cstore::add_extern_mod_stmt_cnum(e.cstore, id, cnum);
}
_ => ()
}
Expand Down
22 changes: 11 additions & 11 deletions src/librustc/metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ pub enum CStore { private(cstore_private), }

type cstore_private =
@{metas: map::HashMap<ast::crate_num, crate_metadata>,
use_crate_map: use_crate_map,
extern_mod_crate_map: extern_mod_crate_map,
mut used_crate_files: ~[Path],
mut used_libraries: ~[~str],
mut used_link_args: ~[~str],
intr: @ident_interner};

// Map from node_id's of local use statements to crate numbers
type use_crate_map = map::HashMap<ast::node_id, ast::crate_num>;
// Map from node_id's of local extern mod statements to crate numbers
type extern_mod_crate_map = map::HashMap<ast::node_id, ast::crate_num>;

// Internal method to retrieve the data from the cstore
pure fn p(cstore: CStore) -> cstore_private {
Expand All @@ -65,7 +65,7 @@ pub fn mk_cstore(intr: @ident_interner) -> CStore {
let meta_cache = map::HashMap();
let crate_map = map::HashMap();
return private(@{metas: meta_cache,
use_crate_map: crate_map,
extern_mod_crate_map: crate_map,
mut used_crate_files: ~[],
mut used_libraries: ~[],
mut used_link_args: ~[],
Expand Down Expand Up @@ -132,14 +132,14 @@ pub fn get_used_link_args(cstore: CStore) -> ~[~str] {
return /*bad*/copy p(cstore).used_link_args;
}

pub fn add_use_stmt_cnum(cstore: CStore, use_id: ast::node_id,
cnum: ast::crate_num) {
p(cstore).use_crate_map.insert(use_id, cnum);
pub fn add_extern_mod_stmt_cnum(
cstore: CStore, emod_id: ast::node_id, cnum: ast::crate_num) {
p(cstore).extern_mod_crate_map.insert(emod_id, cnum);
}

pub fn find_use_stmt_cnum(cstore: CStore,
use_id: ast::node_id) -> Option<ast::crate_num> {
p(cstore).use_crate_map.find(use_id)
pub fn find_extern_mod_stmt_cnum(
cstore: CStore, emod_id: ast::node_id) -> Option<ast::crate_num> {
p(cstore).extern_mod_crate_map.find(emod_id)
}

// returns hashes of crates directly used by this crate. Hashes are
Expand All @@ -148,7 +148,7 @@ pub fn get_dep_hashes(cstore: CStore) -> ~[~str] {
type crate_hash = {name: ~str, hash: ~str};
let mut result = ~[];

for p(cstore).use_crate_map.each_value |cnum| {
for p(cstore).extern_mod_crate_map.each_value |cnum| {
let cdata = cstore::get_crate_data(cstore, cnum);
let hash = decoder::get_crate_hash(cdata.data);
debug!("Add hash[%s]: %s", cdata.name, hash);
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use driver::session;
use driver::session::Session;
use metadata::csearch::{each_path, get_method_names_if_trait};
use metadata::csearch::{get_static_methods_if_impl, get_type_name_if_impl};
use metadata::cstore::find_use_stmt_cnum;
use metadata::cstore::find_extern_mod_stmt_cnum;
use metadata::decoder::{def_like, dl_def, dl_field, dl_impl};
use middle::lang_items::LanguageItems;
use middle::lint::{deny, allow, forbid, level, unused_imports, warn};
Expand Down Expand Up @@ -54,7 +54,7 @@ use syntax::ast::{ty_bool, ty_char, ty_f, ty_f32, ty_f64, ty_float, ty_i};
use syntax::ast::{ty_i16, ty_i32, ty_i64, ty_i8, ty_int, ty_param, ty_path};
use syntax::ast::{ty_str, ty_u, ty_u16, ty_u32, ty_u64, ty_u8, ty_uint};
use syntax::ast::{type_value_ns, ty_param_bound, unnamed_field};
use syntax::ast::{variant, view_item, view_item_import};
use syntax::ast::{variant, view_item, view_item_extern_mod};
use syntax::ast::{view_item_use, view_path_glob, view_path_list};
use syntax::ast::{view_path_simple, visibility, anonymous, named, not};
use syntax::ast::{unsafe_fn};
Expand Down Expand Up @@ -1386,7 +1386,7 @@ pub impl Resolver {
&&_visitor: vt<ReducedGraphParent>) {
let privacy = visibility_to_privacy(view_item.vis);
match /*bad*/copy view_item.node {
view_item_import(view_paths) => {
view_item_use(view_paths) => {
for view_paths.each |view_path| {
// Extract and intern the module part of the path. For
// globs and lists, the path is found directly in the AST;
Expand Down Expand Up @@ -1456,8 +1456,8 @@ pub impl Resolver {
}
}

view_item_use(name, _, node_id) => {
match find_use_stmt_cnum(self.session.cstore, node_id) {
view_item_extern_mod(name, _, node_id) => {
match find_extern_mod_stmt_cnum(self.session.cstore, node_id) {
Some(crate_id) => {
let (child_name_bindings, new_parent) =
self.add_child(name, parent, ForbidDuplicateTypes,
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,8 +1456,8 @@ pub struct view_item {
#[auto_encode]
#[auto_decode]
pub enum view_item_ {
view_item_use(ident, ~[@meta_item], node_id),
view_item_import(~[@view_path]),
view_item_extern_mod(ident, ~[@meta_item], node_id),
view_item_use(~[@view_path]),
}

// Meta-data associated with an item
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,8 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {

visit_view_item: fn@(vi: @view_item) {
match vi.node {
view_item_use(_, _, id) => vfn(id),
view_item_import(vps) => {
view_item_extern_mod(_, _, id) => vfn(id),
view_item_use(vps) => {
for vec::each(vps) |vp| {
match vp.node {
view_path_simple(_, _, _, id) => vfn(id),
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub fn mk_glob_use(cx: ext_ctxt,
node: ast::view_path_glob(mk_raw_path(sp, path), cx.next_id()),
span: sp,
};
@ast::view_item { node: ast::view_item_import(~[glob]),
@ast::view_item { node: ast::view_item_use(~[glob]),
attrs: ~[],
vis: ast::private,
span: sp }
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/pipes/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ pub impl ext_ctxt: ext_ctxt_ast_builder {
+items: ~[@ast::item]) -> @ast::item {
// XXX: Total hack: import `core::kinds::Owned` to work around a
// parser bug whereby `fn f<T: ::kinds::Owned>` doesn't parse.
let vi = ast::view_item_import(~[
let vi = ast::view_item_use(~[
@ast::spanned {
node: ast::view_path_simple(
self.ident_of(~"Owned"),
Expand Down
12 changes: 6 additions & 6 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use ast::{ty_field, ty_fixed_length_vec, ty_fn, ty_infer, ty_mac, ty_method};
use ast::{ty_nil, ty_param, ty_param_bound, ty_path, ty_ptr, ty_rec, ty_rptr};
use ast::{ty_tup, ty_u32, ty_uniq, ty_vec, type_value_ns, uniq};
use ast::{unnamed_field, unsafe_blk, unsafe_fn, variant, view_item};
use ast::{view_item_, view_item_import, view_item_use};
use ast::{view_item_, view_item_extern_mod, view_item_use};
use ast::{view_path, view_path_glob, view_path_list, view_path_simple};
use ast::{visibility, vstore, vstore_box, vstore_fixed, vstore_slice};
use ast::{vstore_uniq};
Expand Down Expand Up @@ -3387,7 +3387,7 @@ pub impl Parser {
let metadata = self.parse_optional_meta();
self.expect(token::SEMI);
iovi_view_item(@ast::view_item {
node: view_item_use(ident, metadata, self.get_id()),
node: view_item_extern_mod(ident, metadata, self.get_id()),
attrs: attrs,
vis: visibility,
span: mk_sp(lo, self.last_span.hi)
Expand Down Expand Up @@ -3768,7 +3768,7 @@ pub impl Parser {
}

fn parse_use() -> view_item_ {
return view_item_import(self.parse_view_paths());
return view_item_use(self.parse_view_paths());
}

fn parse_view_path() -> @view_path {
Expand Down Expand Up @@ -3890,7 +3890,7 @@ pub impl Parser {
self.expect_keyword(~"mod");
let ident = self.parse_ident();
let metadata = self.parse_optional_meta();
view_item_use(ident, metadata, self.get_id())
view_item_extern_mod(ident, metadata, self.get_id())
} else {
fail;
};
Expand Down Expand Up @@ -3937,8 +3937,8 @@ pub impl Parser {
iovi_view_item(view_item) => {
if restricted_to_imports {
match view_item.node {
view_item_import(_) => {}
view_item_use(*) =>
view_item_use(_) => {}
view_item_extern_mod(*) =>
self.fatal(~"\"extern mod\" \
declarations are not \
allowed here")
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,7 @@ pub fn print_view_item(s: ps, item: @ast::view_item) {
print_outer_attributes(s, item.attrs);
print_visibility(s, item.vis);
match item.node {
ast::view_item_use(id, mta, _) => {
ast::view_item_extern_mod(id, mta, _) => {
head(s, ~"extern mod");
print_ident(s, id);
if !mta.is_empty() {
Expand All @@ -1856,7 +1856,7 @@ pub fn print_view_item(s: ps, item: @ast::view_item) {
}
}

ast::view_item_import(vps) => {
ast::view_item_use(vps) => {
head(s, ~"use");
print_view_paths(s, vps);
}
Expand Down