diff options
| -rw-r--r-- | src/librustc/diagnostics.rs | 1 | ||||
| -rw-r--r-- | src/librustc_resolve/lib.rs | 20 | ||||
| -rw-r--r-- | src/test/compile-fail/blind-item-block-middle.rs | 1 | ||||
| -rw-r--r-- | src/test/compile-fail/blind-item-local-shadow.rs (renamed from src/test/run-pass/blind-item-local-shadow.rs) | 7 |
4 files changed, 26 insertions, 3 deletions
diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 1ea79bdf606..2602f38b3ad 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -52,6 +52,7 @@ register_diagnostics! { E0140, E0152, E0153, + E0154, E0157, E0158, E0161, diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index e4453e8fc59..b70980cf1ec 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -3509,6 +3509,26 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } } + // Check for imports appearing after non-item statements. + let mut found_non_item = false; + for statement in block.stmts.iter() { + if let ast::StmtDecl(ref declaration, _) = statement.node { + if let ast::DeclItem(ref i) = declaration.node { + match i.node { + ItemExternCrate(_) | ItemUse(_) if found_non_item => { + span_err!(self.session, i.span, E0154, + "imports are not allowed after non-item statements"); + } + _ => {} + } + } else { + found_non_item = true + } + } else { + found_non_item = true; + } + } + // Descend into the block. visit::walk_block(self, block); diff --git a/src/test/compile-fail/blind-item-block-middle.rs b/src/test/compile-fail/blind-item-block-middle.rs index 24a1e4e24d8..fbb0730f014 100644 --- a/src/test/compile-fail/blind-item-block-middle.rs +++ b/src/test/compile-fail/blind-item-block-middle.rs @@ -14,4 +14,5 @@ fn main() { let bar = 5; //~^ ERROR declaration of `bar` shadows an enum variant or unit-like struct in scope use foo::bar; + //~^ ERROR imports are not allowed after non-item statements } diff --git a/src/test/run-pass/blind-item-local-shadow.rs b/src/test/compile-fail/blind-item-local-shadow.rs index d019215ca04..a28f5f6e557 100644 --- a/src/test/run-pass/blind-item-local-shadow.rs +++ b/src/test/compile-fail/blind-item-local-shadow.rs @@ -9,11 +9,12 @@ // except according to those terms. mod bar { - pub fn foo() -> uint { 42 } + pub fn foo() -> bool { true } } fn main() { - let foo = |&:| 5u; + let foo = |&:| false; use bar::foo; - assert_eq!(foo(), 5u); + //~^ ERROR imports are not allowed after non-item statements + assert_eq!(foo(), false); } |
