Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue when there are multiple candidates for edit_distance_with_substrings #109395

Merged
merged 3 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions compiler/rustc_span/src/edit_distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ pub fn find_best_match_for_name(
fn find_best_match_for_name_impl(
use_substring_score: bool,
candidates: &[Symbol],
lookup: Symbol,
lookup_symbol: Symbol,
dist: Option<usize>,
) -> Option<Symbol> {
let lookup = lookup.as_str();
let lookup = lookup_symbol.as_str();
let lookup_uppercase = lookup.to_uppercase();

// Priority of matches:
Expand All @@ -190,6 +190,7 @@ fn find_best_match_for_name_impl(

let mut dist = dist.unwrap_or_else(|| cmp::max(lookup.len(), 3) / 3);
let mut best = None;
let mut next_candidates = vec![];
chenyukang marked this conversation as resolved.
Show resolved Hide resolved
for c in candidates {
match if use_substring_score {
edit_distance_with_substrings(lookup, c.as_str(), dist)
Expand All @@ -198,12 +199,27 @@ fn find_best_match_for_name_impl(
} {
Some(0) => return Some(*c),
Some(d) => {
dist = d - 1;
best = Some(*c);
if use_substring_score {
dist = d;
next_candidates.push(*c);
best = Some(*c);
} else {
dist = d - 1;
best = Some(*c);
}
chenyukang marked this conversation as resolved.
Show resolved Hide resolved
}
None => {}
}
}

if next_candidates.len() > 1 {
chenyukang marked this conversation as resolved.
Show resolved Hide resolved
best = find_best_match_for_name_impl(
false,
&next_candidates,
lookup_symbol,
Some(lookup.len()),
);
}
if best.is_some() {
return best;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/suggestions/issue-109291.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
println!("Custom backtrace: {}", std::backtrace::Backtrace::forced_capture());
//~^ ERROR no function or associated item name
}
12 changes: 12 additions & 0 deletions tests/ui/suggestions/issue-109291.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0599]: no function or associated item named `forced_capture` found for struct `Backtrace` in the current scope
--> $DIR/issue-109291.rs:2:65
|
LL | println!("Custom backtrace: {}", std::backtrace::Backtrace::forced_capture());
| ^^^^^^^^^^^^^^
| |
| function or associated item not found in `Backtrace`
| help: there is an associated function with a similar name: `force_capture`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.