Dont clobber as ..
rename in import suggestion
This commit is contained in:
parent
9e2536b938
commit
d2404d6dca
5 changed files with 55 additions and 5 deletions
|
@ -161,6 +161,7 @@ impl<'a> Resolver<'a> {
|
|||
found_use,
|
||||
DiagnosticMode::Normal,
|
||||
path,
|
||||
None,
|
||||
);
|
||||
err.emit();
|
||||
} else if let Some((span, msg, sugg, appl)) = suggestion {
|
||||
|
@ -690,6 +691,7 @@ impl<'a> Resolver<'a> {
|
|||
FoundUse::Yes,
|
||||
DiagnosticMode::Pattern,
|
||||
vec![],
|
||||
None,
|
||||
);
|
||||
}
|
||||
err
|
||||
|
@ -1344,6 +1346,7 @@ impl<'a> Resolver<'a> {
|
|||
FoundUse::Yes,
|
||||
DiagnosticMode::Normal,
|
||||
vec![],
|
||||
None,
|
||||
);
|
||||
|
||||
if macro_kind == MacroKind::Derive && (ident.name == sym::Send || ident.name == sym::Sync) {
|
||||
|
@ -2325,6 +2328,7 @@ pub(crate) fn import_candidates(
|
|||
use_placement_span: Option<Span>,
|
||||
candidates: &[ImportSuggestion],
|
||||
mode: DiagnosticMode,
|
||||
append: Option<&str>,
|
||||
) {
|
||||
show_candidates(
|
||||
session,
|
||||
|
@ -2336,6 +2340,7 @@ pub(crate) fn import_candidates(
|
|||
FoundUse::Yes,
|
||||
mode,
|
||||
vec![],
|
||||
append,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2353,10 +2358,12 @@ fn show_candidates(
|
|||
found_use: FoundUse,
|
||||
mode: DiagnosticMode,
|
||||
path: Vec<Segment>,
|
||||
append: Option<&str>,
|
||||
) {
|
||||
if candidates.is_empty() {
|
||||
return;
|
||||
}
|
||||
let append = append.unwrap_or("");
|
||||
|
||||
let mut accessible_path_strings: Vec<(String, &str, Option<DefId>, &Option<String>)> =
|
||||
Vec::new();
|
||||
|
@ -2417,7 +2424,7 @@ fn show_candidates(
|
|||
// produce an additional newline to separate the new use statement
|
||||
// from the directly following item.
|
||||
let additional_newline = if let FoundUse::Yes = found_use { "" } else { "\n" };
|
||||
candidate.0 = format!("{}{};\n{}", add_use, &candidate.0, additional_newline);
|
||||
candidate.0 = format!("{add_use}{}{append};\n{additional_newline}", &candidate.0);
|
||||
}
|
||||
|
||||
err.span_suggestions(
|
||||
|
|
|
@ -547,15 +547,16 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
|||
|
||||
if let Some(candidates) = &err.candidates {
|
||||
match &import.kind {
|
||||
ImportKind::Single { nested: false, .. } => import_candidates(
|
||||
ImportKind::Single { nested: false, source, target, .. } => import_candidates(
|
||||
self.r.session,
|
||||
&self.r.untracked.source_span,
|
||||
&mut diag,
|
||||
Some(err.span),
|
||||
&candidates,
|
||||
DiagnosticMode::Import,
|
||||
(source != target).then(|| format!(" as {target}")).as_deref(),
|
||||
),
|
||||
ImportKind::Single { nested: true, .. } => {
|
||||
ImportKind::Single { nested: true, source, target, .. } => {
|
||||
import_candidates(
|
||||
self.r.session,
|
||||
&self.r.untracked.source_span,
|
||||
|
@ -563,6 +564,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
|||
None,
|
||||
&candidates,
|
||||
DiagnosticMode::Normal,
|
||||
(source != target).then(|| format!(" as {target}")).as_deref(),
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
|
|
16
src/test/ui/imports/bad-import-with-rename.rs
Normal file
16
src/test/ui/imports/bad-import-with-rename.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
mod A {
|
||||
pub type B = ();
|
||||
pub type B2 = ();
|
||||
}
|
||||
|
||||
mod C {
|
||||
use crate::D::B as _;
|
||||
//~^ ERROR unresolved import `crate::D::B`
|
||||
|
||||
use crate::D::B2;
|
||||
//~^ ERROR unresolved import `crate::D::B2`
|
||||
}
|
||||
|
||||
mod D {}
|
||||
|
||||
fn main() {}
|
25
src/test/ui/imports/bad-import-with-rename.stderr
Normal file
25
src/test/ui/imports/bad-import-with-rename.stderr
Normal file
|
@ -0,0 +1,25 @@
|
|||
error[E0432]: unresolved import `crate::D::B`
|
||||
--> $DIR/bad-import-with-rename.rs:7:9
|
||||
|
|
||||
LL | use crate::D::B as _;
|
||||
| ^^^^^^^^^^^^^^^^ no `B` in `D`
|
||||
|
|
||||
help: consider importing this type alias instead
|
||||
|
|
||||
LL | use A::B as _;
|
||||
| ~~~~~~~~~~
|
||||
|
||||
error[E0432]: unresolved import `crate::D::B2`
|
||||
--> $DIR/bad-import-with-rename.rs:10:9
|
||||
|
|
||||
LL | use crate::D::B2;
|
||||
| ^^^^^^^^^^^^ no `B2` in `D`
|
||||
|
|
||||
help: consider importing this type alias instead
|
||||
|
|
||||
LL | use A::B2;
|
||||
| ~~~~~~
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0432`.
|
|
@ -19,8 +19,8 @@ LL | use test as y;
|
|||
| ~~~~
|
||||
help: consider importing this module instead
|
||||
|
|
||||
LL | use test::test;
|
||||
| ~~~~~~~~~~~
|
||||
LL | use test::test as y;
|
||||
| ~~~~~~~~~~~~~~~~
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue