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