Skip to content

Commit 45aa994

Browse files
committed
Fix Ord of compare fix
1 parent b9b7def commit 45aa994

File tree

1 file changed

+7
-7
lines changed
  • crates/ruff_linter/src/fix

1 file changed

+7
-7
lines changed

crates/ruff_linter/src/fix/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ fn apply_fixes<'a>(
130130
/// Compare two fixes.
131131
fn cmp_fix(rule1: Rule, rule2: Rule, fix1: &Fix, fix2: &Fix) -> std::cmp::Ordering {
132132
// Always apply `RedefinedWhileUnused` before `UnusedImport`, as the latter can end up fixing
133-
// the former.
134-
{
135-
match (rule1, rule2) {
136-
(Rule::RedefinedWhileUnused, Rule::UnusedImport) => return std::cmp::Ordering::Less,
137-
(Rule::UnusedImport, Rule::RedefinedWhileUnused) => return std::cmp::Ordering::Greater,
138-
_ => std::cmp::Ordering::Equal,
139-
}
133+
// the former. But we can't apply this just for `RedefinedWhileUnused` and `UnusedImport` because it violates
134+
// `< is transitive: a < b and b < c implies a < c. The same must hold for both == and >.`
135+
// See https://github.com/astral-sh/ruff/issues/12469#issuecomment-2244392085
136+
match (rule1, rule2) {
137+
(Rule::RedefinedWhileUnused, _) => std::cmp::Ordering::Less,
138+
(_, Rule::RedefinedWhileUnused) => std::cmp::Ordering::Greater,
139+
_ => std::cmp::Ordering::Equal,
140140
}
141141
// Apply fixes in order of their start position.
142142
.then_with(|| fix1.min_start().cmp(&fix2.min_start()))

0 commit comments

Comments
 (0)