@@ -353,20 +353,18 @@ impl CrateData {
353
353
return false ;
354
354
}
355
355
356
- let mut opts = self . cfg_options . diff ( & other. cfg_options ) . into_iter ( ) ;
357
- match opts. len ( ) {
358
- 0 => ( ) ,
359
- 1 => {
360
- // Don't care if rust_analyzer CfgAtom is the only cfg in the difference set of self's and other's cfgs.
361
- // https://github.com/rust-lang/rust-analyzer/blob/0840038f02daec6ba3238f05d8caa037d28701a0/crates/project-model/src/workspace.rs#L894
362
- if let Some ( cfg) = opts. next ( ) {
363
- if cfg. to_string ( ) != "rust_analyzer" {
364
- return false ;
365
- }
366
- }
356
+ let mut opts = self . cfg_options . difference ( & other. cfg_options ) ;
357
+ if let Some ( it) = opts. next ( ) {
358
+ // Don't care if rust_analyzer CfgAtom is the only cfg in the difference set of self's and other's cfgs.
359
+ // https://github.com/rust-lang/rust-analyzer/blob/0840038f02daec6ba3238f05d8caa037d28701a0/crates/project-model/src/workspace.rs#L894
360
+ if it. to_string ( ) != "rust_analyzer" {
361
+ return false ;
367
362
}
368
- _ => return false ,
369
- } ;
363
+
364
+ if let Some ( _) = opts. next ( ) {
365
+ return false ;
366
+ }
367
+ }
370
368
371
369
if self . env != other. env {
372
370
return false ;
@@ -378,8 +376,8 @@ impl CrateData {
378
376
if ignore_dev_deps {
379
377
return slf_deps
380
378
. clone ( )
381
- . filter ( |it| it. kind == DependencyKind :: Normal )
382
- . eq ( other_deps. clone ( ) . filter ( |it| it. kind == DependencyKind :: Normal ) ) ;
379
+ . filter ( |it| it. kind != DependencyKind :: Dev )
380
+ . eq ( other_deps. clone ( ) . filter ( |it| it. kind != DependencyKind :: Dev ) ) ;
383
381
}
384
382
385
383
slf_deps. eq ( other_deps)
@@ -524,7 +522,7 @@ impl CrateGraph {
524
522
525
523
self . check_cycle_after_dependency ( from, dep. crate_id ) ?;
526
524
527
- self . arena [ from] . add_dep_unchecked ( dep) ;
525
+ self . arena [ from] . add_dep ( dep) ;
528
526
Ok ( ( ) )
529
527
}
530
528
@@ -667,7 +665,12 @@ impl CrateGraph {
667
665
}
668
666
( a @ CrateOrigin :: Local { .. } , CrateOrigin :: Library { .. } )
669
667
| ( a @ CrateOrigin :: Library { .. } , CrateOrigin :: Local { .. } ) => {
670
- // See #15656 for a relevant example.
668
+ // If the origins differ, check if the two crates are equal without
669
+ // considering the dev dependencies, if they are, they most likely are in
670
+ // different loaded workspaces which may cause issues. We keep the local
671
+ // version and discard the library one as the local version may have
672
+ // dev-dependencies that we want to keep resolving. See #15656 for more
673
+ // information.
671
674
if data. eq_ignoring_origin_and_deps ( & crate_data, true ) {
672
675
return Some ( ( id, if a. is_local ( ) { false } else { true } ) ) ;
673
676
}
@@ -681,22 +684,12 @@ impl CrateGraph {
681
684
if let Some ( ( res, should_update_lib_to_local) ) = res {
682
685
id_map. insert ( topo, res) ;
683
686
if should_update_lib_to_local {
684
- let origin_old = self . arena [ res] . origin . clone ( ) ;
685
- assert ! ( origin_old. is_lib( ) ) ;
686
-
687
- if let CrateOrigin :: Library { repo, name } = origin_old {
688
- self . arena [ res] . origin = CrateOrigin :: Local { repo, name : Some ( name) } ;
689
- }
687
+ assert ! ( self . arena[ res] . origin. is_lib( ) ) ;
688
+ assert ! ( crate_data. origin. is_local( ) ) ;
689
+ self . arena [ res] . origin = crate_data. origin . clone ( ) ;
690
690
691
691
// Move local's dev dependencies into the newly-local-formerly-lib crate.
692
- let dev_deps = crate_data
693
- . dependencies
694
- . clone ( )
695
- . into_iter ( )
696
- . filter ( |dep| dep. kind ( ) == DependencyKind :: Dev )
697
- . collect :: < Vec < Dependency > > ( ) ;
698
-
699
- self . arena [ res] . add_dep ( dev_deps) . unwrap_or_default ( ) ;
692
+ self . arena [ res] . dependencies = crate_data. dependencies . clone ( ) ;
700
693
}
701
694
} else {
702
695
let id = self . arena . alloc ( crate_data. clone ( ) ) ;
@@ -766,34 +759,12 @@ impl ops::Index<CrateId> for CrateGraph {
766
759
}
767
760
}
768
761
769
- struct ExistingDepsError ( Vec < Dependency > ) ;
770
-
771
762
impl CrateData {
772
763
/// Add a dependency to `self` without checking if the dependency
773
764
// is existent among `self.dependencies`.
774
- fn add_dep_unchecked ( & mut self , dep : Dependency ) {
765
+ fn add_dep ( & mut self , dep : Dependency ) {
775
766
self . dependencies . push ( dep)
776
767
}
777
-
778
- /// Add `deps` to `self` if the dependency is not already listed.
779
- /// Finally returning an `Err` propagating the dependencies it couldn't add.
780
- fn add_dep ( & mut self , deps : Vec < Dependency > ) -> Result < ( ) , ExistingDepsError > {
781
- let mut existing_deps: Vec < Dependency > = vec ! [ ] ;
782
-
783
- deps. into_iter ( ) . for_each ( |dep| {
784
- if !self . dependencies . contains ( & dep) {
785
- self . dependencies . push ( dep) ;
786
- } else {
787
- existing_deps. push ( dep) ;
788
- }
789
- } ) ;
790
-
791
- if !existing_deps. is_empty ( ) {
792
- return Err ( ExistingDepsError ( existing_deps) ) ;
793
- }
794
-
795
- Ok ( ( ) )
796
- }
797
768
}
798
769
799
770
impl FromStr for Edition {
0 commit comments