rust/compiler/rustc_parse/src
Matthias Krüger 226ce31edd
Rollup merge of #108200 - jhpratt:restricted-damerau-levenshtein-distance, r=tmiasko
Use restricted Damerau-Levenshtein distance for diagnostics

This replaces the existing Levenshtein algorithm with the Damerau-Levenshtein algorithm. This means that "ab" to "ba" is one change (a transposition) instead of two (a deletion and insertion). More specifically, this is a _restricted_ implementation, in that "ca" to "abc" cannot be performed as "ca" → "ac" → "abc", as there is an insertion in the middle of a transposition. I believe that errors like that are sufficiently rare that it's not worth taking into account.

This was first brought up [on IRLO](https://internals.rust-lang.org/t/18227) when it was noticed that the diagnostic for `prinltn!` (transposed L and T) was `print!` and not `println!`. Only a single existing UI test was effected, with the result being an objective improvement.

~~I have left the method name and various other references to the Levenshtein algorithm untouched, as the exact manner in which the edit distance is calculated should not be relevant to the caller.~~

r? ``@estebank``

``@rustbot`` label +A-diagnostics +C-enhancement
2023-02-20 14:32:55 +01:00
..
lexer Don't recover lifetimes/labels containing emojis as character literals 2023-02-14 17:31:58 +08:00
parser Reduce limit on macro_rules! diagnostic 2023-02-19 04:17:58 +00:00
errors.rs Rollup merge of #107446 - clubby789:rustc-parse-diag-migrate, r=compiler-errors 2023-02-09 11:21:57 +01:00
lib.rs Split MacArgs in two. 2022-11-22 09:04:15 +11:00
validate_attr.rs Avoid unnecessary MetaItem/Attribute conversions. 2022-11-29 12:08:57 +11:00