Skip to content

Commit 621257d

Browse files
committed
Add ignore_missing_submod config option
1 parent ee2bed9 commit 621257d

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
@@ -1288,6 +1288,14 @@ If you want to ignore every file under the directory where you put your rustfmt.
12881288
ignore = ["/"]
12891289
```
12901290

1291+
## `ignore_missing_submod`
1292+
1293+
Ignore missing submodule error.
1294+
1295+
- **Default value**: `false`
1296+
- **Possible values**: `true`, `false`
1297+
- **Stable**: Yes
1298+
12911299
## `imports_indent`
12921300

12931301
Indent style of imports

src/config/mod.rs

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

177178
// Not user-facing
178179
verbose: Verbosity, Verbosity::Normal, false, "How much to information to emit to the user";
@@ -681,6 +682,7 @@ hide_parse_errors = false
681682
error_on_line_overflow = false
682683
error_on_unformatted = false
683684
ignore = []
685+
ignore_missing_submod = false
684686
emit_mode = "Files"
685687
make_backup = false
686688
"#,

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
@@ -61,6 +61,7 @@ pub(crate) struct ModResolver<'ast, 'sess> {
6161
directory: Directory,
6262
file_map: FileModMap<'ast>,
6363
recursive: bool,
64+
ignore_missing_submod: bool,
6465
}
6566

6667
/// Represents errors while trying to resolve modules.
@@ -104,6 +105,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
104105
parse_sess: &'sess ParseSess,
105106
directory_ownership: DirectoryOwnership,
106107
recursive: bool,
108+
ignore_missing_submod: bool,
107109
) -> Self {
108110
ModResolver {
109111
directory: Directory {
@@ -113,6 +115,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
113115
file_map: BTreeMap::new(),
114116
parse_sess,
115117
recursive,
118+
ignore_missing_submod,
116119
}
117120
}
118121

@@ -248,6 +251,14 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
248251
// mod foo;
249252
// Look for an extern file.
250253
self.find_external_module(item.ident, &item.attrs, sub_mod)
254+
.or_else(|err| match err.kind {
255+
ModuleResolutionErrorKind::NotFound { file: _ }
256+
if self.ignore_missing_submod =>
257+
{
258+
Ok(None)
259+
}
260+
_ => Err(err),
261+
})
251262
} else {
252263
// An internal module (`mod foo { /* ... */ }`);
253264
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)