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

Commit 1b18e2a

Browse files
committed
fix(resolve): report unresolved imports firstly
1 parent b95fd85 commit 1b18e2a

File tree

3 files changed

+64
-23
lines changed

3 files changed

+64
-23
lines changed

compiler/rustc_resolve/src/imports.rs

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

477477
for (is_indeterminate, import) in determined_imports
478-
.into_iter()
478+
.iter()
479479
.map(|i| (false, i))
480-
.chain(indeterminate_imports.into_iter().map(|i| (true, i)))
480+
.chain(indeterminate_imports.iter().map(|i| (true, i)))
481481
{
482-
let unresolved_import_error = self.finalize_import(import);
482+
let unresolved_import_error = self.finalize_import(*import);
483483

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

488488
if let Some(err) = unresolved_import_error {
489489
if let ImportKind::Single { source, ref source_bindings, .. } = import.kind {
@@ -505,27 +505,34 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
505505
errors = vec![];
506506
}
507507
if seen_spans.insert(err.span) {
508-
errors.push((import, err));
508+
errors.push((*import, err));
509509
prev_root_id = import.root_id;
510510
}
511-
} else if is_indeterminate {
512-
let path = import_path_to_string(
513-
&import.module_path.iter().map(|seg| seg.ident).collect::<Vec<_>>(),
514-
&import.kind,
515-
import.span,
516-
);
517-
let err = UnresolvedImportError {
518-
span: import.span,
519-
label: None,
520-
note: None,
521-
suggestion: None,
522-
candidates: None,
523-
};
524-
// FIXME: there should be a better way of doing this than
525-
// formatting this as a string then checking for `::`
526-
if path.contains("::") {
527-
errors.push((import, err))
528-
}
511+
}
512+
}
513+
514+
if !errors.is_empty() {
515+
self.throw_unresolved_import_error(errors);
516+
return;
517+
}
518+
519+
for import in &indeterminate_imports {
520+
let path = import_path_to_string(
521+
&import.module_path.iter().map(|seg| seg.ident).collect::<Vec<_>>(),
522+
&import.kind,
523+
import.span,
524+
);
525+
let err = UnresolvedImportError {
526+
span: import.span,
527+
label: None,
528+
note: None,
529+
suggestion: None,
530+
candidates: None,
531+
};
532+
// FIXME: there should be a better way of doing this than
533+
// formatting this as a string then checking for `::`
534+
if path.contains("::") {
535+
errors.push((*import, err))
529536
}
530537
}
531538

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() {}

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)