X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=clippy_lints%2Fsrc%2Fmethods%2Futils.rs;h=11ad881ee7b95bf1d29b58b89111e85a58b575b7;hb=3c8f90bd5a03872a9b9088facc3bf9ec8ac42dd0;hp=f6bf37e08b96614007217d910fe0778d3c8ffa6b;hpb=f6d1f368db9e726fde825dc2525cdec07673b416;p=rust.git diff --git a/clippy_lints/src/methods/utils.rs b/clippy_lints/src/methods/utils.rs index f6bf37e08b9..11ad881ee7b 100644 --- a/clippy_lints/src/methods/utils.rs +++ b/clippy_lints/src/methods/utils.rs @@ -17,18 +17,16 @@ fn may_slice<'a>(cx: &LateContext<'a>, ty: Ty<'a>) -> bool { match ty.kind() { ty::Slice(_) => true, ty::Adt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()), - ty::Adt(..) => is_type_diagnostic_item(cx, ty, sym::vec_type), - ty::Array(_, size) => size - .try_eval_usize(cx.tcx, cx.param_env) - .map_or(false, |size| size < 32), + ty::Adt(..) => is_type_diagnostic_item(cx, ty, sym::Vec), + ty::Array(_, size) => size.try_eval_usize(cx.tcx, cx.param_env).is_some(), ty::Ref(_, inner, _) => may_slice(cx, inner), _ => false, } } - if let hir::ExprKind::MethodCall(path, _, args, _) = expr.kind { - if path.ident.name == sym::iter && may_slice(cx, cx.typeck_results().expr_ty(&args[0])) { - Some(&args[0]) + if let hir::ExprKind::MethodCall(path, _, [self_arg, ..], _) = &expr.kind { + if path.ident.name == sym::iter && may_slice(cx, cx.typeck_results().expr_ty(self_arg)) { + Some(self_arg) } else { None } @@ -68,7 +66,13 @@ pub(super) fn get_hint_if_single_char_arg( // for regular string: "a" &snip[1..(snip.len() - 1)] }; - let hint = format!("'{}'", if ch == "'" { "\\'" } else { ch }); + + let hint = format!("'{}'", match ch { + "'" => "\\'" , + r"\" => "\\\\", + _ => ch, + }); + Some(hint) } else { None