Skip to content

Commit 6b12b6b

Browse files
committed
Keep track of parse errors in mods and don't emit resolve errors for paths involving them
When we expand a `mod foo;` and parse `foo.rs`, we now track whether that file had an unrecovered parse error that reached the end of the file. If so, we keep that information around. When resolving a path like `foo::bar`, we do not emit any errors for "`bar` not found in `foo`", as we know that the parse error might have caused `bar` to not be parsed and accounted for. When this happens in an existing project, every path referencing `foo` would be an irrelevant compile error. Instead, we now skip emitting anything until `foo.rs` is fixed. Tellingly enough, we didn't have any test for errors caused by `mod` expansion. Fix #97734.
1 parent 4e46d2f commit 6b12b6b

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

src/items.rs

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

src/modules.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,11 @@ 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, _, _))), _) | (_, Cow::Owned(items)) => {
323-
self.visit_mod_outside_ast(items)
324-
}
322+
(Some(Cow::Owned(ast::ModKind::Loaded(items, _, _, _))), _)
323+
| (_, Cow::Owned(items)) => self.visit_mod_outside_ast(items),
325324
(_, _) => Ok(()),
326325
}
327326
}

src/visitor.rs

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

930-
if let ast::ModKind::Loaded(ref items, ast::Inline::Yes, ref spans) = mod_kind {
930+
if let ast::ModKind::Loaded(ref items, ast::Inline::Yes, ref spans, _) = mod_kind {
931931
let ast::ModSpans {
932932
inner_span,
933933
inject_use_span: _,

0 commit comments

Comments
 (0)