1 use clippy_utils::diagnostics::span_lint_and_then;
2 use clippy_utils::ty::implements_trait;
3 use clippy_utils::{get_trait_def_id, match_def_path, paths};
4 use rustc_ast::ast::{LitIntType, LitKind};
5 use rustc_errors::Applicability;
6 use rustc_hir::{Expr, ExprKind};
7 use rustc_lint::LateContext;
10 use super::SEEK_TO_START_INSTEAD_OF_REWIND;
12 pub(super) fn check<'tcx>(
13 cx: &LateContext<'tcx>,
20 let ty = cx.typeck_results().expr_ty(recv).peel_refs();
22 if let Some(seek_trait_id) = get_trait_def_id(cx, &paths::STD_IO_SEEK) &&
23 implements_trait(cx, ty, seek_trait_id, &[]) &&
24 let ExprKind::Call(func, args1) = arg.kind &&
25 let ExprKind::Path(ref path) = func.kind &&
26 let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id() &&
27 match_def_path(cx, def_id, &paths::STD_IO_SEEKFROM_START) &&
29 let ExprKind::Lit(ref lit) = args1[0].kind &&
30 let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node
32 let method_call_span = expr.span.with_lo(name_span.lo());
35 SEEK_TO_START_INSTEAD_OF_REWIND,
37 "used `seek` to go to the start of the stream",
39 let app = Applicability::MachineApplicable;
41 diag.span_suggestion(method_call_span, "replace with", "rewind()", app);