Skip to content

Commit 81d3329

Browse files
committed
Move adjust_derefs_manually_drop into clippy_utils
1 parent fc811f7 commit 81d3329

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

clippy_lints/src/dereference.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
22
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
33
use clippy_utils::sugg::has_enclosing_paren;
4-
use clippy_utils::ty::{implements_trait, is_manually_drop};
4+
use clippy_utils::ty::{adjust_derefs_manually_drop, implements_trait, is_manually_drop};
55
use clippy_utils::{
66
DefinedTy, ExprUseNode, expr_use_ctxt, get_parent_expr, is_block_like, is_lint_allowed, path_to_local,
77
peel_middle_ty_refs,
88
};
9-
use core::mem;
109
use rustc_ast::util::parser::ExprPrecedence;
1110
use rustc_data_structures::fx::FxIndexMap;
1211
use rustc_errors::Applicability;
@@ -709,14 +708,6 @@ fn try_parse_ref_op<'tcx>(
709708
}
710709
}
711710

712-
// Checks if the adjustments contains a deref of `ManuallyDrop<_>`
713-
fn adjust_derefs_manually_drop<'tcx>(adjustments: &'tcx [Adjustment<'tcx>], mut ty: Ty<'tcx>) -> bool {
714-
adjustments.iter().any(|a| {
715-
let ty = mem::replace(&mut ty, a.target);
716-
matches!(a.kind, Adjust::Deref(Some(ref op)) if op.mutbl == Mutability::Mut) && is_manually_drop(ty)
717-
})
718-
}
719-
720711
// Checks whether the type for a deref call actually changed the type, not just the mutability of
721712
// the reference.
722713
fn deref_method_same_type<'tcx>(result_ty: Ty<'tcx>, arg_ty: Ty<'tcx>) -> bool {

clippy_utils/src/ty/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_lint::LateContext;
1717
use rustc_middle::mir::ConstValue;
1818
use rustc_middle::mir::interpret::Scalar;
1919
use rustc_middle::traits::EvaluationResult;
20+
use rustc_middle::ty::adjustment::{Adjust, Adjustment};
2021
use rustc_middle::ty::layout::ValidityRequirement;
2122
use rustc_middle::ty::{
2223
self, AdtDef, AliasTy, AssocItem, AssocTag, Binder, BoundRegion, FnSig, GenericArg, GenericArgKind, GenericArgsRef,
@@ -30,7 +31,7 @@ use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt;
3031
use rustc_trait_selection::traits::{Obligation, ObligationCause};
3132
use std::assert_matches::debug_assert_matches;
3233
use std::collections::hash_map::Entry;
33-
use std::iter;
34+
use std::{iter, mem};
3435

3536
use crate::path_res;
3637
use crate::paths::{PathNS, lookup_path_str};
@@ -1361,3 +1362,11 @@ pub fn is_slice_like<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
13611362
|| ty.is_array()
13621363
|| matches!(ty.kind(), ty::Adt(adt_def, _) if cx.tcx.is_diagnostic_item(sym::Vec, adt_def.did()))
13631364
}
1365+
1366+
/// Checks if the adjustments contain a mutable dereference of a `ManuallyDrop<_>`.
1367+
pub fn adjust_derefs_manually_drop<'tcx>(adjustments: &'tcx [Adjustment<'tcx>], mut ty: Ty<'tcx>) -> bool {
1368+
adjustments.iter().any(|a| {
1369+
let ty = mem::replace(&mut ty, a.target);
1370+
matches!(a.kind, Adjust::Deref(Some(op)) if op.mutbl == Mutability::Mut) && is_manually_drop(ty)
1371+
})
1372+
}

0 commit comments

Comments
 (0)