1
Fork 0

sugg: suggest the usage of boolean value when there is a typo in the keyword

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
Vincenzo Palazzo 2022-08-20 20:47:31 +00:00
parent dd01122b5c
commit 69715c9033
3 changed files with 59 additions and 5 deletions

View file

@ -250,13 +250,30 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
.map_or_else(String::new, |res| format!("{} ", res.descr()));
(mod_prefix, format!("`{}`", Segment::names_to_string(mod_path)), None)
};
let (fallback_label, suggestion) = if path_str == "async"
&& expected.starts_with("struct")
{
("`async` blocks are only allowed in Rust 2018 or later".to_string(), suggestion)
} else {
// check if we are in situation of typo like `True` instead of `true`.
let override_suggestion =
if ["true", "false"].contains(&item_str.to_string().to_lowercase().as_str()) {
let item_typo = item_str.to_string().to_lowercase();
Some((
item_span,
"you may want to use a bool value instead",
format!("{}", item_typo),
))
} else {
suggestion
};
(format!("not found in {mod_str}"), override_suggestion)
};
BaseError {
msg: format!("cannot find {expected} `{item_str}` in {mod_prefix}{mod_str}"),
fallback_label: if path_str == "async" && expected.starts_with("struct") {
"`async` blocks are only allowed in Rust 2018 or later".to_string()
} else {
format!("not found in {mod_str}")
},
fallback_label,
span: item_span,
span_label: None,
could_be_expr: false,