mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-10 14:02:57 +00:00
fix: handle external mods imported via external->inline load hierarchy
This commit is contained in:
parent
e75c4d7ee9
commit
a5f85058ac
@ -321,7 +321,9 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
|
||||
(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),
|
||||
(Some(Cow::Owned(ast::ModKind::Loaded(items, _, _))), _) | (_, Cow::Owned(items)) => {
|
||||
self.visit_mod_outside_ast(items)
|
||||
}
|
||||
(_, _) => Ok(()),
|
||||
}
|
||||
}
|
||||
|
@ -5,21 +5,39 @@ 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);
|
||||
fn verify_mod_resolution(input_file_name: &str, exp_misformatted_files: &[&str]) {
|
||||
let input_file = PathBuf::from(input_file_name);
|
||||
let config = read_config(&input_file);
|
||||
let mut session = Session::<io::Stdout>::new(config, None);
|
||||
let report = session
|
||||
.format(Input::File(filename.into()))
|
||||
.format(Input::File(input_file_name.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",
|
||||
))));
|
||||
for exp_file in exp_misformatted_files {
|
||||
assert!(errors_by_file.contains_key(&FileName::Real(PathBuf::from(exp_file))));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_out_of_line_mods_loaded() {
|
||||
// See also https://github.com/rust-lang/rustfmt/issues/4874
|
||||
verify_mod_resolution(
|
||||
"tests/mod-resolver/issue-4874/main.rs",
|
||||
&[
|
||||
"tests/mod-resolver/issue-4874/bar/baz.rs",
|
||||
"tests/mod-resolver/issue-4874/foo/qux.rs",
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn out_of_line_nested_inline_within_out_of_line() {
|
||||
// See also https://github.com/rust-lang/rustfmt/issues/5063
|
||||
verify_mod_resolution(
|
||||
"tests/mod-resolver/issue-5063/main.rs",
|
||||
&[
|
||||
"tests/mod-resolver/issue-5063/foo/bar/baz.rs",
|
||||
"tests/mod-resolver/issue-5063/foo.rs",
|
||||
],
|
||||
);
|
||||
}
|
||||
|
2
tests/mod-resolver/issue-5063/foo.rs
Normal file
2
tests/mod-resolver/issue-5063/foo.rs
Normal file
@ -0,0 +1,2 @@
|
||||
mod bar {
|
||||
mod baz;}
|
1
tests/mod-resolver/issue-5063/foo/bar/baz.rs
Normal file
1
tests/mod-resolver/issue-5063/foo/bar/baz.rs
Normal file
@ -0,0 +1 @@
|
||||
fn baz() { }
|
5
tests/mod-resolver/issue-5063/main.rs
Normal file
5
tests/mod-resolver/issue-5063/main.rs
Normal file
@ -0,0 +1,5 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
||||
mod foo;
|
Loading…
Reference in New Issue
Block a user