// 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.