Skip to content

Commit b63507d

Browse files
committed
Prevent impossible combinations in ast::ModKind.
`ModKind::Loaded` has an `inline` field and a `had_parse_error` field. If the `inline` field is `Inline::Yes` then `had_parse_error` must be `Ok(())`. This commit moves the `had_parse_error` field into the `Inline::No` variant. This makes it impossible to create the nonsensical combination of `inline == Inline::Yes` and `had_parse_error = Err(_)`.
1 parent c9ee26f commit b63507d

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3600,7 +3600,7 @@ pub(crate) fn rewrite_extern_crate(
36003600
pub(crate) fn is_mod_decl(item: &ast::Item) -> bool {
36013601
!matches!(
36023602
item.kind,
3603-
ast::ItemKind::Mod(_, _, ast::ModKind::Loaded(_, ast::Inline::Yes, _, _))
3603+
ast::ItemKind::Mod(_, _, ast::ModKind::Loaded(_, ast::Inline::Yes, _))
36043604
)
36053605
}
36063606

src/modules.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,12 @@ impl<'ast, 'psess, 'c> ModResolver<'ast, 'psess> {
316316
self.directory = directory;
317317
}
318318
match (sub_mod.ast_mod_kind, sub_mod.items) {
319-
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, _, _, _))), _) => {
319+
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, _, _))), _) => {
320320
self.visit_mod_from_ast(items)
321321
}
322-
(Some(Cow::Owned(ast::ModKind::Loaded(items, _, _, _))), _)
323-
| (_, Cow::Owned(items)) => self.visit_mod_outside_ast(items),
322+
(Some(Cow::Owned(ast::ModKind::Loaded(items, _, _))), _) | (_, Cow::Owned(items)) => {
323+
self.visit_mod_outside_ast(items)
324+
}
324325
(_, _) => Ok(()),
325326
}
326327
}

src/visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
942942
let ident_str = rewrite_ident(&self.get_context(), ident).to_owned();
943943
self.push_str(&ident_str);
944944

945-
if let ast::ModKind::Loaded(ref items, ast::Inline::Yes, ref spans, _) = mod_kind {
945+
if let ast::ModKind::Loaded(ref items, ast::Inline::Yes, ref spans) = mod_kind {
946946
let ast::ModSpans {
947947
inner_span,
948948
inject_use_span: _,

0 commit comments

Comments
 (0)