Skip to content

Commit b9e2186

Browse files
committed
non_copy_const: use InteriorMut
1 parent 3e5d7e4 commit b9e2186

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

clippy_lints/src/non_copy_const.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant};
2222
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
2323
use clippy_utils::is_in_const_context;
2424
use clippy_utils::macros::macro_backtrace;
25-
use clippy_utils::paths::{PathNS, lookup_path_str};
26-
use clippy_utils::ty::{get_field_idx_by_name, implements_trait};
25+
use clippy_utils::ty::{InteriorMut, get_field_idx_by_name, implements_trait};
2726
use rustc_data_structures::fx::FxHashMap;
2827
use rustc_hir::def::{DefKind, Res};
29-
use rustc_hir::def_id::{DefId, DefIdSet};
28+
use rustc_hir::def_id::DefId;
3029
use rustc_hir::{
3130
Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, Node, StructTailExpr, TraitItem, TraitItemKind, UnOp,
3231
};
@@ -250,7 +249,7 @@ impl<'tcx> BorrowSource<'tcx> {
250249
}
251250

252251
pub struct NonCopyConst<'tcx> {
253-
ignore_tys: DefIdSet,
252+
interior_mut: InteriorMut<'tcx>,
254253
// Cache checked types. We can recurse through a type multiple times so this
255254
// can be hit quite frequently.
256255
freeze_tys: FxHashMap<Ty<'tcx>, IsFreeze>,
@@ -261,11 +260,7 @@ impl_lint_pass!(NonCopyConst<'_> => [DECLARE_INTERIOR_MUTABLE_CONST, BORROW_INTE
261260
impl<'tcx> NonCopyConst<'tcx> {
262261
pub fn new(tcx: TyCtxt<'tcx>, conf: &'static Conf) -> Self {
263262
Self {
264-
ignore_tys: conf
265-
.ignore_interior_mutability
266-
.iter()
267-
.flat_map(|ignored_ty| lookup_path_str(tcx, PathNS::Type, ignored_ty))
268-
.collect(),
263+
interior_mut: InteriorMut::new(tcx, &conf.ignore_interior_mutability),
269264
freeze_tys: FxHashMap::default(),
270265
}
271266
}
@@ -285,7 +280,7 @@ impl<'tcx> NonCopyConst<'tcx> {
285280
*e = IsFreeze::No;
286281
return IsFreeze::No;
287282
},
288-
ty::Adt(adt, _) if self.ignore_tys.contains(&adt.did()) => return IsFreeze::Yes,
283+
ty::Adt(_, _) if !self.interior_mut.is_interior_mut_ty(cx, ty) => return IsFreeze::Yes,
289284
ty::Adt(adt, args) if adt.is_enum() => IsFreeze::from_variants(adt.variants().iter().map(|v| {
290285
IsFreeze::from_fields(
291286
v.fields

0 commit comments

Comments
 (0)