54
54
use crate :: creader:: CStore ;
55
55
use crate :: errors:: {
56
56
BadPanicStrategy , CrateDepMultiple , IncompatiblePanicInDropStrategy , LibRequired ,
57
- RequiredPanicStrategy , RlibRequired , RustcLibRequired , TwoPanicRuntimes ,
57
+ NonStaticCrateDep , RequiredPanicStrategy , RlibRequired , RustcLibRequired , TwoPanicRuntimes ,
58
58
} ;
59
59
60
60
use rustc_data_structures:: fx:: FxHashMap ;
@@ -123,13 +123,15 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
123
123
CrateType :: Rlib => Linkage :: NotLinked ,
124
124
} ;
125
125
126
+ let mut unavailable_as_static = Vec :: new ( ) ;
127
+
126
128
match preferred_linkage {
127
129
// If the crate is not linked, there are no link-time dependencies.
128
130
Linkage :: NotLinked => return Vec :: new ( ) ,
129
131
Linkage :: Static => {
130
132
// Attempt static linkage first. For dylibs and executables, we may be
131
133
// able to retry below with dynamic linkage.
132
- if let Some ( v) = attempt_static ( tcx) {
134
+ if let Some ( v) = attempt_static ( tcx, & mut unavailable_as_static ) {
133
135
return v;
134
136
}
135
137
@@ -169,11 +171,11 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
169
171
let src = tcx. used_crate_source ( cnum) ;
170
172
if src. dylib . is_some ( ) {
171
173
info ! ( "adding dylib: {}" , name) ;
172
- add_library ( tcx, cnum, RequireDynamic , & mut formats) ;
174
+ add_library ( tcx, cnum, RequireDynamic , & mut formats, & mut unavailable_as_static ) ;
173
175
let deps = tcx. dylib_dependency_formats ( cnum) ;
174
176
for & ( depnum, style) in deps. iter ( ) {
175
177
info ! ( "adding {:?}: {}" , style, tcx. crate_name( depnum) ) ;
176
- add_library ( tcx, depnum, style, & mut formats) ;
178
+ add_library ( tcx, depnum, style, & mut formats, & mut unavailable_as_static ) ;
177
179
}
178
180
}
179
181
}
@@ -201,7 +203,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
201
203
{
202
204
assert ! ( src. rlib. is_some( ) || src. rmeta. is_some( ) ) ;
203
205
info ! ( "adding staticlib: {}" , tcx. crate_name( cnum) ) ;
204
- add_library ( tcx, cnum, RequireStatic , & mut formats) ;
206
+ add_library ( tcx, cnum, RequireStatic , & mut formats, & mut unavailable_as_static ) ;
205
207
ret[ cnum. as_usize ( ) - 1 ] = Linkage :: Static ;
206
208
}
207
209
}
@@ -252,6 +254,7 @@ fn add_library(
252
254
cnum : CrateNum ,
253
255
link : LinkagePreference ,
254
256
m : & mut FxHashMap < CrateNum , LinkagePreference > ,
257
+ unavailable_as_static : & mut Vec < CrateNum > ,
255
258
) {
256
259
match m. get ( & cnum) {
257
260
Some ( & link2) => {
@@ -263,7 +266,13 @@ fn add_library(
263
266
// This error is probably a little obscure, but I imagine that it
264
267
// can be refined over time.
265
268
if link2 != link || link == RequireStatic {
266
- tcx. dcx ( ) . emit_err ( CrateDepMultiple { crate_name : tcx. crate_name ( cnum) } ) ;
269
+ tcx. dcx ( ) . emit_err ( CrateDepMultiple {
270
+ crate_name : tcx. crate_name ( cnum) ,
271
+ non_static_deps : unavailable_as_static
272
+ . drain ( ..)
273
+ . map ( |cnum| NonStaticCrateDep { crate_name : tcx. crate_name ( cnum) } )
274
+ . collect ( ) ,
275
+ } ) ;
267
276
}
268
277
}
269
278
None => {
@@ -272,7 +281,7 @@ fn add_library(
272
281
}
273
282
}
274
283
275
- fn attempt_static ( tcx : TyCtxt < ' _ > ) -> Option < DependencyList > {
284
+ fn attempt_static ( tcx : TyCtxt < ' _ > , unavailable : & mut Vec < CrateNum > ) -> Option < DependencyList > {
276
285
let all_crates_available_as_rlib = tcx
277
286
. crates ( ( ) )
278
287
. iter ( )
@@ -281,7 +290,11 @@ fn attempt_static(tcx: TyCtxt<'_>) -> Option<DependencyList> {
281
290
if tcx. dep_kind ( cnum) . macros_only ( ) {
282
291
return None ;
283
292
}
284
- Some ( tcx. used_crate_source ( cnum) . rlib . is_some ( ) )
293
+ let is_rlib = tcx. used_crate_source ( cnum) . rlib . is_some ( ) ;
294
+ if !is_rlib {
295
+ unavailable. push ( cnum) ;
296
+ }
297
+ Some ( is_rlib)
285
298
} )
286
299
. all ( |is_rlib| is_rlib) ;
287
300
if !all_crates_available_as_rlib {
0 commit comments