Skip to content

Commit dcabd04

Browse files
authored
F401 use BTreeMap instead of FxHashMap (#11621)
* Potentially resolves #11619 (nondeterministic hashmap order across different architectures) in F401 by replacing a hashmap with nondeterministic traversal order with an ordered mapping. I'm not sure how to test this with our CI/CD. I don't have an s390x machine at home. Should I try it in Qemu?
1 parent 3aa7e35 commit dcabd04

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::borrow::Cow;
22
use std::iter;
33

44
use anyhow::{anyhow, bail, Result};
5-
use rustc_hash::FxHashMap;
5+
use std::collections::BTreeMap;
66

77
use ruff_diagnostics::{Applicability, Diagnostic, Fix, FixAvailability, Violation};
88
use ruff_macros::{derive_message_formats, violation};
@@ -220,8 +220,8 @@ fn find_dunder_all_exprs<'a>(semantic: &'a SemanticModel) -> Vec<&'a ast::Expr>
220220
///
221221
pub(crate) fn unused_import(checker: &Checker, scope: &Scope, diagnostics: &mut Vec<Diagnostic>) {
222222
// Collect all unused imports by statement.
223-
let mut unused: FxHashMap<(NodeId, Exceptions), Vec<ImportBinding>> = FxHashMap::default();
224-
let mut ignored: FxHashMap<(NodeId, Exceptions), Vec<ImportBinding>> = FxHashMap::default();
223+
let mut unused: BTreeMap<(NodeId, Exceptions), Vec<ImportBinding>> = BTreeMap::default();
224+
let mut ignored: BTreeMap<(NodeId, Exceptions), Vec<ImportBinding>> = BTreeMap::default();
225225

226226
for binding_id in scope.binding_ids() {
227227
let binding = checker.semantic().binding(binding_id);

crates/ruff_python_semantic/src/binding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ pub enum BindingKind<'a> {
565565
}
566566

567567
bitflags! {
568-
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
568+
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
569569
pub struct Exceptions: u8 {
570570
const NAME_ERROR = 0b0000_0001;
571571
const MODULE_NOT_FOUND_ERROR = 0b0000_0010;

0 commit comments

Comments
 (0)