Skip to content

Commit 3688b33

Browse files
committed
Move adjust_derefs_manually_drop into clippy_utils
1 parent 604b7b0 commit 3688b33

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
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;
@@ -707,14 +706,6 @@ fn try_parse_ref_op<'tcx>(
707706
))
708707
}
709708

710-
// Checks if the adjustments contains a deref of `ManuallyDrop<_>`
711-
fn adjust_derefs_manually_drop<'tcx>(adjustments: &'tcx [Adjustment<'tcx>], mut ty: Ty<'tcx>) -> bool {
712-
adjustments.iter().any(|a| {
713-
let ty = mem::replace(&mut ty, a.target);
714-
matches!(a.kind, Adjust::Deref(Some(ref op)) if op.mutbl == Mutability::Mut) && is_manually_drop(ty)
715-
})
716-
}
717-
718709
// Checks whether the type for a deref call actually changed the type, not just the mutability of
719710
// the reference.
720711
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 & 2 deletions
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};
@@ -1362,7 +1363,6 @@ pub fn is_slice_like<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
13621363
|| matches!(ty.kind(), ty::Adt(adt_def, _) if cx.tcx.is_diagnostic_item(sym::Vec, adt_def.did()))
13631364
}
13641365

1365-
/// Gets the index of a field by name.
13661366
pub fn get_field_idx_by_name(ty: Ty<'_>, name: Symbol) -> Option<usize> {
13671367
match *ty.kind() {
13681368
ty::Adt(def, _) if def.is_union() || def.is_struct() => {
@@ -1372,3 +1372,11 @@ pub fn get_field_idx_by_name(ty: Ty<'_>, name: Symbol) -> Option<usize> {
13721372
_ => None,
13731373
}
13741374
}
1375+
1376+
/// Checks if the adjustments contain a mutable dereference of a `ManuallyDrop<_>`.
1377+
pub fn adjust_derefs_manually_drop<'tcx>(adjustments: &'tcx [Adjustment<'tcx>], mut ty: Ty<'tcx>) -> bool {
1378+
adjustments.iter().any(|a| {
1379+
let ty = mem::replace(&mut ty, a.target);
1380+
matches!(a.kind, Adjust::Deref(Some(op)) if op.mutbl == Mutability::Mut) && is_manually_drop(ty)
1381+
})
1382+
}

0 commit comments

Comments
 (0)