Skip to content

Commit 0343b0d

Browse files
committed
rustc: fix fallout of merging ast::ViewItem into ast::Item.
1 parent 41bb8c9 commit 0343b0d

File tree

10 files changed

+99
-132
lines changed

10 files changed

+99
-132
lines changed

src/librustc/lint/builtin.rs

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

1205-
fn check_view_item(&mut self, cx: &Context, view_item: &ast::ViewItem) {
1206-
match view_item.node {
1207-
ast::ViewItemUse(ref view_path) => {
1205+
fn check_item(&mut self, cx: &Context, item: &ast::Item) {
1206+
match item.node {
1207+
ast::ItemUse(ref view_path) => {
12081208
match view_path.node {
1209-
ast::ViewPathList(_, ref items, _) => {
1209+
ast::ViewPathList(_, ref items) => {
12101210
if items.len() == 1 {
12111211
match items[0].node {
12121212
ast::PathListIdent {ref name, ..} => {
12131213
let m = format!("braces around {} is unnecessary",
12141214
token::get_ident(*name).get());
1215-
cx.span_lint(UNUSED_IMPORT_BRACES, view_item.span,
1215+
cx.span_lint(UNUSED_IMPORT_BRACES, item.span,
12161216
&m[]);
12171217
},
12181218
_ => ()
@@ -1709,22 +1709,6 @@ impl LintPass for Stability {
17091709
}
17101710
}
17111711

1712-
fn check_view_item(&mut self, cx: &Context, item: &ast::ViewItem) {
1713-
// compiler-generated `extern crate` statements have a dummy span.
1714-
if item.span == DUMMY_SP { return }
1715-
1716-
let id = match item.node {
1717-
ast::ViewItemExternCrate(_, _, id) => id,
1718-
ast::ViewItemUse(..) => return,
1719-
};
1720-
let cnum = match cx.tcx.sess.cstore.find_extern_mod_stmt_cnum(id) {
1721-
Some(cnum) => cnum,
1722-
None => return,
1723-
};
1724-
let id = ast::DefId { krate: cnum, node: ast::CRATE_NODE_ID };
1725-
self.lint(cx, id, item.span);
1726-
}
1727-
17281712
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
17291713
if self.is_internal(cx, e.span) { return; }
17301714

@@ -1776,6 +1760,17 @@ impl LintPass for Stability {
17761760
if self.is_internal(cx, item.span) { return }
17771761

17781762
match item.node {
1763+
ast::ItemExternCrate(_) => {
1764+
// compiler-generated `extern crate` items have a dummy span.
1765+
if item.span == DUMMY_SP { return }
1766+
1767+
let cnum = match cx.tcx.sess.cstore.find_extern_mod_stmt_cnum(item.id) {
1768+
Some(cnum) => cnum,
1769+
None => return,
1770+
};
1771+
let id = ast::DefId { krate: cnum, node: ast::CRATE_NODE_ID };
1772+
self.lint(cx, id, item.span);
1773+
}
17791774
ast::ItemTrait(_, _, ref supertraits, _) => {
17801775
for t in supertraits.iter() {
17811776
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
@@ -603,14 +603,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
603603
})
604604
}
605605

606-
fn visit_view_item(&mut self, i: &ast::ViewItem) {
607-
self.with_lint_attrs(&i.attrs[], |cx| {
608-
run_lints!(cx, check_view_item, i);
609-
cx.visit_ids(|v| v.visit_view_item(i));
610-
visit::walk_view_item(cx, i);
611-
})
612-
}
613-
614606
fn visit_pat(&mut self, p: &ast::Pat) {
615607
run_lints!(self, check_pat, p);
616608
visit::walk_pat(self, p);

src/librustc/lint/mod.rs

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

src/librustc/metadata/creader.rs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ pub struct CrateReader<'a> {
4040
}
4141

4242
impl<'a, 'v> visit::Visitor<'v> for CrateReader<'a> {
43-
fn visit_view_item(&mut self, a: &ast::ViewItem) {
44-
self.process_view_item(a);
45-
visit::walk_view_item(self, a);
46-
}
4743
fn visit_item(&mut self, a: &ast::Item) {
4844
self.process_item(a);
4945
visit::walk_item(self, a);
@@ -64,9 +60,8 @@ fn dump_crates(cstore: &CStore) {
6460
})
6561
}
6662

67-
fn should_link(i: &ast::ViewItem) -> bool {
63+
fn should_link(i: &ast::Item) -> bool {
6864
!attr::contains_name(&i.attrs[], "no_link")
69-
7065
}
7166

7267
struct CrateInfo {
@@ -181,29 +176,10 @@ impl<'a> CrateReader<'a> {
181176
}
182177
}
183178

184-
fn process_view_item(&mut self, i: &ast::ViewItem) {
185-
if !should_link(i) {
186-
return;
187-
}
188-
189-
match self.extract_crate_info(i) {
190-
Some(info) => {
191-
let (cnum, _, _) = self.resolve_crate(&None,
192-
&info.ident[],
193-
&info.name[],
194-
None,
195-
i.span,
196-
PathKind::Crate);
197-
self.sess.cstore.add_extern_mod_stmt_cnum(info.id, cnum);
198-
}
199-
None => ()
200-
}
201-
}
202-
203-
fn extract_crate_info(&self, i: &ast::ViewItem) -> Option<CrateInfo> {
179+
fn extract_crate_info(&self, i: &ast::Item) -> Option<CrateInfo> {
204180
match i.node {
205-
ast::ViewItemExternCrate(ident, ref path_opt, id) => {
206-
let ident = token::get_ident(ident);
181+
ast::ItemExternCrate(ref path_opt) => {
182+
let ident = token::get_ident(i.ident);
207183
debug!("resolving extern crate stmt. ident: {} path_opt: {:?}",
208184
ident, path_opt);
209185
let name = match *path_opt {
@@ -218,16 +194,34 @@ impl<'a> CrateReader<'a> {
218194
Some(CrateInfo {
219195
ident: ident.get().to_string(),
220196
name: name,
221-
id: id,
197+
id: i.id,
222198
should_link: should_link(i),
223199
})
224200
}
225201
_ => None
226202
}
227203
}
228204

229-
fn process_item(&self, i: &ast::Item) {
205+
fn process_item(&mut self, i: &ast::Item) {
230206
match i.node {
207+
ast::ItemExternCrate(_) => {
208+
if !should_link(i) {
209+
return;
210+
}
211+
212+
match self.extract_crate_info(i) {
213+
Some(info) => {
214+
let (cnum, _, _) = self.resolve_crate(&None,
215+
&info.ident[],
216+
&info.name[],
217+
None,
218+
i.span,
219+
PathKind::Crate);
220+
self.sess.cstore.add_extern_mod_stmt_cnum(info.id, cnum);
221+
}
222+
None => ()
223+
}
224+
}
231225
ast::ItemForeignMod(ref fm) => {
232226
if fm.abi == abi::Rust || fm.abi == abi::RustIntrinsic {
233227
return;
@@ -533,7 +527,7 @@ impl<'a> CrateReader<'a> {
533527

534528
#[derive(Copy)]
535529
pub enum CrateOrString<'a> {
536-
Krate(&'a ast::ViewItem),
530+
Krate(&'a ast::Item),
537531
Str(&'a str)
538532
}
539533

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
rbml_w.end_tag();
14571457
}
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/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(..) |

src/librustc/plugin/load.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ pub fn load_plugins(sess: &Session, krate: &ast::Crate,
7373
// We need to error on `#[macro_use] extern crate` when it isn't at the
7474
// crate root, because `$crate` won't work properly. Identify these by
7575
// spans, because the crate map isn't set up yet.
76-
for vi in krate.module.view_items.iter() {
77-
loader.span_whitelist.insert(vi.span);
76+
for item in krate.module.items.iter() {
77+
if let ast::ItemExternCrate(_) = item.node {
78+
loader.span_whitelist.insert(item.span);
79+
}
7880
}
7981

8082
visit::walk_crate(&mut loader, krate);
@@ -91,18 +93,21 @@ pub fn load_plugins(sess: &Session, krate: &ast::Crate,
9193

9294
// note that macros aren't expanded yet, and therefore macros can't add plugins.
9395
impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
94-
fn visit_view_item(&mut self, vi: &ast::ViewItem) {
96+
fn visit_item(&mut self, item: &ast::Item) {
9597
// We're only interested in `extern crate`.
96-
match vi.node {
97-
ast::ViewItemExternCrate(..) => (),
98-
_ => return,
98+
match item.node {
99+
ast::ItemExternCrate(_) => {}
100+
_ => {
101+
visit::walk_item(self, item);
102+
return;
103+
}
99104
}
100105

101106
// Parse the attributes relating to macro / plugin loading.
102107
let mut plugin_attr = None;
103108
let mut macro_selection = Some(HashSet::new()); // None => load all
104109
let mut reexport = HashSet::new();
105-
for attr in vi.attrs.iter() {
110+
for attr in item.attrs.iter() {
106111
let mut used = true;
107112
match attr.name().get() {
108113
"phase" => {
@@ -155,7 +160,10 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
155160
}
156161
}
157162

158-
self.load_plugin(CrateOrString::Krate(vi), plugin_attr, macro_selection, Some(reexport))
163+
self.load_plugin(CrateOrString::Krate(item),
164+
plugin_attr,
165+
macro_selection,
166+
Some(reexport))
159167
}
160168

161169
fn visit_mac(&mut self, _: &ast::Mac) {

0 commit comments

Comments
 (0)