Skip to content

Commit 524b9e1

Browse files
authored
Unrolled build for rust-lang#118381
Rollup merge of rust-lang#118381 - Enselic:edit-dist-len, r=WaffleLapkin rustc_span: Use correct edit distance start length for suggestions Otherwise the suggestions can be off-base for non-ASCII identifiers. For example suggesting that `Ok` is a name similar to `读文`. Closes rust-lang#72553.
2 parents 49b3924 + 45fc842 commit 524b9e1

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

compiler/rustc_span/src/edit_distance.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,11 @@ fn find_best_match_for_name_impl(
188188
return Some(*c);
189189
}
190190

191-
let mut dist = dist.unwrap_or_else(|| cmp::max(lookup.len(), 3) / 3);
191+
// `fn edit_distance()` use `chars()` to calculate edit distance, so we must
192+
// also use `chars()` (and not `str::len()`) to calculate length here.
193+
let lookup_len = lookup.chars().count();
194+
195+
let mut dist = dist.unwrap_or_else(|| cmp::max(lookup_len, 3) / 3);
192196
let mut best = None;
193197
// store the candidates with the same distance, only for `use_substring_score` current.
194198
let mut next_candidates = vec![];
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
// There shall be no suggestions here. In particular not `Ok`.
3+
let _ = 读文; //~ ERROR cannot find value `读文` in this scope
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0425]: cannot find value `读文` in this scope
2+
--> $DIR/non_ascii_ident.rs:3:13
3+
|
4+
LL | let _ = 读文;
5+
| ^^^^ not found in this scope
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)