Skip to content

Commit cbc18ff

Browse files
committed
rustc: fix fallout of merging ast::ViewItem into ast::Item.
1 parent 0990b79 commit cbc18ff

File tree

10 files changed

+92
-136
lines changed

10 files changed

+92
-136
lines changed

src/librustc/lint/builtin.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,17 +1200,17 @@ impl LintPass for UnusedImportBraces {
12001200
lint_array!(UNUSED_IMPORT_BRACES)
12011201
}
12021202

1203-
fn check_view_item(&mut self, cx: &Context, view_item: &ast::ViewItem) {
1204-
match view_item.node {
1205-
ast::ViewItemUse(ref view_path) => {
1203+
fn check_item(&mut self, cx: &Context, item: &ast::Item) {
1204+
match item.node {
1205+
ast::ItemUse(ref view_path) => {
12061206
match view_path.node {
1207-
ast::ViewPathList(_, ref items, _) => {
1207+
ast::ViewPathList(_, ref items) => {
12081208
if items.len() == 1 {
12091209
match items[0].node {
12101210
ast::PathListIdent {ref name, ..} => {
12111211
let m = format!("braces around {} is unnecessary",
12121212
token::get_ident(*name).get());
1213-
cx.span_lint(UNUSED_IMPORT_BRACES, view_item.span,
1213+
cx.span_lint(UNUSED_IMPORT_BRACES, item.span,
12141214
m[]);
12151215
},
12161216
_ => ()
@@ -1716,22 +1716,6 @@ impl LintPass for Stability {
17161716
lint_array!(DEPRECATED, EXPERIMENTAL, UNSTABLE)
17171717
}
17181718

1719-
fn check_view_item(&mut self, cx: &Context, item: &ast::ViewItem) {
1720-
// compiler-generated `extern crate` statements have a dummy span.
1721-
if item.span == DUMMY_SP { return }
1722-
1723-
let id = match item.node {
1724-
ast::ViewItemExternCrate(_, _, id) => id,
1725-
ast::ViewItemUse(..) => return,
1726-
};
1727-
let cnum = match cx.tcx.sess.cstore.find_extern_mod_stmt_cnum(id) {
1728-
Some(cnum) => cnum,
1729-
None => return,
1730-
};
1731-
let id = ast::DefId { krate: cnum, node: ast::CRATE_NODE_ID };
1732-
self.lint(cx, id, item.span);
1733-
}
1734-
17351719
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
17361720
if self.is_internal(cx, e.span) { return; }
17371721

@@ -1782,6 +1766,17 @@ impl LintPass for Stability {
17821766
if self.is_internal(cx, item.span) { return }
17831767

17841768
match item.node {
1769+
ast::ItemExternCrate(_) => {
1770+
// compiler-generated `extern crate` items have a dummy span.
1771+
if item.span == DUMMY_SP { return }
1772+
1773+
let cnum = match cx.tcx.sess.cstore.find_extern_mod_stmt_cnum(item.id) {
1774+
Some(cnum) => cnum,
1775+
None => return,
1776+
};
1777+
let id = ast::DefId { krate: cnum, node: ast::CRATE_NODE_ID };
1778+
self.lint(cx, id, item.span);
1779+
}
17851780
ast::ItemTrait(_, _, ref supertraits, _) => {
17861781
for t in supertraits.iter() {
17871782
if let ast::TraitTyParamBound(ref t, _) = *t {

src/librustc/lint/context.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -557,14 +557,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
557557
})
558558
}
559559

560-
fn visit_view_item(&mut self, i: &ast::ViewItem) {
561-
self.with_lint_attrs(i.attrs[], |cx| {
562-
run_lints!(cx, check_view_item, i);
563-
cx.visit_ids(|v| v.visit_view_item(i));
564-
visit::walk_view_item(cx, i);
565-
})
566-
}
567-
568560
fn visit_pat(&mut self, p: &ast::Pat) {
569561
run_lints!(self, check_pat, p);
570562
visit::walk_pat(self, p);

src/librustc/lint/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ pub trait LintPass {
130130
fn check_crate(&mut self, _: &Context, _: &ast::Crate) { }
131131
fn check_ident(&mut self, _: &Context, _: Span, _: ast::Ident) { }
132132
fn check_mod(&mut self, _: &Context, _: &ast::Mod, _: Span, _: ast::NodeId) { }
133-
fn check_view_item(&mut self, _: &Context, _: &ast::ViewItem) { }
134133
fn check_foreign_item(&mut self, _: &Context, _: &ast::ForeignItem) { }
135134
fn check_item(&mut self, _: &Context, _: &ast::Item) { }
136135
fn check_local(&mut self, _: &Context, _: &ast::Local) { }

src/librustc/metadata/creader.rs

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ pub fn read_crates(sess: &Session,
6060
}
6161

6262
impl<'a, 'v> visit::Visitor<'v> for Env<'a> {
63-
fn visit_view_item(&mut self, a: &ast::ViewItem) {
64-
visit_view_item(self, a);
65-
visit::walk_view_item(self, a);
66-
}
6763
fn visit_item(&mut self, a: &ast::Item) {
6864
visit_item(self, a);
6965
visit::walk_item(self, a);
@@ -114,7 +110,7 @@ fn visit_crate(e: &Env, c: &ast::Crate) {
114110
}
115111
}
116112

117-
fn should_link(i: &ast::ViewItem) -> bool {
113+
fn should_link(i: &ast::Item) -> bool {
118114
i.attrs.iter().all(|attr| {
119115
attr.name().get() != "phase" ||
120116
attr.meta_item_list().map_or(false, |phases| {
@@ -123,37 +119,17 @@ fn should_link(i: &ast::ViewItem) -> bool {
123119
})
124120
}
125121

126-
fn visit_view_item(e: &mut Env, i: &ast::ViewItem) {
127-
if !should_link(i) {
128-
return;
129-
}
130-
131-
match extract_crate_info(e, i) {
132-
Some(info) => {
133-
let (cnum, _, _) = resolve_crate(e,
134-
&None,
135-
info.ident[],
136-
info.name[],
137-
None,
138-
i.span,
139-
PathKind::Crate);
140-
e.sess.cstore.add_extern_mod_stmt_cnum(info.id, cnum);
141-
}
142-
None => ()
143-
}
144-
}
145-
146122
struct CrateInfo {
147123
ident: String,
148124
name: String,
149125
id: ast::NodeId,
150126
should_link: bool,
151127
}
152128

153-
fn extract_crate_info(e: &Env, i: &ast::ViewItem) -> Option<CrateInfo> {
129+
fn extract_crate_info(e: &Env, i: &ast::Item) -> Option<CrateInfo> {
154130
match i.node {
155-
ast::ViewItemExternCrate(ident, ref path_opt, id) => {
156-
let ident = token::get_ident(ident);
131+
ast::ItemExternCrate(ref path_opt) => {
132+
let ident = token::get_ident(i.ident);
157133
debug!("resolving extern crate stmt. ident: {} path_opt: {}",
158134
ident, path_opt);
159135
let name = match *path_opt {
@@ -168,7 +144,7 @@ fn extract_crate_info(e: &Env, i: &ast::ViewItem) -> Option<CrateInfo> {
168144
Some(CrateInfo {
169145
ident: ident.get().to_string(),
170146
name: name,
171-
id: id,
147+
id: i.id,
172148
should_link: should_link(i),
173149
})
174150
}
@@ -198,8 +174,23 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
198174
}
199175
}
200176

201-
fn visit_item(e: &Env, i: &ast::Item) {
177+
fn visit_item(e: &mut Env, i: &ast::Item) {
202178
match i.node {
179+
ast::ItemExternCrate(_) => {
180+
if !should_link(i) {
181+
return;
182+
}
183+
184+
let info = extract_crate_info(e, i).unwrap();
185+
let (cnum, _, _) = resolve_crate(e,
186+
&None,
187+
info.ident[],
188+
info.name[],
189+
None,
190+
i.span,
191+
PathKind::Crate);
192+
e.sess.cstore.add_extern_mod_stmt_cnum(info.id, cnum);
193+
}
203194
ast::ItemForeignMod(ref fm) => {
204195
if fm.abi == abi::Rust || fm.abi == abi::RustIntrinsic {
205196
return;
@@ -457,8 +448,7 @@ impl<'a> PluginMetadataReader<'a> {
457448
}
458449
}
459450

460-
pub fn read_plugin_metadata(&mut self,
461-
krate: &ast::ViewItem) -> PluginMetadata {
451+
pub fn read_plugin_metadata(&mut self, krate: &ast::Item) -> PluginMetadata {
462452
let info = extract_crate_info(&self.env, krate).unwrap();
463453
let target_triple = self.env.sess.opts.target_triple[];
464454
let is_cross = target_triple != config::host_triple();

src/librustc/metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,8 +1456,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
14561456
// Encode inherent implementations for this trait.
14571457
encode_inherent_implementations(ecx, rbml_w, def_id);
14581458
}
1459-
ast::ItemMac(..) => {
1460-
// macros are encoded separately
1459+
ast::ItemExternCrate(_) | ast::ItemUse(_) |ast::ItemMac(..) => {
1460+
// these are encoded separately
14611461
}
14621462
}
14631463
}

src/librustc/middle/astencode.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,6 @@ impl Folder for NestedItemsDropper {
332332
}
333333
}).collect();
334334
let blk_sans_items = P(ast::Block {
335-
view_items: Vec::new(), // I don't know if we need the view_items
336-
// here, but it doesn't break tests!
337335
stmts: stmts_sans_items,
338336
expr: expr,
339337
id: id,

src/librustc/middle/privacy.rs

Lines changed: 37 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,38 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
864864

865865
impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
866866
fn visit_item(&mut self, item: &ast::Item) {
867+
match item.node {
868+
ast::ItemUse(ref vpath) => {
869+
match vpath.node {
870+
ast::ViewPathSimple(..) | ast::ViewPathGlob(..) => {}
871+
ast::ViewPathList(ref prefix, ref list) => {
872+
for pid in list.iter() {
873+
match pid.node {
874+
ast::PathListIdent { id, name } => {
875+
debug!("privacy - ident item {}", id);
876+
let seg = ast::PathSegment {
877+
identifier: name,
878+
parameters: ast::PathParameters::none(),
879+
};
880+
let segs = vec![seg];
881+
let path = ast::Path {
882+
global: false,
883+
span: pid.span,
884+
segments: segs,
885+
};
886+
self.check_path(pid.span, id, &path);
887+
}
888+
ast::PathListMod { id } => {
889+
debug!("privacy - mod item {}", id);
890+
self.check_path(pid.span, id, prefix);
891+
}
892+
}
893+
}
894+
}
895+
}
896+
}
897+
_ => {}
898+
}
867899
let orig_curitem = replace(&mut self.curitem, item.id);
868900
visit::walk_item(self, item);
869901
self.curitem = orig_curitem;
@@ -960,42 +992,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
960992
visit::walk_expr(self, expr);
961993
}
962994

963-
fn visit_view_item(&mut self, a: &ast::ViewItem) {
964-
match a.node {
965-
ast::ViewItemExternCrate(..) => {}
966-
ast::ViewItemUse(ref vpath) => {
967-
match vpath.node {
968-
ast::ViewPathSimple(..) | ast::ViewPathGlob(..) => {}
969-
ast::ViewPathList(ref prefix, ref list, _) => {
970-
for pid in list.iter() {
971-
match pid.node {
972-
ast::PathListIdent { id, name } => {
973-
debug!("privacy - ident item {}", id);
974-
let seg = ast::PathSegment {
975-
identifier: name,
976-
parameters: ast::PathParameters::none(),
977-
};
978-
let segs = vec![seg];
979-
let path = ast::Path {
980-
global: false,
981-
span: pid.span,
982-
segments: segs,
983-
};
984-
self.check_path(pid.span, id, &path);
985-
}
986-
ast::PathListMod { id } => {
987-
debug!("privacy - mod item {}", id);
988-
self.check_path(pid.span, id, prefix);
989-
}
990-
}
991-
}
992-
}
993-
}
994-
}
995-
}
996-
visit::walk_view_item(self, a);
997-
}
998-
999995
fn visit_pat(&mut self, pattern: &ast::Pat) {
1000996
// Foreign functions do not have their patterns mapped in the def_map,
1001997
// and there's nothing really relevant there anyway, so don't bother
@@ -1103,23 +1099,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for SanePrivacyVisitor<'a, 'tcx> {
11031099
visit::walk_fn(self, fk, fd, b, s);
11041100
self.in_fn = orig_in_fn;
11051101
}
1106-
1107-
fn visit_view_item(&mut self, i: &ast::ViewItem) {
1108-
match i.vis {
1109-
ast::Inherited => {}
1110-
ast::Public => {
1111-
if self.in_fn {
1112-
self.tcx.sess.span_err(i.span, "unnecessary `pub`, imports \
1113-
in functions are never \
1114-
reachable");
1115-
} else if let ast::ViewItemExternCrate(..) = i.node {
1116-
self.tcx.sess.span_err(i.span, "`pub` visibility \
1117-
is not allowed");
1118-
}
1119-
}
1120-
}
1121-
visit::walk_view_item(self, i);
1122-
}
11231102
}
11241103

11251104
impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
@@ -1196,7 +1175,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
11961175

11971176
ast::ItemConst(..) | ast::ItemStatic(..) | ast::ItemStruct(..) |
11981177
ast::ItemFn(..) | ast::ItemMod(..) | ast::ItemTy(..) |
1199-
ast::ItemMac(..) => {}
1178+
ast::ItemExternCrate(_) | ast::ItemUse(_) | ast::ItemMac(..) => {}
12001179
}
12011180
}
12021181

@@ -1253,6 +1232,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
12531232
}
12541233
}
12551234

1235+
ast::ItemExternCrate(_) | ast::ItemUse(_) |
12561236
ast::ItemStatic(..) | ast::ItemConst(..) |
12571237
ast::ItemFn(..) | ast::ItemMod(..) | ast::ItemTy(..) |
12581238
ast::ItemMac(..) => {}
@@ -1555,11 +1535,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
15551535

15561536

15571537
// we don't need to introspect into these at all: an
1558-
// expression/block context can't possibly contain exported
1559-
// things, and neither do view_items. (Making them no-ops stops us
1560-
// from traversing the whole AST without having to be super
1561-
// careful about our `walk_...` calls above.)
1562-
fn visit_view_item(&mut self, _: &ast::ViewItem) {}
1538+
// expression/block context can't possibly contain exported things.
1539+
// (Making them no-ops stops us from traversing the whole AST without
1540+
// having to be super careful about our `walk_...` calls above.)
15631541
fn visit_block(&mut self, _: &ast::Block) {}
15641542
fn visit_expr(&mut self, _: &ast::Expr) {}
15651543
}

src/librustc/middle/reachable.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
297297
// These are normal, nothing reachable about these
298298
// inherently and their children are already in the
299299
// worklist, as determined by the privacy pass
300+
ast::ItemExternCrate(_) | ast::ItemUse(_) |
300301
ast::ItemTy(..) | ast::ItemStatic(_, _, _) |
301302
ast::ItemMod(..) | ast::ItemForeignMod(..) |
302303
ast::ItemImpl(..) | ast::ItemTrait(..) |

src/librustc/middle/resolve_lifetime.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
9494
// Fn lifetimes get added in visit_fn below:
9595
visit::walk_item(this, item);
9696
}
97+
ast::ItemExternCrate(_) |
98+
ast::ItemUse(_) |
9799
ast::ItemMod(..) |
98100
ast::ItemMac(..) |
99101
ast::ItemForeignMod(..) |

0 commit comments

Comments
 (0)