Skip to content

Commit 5025a53

Browse files
authored
Merge pull request #2502 from topecongiro/fix-reorder-module
Fix reorder module
2 parents 7dba56f + 0bd77f2 commit 5025a53

File tree

7 files changed

+24
-2
lines changed

7 files changed

+24
-2
lines changed

src/reorder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use attr::filter_inline_attrs;
2323
use codemap::LineRangeUtils;
2424
use comment::combine_strs_with_missing_comments;
2525
use imports::{path_to_imported_ident, rewrite_import};
26-
use items::{rewrite_extern_crate, rewrite_mod};
26+
use items::{is_mod_decl, rewrite_extern_crate, rewrite_mod};
2727
use lists::{itemize_list, write_list, ListFormatting};
2828
use rewrite::{Rewrite, RewriteContext};
2929
use shape::Shape;
@@ -234,7 +234,7 @@ impl ReorderableItemKind {
234234
match item.node {
235235
_ if contains_macro_use_attr(item) => ReorderableItemKind::Other,
236236
ast::ItemKind::ExternCrate(..) => ReorderableItemKind::ExternCrate,
237-
ast::ItemKind::Mod(..) => ReorderableItemKind::Mod,
237+
ast::ItemKind::Mod(..) if is_mod_decl(item) => ReorderableItemKind::Mod,
238238
ast::ItemKind::Use(..) => ReorderableItemKind::Use,
239239
_ => ReorderableItemKind::Other,
240240
}

tests/source/issue-2482/a.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// rustfmt-reorder_modules: true
2+
3+
// Do not reorder inline modules.
4+
5+
mod c;
6+
mod a {
7+
fn a() {}
8+
}
9+
mod b;

tests/source/issue-2482/b.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn b() {}

tests/source/issue-2482/c.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn c() {}

tests/target/issue-2482/a.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// rustfmt-reorder_modules: true
2+
3+
// Do not reorder inline modules.
4+
5+
mod c;
6+
mod a {
7+
fn a() {}
8+
}
9+
mod b;

tests/target/issue-2482/b.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn b() {}

tests/target/issue-2482/c.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn c() {}

0 commit comments

Comments
 (0)