Skip to content

Commit

Permalink
Silence use foo::Bar; error if Bar isn't found in foo and `foo.…
Browse files Browse the repository at this point in the history
…rs` has parse errors
  • Loading branch information
estebank committed Dec 10, 2024
1 parent 69fb612 commit 27420c6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
7 changes: 6 additions & 1 deletion compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

fn throw_unresolved_import_error(
&mut self,
errors: Vec<(Import<'_>, UnresolvedImportError)>,
mut errors: Vec<(Import<'_>, UnresolvedImportError)>,
glob_error: bool,
) {
errors.retain(|(_import, err)| match err.module {
// Skip `use` errors for `use foo::Bar;` if `foo.rs` has unrecovered parse errors.
Some(def_id) if self.mods_with_parse_errors.contains(&def_id) => false,
_ => true,
});
if errors.is_empty() {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/resolve/parse-error-resolve.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod parse_error;
use parse_error::Canonical; //~ ERROR E0432
use parse_error::Canonical; // ok, `parse_error.rs` had parse errors

fn main() {
let _ = "" + 1; //~ ERROR E0369
Expand Down
11 changes: 2 additions & 9 deletions tests/ui/resolve/parse-error-resolve.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ help: you might have meant to end the type parameters here
LL | impl<S: Into<std::borrow::Cow<'static, str>>> From<S> for Canonical {
| +

error[E0432]: unresolved import `parse_error::Canonical`
--> $DIR/parse-error-resolve.rs:2:5
|
LL | use parse_error::Canonical;
| ^^^^^^^^^^^^^^^^^^^^^^ no `Canonical` in `parse_error`

error[E0369]: cannot add `{integer}` to `&str`
--> $DIR/parse-error-resolve.rs:5:16
|
Expand All @@ -23,7 +17,6 @@ LL | let _ = "" + 1;
| |
| &str

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

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

0 comments on commit 27420c6

Please sign in to comment.