Note alternative import candidates in nested use tree
This commit is contained in:
parent
564435f20a
commit
9e2536b938
@ -2309,7 +2309,7 @@ enum FoundUse {
|
||||
}
|
||||
|
||||
/// Whether a binding is part of a pattern or a use statement. Used for diagnostics.
|
||||
enum DiagnosticMode {
|
||||
pub(crate) enum DiagnosticMode {
|
||||
Normal,
|
||||
/// The binding is part of a pattern
|
||||
Pattern,
|
||||
@ -2324,6 +2324,7 @@ pub(crate) fn import_candidates(
|
||||
// This is `None` if all placement locations are inside expansions
|
||||
use_placement_span: Option<Span>,
|
||||
candidates: &[ImportSuggestion],
|
||||
mode: DiagnosticMode,
|
||||
) {
|
||||
show_candidates(
|
||||
session,
|
||||
@ -2333,7 +2334,7 @@ pub(crate) fn import_candidates(
|
||||
candidates,
|
||||
Instead::Yes,
|
||||
FoundUse::Yes,
|
||||
DiagnosticMode::Import,
|
||||
mode,
|
||||
vec![],
|
||||
);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! A bunch of methods and structures more or less related to resolving imports.
|
||||
|
||||
use crate::diagnostics::{import_candidates, Suggestion};
|
||||
use crate::diagnostics::{import_candidates, DiagnosticMode, Suggestion};
|
||||
use crate::Determinacy::{self, *};
|
||||
use crate::Namespace::*;
|
||||
use crate::{module_to_string, names_to_string, ImportSuggestion};
|
||||
@ -402,7 +402,7 @@ struct UnresolvedImportError {
|
||||
label: Option<String>,
|
||||
note: Option<String>,
|
||||
suggestion: Option<Suggestion>,
|
||||
candidate: Option<Vec<ImportSuggestion>>,
|
||||
candidates: Option<Vec<ImportSuggestion>>,
|
||||
}
|
||||
|
||||
pub struct ImportResolver<'a, 'b> {
|
||||
@ -489,7 +489,7 @@ pub fn finalize_imports(&mut self) {
|
||||
label: None,
|
||||
note: None,
|
||||
suggestion: None,
|
||||
candidate: None,
|
||||
candidates: None,
|
||||
};
|
||||
// FIXME: there should be a better way of doing this than
|
||||
// formatting this as a string then checking for `::`
|
||||
@ -545,15 +545,26 @@ fn throw_unresolved_import_error(&self, errors: Vec<(&Import<'_>, UnresolvedImpo
|
||||
diag.multipart_suggestion(&msg, suggestions, applicability);
|
||||
}
|
||||
|
||||
if let Some(candidate) = &err.candidate {
|
||||
if let Some(candidates) = &err.candidates {
|
||||
match &import.kind {
|
||||
ImportKind::Single { nested: false, .. } => import_candidates(
|
||||
self.r.session,
|
||||
&self.r.untracked.source_span,
|
||||
&mut diag,
|
||||
Some(err.span),
|
||||
&candidate,
|
||||
&candidates,
|
||||
DiagnosticMode::Import,
|
||||
),
|
||||
ImportKind::Single { nested: true, .. } => {
|
||||
import_candidates(
|
||||
self.r.session,
|
||||
&self.r.untracked.source_span,
|
||||
&mut diag,
|
||||
None,
|
||||
&candidates,
|
||||
DiagnosticMode::Normal,
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@ -717,14 +728,14 @@ fn finalize_import(&mut self, import: &'b Import<'b>) -> Option<UnresolvedImport
|
||||
String::from("a similar path exists"),
|
||||
Applicability::MaybeIncorrect,
|
||||
)),
|
||||
candidate: None,
|
||||
candidates: None,
|
||||
},
|
||||
None => UnresolvedImportError {
|
||||
span,
|
||||
label: Some(label),
|
||||
note: None,
|
||||
suggestion,
|
||||
candidate: None,
|
||||
candidates: None,
|
||||
},
|
||||
};
|
||||
return Some(err);
|
||||
@ -771,7 +782,7 @@ fn finalize_import(&mut self, import: &'b Import<'b>) -> Option<UnresolvedImport
|
||||
)),
|
||||
note: None,
|
||||
suggestion: None,
|
||||
candidate: None,
|
||||
candidates: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -953,7 +964,7 @@ fn finalize_import(&mut self, import: &'b Import<'b>) -> Option<UnresolvedImport
|
||||
label: Some(label),
|
||||
note,
|
||||
suggestion,
|
||||
candidate: if !parent_suggestion.is_empty() {
|
||||
candidates: if !parent_suggestion.is_empty() {
|
||||
Some(parent_suggestion)
|
||||
} else {
|
||||
None
|
||||
|
@ -1,14 +1,27 @@
|
||||
// edition: 2021
|
||||
|
||||
#![allow(unused)]
|
||||
|
||||
mod A {
|
||||
pub(crate) type AA = ();
|
||||
pub(crate) type BB = ();
|
||||
|
||||
mod A2 {
|
||||
use super::{super::C::D::AA, AA as _};
|
||||
//~^ ERROR unresolved import
|
||||
}
|
||||
}
|
||||
|
||||
mod C {}
|
||||
mod C {
|
||||
pub mod D {}
|
||||
}
|
||||
|
||||
mod B {
|
||||
use crate::C::{self, AA};
|
||||
//~^ ERROR unresolved import `crate::C::AA`
|
||||
//~^ ERROR unresolved import
|
||||
|
||||
use crate::{A, C::BB};
|
||||
//~^ ERROR unresolved import
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,9 +1,30 @@
|
||||
error[E0432]: unresolved import `super::super::C::D::AA`
|
||||
--> $DIR/bad-import-in-nested.rs:10:21
|
||||
|
|
||||
LL | use super::{super::C::D::AA, AA as _};
|
||||
| ^^^^^^^^^^^^^^^ no `AA` in `C::D`
|
||||
|
|
||||
= note: consider importing this type alias instead:
|
||||
crate::A::AA
|
||||
|
||||
error[E0432]: unresolved import `crate::C::AA`
|
||||
--> $DIR/bad-import-in-nested.rs:10:26
|
||||
--> $DIR/bad-import-in-nested.rs:20:26
|
||||
|
|
||||
LL | use crate::C::{self, AA};
|
||||
| ^^ no `AA` in `C`
|
||||
|
|
||||
= note: consider importing this type alias instead:
|
||||
crate::A::AA
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0432]: unresolved import `crate::C::BB`
|
||||
--> $DIR/bad-import-in-nested.rs:23:20
|
||||
|
|
||||
LL | use crate::{A, C::BB};
|
||||
| ^^^^^ no `BB` in `C`
|
||||
|
|
||||
= note: consider importing this type alias instead:
|
||||
crate::A::BB
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0432`.
|
||||
|
Loading…
Reference in New Issue
Block a user