@@ -374,64 +374,24 @@ impl CrateGraph {
374374 self . arena . alloc ( data)
375375 }
376376
377- /// Remove the crate from crate graph. If any crates depend on this crate, the dependency would be replaced
378- /// with the second input.
379- pub fn remove_and_replace (
380- & mut self ,
381- id : CrateId ,
382- replace_with : CrateId ,
383- ) -> Result < ( ) , CyclicDependenciesError > {
384- for ( x, data) in self . arena . iter ( ) {
385- if x == id {
386- continue ;
387- }
388- for edge in & data. dependencies {
389- if edge. crate_id == id {
390- self . check_cycle_after_dependency ( edge. crate_id , replace_with) ?;
391- }
392- }
393- }
394- // if everything was ok, start to replace
395- for ( x, data) in self . arena . iter_mut ( ) {
396- if x == id {
397- continue ;
398- }
399- for edge in & mut data. dependencies {
400- if edge. crate_id == id {
401- edge. crate_id = replace_with;
402- }
403- }
404- }
405- Ok ( ( ) )
406- }
407-
408377 pub fn add_dep (
409378 & mut self ,
410379 from : CrateId ,
411380 dep : Dependency ,
412381 ) -> Result < ( ) , CyclicDependenciesError > {
413382 let _p = tracing:: info_span!( "add_dep" ) . entered ( ) ;
414383
415- self . check_cycle_after_dependency ( from, dep. crate_id ) ?;
416-
417- self . arena [ from] . add_dep ( dep) ;
418- Ok ( ( ) )
419- }
420-
421- /// Check if adding a dep from `from` to `to` creates a cycle. To figure
422- /// that out, look for a path in the *opposite* direction, from `to` to
423- /// `from`.
424- fn check_cycle_after_dependency (
425- & self ,
426- from : CrateId ,
427- to : CrateId ,
428- ) -> Result < ( ) , CyclicDependenciesError > {
429- if let Some ( path) = self . find_path ( & mut FxHashSet :: default ( ) , to, from) {
384+ // Check if adding a dep from `from` to `to` creates a cycle. To figure
385+ // that out, look for a path in the *opposite* direction, from `to` to
386+ // `from`.
387+ if let Some ( path) = self . find_path ( & mut FxHashSet :: default ( ) , dep. crate_id , from) {
430388 let path = path. into_iter ( ) . map ( |it| ( it, self [ it] . display_name . clone ( ) ) ) . collect ( ) ;
431389 let err = CyclicDependenciesError { path } ;
432- assert ! ( err. from( ) . 0 == from && err. to( ) . 0 == to ) ;
390+ assert ! ( err. from( ) . 0 == from && err. to( ) . 0 == dep . crate_id ) ;
433391 return Err ( err) ;
434392 }
393+
394+ self . arena [ from] . add_dep ( dep) ;
435395 Ok ( ( ) )
436396 }
437397
0 commit comments