Deny imports after non-item statements.
This commit is contained in:
parent
5e07f5a792
commit
2d17a33878
4 changed files with 26 additions and 3 deletions
|
|
@ -52,6 +52,7 @@ register_diagnostics! {
|
|||
E0140,
|
||||
E0152,
|
||||
E0153,
|
||||
E0154,
|
||||
E0157,
|
||||
E0158,
|
||||
E0161,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue