use clippy_utils::diagnostics::span_lint;
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
-use clippy_utils::{get_trait_def_id, higher, match_def_path, path_def_id, paths};
-use rustc_hir::{BorrowKind, Expr, ExprKind};
+use clippy_utils::{higher, match_def_path, path_def_id, paths};
+use rustc_hir::{BorrowKind, Closure, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::symbol::{sym, Symbol};
/// ### Example
/// ```rust
/// let infinite_iter = 0..;
+ /// # #[allow(unused)]
/// [0..].iter().zip(infinite_iter.take_while(|x| *x > 5));
/// ```
#[clippy::version = "pre 1.29.0"]
}
}
if method.ident.name == sym!(flat_map) && args.len() == 2 {
- if let ExprKind::Closure(_, _, body_id, _, _) = args[1].kind {
- let body = cx.tcx.hir().body(body_id);
+ if let ExprKind::Closure(&Closure { body, .. }) = args[1].kind {
+ let body = cx.tcx.hir().body(body);
return is_infinite(cx, &body.value);
}
}
}
}
if method.ident.name == sym!(last) && args.len() == 1 {
- let not_double_ended = get_trait_def_id(cx, &paths::DOUBLE_ENDED_ITERATOR).map_or(false, |id| {
- !implements_trait(cx, cx.typeck_results().expr_ty(&args[0]), id, &[])
- });
+ let not_double_ended = cx
+ .tcx
+ .get_diagnostic_item(sym::DoubleEndedIterator)
+ .map_or(false, |id| {
+ !implements_trait(cx, cx.typeck_results().expr_ty(&args[0]), id, &[])
+ });
if not_double_ended {
return is_infinite(cx, &args[0]);
}