Skip to content

Commit

Permalink
repair Ord for UseSegment (#6375)
Browse files Browse the repository at this point in the history
Previously, `Ord` for `UseSegment` was not Transitive, causing `user-provided comparison function
does not correctly implement a total order` panic.
  • Loading branch information
ajewellamz authored Nov 4, 2024
1 parent 96cc01b commit 777e25a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,10 +943,10 @@ impl Ord for UseSegment {
version_sort(ia, ib)
} else {
// snake_case < CamelCase < UPPER_SNAKE_CASE
if ia.starts_with(char::is_uppercase) && ib.starts_with(char::is_lowercase) {
if ia.starts_with(char::is_uppercase) && !ib.starts_with(char::is_uppercase) {
return Ordering::Greater;
}
if ia.starts_with(char::is_lowercase) && ib.starts_with(char::is_uppercase) {
if !ia.starts_with(char::is_uppercase) && ib.starts_with(char::is_uppercase) {
return Ordering::Less;
}
if is_upper_snake_case(ia) && !is_upper_snake_case(ib) {
Expand Down
24 changes: 24 additions & 0 deletions tests/source/issue-6333.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// rustfmt-edition: 2021
// rustfmt-max_width: 125
pub use ::dafny_runtime::Sequence;
pub use ::std::rc::Rc;
pub use crate::r#_StructuredEncryptionUtil_Compile::CanonCryptoItem;
pub use ::dafny_runtime::itertools::Itertools;
pub use crate::software::amazon::cryptography::dbencryptionsdk::structuredencryption::internaldafny::types::CryptoAction;
pub use crate::software::amazon::cryptography::materialproviders::internaldafny::types::EncryptedDataKey;
pub use ::dafny_runtime::Object;
pub use crate::software::amazon::cryptography::primitives::internaldafny::types::IAwsCryptographicPrimitivesClient;
pub use crate::software::amazon::cryptography::materialproviders::internaldafny::types::AlgorithmSuiteInfo;
pub use ::dafny_runtime::DafnyCharUTF16;
pub use crate::r#_StructuredEncryptionUtil_Compile::MessageID;
pub use crate::software::amazon::cryptography::materialproviders::internaldafny::types::EncryptionMaterials;
pub use crate::r#_Wrappers_Compile::Outcome;
pub use ::dafny_runtime::string_utf16_of;
pub use ::dafny_runtime::int;
pub use ::dafny_runtime::MapBuilder;
pub use ::dafny_runtime::_System::nat;
pub use crate::software::amazon::cryptography::primitives::internaldafny::types::HMacInput;
pub use ::dafny_runtime::rd;
pub use ::dafny_runtime::truncate;
pub use ::dafny_runtime::DafnyTypeEq;
pub use ::dafny_runtime::DafnyType;
24 changes: 24 additions & 0 deletions tests/target/issue-6333-2024.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// rustfmt-edition: 2024
// rustfmt-max_width: 125
pub use crate::r#_StructuredEncryptionUtil_Compile::CanonCryptoItem;
pub use crate::r#_StructuredEncryptionUtil_Compile::MessageID;
pub use crate::r#_Wrappers_Compile::Outcome;
pub use crate::software::amazon::cryptography::dbencryptionsdk::structuredencryption::internaldafny::types::CryptoAction;
pub use crate::software::amazon::cryptography::materialproviders::internaldafny::types::AlgorithmSuiteInfo;
pub use crate::software::amazon::cryptography::materialproviders::internaldafny::types::EncryptedDataKey;
pub use crate::software::amazon::cryptography::materialproviders::internaldafny::types::EncryptionMaterials;
pub use crate::software::amazon::cryptography::primitives::internaldafny::types::HMacInput;
pub use crate::software::amazon::cryptography::primitives::internaldafny::types::IAwsCryptographicPrimitivesClient;
pub use ::dafny_runtime::_System::nat;
pub use ::dafny_runtime::DafnyCharUTF16;
pub use ::dafny_runtime::DafnyType;
pub use ::dafny_runtime::DafnyTypeEq;
pub use ::dafny_runtime::MapBuilder;
pub use ::dafny_runtime::Object;
pub use ::dafny_runtime::Sequence;
pub use ::dafny_runtime::int;
pub use ::dafny_runtime::itertools::Itertools;
pub use ::dafny_runtime::rd;
pub use ::dafny_runtime::string_utf16_of;
pub use ::dafny_runtime::truncate;
pub use ::std::rc::Rc;
24 changes: 24 additions & 0 deletions tests/target/issue-6333.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// rustfmt-edition: 2021
// rustfmt-max_width: 125
pub use crate::r#_StructuredEncryptionUtil_Compile::CanonCryptoItem;
pub use crate::r#_StructuredEncryptionUtil_Compile::MessageID;
pub use crate::r#_Wrappers_Compile::Outcome;
pub use crate::software::amazon::cryptography::dbencryptionsdk::structuredencryption::internaldafny::types::CryptoAction;
pub use crate::software::amazon::cryptography::materialproviders::internaldafny::types::AlgorithmSuiteInfo;
pub use crate::software::amazon::cryptography::materialproviders::internaldafny::types::EncryptedDataKey;
pub use crate::software::amazon::cryptography::materialproviders::internaldafny::types::EncryptionMaterials;
pub use crate::software::amazon::cryptography::primitives::internaldafny::types::HMacInput;
pub use crate::software::amazon::cryptography::primitives::internaldafny::types::IAwsCryptographicPrimitivesClient;
pub use ::dafny_runtime::_System::nat;
pub use ::dafny_runtime::int;
pub use ::dafny_runtime::itertools::Itertools;
pub use ::dafny_runtime::rd;
pub use ::dafny_runtime::string_utf16_of;
pub use ::dafny_runtime::truncate;
pub use ::dafny_runtime::DafnyCharUTF16;
pub use ::dafny_runtime::DafnyType;
pub use ::dafny_runtime::DafnyTypeEq;
pub use ::dafny_runtime::MapBuilder;
pub use ::dafny_runtime::Object;
pub use ::dafny_runtime::Sequence;
pub use ::std::rc::Rc;

0 comments on commit 777e25a

Please sign in to comment.