]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_codegen_utils/symbol_names.rs
Rollup merge of #68514 - lzutao:fmt-Self, r=Dylan-DPC
[rust.git] / src / librustc_codegen_utils / symbol_names.rs
index 96a74f96fcf6054ba64b5dbb3721e30d949d1251..6713459f627ef726823ee4f247a025392112c560 100644 (file)
@@ -126,29 +126,10 @@ fn symbol_name_provider(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::Symb
         // This closure determines the instantiating crate for instances that
         // need an instantiating-crate-suffix for their symbol name, in order
         // to differentiate between local copies.
-        //
-        // For generics we might find re-usable upstream instances. For anything
-        // else we rely on their being a local copy available.
-
         if is_generic(instance.substs) {
-            let def_id = instance.def_id();
-
-            if !def_id.is_local() && tcx.sess.opts.share_generics() {
-                // If we are re-using a monomorphization from another crate,
-                // we have to compute the symbol hash accordingly.
-                let upstream_monomorphizations = tcx.upstream_monomorphizations_for(def_id);
-
-                upstream_monomorphizations
-                    .and_then(|monos| monos.get(&instance.substs).cloned())
-                    // If there is no instance available upstream, there'll be
-                    // one in the current crate.
-                    .unwrap_or(LOCAL_CRATE)
-            } else {
-                // For generic functions defined in the current crate, there
-                // can be no upstream instances. Also, if we don't share
-                // generics, we'll instantiate a local copy too.
-                LOCAL_CRATE
-            }
+            // For generics we might find re-usable upstream instances. If there
+            // is one, we rely on the symbol being instantiated locally.
+            instance.upstream_monomorphization(tcx).unwrap_or(LOCAL_CRATE)
         } else {
             // For non-generic things that need to avoid naming conflicts, we
             // always instantiate a copy in the local crate.