Rollup merge of #113920 - bvanjoi:fix-81413, r=petrochenkov
fix(resolve): report unresolved imports firstly Fixes #81413 An easy fix, r? ```@petrochenkov```
This commit is contained in:
commit
2de51cce90
@ -533,15 +533,15 @@ pub(crate) fn finalize_imports(&mut self) {
|
||||
let indeterminate_imports = mem::take(&mut self.indeterminate_imports);
|
||||
|
||||
for (is_indeterminate, import) in determined_imports
|
||||
.into_iter()
|
||||
.iter()
|
||||
.map(|i| (false, i))
|
||||
.chain(indeterminate_imports.into_iter().map(|i| (true, i)))
|
||||
.chain(indeterminate_imports.iter().map(|i| (true, i)))
|
||||
{
|
||||
let unresolved_import_error = self.finalize_import(import);
|
||||
let unresolved_import_error = self.finalize_import(*import);
|
||||
|
||||
// If this import is unresolved then create a dummy import
|
||||
// resolution for it so that later resolve stages won't complain.
|
||||
self.import_dummy_binding(import, is_indeterminate);
|
||||
self.import_dummy_binding(*import, is_indeterminate);
|
||||
|
||||
if let Some(err) = unresolved_import_error {
|
||||
if let ImportKind::Single { source, ref source_bindings, .. } = import.kind {
|
||||
@ -563,27 +563,34 @@ pub(crate) fn finalize_imports(&mut self) {
|
||||
errors = vec![];
|
||||
}
|
||||
if seen_spans.insert(err.span) {
|
||||
errors.push((import, err));
|
||||
errors.push((*import, err));
|
||||
prev_root_id = import.root_id;
|
||||
}
|
||||
} else if is_indeterminate {
|
||||
let path = import_path_to_string(
|
||||
&import.module_path.iter().map(|seg| seg.ident).collect::<Vec<_>>(),
|
||||
&import.kind,
|
||||
import.span,
|
||||
);
|
||||
let err = UnresolvedImportError {
|
||||
span: import.span,
|
||||
label: None,
|
||||
note: None,
|
||||
suggestion: None,
|
||||
candidates: None,
|
||||
};
|
||||
// FIXME: there should be a better way of doing this than
|
||||
// formatting this as a string then checking for `::`
|
||||
if path.contains("::") {
|
||||
errors.push((import, err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !errors.is_empty() {
|
||||
self.throw_unresolved_import_error(errors);
|
||||
return;
|
||||
}
|
||||
|
||||
for import in &indeterminate_imports {
|
||||
let path = import_path_to_string(
|
||||
&import.module_path.iter().map(|seg| seg.ident).collect::<Vec<_>>(),
|
||||
&import.kind,
|
||||
import.span,
|
||||
);
|
||||
let err = UnresolvedImportError {
|
||||
span: import.span,
|
||||
label: None,
|
||||
note: None,
|
||||
suggestion: None,
|
||||
candidates: None,
|
||||
};
|
||||
// FIXME: there should be a better way of doing this than
|
||||
// formatting this as a string then checking for `::`
|
||||
if path.contains("::") {
|
||||
errors.push((*import, err))
|
||||
}
|
||||
}
|
||||
|
||||
|
23
tests/ui/imports/issue-81413.rs
Normal file
23
tests/ui/imports/issue-81413.rs
Normal file
@ -0,0 +1,23 @@
|
||||
pub const ITEM: Item = Item;
|
||||
|
||||
pub struct Item;
|
||||
|
||||
pub fn item() {}
|
||||
|
||||
pub use doesnt_exist::*;
|
||||
//~^ ERROR unresolved import `doesnt_exist`
|
||||
mod a {
|
||||
use crate::{item, Item, ITEM};
|
||||
}
|
||||
|
||||
mod b {
|
||||
use crate::item;
|
||||
use crate::Item;
|
||||
use crate::ITEM;
|
||||
}
|
||||
|
||||
mod c {
|
||||
use crate::item;
|
||||
}
|
||||
|
||||
fn main() {}
|
11
tests/ui/imports/issue-81413.stderr
Normal file
11
tests/ui/imports/issue-81413.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error[E0432]: unresolved import `doesnt_exist`
|
||||
--> $DIR/issue-81413.rs:7:9
|
||||
|
|
||||
LL | pub use doesnt_exist::*;
|
||||
| ^^^^^^^^^^^^ maybe a missing crate `doesnt_exist`?
|
||||
|
|
||||
= help: consider adding `extern crate doesnt_exist` to use the `doesnt_exist` crate
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0432`.
|
Loading…
Reference in New Issue
Block a user