Skip to content

Commit 5ea0509

Browse files
committed
auto merge of #13671 : dcrewi/rust/lint-directives-on-use-items, r=alexcrichton
Fixes #10534
2 parents b553944 + e72d49a commit 5ea0509

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

src/librustc/middle/lint.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,9 @@ impl<'a> Visitor<()> for Context<'a> {
16381638
fn visit_view_item(&mut self, i: &ast::ViewItem, _: ()) {
16391639
self.with_lint_attrs(i.attrs.as_slice(), |cx| {
16401640
check_attrs_usage(cx, i.attrs.as_slice());
1641+
1642+
cx.visit_ids(|v| v.visit_view_item(i, ()));
1643+
16411644
visit::walk_view_item(cx, i, ());
16421645
})
16431646
}

src/libsyntax/ast_util.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -396,6 +396,13 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
396396
}
397397

398398
fn visit_view_item(&mut self, view_item: &ViewItem, env: ()) {
399+
if !self.pass_through_items {
400+
if self.visited_outermost {
401+
return;
402+
} else {
403+
self.visited_outermost = true;
404+
}
405+
}
399406
match view_item.node {
400407
ViewItemExternCrate(_, _, node_id) => {
401408
self.operation.visit_id(node_id)
@@ -417,7 +424,8 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
417424
}
418425
}
419426
}
420-
visit::walk_view_item(self, view_item, env)
427+
visit::walk_view_item(self, view_item, env);
428+
self.visited_outermost = false;
421429
}
422430

423431
fn visit_foreign_item(&mut self, foreign_item: &ForeignItem, env: ()) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![deny(unused_imports)]
12+
13+
// The aim of this test is to ensure that deny/allow/warn directives
14+
// are applied to individual "use" statements instead of silently
15+
// ignored.
16+
17+
#[allow(dead_code)]
18+
mod a { pub static x: int = 3; pub static y: int = 4; }
19+
20+
mod b {
21+
use a::x; //~ ERROR: unused import
22+
#[allow(unused_imports)]
23+
use a::y; // no error here
24+
}
25+
26+
#[allow(unused_imports)]
27+
mod c {
28+
use a::x;
29+
#[deny(unused_imports)]
30+
use a::y; //~ ERROR: unused import
31+
}
32+
33+
fn main() {}

0 commit comments

Comments
 (0)