Skip to content

Commit

Permalink
suggest to use core::iter::repeat_n in a no_std environment
Browse files Browse the repository at this point in the history
  • Loading branch information
lapla-cogito committed Dec 20, 2024
1 parent 672d7c0 commit 2208d8a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions clippy_lints/src/methods/manual_repeat_n.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::msrvs::{self, Msrv};
use clippy_utils::source::{snippet, snippet_with_context};
use clippy_utils::{expr_use_ctxt, fn_def_id, is_trait_method};
use clippy_utils::{expr_use_ctxt, fn_def_id, is_trait_method, std_or_core};
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::LateContext;
Expand All @@ -23,6 +23,7 @@ pub(super) fn check<'tcx>(
&& let ExprKind::Call(_, [repeat_arg]) = repeat_expr.kind
&& let Some(def_id) = fn_def_id(cx, repeat_expr)
&& cx.tcx.is_diagnostic_item(sym::iter_repeat, def_id)
&& let Some(std_or_core) = std_or_core(cx)
{
let mut app = Applicability::MachineApplicable;
span_lint_and_sugg(
Expand All @@ -32,7 +33,7 @@ pub(super) fn check<'tcx>(
"this `.repeat().take()` can be written more concisely",
"consider using `repeat_n()` instead",
format!(
"std::iter::repeat_n({}, {})",
"{std_or_core}::iter::repeat_n({}, {})",
snippet_with_context(cx, repeat_arg.span, expr.span.ctxt(), "..", &mut app).0,
snippet(cx, take_arg.span, "")
),
Expand Down

0 comments on commit 2208d8a

Please sign in to comment.