about summary refs log tree commit diff
path: root/compiler/rustc_monomorphize/src
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2023-10-18 14:34:53 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2023-10-18 14:42:57 +1100
commit4f923376b6d08a222c08d0ee15ea7c0742ebaa4a (patch)
tree5dedd437ac6edbf58c8b9bf64c924bac30b31902 /compiler/rustc_monomorphize/src
parent55c5ab9fbcdae47dbbae8014ecb7c62f78906dea (diff)
downloadrust-4f923376b6d08a222c08d0ee15ea7c0742ebaa4a.tar.gz
rust-4f923376b6d08a222c08d0ee15ea7c0742ebaa4a.zip
Streamline `build_skip_move_check_fns`.
It's just a `filter_map(...).collect()`.
Diffstat (limited to 'compiler/rustc_monomorphize/src')
-rw-r--r--compiler/rustc_monomorphize/src/collector.rs41
1 files changed, 10 insertions, 31 deletions
diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs
index c36010474d5..eb1c7db026e 100644
--- a/compiler/rustc_monomorphize/src/collector.rs
+++ b/compiler/rustc_monomorphize/src/collector.rs
@@ -1381,17 +1381,6 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
     }
 }
 
-fn add_assoc_fn<'tcx>(
-    tcx: TyCtxt<'tcx>,
-    def_id: Option<DefId>,
-    fn_ident: Ident,
-    skip_move_check_fns: &mut Vec<DefId>,
-) {
-    if let Some(def_id) = def_id.and_then(|def_id| assoc_fn_of_type(tcx, def_id, fn_ident)) {
-        skip_move_check_fns.push(def_id);
-    }
-}
-
 fn assoc_fn_of_type<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fn_ident: Ident) -> Option<DefId> {
     for impl_def_id in tcx.inherent_impls(def_id) {
         if let Some(new) = tcx.associated_items(impl_def_id).find_by_name_and_kind(
@@ -1407,26 +1396,16 @@ fn assoc_fn_of_type<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fn_ident: Ident) ->
 }
 
 fn build_skip_move_check_fns(tcx: TyCtxt<'_>) -> Vec<DefId> {
-    let mut skip_move_check_fns = vec![];
-    add_assoc_fn(
-        tcx,
-        tcx.lang_items().owned_box(),
-        Ident::from_str("new"),
-        &mut skip_move_check_fns,
-    );
-    add_assoc_fn(
-        tcx,
-        tcx.get_diagnostic_item(sym::Arc),
-        Ident::from_str("new"),
-        &mut skip_move_check_fns,
-    );
-    add_assoc_fn(
-        tcx,
-        tcx.get_diagnostic_item(sym::Rc),
-        Ident::from_str("new"),
-        &mut skip_move_check_fns,
-    );
-    skip_move_check_fns
+    let fns = [
+        (tcx.lang_items().owned_box(), "new"),
+        (tcx.get_diagnostic_item(sym::Rc), "new"),
+        (tcx.get_diagnostic_item(sym::Arc), "new"),
+    ];
+    fns.into_iter()
+        .filter_map(|(def_id, fn_name)| {
+            def_id.and_then(|def_id| assoc_fn_of_type(tcx, def_id, Ident::from_str(fn_name)))
+        })
+        .collect::<Vec<_>>()
 }
 
 /// Scans the MIR in order to find function calls, closures, and drop-glue.