Change:
Given the following code: The current output is: <!-- The following is not always necessary. --Ideally the output should include a note suggesting the variant with the same name (but different case):
label +C-enhancement +D-newcomer-roadblock
This only doesn't Just Work because the Levenshtein thing is case sensitive, right? There is some special-casing for case-insensitive suggestions but afaict it only applies if the case-sensitive Levenshtein distance is also already low, which seems wrong at first glance.
im working on this Edit: I'm not working on this anymore because I ran out of time getting past incremental compilation / llvm errors after a rebase.
Okay, judging by , this is explicitly not supposed to work. shrug emoji Edit: Okay, maybe that test case didn't really care. The use of case-insensitive match as tie breaker for equal levenshtein distance only was introduced with afaict.

Discussion:
let lookup = &lookup.as_str(); let max_dist = dist.unwrap_or_else(|| cmp::max(lookup.len(), 3) / 3); <del> let (case_insensitive_match, levenshtein_match) = name_vec </del> <ins> // Priority of matches: // 1. Exact case insensitive match // 2. Levenshtein distance match // 3. Sorted word match if let Some(case_insensitive_match) = name_vec.iter().find(|candidate| candidate.as_str().to_uppercase() == lookup.to_uppercase()) { return Some(*case_insensitive_match); } let levenshtein_match = name_vec </ins> .iter() .filter_map(|&name| { let dist = lev_distance(lookup, &name.as_str()); if dist <= max_dist { Some((name, dist)) } else { None } }) // Here we are collecting the next structure: <del> // (case_insensitive_match, (levenshtein_match, levenshtein_distance)) .fold((None, None), |result, (candidate, dist)| { ( if candidate.as_str().to_uppercase() == lookup.to_uppercase() { Some(candidate) } else { result.0 }, match result.1 { None => Some((candidate, dist)), Some((c, d)) => Some(if dist < d { (candidate, dist) } else { (c, d) }), }, ) </del> <ins> // (levenshtein_match, levenshtein_distance) .fold(None, |result, (candidate, dist)| match result { None => Some((candidate, dist)), Some((c, d)) => Some(if dist < d { (candidate, dist) } else { (c, d) }), </ins> }); <del> // Priority of matches: // 1. Exact case insensitive match // 2. Levenshtein distance match // 3. Sorted word match if let Some(candidate) = case_insensitive_match { Some(candidate) } else if levenshtein_match.is_some() { </del> <ins> if levenshtein_match.is_some() { </ins> levenshtein_match.map(|(candidate, _)| candidate) } else { find_match_by_sorted_words(name_vec, lookup)

assert_eq!(find_best_match_for_name(&input, Symbol::intern("1111111111"), None), None); <del> let input = vec![Symbol::intern("aAAA")]; </del> <ins> let input = vec![Symbol::intern("AAAA")]; </ins> assert_eq!( <del> find_best_match_for_name(&input, Symbol::intern("AAAA"), None), Some(Symbol::intern("aAAA")) </del> <ins> find_best_match_for_name(&input, Symbol::intern("aaaa"), None), Some(Symbol::intern("AAAA")) </ins> ); let input = vec![Symbol::intern("AAAA")]; <del> // Returns None because `lev_distance > max_dist / 3` assert_eq!(find_best_match_for_name(&input, Symbol::intern("aaaa"), None), None); let input = vec![Symbol::intern("AAAA")]; </del> assert_eq!( find_best_match_for_name(&input, Symbol::intern("aaaa"), Some(4)), Some(Symbol::intern("AAAA"))

--> $DIR/rustc-macro-transparency.rs:26:5 | LL |     Opaque; <del> |     ^^^^^^ help: a local variable with a similar name exists (notice the capitalization): `opaque` </del> <ins> |     ^^^^^^ not found in this scope </ins> error[E0423]: expected value, found macro `semitransparent` --> $DIR/rustc-macro-transparency.rs:29:5 | <ins> LL |     struct SemiTransparent; |     ----------------------- similarly named unit struct `SemiTransparent` defined here ... </ins> LL |     semitransparent; |     ^^^^^^^^^^^^^^^ not a value |

| LL |     semitransparent!; |                    + <ins> help: a unit struct with a similar name exists | LL |     SemiTransparent; |     ~~~~~~~~~~~~~~~ </ins> error[E0423]: expected value, found macro `opaque` --> $DIR/rustc-macro-transparency.rs:30:5 | <ins> LL |     struct Opaque; |     -------------- similarly named unit struct `Opaque` defined here ... </ins> LL |     opaque; |     ^^^^^^ not a value |

| LL |     opaque!; |           + <ins> help: a unit struct with a similar name exists | LL |     Opaque; |     ~~~~~~ </ins> error: aborting due to 3 previous errors

| -------------- variant or associated item `PIE` not found here ... LL |     ApplePie = Delicious::Apple as isize | Delicious::PIE as isize, <del> |                                                       ^^^ variant or associated item not found in `Delicious` </del> <ins> |                                                       ^^^ |                                                       | |                                                       variant or associated item not found in `Delicious` |                                                       help: there is a variant with a similar name: `Pie` </ins> error: aborting due to previous error