about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-04-01 21:28:39 +0000
committerbors <bors@rust-lang.org>2025-04-01 21:28:39 +0000
commit9b7d5ac8180f70110e94f92ccbf8fa2263d24c73 (patch)
treecce198e428fef23c04ff18ed73617b8bf8f80dc8 /compiler/rustc_resolve/src
parente2014e876e3efaa69bf51c19579adb16c3df5f81 (diff)
parent99826dd9c79a8603b0f88d0b091cc86d0dec523f (diff)
downloadrust-9b7d5ac8180f70110e94f92ccbf8fa2263d24c73.tar.gz
rust-9b7d5ac8180f70110e94f92ccbf8fa2263d24c73.zip
Auto merge of #139220 - matthiaskrgr:rollup-v1un5wz, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #110406 (rustdoc-json: Add test for #[automatically_derived] attribute)
 - #138790 (Note potential but private items in show_candidates)
 - #139002 (Add release notes for 1.86.0)
 - #139022 (increment depth of nested obligations)
 - #139129 (Add tests for slice bounds check optimization)
 - #139188 (PassWrapper: adapt for llvm/llvm-project@94122d58fc77079a291a3d008914…)
 - #139193 (Feed HIR for by-move coroutine body def, since the inliner tries to read its attrs)
 - #139202 (Improve docs of ValTreeKind)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_resolve/src')
-rw-r--r--compiler/rustc_resolve/src/diagnostics.rs22
-rw-r--r--compiler/rustc_resolve/src/imports.rs2
2 files changed, 12 insertions, 12 deletions
diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs
index d886a81b57d..6dc854758da 100644
--- a/compiler/rustc_resolve/src/diagnostics.rs
+++ b/compiler/rustc_resolve/src/diagnostics.rs
@@ -1325,11 +1325,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
             })
         }
 
-        // If only some candidates are accessible, take just them
-        if !candidates.iter().all(|v: &ImportSuggestion| !v.accessible) {
-            candidates.retain(|x| x.accessible)
-        }
-
         candidates
     }
 
@@ -1793,7 +1788,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
                 &import_suggestions,
                 Instead::Yes,
                 FoundUse::Yes,
-                DiagMode::Import { append: single_nested },
+                DiagMode::Import { append: single_nested, unresolved_import: false },
                 vec![],
                 "",
             );
@@ -2750,6 +2745,8 @@ pub(crate) enum DiagMode {
     Pattern,
     /// The binding is part of a use statement
     Import {
+        /// `true` means diagnostics is for unresolved import
+        unresolved_import: bool,
         /// `true` mean add the tips afterward for case `use a::{b,c}`,
         /// rather than replacing within.
         append: bool,
@@ -2800,6 +2797,7 @@ fn show_candidates(
         return false;
     }
 
+    let mut showed = false;
     let mut accessible_path_strings: Vec<PathString<'_>> = Vec::new();
     let mut inaccessible_path_strings: Vec<PathString<'_>> = Vec::new();
 
@@ -2958,8 +2956,11 @@ fn show_candidates(
             append_candidates(&mut msg, accessible_path_strings);
             err.help(msg);
         }
-        true
-    } else if !(inaccessible_path_strings.is_empty() || matches!(mode, DiagMode::Import { .. })) {
+        showed = true;
+    }
+    if !inaccessible_path_strings.is_empty()
+        && (!matches!(mode, DiagMode::Import { unresolved_import: false, .. }))
+    {
         let prefix =
             if let DiagMode::Pattern = mode { "you might have meant to match on " } else { "" };
         if let [(name, descr, source_span, note, _)] = &inaccessible_path_strings[..] {
@@ -3022,10 +3023,9 @@ fn show_candidates(
 
             err.span_note(multi_span, msg);
         }
-        true
-    } else {
-        false
+        showed = true;
     }
+    showed
 }
 
 #[derive(Debug)]
diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs
index 454460e10dc..0b3633a452c 100644
--- a/compiler/rustc_resolve/src/imports.rs
+++ b/compiler/rustc_resolve/src/imports.rs
@@ -734,7 +734,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
                         &mut diag,
                         Some(err.span),
                         candidates,
-                        DiagMode::Import { append: false },
+                        DiagMode::Import { append: false, unresolved_import: true },
                         (source != target)
                             .then(|| format!(" as {target}"))
                             .as_deref()