@@ -329,12 +329,10 @@ pub struct CrateData {
329
329
}
330
330
331
331
impl CrateData {
332
- /**
333
- Check if [`other`] is almost equal to [`self`].
334
- This method has some obscure bits. These are mostly there to be compliant with
335
- some patches. References to the patches are given.
336
- */
337
- pub fn almost_eq ( & self , other : & CrateData ) -> bool {
332
+ /// Check if [`other`] is almost equal to [`self`] ignoring `CrateOrigin` value.
333
+ pub fn eq_ignoring_origin ( & self , other : & CrateData ) -> bool {
334
+ // This method has some obscure bits. These are mostly there to be compliant with
335
+ // some patches. References to the patches are given.
338
336
if self . root_file_id != other. root_file_id {
339
337
return false ;
340
338
}
@@ -356,16 +354,16 @@ impl CrateData {
356
354
}
357
355
358
356
let mut opts = self . cfg_options . clone ( ) ;
359
- opts. apply_diff ( CfgDiff {
360
- disable : other. cfg_options . clone ( ) . into_iter ( ) . collect ( ) ,
361
- enable : vec ! [ ] ,
362
- } ) ;
357
+ opts. apply_diff (
358
+ CfgDiff :: new ( vec ! [ ] , other. cfg_options . clone ( ) . into_iter ( ) . collect ( ) )
359
+ . expect ( "CfgOptions were expected to contain no duplicates." ) ,
360
+ ) ;
363
361
364
362
let mut cfgs = opts. into_iter ( ) ;
365
363
if let Some ( cfg) = cfgs. next ( ) {
366
364
// Don't care if rust_analyzer CfgAtom is the only cfg in the difference set of self's and other's cfgs.
367
365
// https://github.com/rust-lang/rust-analyzer/blob/0840038f02daec6ba3238f05d8caa037d28701a0/crates/project-model/src/workspace.rs#L894
368
- if ! cfgs. next ( ) . is_none ( ) || cfg. to_string ( ) != "rust_analyzer" {
366
+ if cfgs. next ( ) . is_some ( ) || cfg. to_string ( ) != "rust_analyzer" {
369
367
return false ;
370
368
}
371
369
}
@@ -686,41 +684,35 @@ impl CrateGraph {
686
684
/// Note that for deduplication to fully work, `self`'s crate dependencies must be sorted by crate id.
687
685
/// If the crate dependencies were sorted, the resulting graph from this `extend` call will also have the crate dependencies sorted.
688
686
pub fn extend ( & mut self , mut other : CrateGraph , proc_macros : & mut ProcMacroPaths ) {
689
- enum ExtendStrategy {
690
- Dedup ( CrateId ) ,
691
- Replace ( CrateId ) ,
692
- }
693
-
694
687
let topo = other. crates_in_topological_order ( ) ;
695
688
let mut id_map: FxHashMap < CrateId , CrateId > = FxHashMap :: default ( ) ;
696
689
for topo in topo {
697
690
let crate_data = & mut other. arena [ topo] ;
698
691
699
- crate_data. dependencies . iter_mut ( ) . for_each ( |dep| {
700
- dep. crate_id = id_map[ & dep. crate_id ] ;
701
- } ) ;
692
+ crate_data. dependencies . iter_mut ( ) . for_each ( |dep| dep. crate_id = id_map[ & dep. crate_id ] ) ;
702
693
crate_data. dependencies . sort_by_key ( |dep| dep. crate_id ) ;
703
694
let res = self . arena . iter ( ) . find_map ( |( id, data) | {
704
- if data. almost_eq ( crate_data) {
695
+ if data. eq_ignoring_origin ( crate_data) {
705
696
if data. origin . is_lib ( ) && crate_data. origin . is_local ( ) {
706
697
// See #15656 for a relevant example.
707
- return Some ( ExtendStrategy :: Replace ( id) ) ;
698
+ return Some ( ( id, true ) ) ;
708
699
}
709
700
710
- return Some ( ExtendStrategy :: Dedup ( id) ) ;
701
+ return Some ( ( id, false ) ) ;
711
702
}
712
703
None
713
704
} ) ;
714
705
715
- if let Some ( res) = res {
716
- match res {
717
- ExtendStrategy :: Dedup ( res) => id_map. insert ( topo, res) ,
718
- ExtendStrategy :: Replace ( res) => {
719
- let id = self . arena . alloc ( crate_data. clone ( ) ) ;
720
- let _ = self . remove_and_replace ( res, id) ;
721
- id_map. insert ( topo, id)
706
+ if let Some ( ( res, should_update_lib_to_local) ) = res {
707
+ id_map. insert ( topo, res) ;
708
+ if should_update_lib_to_local {
709
+ let origin_old = self . arena [ res] . origin . clone ( ) ;
710
+ assert ! ( origin_old. is_lib( ) ) ;
711
+
712
+ if let CrateOrigin :: Library { repo, name } = origin_old {
713
+ self . arena [ res] . origin = CrateOrigin :: Local { repo, name : Some ( name) } ;
722
714
}
723
- } ;
715
+ }
724
716
} else {
725
717
let id = self . arena . alloc ( crate_data. clone ( ) ) ;
726
718
id_map. insert ( topo, id) ;
0 commit comments