|
1 | 1 | use rustc_abi::Size; |
2 | | -use rustc_data_structures::fx::FxIndexSet; |
| 2 | +use rustc_hir::def::DefKind; |
3 | 3 | use rustc_hir::def_id::DefId; |
4 | 4 | use rustc_hir::limit::Limit; |
5 | 5 | use rustc_middle::mir::visit::Visitor as MirVisitor; |
6 | 6 | use rustc_middle::mir::{self, Location, traversal}; |
7 | | -use rustc_middle::ty::{self, AssocTag, Instance, Ty, TyCtxt, TypeFoldable}; |
| 7 | +use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable}; |
8 | 8 | use rustc_session::lint::builtin::LARGE_ASSIGNMENTS; |
9 | | -use rustc_span::{Ident, Span, Spanned, sym}; |
| 9 | +use rustc_span::{Span, Spanned, sym}; |
10 | 10 | use tracing::{debug, trace}; |
11 | 11 |
|
12 | 12 | use crate::errors::LargeAssignmentsLint; |
@@ -98,7 +98,7 @@ impl<'tcx> MoveCheckVisitor<'tcx> { |
98 | 98 | let ty::FnDef(def_id, _) = *callee_ty.kind() else { |
99 | 99 | return; |
100 | 100 | }; |
101 | | - if self.tcx.skip_move_check_fns(()).contains(&def_id) { |
| 101 | + if should_skip_fn(self.tcx, def_id) { |
102 | 102 | return; |
103 | 103 | } |
104 | 104 |
|
@@ -188,29 +188,18 @@ impl<'tcx> MoveCheckVisitor<'tcx> { |
188 | 188 | } |
189 | 189 | } |
190 | 190 |
|
191 | | -fn assoc_fn_of_type<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fn_ident: Ident) -> Option<DefId> { |
192 | | - for &impl_def_id in tcx.inherent_impls(def_id) { |
193 | | - if let Some(new) = tcx.associated_items(impl_def_id).find_by_ident_and_kind( |
194 | | - tcx, |
195 | | - fn_ident, |
196 | | - AssocTag::Fn, |
197 | | - def_id, |
198 | | - ) { |
199 | | - return Some(new.def_id); |
200 | | - } |
| 191 | +/// Return `true` if `def_id` is `Box::new`, `Rc::new` or `Arc::new`. |
| 192 | +fn should_skip_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool { |
| 193 | + if let DefKind::AssocFn = tcx.def_kind(def_id) |
| 194 | + && tcx.item_name(def_id) == sym::new |
| 195 | + && let parent = tcx.parent(def_id) |
| 196 | + && let DefKind::Impl { of_trait: false } = tcx.def_kind(parent) |
| 197 | + && let ty::Adt(adt_def, ..) = |
| 198 | + tcx.type_of(parent).instantiate_identity().skip_normalization().kind() |
| 199 | + { |
| 200 | + return Some(adt_def.did()) == tcx.lang_items().owned_box() |
| 201 | + || Some(adt_def.did()) == tcx.get_diagnostic_item(sym::Rc) |
| 202 | + || Some(adt_def.did()) == tcx.get_diagnostic_item(sym::Arc); |
201 | 203 | } |
202 | | - None |
203 | | -} |
204 | | - |
205 | | -pub(crate) fn skip_move_check_fns(tcx: TyCtxt<'_>, _: ()) -> FxIndexSet<DefId> { |
206 | | - let fns = [ |
207 | | - (tcx.lang_items().owned_box(), "new"), |
208 | | - (tcx.get_diagnostic_item(sym::Rc), "new"), |
209 | | - (tcx.get_diagnostic_item(sym::Arc), "new"), |
210 | | - ]; |
211 | | - fns.into_iter() |
212 | | - .filter_map(|(def_id, fn_name)| { |
213 | | - def_id.and_then(|def_id| assoc_fn_of_type(tcx, def_id, Ident::from_str(fn_name))) |
214 | | - }) |
215 | | - .collect() |
| 204 | + false |
216 | 205 | } |
0 commit comments