]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_metadata/src/dependency_format.rs
Auto merge of #107843 - bjorn3:sync_cg_clif-2023-02-09, r=bjorn3
[rust.git] / compiler / rustc_metadata / src / dependency_format.rs
index cee4ba56a9d8f863180eefcb1c3bb4e7745ae23c..39ef4276faf10360b96efa1eda9a5f504cee1b6b 100644 (file)
@@ -113,37 +113,37 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
         CrateType::Staticlib => Linkage::Static,
     };
 
-    if preferred_linkage == Linkage::NotLinked {
+    match preferred_linkage {
         // If the crate is not linked, there are no link-time dependencies.
-        return Vec::new();
-    }
-
-    if preferred_linkage == Linkage::Static {
-        // Attempt static linkage first. For dylibs and executables, we may be
-        // able to retry below with dynamic linkage.
-        if let Some(v) = attempt_static(tcx) {
-            return v;
-        }
+        Linkage::NotLinked => return Vec::new(),
+        Linkage::Static => {
+            // Attempt static linkage first. For dylibs and executables, we may be
+            // able to retry below with dynamic linkage.
+            if let Some(v) = attempt_static(tcx) {
+                return v;
+            }
 
-        // Staticlibs and static executables must have all static dependencies.
-        // If any are not found, generate some nice pretty errors.
-        if ty == CrateType::Staticlib
-            || (ty == CrateType::Executable
-                && sess.crt_static(Some(ty))
-                && !sess.target.crt_static_allows_dylibs)
-        {
-            for &cnum in tcx.crates(()).iter() {
-                if tcx.dep_kind(cnum).macros_only() {
-                    continue;
+            // Staticlibs and static executables must have all static dependencies.
+            // If any are not found, generate some nice pretty errors.
+            if ty == CrateType::Staticlib
+                || (ty == CrateType::Executable
+                    && sess.crt_static(Some(ty))
+                    && !sess.target.crt_static_allows_dylibs)
+            {
+                for &cnum in tcx.crates(()).iter() {
+                    if tcx.dep_kind(cnum).macros_only() {
+                        continue;
+                    }
+                    let src = tcx.used_crate_source(cnum);
+                    if src.rlib.is_some() {
+                        continue;
+                    }
+                    sess.emit_err(RlibRequired { crate_name: tcx.crate_name(cnum) });
                 }
-                let src = tcx.used_crate_source(cnum);
-                if src.rlib.is_some() {
-                    continue;
-                }
-                sess.emit_err(RlibRequired { crate_name: tcx.crate_name(cnum) });
+                return Vec::new();
             }
-            return Vec::new();
         }
+        Linkage::Dynamic | Linkage::IncludedFromDylib => {}
     }
 
     let mut formats = FxHashMap::default();
@@ -283,12 +283,9 @@ fn attempt_static(tcx: TyCtxt<'_>) -> Option<DependencyList> {
     let mut ret = tcx
         .crates(())
         .iter()
-        .map(|&cnum| {
-            if tcx.dep_kind(cnum) == CrateDepKind::Explicit {
-                Linkage::Static
-            } else {
-                Linkage::NotLinked
-            }
+        .map(|&cnum| match tcx.dep_kind(cnum) {
+            CrateDepKind::Explicit => Linkage::Static,
+            CrateDepKind::MacrosOnly | CrateDepKind::Implicit => Linkage::NotLinked,
         })
         .collect::<Vec<_>>();