Skip to content

Commit 0b8a26f

Browse files
authored
Rollup merge of rust-lang#86424 - calebcartwright:rustfmt-mod-resolution, r=Mark-Simulacrum
rustfmt: load nested out-of-line mods correctly This should address rust-lang/rustfmt#4874 r? `@Mark-Simulacrum` Decided to make the change directly in tree here for expediency/to minimize any potential backporting issues, and because there's some subtree sync items I need to get resolved before pulling from r-l/rustfmt
2 parents d13020c + 2608f2c commit 0b8a26f

File tree

7 files changed

+46
-1
lines changed

7 files changed

+46
-1
lines changed

src/modules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
318318
self.directory = directory;
319319
}
320320
match (sub_mod.ast_mod_kind, sub_mod.items) {
321-
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, ast::Inline::No, _))), _) => {
321+
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, _, _))), _) => {
322322
self.visit_mod_from_ast(&items)
323323
}
324324
(Some(Cow::Owned(..)), Cow::Owned(items)) => self.visit_mod_outside_ast(items),

src/test/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::source_file;
1616
use crate::{is_nightly_channel, FormatReport, FormatReportFormatterBuilder, Input, Session};
1717

1818
mod configuration_snippet;
19+
mod mod_resolver;
1920
mod parser;
2021

2122
const DIFF_CONTEXT_SIZE: usize = 3;

src/test/mod_resolver.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use std::io;
2+
use std::path::PathBuf;
3+
4+
use super::read_config;
5+
6+
use crate::{FileName, Input, Session};
7+
8+
#[test]
9+
fn nested_out_of_line_mods_loaded() {
10+
// See also https://github.com/rust-lang/rustfmt/issues/4874
11+
let filename = "tests/mod-resolver/issue-4874/main.rs";
12+
let input_file = PathBuf::from(filename);
13+
let config = read_config(&input_file);
14+
let mut session = Session::<io::Stdout>::new(config, None);
15+
let report = session
16+
.format(Input::File(filename.into()))
17+
.expect("Should not have had any execution errors");
18+
let errors_by_file = &report.internal.borrow().0;
19+
assert!(errors_by_file.contains_key(&FileName::Real(PathBuf::from(
20+
"tests/mod-resolver/issue-4874/bar/baz.rs",
21+
))));
22+
assert!(errors_by_file.contains_key(&FileName::Real(PathBuf::from(
23+
"tests/mod-resolver/issue-4874/foo/qux.rs",
24+
))));
25+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn
2+
fail_fmt_check
3+
(
4+
5+
) {}

tests/mod-resolver/issue-4874/foo.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod qux;
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn
2+
badly_formatted
3+
(
4+
5+
) {}

tests/mod-resolver/issue-4874/main.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}
4+
5+
mod foo;
6+
mod bar {
7+
mod baz;
8+
}

0 commit comments

Comments
 (0)