Skip to content

Commit f6a8655

Browse files
committed
rustc_trans: fix fallout of merging ast::ViewItem into ast::Item.
1 parent 7a5cd9e commit f6a8655

File tree

1 file changed

+105
-114
lines changed

1 file changed

+105
-114
lines changed

src/librustc_trans/save/mod.rs

Lines changed: 105 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,111 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
10321032
}
10331033

10341034
match item.node {
1035+
ast::ItemUse(ref use_item) => {
1036+
match use_item.node {
1037+
ast::ViewPathSimple(ident, ref path) => {
1038+
let sub_span = self.span.span_for_last_ident(path.span);
1039+
let mod_id = match self.lookup_type_ref(item.id) {
1040+
Some(def_id) => {
1041+
match self.lookup_def_kind(item.id, path.span) {
1042+
Some(kind) => self.fmt.ref_str(kind,
1043+
path.span,
1044+
sub_span,
1045+
def_id,
1046+
self.cur_scope),
1047+
None => {},
1048+
}
1049+
Some(def_id)
1050+
},
1051+
None => None,
1052+
};
1053+
1054+
// 'use' always introduces an alias, if there is not an explicit
1055+
// one, there is an implicit one.
1056+
let sub_span =
1057+
match self.span.sub_span_after_keyword(use_item.span, keywords::As) {
1058+
Some(sub_span) => Some(sub_span),
1059+
None => sub_span,
1060+
};
1061+
1062+
self.fmt.use_alias_str(path.span,
1063+
sub_span,
1064+
item.id,
1065+
mod_id,
1066+
get_ident(ident).get(),
1067+
self.cur_scope);
1068+
self.write_sub_paths_truncated(path);
1069+
}
1070+
ast::ViewPathGlob(ref path) => {
1071+
// Make a comma-separated list of names of imported modules.
1072+
let mut name_string = String::new();
1073+
let glob_map = &self.analysis.glob_map;
1074+
let glob_map = glob_map.as_ref().unwrap();
1075+
if glob_map.contains_key(&item.id) {
1076+
let names = glob_map.index(&item.id);
1077+
for n in names.iter() {
1078+
if name_string.len() > 0 {
1079+
name_string.push_str(", ");
1080+
}
1081+
name_string.push_str(n.as_str());
1082+
}
1083+
}
1084+
1085+
let sub_span = self.span.sub_span_of_token(path.span,
1086+
token::BinOp(token::Star));
1087+
self.fmt.use_glob_str(path.span,
1088+
sub_span,
1089+
item.id,
1090+
name_string.as_slice(),
1091+
self.cur_scope);
1092+
self.write_sub_paths(path);
1093+
}
1094+
ast::ViewPathList(ref path, ref list) => {
1095+
for plid in list.iter() {
1096+
match plid.node {
1097+
ast::PathListIdent { id, .. } => {
1098+
match self.lookup_type_ref(id) {
1099+
Some(def_id) =>
1100+
match self.lookup_def_kind(id, plid.span) {
1101+
Some(kind) => {
1102+
self.fmt.ref_str(
1103+
kind, plid.span,
1104+
Some(plid.span),
1105+
def_id, self.cur_scope);
1106+
}
1107+
None => ()
1108+
},
1109+
None => ()
1110+
}
1111+
},
1112+
ast::PathListMod { .. } => ()
1113+
}
1114+
}
1115+
1116+
self.write_sub_paths(path);
1117+
}
1118+
}
1119+
}
1120+
ast::ItemExternCrate(ref s) => {
1121+
let name = get_ident(item.ident);
1122+
let name = name.get();
1123+
let s = match *s {
1124+
Some((ref s, _)) => s.get().to_string(),
1125+
None => name.to_string(),
1126+
};
1127+
let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Crate);
1128+
let cnum = match self.sess.cstore.find_extern_mod_stmt_cnum(item.id) {
1129+
Some(cnum) => cnum,
1130+
None => 0,
1131+
};
1132+
self.fmt.extern_crate_str(item.span,
1133+
sub_span,
1134+
item.id,
1135+
cnum,
1136+
name,
1137+
s[],
1138+
self.cur_scope);
1139+
}
10351140
ast::ItemFn(ref decl, _, _, ref ty_params, ref body) =>
10361141
self.process_fn(item, &**decl, ty_params, &**body),
10371142
ast::ItemStatic(ref typ, mt, ref expr) =>
@@ -1155,120 +1260,6 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
11551260
}
11561261
}
11571262

