about summary refs log tree commit diff
path: root/src/rustllvm/RustWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-08-04 10:13:55 +0000
committerbors <bors@rust-lang.org>2017-08-04 10:13:55 +0000
commitf2a5af7a4c7424acc9acc52161fb57210a4bb219 (patch)
tree3a1c9f259c17e8f2bfa2d95f043f869ac638053f /src/rustllvm/RustWrapper.cpp
parentc523b3f95498cf35a2f1a6bb8c071394ca4a6143 (diff)
parent2dbfa3995e44af6ce4fbeaa2f9de4730e5d2fbd5 (diff)
downloadrust-f2a5af7a4c7424acc9acc52161fb57210a4bb219.tar.gz
rust-f2a5af7a4c7424acc9acc52161fb57210a4bb219.zip
Auto merge of #43442 - zackmdavis:note_available_field_names_if_levenshtein_fails, r=nikomatsakis
field does not exist error: note fields if Levenshtein suggestion fails

When trying to access or initialize a nonexistent field, if we can't infer what
field was meant (by virtue of the purported field in the source being a small
Levenshtein distance away from an actual field, suggestive of a typo), issue a
note listing all the available fields. To reduce terminal clutter, we don't
issue the note when we have a `find_best_match_for_name` Levenshtein
suggestion: the suggestion is probably right.

The third argument of the call to `find_best_match_for_name` is changed to
`None`, accepting the default maximum Levenshtein distance of one-third of the
identifier supplied for correction. The previous value of `Some(name.len())`
was overzealous, inappropriately very Levenshtein-distant suggestions when the
attempted field access could not plausibly be a mere typo. For example, if a
struct has fields `mule` and `phone`, but I type `.donkey`, I'd rather the
error have a note listing that the available fields are, in fact, `mule` and
`phone` (which is the behavior induced by this patch) rather than the error
asking "did you mean `phone`?" (which is the behavior on master). The "only
find fits with at least one matching letter" comment was accurate when it was
first introduced in 09d992471 (January 2015), but is a vicious lie in its
present context before a call to `find_best_match_for_name` and must be
destroyed (replacing every letter is within a Levenshtein distance of name.len()).

The present author claims that this suffices to resolve #42599.
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions