1 use crate::utils::{is_type_diagnostic_item, snippet_with_applicability, span_lint_and_sugg};
2 use if_chain::if_chain;
3 use rustc_errors::Applicability;
4 use rustc_hir::{Expr, ExprKind};
5 use rustc_lint::LateContext;
10 pub(super) fn lints<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, iter_args: &'tcx [Expr<'tcx>]) {
12 if let ExprKind::MethodCall(_, _, ref args, _) = expr.kind;
13 let ty = cx.typeck_results().expr_ty(&iter_args[0]).peel_refs();
14 let caller_type = if is_type_diagnostic_item(cx, ty, sym::string_type) {
16 } else if ty.is_str() {
21 if let Some(caller_type) = caller_type;
23 let mut applicability = Applicability::MachineApplicable;
28 &format!("called `.byte().nth()` on a `{}`", caller_type),
31 "{}.as_bytes().get({})",
32 snippet_with_applicability(cx, iter_args[0].span, "..", &mut applicability),
33 snippet_with_applicability(cx, args[1].span, "..", &mut applicability)