Skip to content

Commit f030d1f

Browse files
committed
Auto merge of #31144 - jseyfried:remove_import_ordering_restriction, r=nrc
We no longer require `use` and `extern crate` items to precede other items in modules thanks to [RFC #385](rust-lang/rfcs#385), but we still require `use` and `extern crate` items to precede statements in blocks (other items can appear anywhere in a block). I think that this is a needless distinction between imports and other items that contradicts the intent of the RFC.
2 parents 33b73e9 + f05bc16 commit f030d1f

File tree

3 files changed

+0
-25
lines changed

3 files changed

+0
-25
lines changed

src/librustc_resolve/lib.rs

-23
Original file line numberDiff line numberDiff line change
@@ -2516,29 +2516,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
25162516
self.value_ribs.push(Rib::new(NormalRibKind));
25172517
}
25182518

2519-
// Check for imports appearing after non-item statements.
2520-
let mut found_non_item = false;
2521-
for statement in &block.stmts {
2522-
if let hir::StmtDecl(ref declaration, _) = statement.node {
2523-
if let hir::DeclItem(i) = declaration.node {
2524-
let i = self.ast_map.expect_item(i.id);
2525-
match i.node {
2526-
ItemExternCrate(_) | ItemUse(_) if found_non_item => {
2527-
span_err!(self.session,
2528-
i.span,
2529-
E0154,
2530-
"imports are not allowed after non-item statements");
2531-
}
2532-
_ => {}
2533-
}
2534-
} else {
2535-
found_non_item = true
2536-
}
2537-
} else {
2538-
found_non_item = true;
2539-
}
2540-
}
2541-
25422519
// Descend into the block.
25432520
intravisit::walk_block(self, block);
25442521

src/test/compile-fail/blind-item-block-middle.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ fn main() {
1414
let bar = 5;
1515
//~^ ERROR declaration of `bar` shadows an enum variant or unit-like struct in scope
1616
use foo::bar;
17-
//~^ ERROR imports are not allowed after non-item statements
1817
}

src/test/compile-fail/blind-item-local-shadow.rs renamed to src/test/run-pass/blind-item-local-shadow.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ mod bar {
1515
fn main() {
1616
let foo = || false;
1717
use bar::foo;
18-
//~^ ERROR imports are not allowed after non-item statements
1918
assert_eq!(foo(), false);
2019
}

0 commit comments

Comments
 (0)