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.
This commit is contained in:
Esteban Küber 2024-12-05 21:19:08 +00:00
parent 3f52583c6a
commit 69fb612608
26 changed files with 128 additions and 93 deletions

View file

@ -4,22 +4,5 @@ error: circular modules: $DIR/circular_modules_main.rs -> $DIR/circular_modules_
LL | mod circular_modules_main;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0425]: cannot find function `hi_str` in module `circular_modules_main`
--> $DIR/circular_modules_hello.rs:7:43
|
LL | println!("{}", circular_modules_main::hi_str());
| ^^^^^^ not found in `circular_modules_main`
|
help: consider importing this function
|
LL + use hi_str;
|
help: if you import `hi_str`, refer to it directly
|
LL - println!("{}", circular_modules_main::hi_str());
LL + println!("{}", hi_str());
|
error: aborting due to 1 previous error
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0425`.

View file

@ -3,5 +3,5 @@ use parse_error::Canonical; //~ ERROR E0432
fn main() {
let _ = "" + 1; //~ ERROR E0369
parse_error::Canonical.foo(); //~ ERROR E0425
parse_error::Canonical.foo(); // ok, `parse_error.rs` had parse errors
}

View file

@ -15,12 +15,6 @@ error[E0432]: unresolved import `parse_error::Canonical`
LL | use parse_error::Canonical;
| ^^^^^^^^^^^^^^^^^^^^^^ no `Canonical` in `parse_error`
error[E0425]: cannot find value `Canonical` in module `parse_error`
--> $DIR/parse-error-resolve.rs:6:18
|
LL | parse_error::Canonical.foo();
| ^^^^^^^^^ not found in `parse_error`
error[E0369]: cannot add `{integer}` to `&str`
--> $DIR/parse-error-resolve.rs:5:16
|
@ -29,7 +23,7 @@ LL | let _ = "" + 1;
| |
| &str
error: aborting due to 4 previous errors
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0369, E0425, E0432.
Some errors have detailed explanations: E0369, E0432.
For more information about an error, try `rustc --explain E0369`.