@@ -591,45 +591,10 @@ impl Ord for SourceId {
591
591
return Ordering :: Equal ;
592
592
}
593
593
594
- // Sort first based on `kind`, deferring to the URL comparison below if
594
+ // Sort first based on `kind`, deferring to the URL comparison if
595
595
// the kinds are equal.
596
- match self . inner . kind . cmp ( & other. inner . kind ) {
597
- Ordering :: Equal => { }
598
- other => return other,
599
- }
600
-
601
- let ord = self . inner . canonical_url . cmp ( & other. inner . canonical_url ) ;
602
-
603
- match ( & self . inner . kind , & other. inner . kind ) {
604
- ( SourceKind :: Git ( _) , SourceKind :: Git ( _) ) => {
605
- // In the pre-PR code we returned Ord here,
606
- // so there is no chance that this commit has broken anything about this match arm.
607
- }
608
- _ => {
609
- // In the pre-PR code we returned cmp of url here, so let's make sure that's the same.
610
- assert_eq ! ( self . inner. url. cmp( & other. inner. url) , ord) ;
611
- // I am quite sure that this assert will never fire.
612
- // In order for it to fire either `url`s are equal but `canonical_url`s are not,
613
- // or the other way around. The algorithm for constructing a canonical URL is deterministic,
614
- // so if it's given the same URL it will return the same canonical URL.
615
-
616
- // But what if we have two different URLs that canonical eyes the same?
617
- // I assert that the second one would get thrown out when the second `SourceId` was interned.
618
- // `SourceId::new` is the only way to make a `SourceId`. It allways construct them with
619
- // `precise: None`. Furthermore, it uses `SourceId::wrap` to see if it has ever constructed
620
- // a previous instance with a `SourceIdInner` that is `SourceIdInner::eq` with the one beeing added.
621
- // `SourceIdInner::eq` only looks at `kind`, `precise`, and `canonical_url`.
622
- // Proof by contradiction: If we had constructed two `SourceId` that:
623
- // 1. have the same `kind` (check that a few lines ago)
624
- // 2. have the same `precise` (as at construction time it is allways None)
625
- // 3. have the same `canonical_url` (by the assumption of this paragraph)
626
- // then the `ptr::eq` would return equal. Even if they were constructed with different `url`s,
627
- // `SourceId::wrap` would have noticed that they `SourceIdInner::eq`
628
- // and thus returned a pointer to the first one.
629
- }
630
- }
631
-
632
- ord
596
+ let ord_kind = self . inner . kind . cmp ( & other. inner . kind ) ;
597
+ ord_kind. then_with ( || self . inner . canonical_url . cmp ( & other. inner . canonical_url ) )
633
598
}
634
599
}
635
600
0 commit comments