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.
This commit is contained in:
Jubilee 2024-07-12 13:47:07 -07:00 committed by GitHub
commit afb2fbf692
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 125 additions and 6 deletions

View file

@ -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 }
};
(