Rollup merge of #125381 - estebank:issue-96799, r=petrochenkov
Silence some resolve errors when there have been glob import errors When encountering `use foo::*;` where `foo` fails to be found, and we later encounter resolution errors, we silence those later errors. A single case of the above, for an *existing* import on a big codebase would otherwise have a huge number of knock-down spurious errors. Ideally, instead of a global flag to silence all subsequent resolve errors, we'd want to introduce an unnameable binding in the appropriate rib as a sentinel when there's a failed glob import, so when we encounter a resolve error we can search for that sentinel and if found, and only then, silence that error. The current approach is just a quick proof of concept to iterate over. Partially address #96799.
This commit is contained in:
commit
bc1a069ec5
11 changed files with 131 additions and 19 deletions
|
@ -537,6 +537,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
let determined_imports = mem::take(&mut self.determined_imports);
|
||||
let indeterminate_imports = mem::take(&mut self.indeterminate_imports);
|
||||
|
||||
let mut glob_error = false;
|
||||
for (is_indeterminate, import) in determined_imports
|
||||
.iter()
|
||||
.map(|i| (false, i))
|
||||
|
@ -548,6 +549,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
self.import_dummy_binding(*import, is_indeterminate);
|
||||
|
||||
if let Some(err) = unresolved_import_error {
|
||||
glob_error |= import.is_glob();
|
||||
|
||||
if let ImportKind::Single { source, ref source_bindings, .. } = import.kind {
|
||||
if source.name == kw::SelfLower {
|
||||
// Silence `unresolved import` error if E0429 is already emitted
|
||||
|
@ -563,7 +566,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
{
|
||||
// In the case of a new import line, throw a diagnostic message
|
||||
// for the previous line.
|
||||
self.throw_unresolved_import_error(errors);
|
||||
self.throw_unresolved_import_error(errors, glob_error);
|
||||
errors = vec![];
|
||||
}
|
||||
if seen_spans.insert(err.span) {
|
||||
|
@ -574,7 +577,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
}
|
||||
|
||||
if !errors.is_empty() {
|
||||
self.throw_unresolved_import_error(errors);
|
||||
self.throw_unresolved_import_error(errors, glob_error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -600,9 +603,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
if !errors.is_empty() {
|
||||
self.throw_unresolved_import_error(errors);
|
||||
}
|
||||
self.throw_unresolved_import_error(errors, glob_error);
|
||||
}
|
||||
|
||||
pub(crate) fn check_hidden_glob_reexports(
|
||||
|
@ -672,7 +673,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn throw_unresolved_import_error(&mut self, errors: Vec<(Import<'_>, UnresolvedImportError)>) {
|
||||
fn throw_unresolved_import_error(
|
||||
&mut self,
|
||||
errors: Vec<(Import<'_>, UnresolvedImportError)>,
|
||||
glob_error: bool,
|
||||
) {
|
||||
if errors.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
@ -751,7 +756,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
diag.emit();
|
||||
let guar = diag.emit();
|
||||
if glob_error {
|
||||
self.glob_error = Some(guar);
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempts to resolve the given import, returning:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue