Skip to content

Commit a860a72

Browse files
committed
Fix issue when there are multiple candidates for edit_distance_with_substrings
1 parent c90eb48 commit a860a72

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

compiler/rustc_span/src/edit_distance.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ pub fn find_best_match_for_name(
174174
fn find_best_match_for_name_impl(
175175
use_substring_score: bool,
176176
candidates: &[Symbol],
177-
lookup: Symbol,
177+
lookup_symbol: Symbol,
178178
dist: Option<usize>,
179179
) -> Option<Symbol> {
180-
let lookup = lookup.as_str();
180+
let lookup = lookup_symbol.as_str();
181181
let lookup_uppercase = lookup.to_uppercase();
182182

183183
// Priority of matches:
@@ -190,6 +190,7 @@ fn find_best_match_for_name_impl(
190190

191191
let mut dist = dist.unwrap_or_else(|| cmp::max(lookup.len(), 3) / 3);
192192
let mut best = None;
193+
let mut next_candidates = vec![];
193194
for c in candidates {
194195
match if use_substring_score {
195196
edit_distance_with_substrings(lookup, c.as_str(), dist)
@@ -198,12 +199,27 @@ fn find_best_match_for_name_impl(
198199
} {
199200
Some(0) => return Some(*c),
200201
Some(d) => {
201-
dist = d - 1;
202-
best = Some(*c);
202+
if use_substring_score {
203+
dist = d;
204+
next_candidates.push(*c);
205+
best = Some(*c);
206+
} else {
207+
dist = d - 1;
208+
best = Some(*c);
209+
}
203210
}
204211
None => {}
205212
}
206213
}
214+
215+
if next_candidates.len() > 1 {
216+
best = find_best_match_for_name_impl(
217+
false,
218+
&next_candidates,
219+
lookup_symbol,
220+
Some(lookup.len()),
221+
);
222+
}
207223
if best.is_some() {
208224
return best;
209225
}

tests/ui/suggestions/issue-109291.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
println!("Custom backtrace: {}", std::backtrace::Backtrace::forced_capture());
3+
//~^ ERROR no function or associated item name
4+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0599]: no function or associated item named `forced_capture` found for struct `Backtrace` in the current scope
2+
--> $DIR/issue-109291.rs:2:65
3+
|
4+
LL | println!("Custom backtrace: {}", std::backtrace::Backtrace::forced_capture());
5+
| ^^^^^^^^^^^^^^
6+
| |
7+
| function or associated item not found in `Backtrace`
8+
| help: there is an associated function with a similar name: `force_capture`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)