11//! Validates all used crates and extern libraries and loads their metadata
22
33use std:: error:: Error ;
4- use std:: ops:: Fn ;
54use std:: path:: Path ;
65use std:: str:: FromStr ;
76use std:: time:: Duration ;
@@ -276,12 +275,6 @@ impl CStore {
276275 . filter_map ( |( cnum, data) | data. as_deref ( ) . map ( |data| ( cnum, data) ) )
277276 }
278277
279- fn iter_crate_data_mut ( & mut self ) -> impl Iterator < Item = ( CrateNum , & mut CrateMetadata ) > {
280- self . metas
281- . iter_enumerated_mut ( )
282- . filter_map ( |( cnum, data) | data. as_deref_mut ( ) . map ( |data| ( cnum, data) ) )
283- }
284-
285278 fn push_dependencies_in_postorder ( & self , deps : & mut IndexSet < CrateNum > , cnum : CrateNum ) {
286279 if !deps. contains ( & cnum) {
287280 let data = self . get_crate_data ( cnum) ;
@@ -307,13 +300,6 @@ impl CStore {
307300 deps
308301 }
309302
310- fn crate_dependencies_in_reverse_postorder (
311- & self ,
312- cnum : CrateNum ,
313- ) -> impl Iterator < Item = CrateNum > {
314- self . crate_dependencies_in_postorder ( cnum) . into_iter ( ) . rev ( )
315- }
316-
317303 pub ( crate ) fn injected_panic_runtime ( & self ) -> Option < CrateNum > {
318304 self . injected_panic_runtime
319305 }
@@ -966,27 +952,16 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
966952 // If we need a panic runtime, we try to find an existing one here. At
967953 // the same time we perform some general validation of the DAG we've got
968954 // going such as ensuring everything has a compatible panic strategy.
969- //
970- // The logic for finding the panic runtime here is pretty much the same
971- // as the allocator case with the only addition that the panic strategy
972- // compilation mode also comes into play.
973955 let desired_strategy = self . sess . panic_strategy ( ) ;
974956 let mut runtime_found = false ;
975957 let mut needs_panic_runtime = attr:: contains_name ( & krate. attrs , sym:: needs_panic_runtime) ;
976958
977- let mut panic_runtimes = Vec :: new ( ) ;
978- for ( cnum, data) in self . cstore . iter_crate_data ( ) {
959+ for ( _cnum, data) in self . cstore . iter_crate_data ( ) {
979960 needs_panic_runtime = needs_panic_runtime || data. needs_panic_runtime ( ) ;
980961 if data. is_panic_runtime ( ) {
981- // Inject a dependency from all #![needs_panic_runtime] to this
982- // #![panic_runtime] crate.
983- panic_runtimes. push ( cnum) ;
984962 runtime_found = runtime_found || data. dep_kind ( ) == CrateDepKind :: Explicit ;
985963 }
986964 }
987- for cnum in panic_runtimes {
988- self . inject_dependency_if ( cnum, "a panic runtime" , & |data| data. needs_panic_runtime ( ) ) ;
989- }
990965
991966 // If an explicitly linked and matching panic runtime was found, or if
992967 // we just don't need one at all, then we're done here and there's
@@ -997,12 +972,10 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
997972
998973 // By this point we know that we (a) need a panic runtime and (b) no
999974 // panic runtime was explicitly linked. Here we just load an appropriate
1000- // default runtime for our panic strategy and then inject the
1001- // dependencies.
975+ // default runtime for our panic strategy.
1002976 //
1003977 // We may resolve to an already loaded crate (as the crate may not have
1004- // been explicitly linked prior to this) and we may re-inject
1005- // dependencies again, but both of those situations are fine.
978+ // been explicitly linked prior to this), but this is fine.
1006979 //
1007980 // Also note that we have yet to perform validation of the crate graph
1008981 // in terms of everyone has a compatible panic runtime format, that's
@@ -1031,7 +1004,6 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
10311004 }
10321005
10331006 self . cstore . injected_panic_runtime = Some ( cnum) ;
1034- self . inject_dependency_if ( cnum, "a panic runtime" , & |data| data. needs_panic_runtime ( ) ) ;
10351007 }
10361008
10371009 fn inject_profiler_runtime ( & mut self ) {
@@ -1212,45 +1184,6 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
12121184 }
12131185 }
12141186
1215- fn inject_dependency_if (
1216- & mut self ,
1217- krate : CrateNum ,
1218- what : & str ,
1219- needs_dep : & dyn Fn ( & CrateMetadata ) -> bool ,
1220- ) {
1221- // Don't perform this validation if the session has errors, as one of
1222- // those errors may indicate a circular dependency which could cause
1223- // this to stack overflow.
1224- if self . dcx ( ) . has_errors ( ) . is_some ( ) {
1225- return ;
1226- }
1227-
1228- // Before we inject any dependencies, make sure we don't inject a
1229- // circular dependency by validating that this crate doesn't
1230- // transitively depend on any crates satisfying `needs_dep`.
1231- for dep in self . cstore . crate_dependencies_in_reverse_postorder ( krate) {
1232- let data = self . cstore . get_crate_data ( dep) ;
1233- if needs_dep ( & data) {
1234- self . dcx ( ) . emit_err ( errors:: NoTransitiveNeedsDep {
1235- crate_name : self . cstore . get_crate_data ( krate) . name ( ) ,
1236- needs_crate_name : what,
1237- deps_crate_name : data. name ( ) ,
1238- } ) ;
1239- }
1240- }
1241-
1242- // All crates satisfying `needs_dep` do not explicitly depend on the
1243- // crate provided for this compile, but in order for this compilation to
1244- // be successfully linked we need to inject a dependency (to order the
1245- // crates on the command line correctly).
1246- for ( cnum, data) in self . cstore . iter_crate_data_mut ( ) {
1247- if needs_dep ( data) {
1248- info ! ( "injecting a dep from {} to {}" , cnum, krate) ;
1249- data. add_dependency ( krate) ;
1250- }
1251- }
1252- }
1253-
12541187 fn report_unused_deps ( & mut self , krate : & ast:: Crate ) {
12551188 // Make a point span rather than covering the whole file
12561189 let span = krate. spans . inner_span . shrink_to_lo ( ) ;
0 commit comments