@@ -89,11 +89,12 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
8989 // to try to eagerly statically link all dependencies. This is normally
9090 // done for end-product dylibs, not intermediate products.
9191 //
92- // Treat cdylibs similarly. If `-C prefer-dynamic` is set, the caller may
93- // be code-size conscious, but without it, it makes sense to statically
94- // link a cdylib.
95- CrateType :: Dylib | CrateType :: Cdylib if !sess. opts . cg . prefer_dynamic => Linkage :: Static ,
96- CrateType :: Dylib | CrateType :: Cdylib => Linkage :: Dynamic ,
92+ // Treat cdylibs and staticlibs similarly. If `-C prefer-dynamic` is set,
93+ // the caller may be code-size conscious, but without it, it makes sense
94+ // to statically link a cdylib or staticlib.
95+ CrateType :: Dylib | CrateType :: Cdylib | CrateType :: Staticlib => {
96+ if sess. opts . cg . prefer_dynamic { Linkage :: Dynamic } else { Linkage :: Static }
97+ }
9798
9899 // If the global prefer_dynamic switch is turned off, or the final
99100 // executable will be statically linked, prefer static crate linkage.
@@ -108,9 +109,6 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
108109 // No linkage happens with rlibs, we just needed the metadata (which we
109110 // got long ago), so don't bother with anything.
110111 CrateType :: Rlib => Linkage :: NotLinked ,
111-
112- // staticlibs must have all static dependencies.
113- CrateType :: Staticlib => Linkage :: Static ,
114112 } ;
115113
116114 match preferred_linkage {
@@ -123,12 +121,11 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
123121 return v;
124122 }
125123
126- // Staticlibs and static executables must have all static dependencies.
124+ // Static executables must have all static dependencies.
127125 // If any are not found, generate some nice pretty errors.
128- if ty == CrateType :: Staticlib
129- || ( ty == CrateType :: Executable
130- && sess. crt_static ( Some ( ty) )
131- && !sess. target . crt_static_allows_dylibs )
126+ if ty == CrateType :: Executable
127+ && sess. crt_static ( Some ( ty) )
128+ && !sess. target . crt_static_allows_dylibs
132129 {
133130 for & cnum in tcx. crates ( ( ) ) . iter ( ) {
134131 if tcx. dep_kind ( cnum) . macros_only ( ) {
0 commit comments