remove 'as_str' when it's already a str type.

fix #62642
This commit is contained in:
Guanqun Lu 2019-09-24 17:49:25 +08:00
parent 42ec6831b0
commit a5d931050e

View File

@ -518,7 +518,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
if let Some(lev_candidate) = lev_candidate {
fn is_str_ref<'tcx>(ty: Ty<'tcx>) -> bool {
match ty.sty {
ty::Str => true,
ty::Ref(_, ty, _) => is_str_ref(&ty),
_ => false,
}
}
if item_name.as_str() == "as_str" && is_str_ref(&actual) {
err.span_suggestion(
span,
"try to remove `as_str`",
String::new(),
Applicability::MaybeIncorrect,
);
} else if let Some(lev_candidate) = lev_candidate {
let def_kind = lev_candidate.def_kind();
err.span_suggestion(
span,