Remove needless check of returned type
We are checking that we are calling the `as_bytes()` method of `String` or `str`. Checking that it returns a `slice()` does not add anything.
This commit is contained in:
parent
19e305bb57
commit
e42e354f65
2 changed files with 5 additions and 7 deletions
|
|
@ -4925,7 +4925,7 @@ impl Methods {
|
|||
("is_empty", []) => {
|
||||
match method_call(recv) {
|
||||
Some(("as_bytes", prev_recv, [], _, _)) => {
|
||||
needless_as_bytes::check(cx, "is_empty", recv, prev_recv, expr.span);
|
||||
needless_as_bytes::check(cx, "is_empty", prev_recv, expr.span);
|
||||
},
|
||||
Some(("as_str", recv, [], as_str_span, _)) => {
|
||||
redundant_as_str::check(cx, expr, recv, as_str_span, span);
|
||||
|
|
@ -4963,7 +4963,7 @@ impl Methods {
|
|||
},
|
||||
("len", []) => {
|
||||
if let Some(("as_bytes", prev_recv, [], _, _)) = method_call(recv) {
|
||||
needless_as_bytes::check(cx, "len", recv, prev_recv, expr.span);
|
||||
needless_as_bytes::check(cx, "len", prev_recv, expr.span);
|
||||
}
|
||||
},
|
||||
("lock", []) => {
|
||||
|
|
|
|||
|
|
@ -8,11 +8,9 @@ use rustc_span::Span;
|
|||
|
||||
use super::NEEDLESS_AS_BYTES;
|
||||
|
||||
pub fn check(cx: &LateContext<'_>, method: &str, recv: &Expr<'_>, prev_recv: &Expr<'_>, span: Span) {
|
||||
if cx.typeck_results().expr_ty_adjusted(recv).peel_refs().is_slice()
|
||||
&& let ty1 = cx.typeck_results().expr_ty_adjusted(prev_recv).peel_refs()
|
||||
&& (is_type_lang_item(cx, ty1, LangItem::String) || ty1.is_str())
|
||||
{
|
||||
pub fn check(cx: &LateContext<'_>, method: &str, prev_recv: &Expr<'_>, span: Span) {
|
||||
let ty1 = cx.typeck_results().expr_ty_adjusted(prev_recv).peel_refs();
|
||||
if is_type_lang_item(cx, ty1, LangItem::String) || ty1.is_str() {
|
||||
let mut app = Applicability::MachineApplicable;
|
||||
let sugg = Sugg::hir_with_context(cx, prev_recv, span.ctxt(), "..", &mut app);
|
||||
span_lint_and_sugg(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue