Skip to content

Commit 27420c6

Browse files
committed
Silence use foo::Bar; error if Bar isn't found in foo and foo.rs has parse errors
1 parent 69fb612 commit 27420c6

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

compiler/rustc_resolve/src/imports.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
670670

671671
fn throw_unresolved_import_error(
672672
&mut self,
673-
errors: Vec<(Import<'_>, UnresolvedImportError)>,
673+
mut errors: Vec<(Import<'_>, UnresolvedImportError)>,
674674
glob_error: bool,
675675
) {
676+
errors.retain(|(_import, err)| match err.module {
677+
// Skip `use` errors for `use foo::Bar;` if `foo.rs` has unrecovered parse errors.
678+
Some(def_id) if self.mods_with_parse_errors.contains(&def_id) => false,
679+
_ => true,
680+
});
676681
if errors.is_empty() {
677682
return;
678683
}

tests/ui/resolve/parse-error-resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mod parse_error;
2-
use parse_error::Canonical; //~ ERROR E0432
2+
use parse_error::Canonical; // ok, `parse_error.rs` had parse errors
33

44
fn main() {
55
let _ = "" + 1; //~ ERROR E0369

tests/ui/resolve/parse-error-resolve.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ help: you might have meant to end the type parameters here
99
LL | impl<S: Into<std::borrow::Cow<'static, str>>> From<S> for Canonical {
1010
| +
1111

12-
error[E0432]: unresolved import `parse_error::Canonical`
13-
--> $DIR/parse-error-resolve.rs:2:5
14-
|
15-
LL | use parse_error::Canonical;
16-
| ^^^^^^^^^^^^^^^^^^^^^^ no `Canonical` in `parse_error`
17-
1812
error[E0369]: cannot add `{integer}` to `&str`
1913
--> $DIR/parse-error-resolve.rs:5:16
2014
|
@@ -23,7 +17,6 @@ LL | let _ = "" + 1;
2317
| |
2418
| &str
2519

26-
error: aborting due to 3 previous errors
20+
error: aborting due to 2 previous errors
2721

28-
Some errors have detailed explanations: E0369, E0432.
29-
For more information about an error, try `rustc --explain E0369`.
22+
For more information about this error, try `rustc --explain E0369`.

0 commit comments

Comments
 (0)