diff options
| author | lapla-cogito <me@lapla.dev> | 2025-01-14 20:37:35 +0900 |
|---|---|---|
| committer | lapla-cogito <me@lapla.dev> | 2025-01-28 06:29:45 +0900 |
| commit | d99eae432563b955da5bddff8ca678ac3f7eb9c8 (patch) | |
| tree | cf5f51418691c6e6128e0d58a39a76093ee93d0b /clippy_lints/src/methods | |
| parent | cb0a479d1f15831f99f0c8b6b730b3c804c5f9e1 (diff) | |
| download | rust-d99eae432563b955da5bddff8ca678ac3f7eb9c8.tar.gz rust-d99eae432563b955da5bddff8ca678ac3f7eb9c8.zip | |
correct suggestion for `drain_collect` in a `no_std` environment
Diffstat (limited to 'clippy_lints/src/methods')
| -rw-r--r-- | clippy_lints/src/methods/drain_collect.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/clippy_lints/src/methods/drain_collect.rs b/clippy_lints/src/methods/drain_collect.rs index 10360b4817b..cbf713a3b17 100644 --- a/clippy_lints/src/methods/drain_collect.rs +++ b/clippy_lints/src/methods/drain_collect.rs @@ -1,8 +1,8 @@ use crate::methods::DRAIN_COLLECT; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::is_range_full; use clippy_utils::source::snippet; use clippy_utils::ty::is_type_lang_item; +use clippy_utils::{is_range_full, std_or_core}; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, LangItem, Path, QPath}; use rustc_lint::LateContext; @@ -58,12 +58,13 @@ pub(super) fn check(cx: &LateContext<'_>, args: &[Expr<'_>], expr: &Expr<'_>, re .then_some("Vec") .or_else(|| check_string(cx, args, expr_ty, recv_ty_no_refs, recv_path).then_some("String")) .or_else(|| check_collections(cx, expr_ty, recv_ty_no_refs)) + && let Some(exec_context) = std_or_core(cx) { let recv = snippet(cx, recv.span, "<expr>"); let sugg = if let ty::Ref(..) = recv_ty.kind() { - format!("std::mem::take({recv})") + format!("{exec_context}::mem::take({recv})") } else { - format!("std::mem::take(&mut {recv})") + format!("{exec_context}::mem::take(&mut {recv})") }; span_lint_and_sugg( |
