1 use clippy_utils::diagnostics::span_lint_and_sugg;
2 use clippy_utils::source::snippet_with_applicability;
3 use clippy_utils::ty::is_type_diagnostic_item;
4 use rustc_errors::Applicability;
6 use rustc_lint::LateContext;
11 pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, recv: &'tcx Expr<'tcx>, n_arg: &'tcx Expr<'tcx>) {
12 let ty = cx.typeck_results().expr_ty(recv).peel_refs();
13 let caller_type = if ty.is_str() {
15 } else if is_type_diagnostic_item(cx, ty, sym::String) {
20 let mut applicability = Applicability::MachineApplicable;
25 &format!("called `.byte().nth()` on a `{}`", caller_type),
28 "{}.as_bytes().get({})",
29 snippet_with_applicability(cx, recv.span, "..", &mut applicability),
30 snippet_with_applicability(cx, n_arg.span, "..", &mut applicability)