Skip to content

Commit b9e2897

Browse files
committed
Add ignore_missing_submod config option
1 parent ead0fc9 commit b9e2897

File tree

7 files changed

+35
-0
lines changed

7 files changed

+35
-0
lines changed

Configurations.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,14 @@ If you want to ignore every file under the directory where you put your rustfmt.
13061306
ignore = ["/"]
13071307
```
13081308

1309+
## `ignore_missing_submod`
1310+
1311+
Ignore missing submodule error.
1312+
1313+
- **Default value**: `false`
1314+
- **Possible values**: `true`, `false`
1315+
- **Stable**: Yes
1316+
13091317
## `imports_indent`
13101318

13111319
Indent style of imports

src/config/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ create_config! {
179179
or they are left with trailing whitespaces";
180180
ignore: IgnoreList, IgnoreList::default(), false,
181181
"Skip formatting the specified files and directories";
182+
ignore_missing_submod: bool, false, true, "Ignore missing submodule error";
182183

183184
// Not user-facing
184185
verbose: Verbosity, Verbosity::Normal, false, "How much to information to emit to the user";
@@ -697,6 +698,7 @@ show_parse_errors = true
697698
error_on_line_overflow = false
698699
error_on_unformatted = false
699700
ignore = []
701+
ignore_missing_submod = false
700702
emit_mode = "Files"
701703
make_backup = false
702704
"#,

src/formatting.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ fn format_project<T: FormatHandler>(
135135
&context.parse_session,
136136
directory_ownership.unwrap_or(DirectoryOwnership::UnownedViaBlock),
137137
!input_is_stdin && !config.skip_children(),
138+
config.ignore_missing_submod(),
138139
)
139140
.visit_crate(&krate)?
140141
.into_iter()

src/modules.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub(crate) struct ModResolver<'ast, 'sess> {
6262
directory: Directory,
6363
file_map: FileModMap<'ast>,
6464
recursive: bool,
65+
ignore_missing_submod: bool,
6566
}
6667

6768
/// Represents errors while trying to resolve modules.
@@ -105,6 +106,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
105106
parse_sess: &'sess ParseSess,
106107
directory_ownership: DirectoryOwnership,
107108
recursive: bool,
109+
ignore_missing_submod: bool,
108110
) -> Self {
109111
ModResolver {
110112
directory: Directory {
@@ -114,6 +116,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
114116
file_map: BTreeMap::new(),
115117
parse_sess,
116118
recursive,
119+
ignore_missing_submod,
117120
}
118121
}
119122

@@ -249,6 +252,14 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
249252
// mod foo;
250253
// Look for an extern file.
251254
self.find_external_module(item.ident, &item.attrs, sub_mod)
255+
.or_else(|err| match err.kind {
256+
ModuleResolutionErrorKind::NotFound { file: _ }
257+
if self.ignore_missing_submod =>
258+
{
259+
Ok(None)
260+
}
261+
_ => Err(err),
262+
})
252263
} else {
253264
// An internal module (`mod foo { /* ... */ }`);
254265
Ok(Some(SubModKind::Internal(item)))

tests/config/issue-5609.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignore_missing_submod = true

tests/source/issue-5609.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// rustfmt-config: issue-5609.toml
2+
3+
mod missing_submod;
4+
5+
fn test() {
6+
7+
}

tests/target/issue-5609.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// rustfmt-config: issue-5609.toml
2+
3+
mod missing_submod;
4+
5+
fn test() {}

0 commit comments

Comments
 (0)