Skip to content
/ rust Public
forked from rust-lang/rust

Commit 2de51cc

Browse files
authored
Rollup merge of rust-lang#113920 - bvanjoi:fix-81413, r=petrochenkov
fix(resolve): report unresolved imports firstly Fixes rust-lang#81413 An easy fix, r? ```@petrochenkov```
2 parents 82c50ce + 1b18e2a commit 2de51cc

File tree

3 files changed

+64
-23
lines changed

3 files changed

+64
-23
lines changed

Diff for: compiler/rustc_resolve/src/imports.rs

+30-23
Original file line numberDiff line numberDiff line change
@@ -533,15 +533,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
533533
let indeterminate_imports = mem::take(&mut self.indeterminate_imports);
534534

535535
for (is_indeterminate, import) in determined_imports
536-
.into_iter()
536+
.iter()
537537
.map(|i| (false, i))
538-
.chain(indeterminate_imports.into_iter().map(|i| (true, i)))
538+
.chain(indeterminate_imports.iter().map(|i| (true, i)))
539539
{
540-
let unresolved_import_error = self.finalize_import(import);
540+
let unresolved_import_error = self.finalize_import(*import);
541541

542542
// If this import is unresolved then create a dummy import
543543
// resolution for it so that later resolve stages won't complain.
544-
self.import_dummy_binding(import, is_indeterminate);
544+
self.import_dummy_binding(*import, is_indeterminate);
545545

546546
if let Some(err) = unresolved_import_error {
547547
if let ImportKind::Single { source, ref source_bindings, .. } = import.kind {
@@ -563,27 +563,34 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
563563
errors = vec![];
564564
}
565565
if seen_spans.insert(err.span) {
566-
errors.push((import, err));
566+
errors.push((*import, err));
567567
prev_root_id = import.root_id;
568568
}
569-
} else if is_indeterminate {
570-
let path = import_path_to_string(
571-
&import.module_path.iter().map(|seg| seg.ident).collect::<Vec<_>>(),
572-
&import.kind,
573-
import.span,
574-
);
575-
let err = UnresolvedImportError {
576-
span: import.span,
577-
label: None,
578-
note: None,
579-
suggestion: None,
580-
candidates: None,
581-
};
582-
// FIXME: there should be a better way of doing this than
583-
// formatting this as a string then checking for `::`
584-
if path.contains("::") {
585-
errors.push((import, err))
586-
}
569+
}
570+
}
571+
572+
if !errors.is_empty() {
573+
self.throw_unresolved_import_error(errors);
574+
return;
575+
}
576+
577+
for import in &indeterminate_imports {
578+
let path = import_path_to_string(
579+
&import.module_path.iter().map(|seg| seg.ident).collect::<Vec<_>>(),
580+
&import.kind,
581+
import.span,
582+
);
583+
let err = UnresolvedImportError {
584+
span: import.span,
585+
label: None,
586+
note: None,
587+
suggestion: None,
588+
candidates: None,
589+
};
590+
// FIXME: there should be a better way of doing this than
591+
// formatting this as a string then checking for `::`
592+
if path.contains("::") {
593+
errors.push((*import, err))
587594
}
588595
}
589596

Diff for: tests/ui/imports/issue-81413.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pub const ITEM: Item = Item;
2+
3+
pub struct Item;
4+
5+
pub fn item() {}
6+
7+
pub use doesnt_exist::*;
8+
//~^ ERROR unresolved import `doesnt_exist`
9+
mod a {
10+
use crate::{item, Item, ITEM};
11+
}
12+
13+
mod b {
14+
use crate::item;
15+
use crate::Item;
16+
use crate::ITEM;
17+
}
18+
19+
mod c {
20+
use crate::item;
21+
}
22+
23+
fn main() {}

Diff for: tests/ui/imports/issue-81413.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0432]: unresolved import `doesnt_exist`
2+
--> $DIR/issue-81413.rs:7:9
3+
|
4+
LL | pub use doesnt_exist::*;
5+
| ^^^^^^^^^^^^ maybe a missing crate `doesnt_exist`?
6+
|
7+
= help: consider adding `extern crate doesnt_exist` to use the `doesnt_exist` crate
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)