about summary refs log tree commit diff
path: root/compiler/rustc_resolve
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-12-27 07:05:45 +0000
committerMichael Goulet <michael@errs.io>2022-12-27 07:05:45 +0000
commitd2404d6dca59d34d5b9f0c66b425b08229f20f4b (patch)
tree723f17825489931226a86ac4d14c8b0032d5cd91 /compiler/rustc_resolve
parent9e2536b9389f56386d7f722b403d9730911ee811 (diff)
downloadrust-d2404d6dca59d34d5b9f0c66b425b08229f20f4b.tar.gz
rust-d2404d6dca59d34d5b9f0c66b425b08229f20f4b.zip
Dont clobber `as ..` rename in import suggestion
Diffstat (limited to 'compiler/rustc_resolve')
-rw-r--r--compiler/rustc_resolve/src/diagnostics.rs9
-rw-r--r--compiler/rustc_resolve/src/imports.rs6
2 files changed, 12 insertions, 3 deletions
diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs
index 2e28dad52c7..c8b96aae7a6 100644
--- a/compiler/rustc_resolve/src/diagnostics.rs
+++ b/compiler/rustc_resolve/src/diagnostics.rs
@@ -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(
diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs
index b3593fc9e47..d99c1cb6d3c 100644
--- a/compiler/rustc_resolve/src/imports.rs
+++ b/compiler/rustc_resolve/src/imports.rs
@@ -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(),
                         );
                     }
                     _ => {}