mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
fix(rustfmt): load nested out-of-line mods correctly
This commit is contained in:
parent
58c63cf8de
commit
2608f2c63b
@ -318,7 +318,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
|
||||
self.directory = directory;
|
||||
}
|
||||
match (sub_mod.ast_mod_kind, sub_mod.items) {
|
||||
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, ast::Inline::No, _))), _) => {
|
||||
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, _, _))), _) => {
|
||||
self.visit_mod_from_ast(&items)
|
||||
}
|
||||
(Some(Cow::Owned(..)), Cow::Owned(items)) => self.visit_mod_outside_ast(items),
|
||||
|
@ -16,6 +16,7 @@ use crate::source_file;
|
||||
use crate::{is_nightly_channel, FormatReport, FormatReportFormatterBuilder, Input, Session};
|
||||
|
||||
mod configuration_snippet;
|
||||
mod mod_resolver;
|
||||
mod parser;
|
||||
|
||||
const DIFF_CONTEXT_SIZE: usize = 3;
|
||||
|
25
src/test/mod_resolver.rs
Normal file
25
src/test/mod_resolver.rs
Normal file
@ -0,0 +1,25 @@
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use super::read_config;
|
||||
|
||||
use crate::{FileName, Input, Session};
|
||||
|
||||
#[test]
|
||||
fn nested_out_of_line_mods_loaded() {
|
||||
// See also https://github.com/rust-lang/rustfmt/issues/4874
|
||||
let filename = "tests/mod-resolver/issue-4874/main.rs";
|
||||
let input_file = PathBuf::from(filename);
|
||||
let config = read_config(&input_file);
|
||||
let mut session = Session::<io::Stdout>::new(config, None);
|
||||
let report = session
|
||||
.format(Input::File(filename.into()))
|
||||
.expect("Should not have had any execution errors");
|
||||
let errors_by_file = &report.internal.borrow().0;
|
||||
assert!(errors_by_file.contains_key(&FileName::Real(PathBuf::from(
|
||||
"tests/mod-resolver/issue-4874/bar/baz.rs",
|
||||
))));
|
||||
assert!(errors_by_file.contains_key(&FileName::Real(PathBuf::from(
|
||||
"tests/mod-resolver/issue-4874/foo/qux.rs",
|
||||
))));
|
||||
}
|
5
tests/mod-resolver/issue-4874/bar/baz.rs
Normal file
5
tests/mod-resolver/issue-4874/bar/baz.rs
Normal file
@ -0,0 +1,5 @@
|
||||
fn
|
||||
fail_fmt_check
|
||||
(
|
||||
|
||||
) {}
|
1
tests/mod-resolver/issue-4874/foo.rs
Normal file
1
tests/mod-resolver/issue-4874/foo.rs
Normal file
@ -0,0 +1 @@
|
||||
mod qux;
|
5
tests/mod-resolver/issue-4874/foo/qux.rs
Normal file
5
tests/mod-resolver/issue-4874/foo/qux.rs
Normal file
@ -0,0 +1,5 @@
|
||||
fn
|
||||
badly_formatted
|
||||
(
|
||||
|
||||
) {}
|
8
tests/mod-resolver/issue-4874/main.rs
Normal file
8
tests/mod-resolver/issue-4874/main.rs
Normal file
@ -0,0 +1,8 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
||||
mod foo;
|
||||
mod bar {
|
||||
mod baz;
|
||||
}
|
Loading…
Reference in New Issue
Block a user