|
1 | 1 | use clippy_utils::diagnostics::span_lint_and_sugg;
|
2 |
| -use clippy_utils::is_lang_ctor; |
3 |
| -use clippy_utils::is_no_std_crate; |
4 | 2 | use clippy_utils::source::snippet;
|
| 3 | +use clippy_utils::{get_expr_use_or_unification_node, is_lang_ctor, is_no_std_crate}; |
5 | 4 |
|
6 | 5 | use rustc_errors::Applicability;
|
7 | 6 | use rustc_hir::LangItem::{OptionNone, OptionSome};
|
8 |
| -use rustc_hir::{Expr, ExprKind}; |
| 7 | +use rustc_hir::{Expr, ExprKind, Node}; |
9 | 8 | use rustc_lint::LateContext;
|
10 | 9 |
|
11 | 10 | use super::{ITER_EMPTY, ITER_ONCE};
|
@@ -56,6 +55,24 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, method_name:
|
56 | 55 | _ => return,
|
57 | 56 | };
|
58 | 57 |
|
| 58 | + let is_unified = match get_expr_use_or_unification_node(cx.tcx, expr) { |
| 59 | + Some((Node::Expr(parent), child_id)) => match parent.kind { |
| 60 | + ExprKind::If(e, _, _) | ExprKind::Match(e, _, _) if e.hir_id == child_id => false, |
| 61 | + ExprKind::If(_, _, _) |
| 62 | + | ExprKind::Match(_, _, _) |
| 63 | + | ExprKind::Closure(_) |
| 64 | + | ExprKind::Ret(_) |
| 65 | + | ExprKind::Break(_, _) => true, |
| 66 | + _ => false, |
| 67 | + }, |
| 68 | + Some((Node::Stmt(_) | Node::Local(_), _)) => false, |
| 69 | + _ => true, |
| 70 | + }; |
| 71 | + |
| 72 | + if is_unified { |
| 73 | + return; |
| 74 | + } |
| 75 | + |
59 | 76 | if let Some(i) = item {
|
60 | 77 | let sugg = format!(
|
61 | 78 | "{}::iter::once({}{})",
|
|
0 commit comments