about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
diff options
context:
space:
mode:
authorJubilee <46493976+workingjubilee@users.noreply.github.com>2024-07-12 13:47:07 -0700
committerGitHub <noreply@github.com>2024-07-12 13:47:07 -0700
commitafb2fbf6926e64479f885295fa0a7da27f4040a2 (patch)
tree3e1fd37b8805a40277007ea20656e1594ce8496c /compiler/rustc_resolve/src
parenta6a7129827f942a58783feec4320807774dae6ec (diff)
parentfe5581dd31eb1b86c915e5c3eaae9ebfdea28037 (diff)
downloadrust-afb2fbf6926e64479f885295fa0a7da27f4040a2.tar.gz
rust-afb2fbf6926e64479f885295fa0a7da27f4040a2.zip
Rollup merge of #127310 - chenyukang:yukang-fix-suggest-import-ice, r=estebank
Fix import suggestion ice

Fixes #127302

#127302 only crash in edition 2015
#120074 can only reproduced in edition 2021
so I added revisions in test file.
Diffstat (limited to 'compiler/rustc_resolve/src')
-rw-r--r--compiler/rustc_resolve/src/diagnostics.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs
index 09221041031..e3917acce65 100644
--- a/compiler/rustc_resolve/src/diagnostics.rs
+++ b/compiler/rustc_resolve/src/diagnostics.rs
@@ -1992,12 +1992,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
             if let Some(candidate) = candidates.get(0) {
                 let path = {
                     // remove the possible common prefix of the path
-                    let start_index = (0..failed_segment_idx)
-                        .find(|&i| path[i].ident != candidate.path.segments[i].ident)
+                    let len = candidate.path.segments.len();
+                    let start_index = (0..=failed_segment_idx.min(len - 1))
+                        .find(|&i| path[i].ident.name != candidate.path.segments[i].ident.name)
                         .unwrap_or_default();
-                    let segments = (start_index..=failed_segment_idx)
-                        .map(|s| candidate.path.segments[s].clone())
-                        .collect();
+                    let segments =
+                        (start_index..len).map(|s| candidate.path.segments[s].clone()).collect();
                     Path { segments, span: Span::default(), tokens: None }
                 };
                 (