1 use clippy_utils::diagnostics::span_lint_and_sugg;
2 use clippy_utils::source::snippet_with_applicability;
3 use clippy_utils::{method_chain_args, single_segment_path};
4 use if_chain::if_chain;
5 use rustc_errors::Applicability;
7 use rustc_lint::LateContext;
12 /// Wrapper fn for `CHARS_NEXT_CMP` and `CHARS_LAST_CMP` lints.
15 info: &crate::methods::BinaryExprInfo<'_>,
16 chain_methods: &[&str],
21 if let Some(args) = method_chain_args(info.chain, chain_methods);
22 if let hir::ExprKind::Call(fun, arg_char) = info.other.kind;
23 if arg_char.len() == 1;
24 if let hir::ExprKind::Path(ref qpath) = fun.kind;
25 if let Some(segment) = single_segment_path(qpath);
26 if segment.ident.name == sym::Some;
28 let mut applicability = Applicability::MachineApplicable;
29 let self_ty = cx.typeck_results().expr_ty_adjusted(&args[0][0]).peel_refs();
31 if *self_ty.kind() != ty::Str {
39 &format!("you should use the `{}` method", suggest),
41 format!("{}{}.{}({})",
42 if info.eq { "" } else { "!" },
43 snippet_with_applicability(cx, args[0][0].span, "..", &mut applicability),
45 snippet_with_applicability(cx, arg_char[0].span, "..", &mut applicability)),