1158-
fn visit_view_item(&mut self, i: &ast::ViewItem) {
1159-
if generated_code(i.span) {
1160-
return
1161-
}
1162-
1163-
match i.node {
1164-
ast::ViewItemUse(ref item) => {
1165-
match item.node {
1166-
ast::ViewPathSimple(ident, ref path, id) => {
1167-
let sub_span = self.span.span_for_last_ident(path.span);
1168-
let mod_id = match self.lookup_type_ref(id) {
1169-
Some(def_id) => {
1170-
match self.lookup_def_kind(id, path.span) {
1171-
Some(kind) => self.fmt.ref_str(kind,
1172-
path.span,
1173-
sub_span,
1174-
def_id,
1175-
self.cur_scope),
1176-
None => {},
1177-
}
1178-
Some(def_id)
1179-
},
1180-
None => None,
1181-
};
1182-
1183-
// 'use' always introduces an alias, if there is not an explicit
1184-
// one, there is an implicit one.
1185-
let sub_span =
1186-
match self.span.sub_span_after_keyword(item.span, keywords::As) {
1187-
Some(sub_span) => Some(sub_span),
1188-
None => sub_span,
1189-
};
1190-
1191-
self.fmt.use_alias_str(path.span,
1192-
sub_span,
1193-
id,
1194-
mod_id,
1195-
get_ident(ident).get(),
1196-
self.cur_scope);
1197-
self.write_sub_paths_truncated(path);
1198-
}
1199-
ast::ViewPathGlob(ref path, id) => {
1200-
// Make a comma-separated list of names of imported modules.
1201-
let mut name_string = String::new();
1202-
let glob_map = &self.analysis.glob_map;
1203-
let glob_map = glob_map.as_ref().unwrap();
1204-
if glob_map.contains_key(&id) {
1205-
let names = glob_map.index(&id);
1206-
for n in names.iter() {
1207-
if name_string.len() > 0 {
1208-
name_string.push_str(", ");
1209-
}
1210-
name_string.push_str(n.as_str());
1211-
}
1212-
}
1213-
1214-
let sub_span = self.span.sub_span_of_token(path.span,
1215-
token::BinOp(token::Star));
1216-
self.fmt.use_glob_str(path.span,
1217-
sub_span,
1218-
id,
1219-
name_string.as_slice(),
1220-
self.cur_scope);
1221-
self.write_sub_paths(path);
1222-
}
1223-
ast::ViewPathList(ref path, ref list, _) => {
1224-
for plid in list.iter() {
1225-
match plid.node {
1226-
ast::PathListIdent { id, .. } => {
1227-
match self.lookup_type_ref(id) {
1228-
Some(def_id) =>
1229-
match self.lookup_def_kind(id, plid.span) {
1230-
Some(kind) => {
1231-
self.fmt.ref_str(
1232-
kind, plid.span,
1233-
Some(plid.span),
1234-
def_id, self.cur_scope);
1235-
}
1236-
None => ()
1237-
},
1238-
None => ()
1239-
}
1240-
},
1241-
ast::PathListMod { .. } => ()
1242-
}
1243-
}
1244-
1245-
self.write_sub_paths(path);
1246-
}
1247-
}
1248-
},
1249-
ast::ViewItemExternCrate(ident, ref s, id) => {
1250-
let name = get_ident(ident);
1251-
let name = name.get();
1252-
let s = match *s {
1253-
Some((ref s, _)) => s.get().to_string(),
1254-
None => name.to_string(),
1255-
};
1256-
let sub_span = self.span.sub_span_after_keyword(i.span, keywords::Crate);
1257-
let cnum = match self.sess.cstore.find_extern_mod_stmt_cnum(id) {
1258-
Some(cnum) => cnum,
1259-
None => 0,
1260-
};
1261-
self.fmt.extern_crate_str(i.span,
1262-
sub_span,
1263-
id,
1264-
cnum,
1265-
name,
1266-
s[],
1267-
self.cur_scope);
1268-
},
1269-
}
1270-
}
1271-
12721263
fn visit_ty(&mut self, t: &ast::Ty) {
12731264
if generated_code(t.span) {
12741265
return

0 commit comments

Comments
 (0)