Skip to content

Enable Clippy's iter_over_hash_type lint#25732

Merged
charliermarsh merged 4 commits into
mainfrom
charlie/enable-iter-over-hash-type
Jun 9, 2026
Merged

Enable Clippy's iter_over_hash_type lint#25732
charliermarsh merged 4 commits into
mainfrom
charlie/enable-iter-over-hash-type

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Jun 7, 2026

Copy link
Copy Markdown
Member

Summary

Stacks on #25726 and enables Clippy's iter_over_hash_type restriction lint across the workspace, so new hash-map and hash-set iterations must make their ordering assumptions explicit.

Most existing loops are order-independent and use a site-local #[expect(clippy::iter_over_hash_type)]. At the order-sensitive sites, this sorts before iteration. (In practice, that should stabilize some parser fixtures, configuration diagnostics, union normalization, etc.).

This lint is kind of annoying, but given how much we want to crack down on non-determinism in ty, it seems worthwhile to enable IMO.

@charliermarsh charliermarsh changed the title Enable Clippy's iter_over_hash_type lint Enable Clippy's iter_over_hash_type lint Jun 7, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 7, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 92.23%. The percentage of expected errors that received a diagnostic held steady at 87.42%. The number of fully passing files held steady at 92/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 7, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@charliermarsh charliermarsh marked this pull request as ready for review June 7, 2026 18:17
@charliermarsh charliermarsh added the internal An internal refactor or improvement label Jun 7, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 7, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

Full report with detailed diff (timing results)

@AlexWaygood AlexWaygood removed their request for review June 7, 2026 18:35
@astral-sh-bot

astral-sh-bot Bot commented Jun 7, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@dhruvmanila

Copy link
Copy Markdown
Member

IIUC, I think there was a previous attempt at something similar using custom types in #21686

@MichaReiser MichaReiser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this, but I suggest we add a reason to every suppression explaining why it is okay, because it will now even be harder to find non determinism by hash map iteration because we simply assume; Oh, this is okay. A reason at least allows us to day: No, this reason is no longer true!

#[expect(clippy::iter_over_hash_type, reason = "we want to avoid these idents to be future compatible")]

let existing = existing_tests(&tests_dir)?;

let mut updated_files = vec![];
let mut sorted_tests = tests.iter().collect::<Vec<_>>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you say more why it's important to sort here? Same below

Comment thread crates/ruff_workspace/src/options.rs Outdated
}

let mut normalized_aliases: FxHashMap<String, String> = FxHashMap::default();
let mut aliases = aliases.into_iter().collect::<Vec<_>>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure sorting here is required? It may mean that ruff's error message changes from run to run, but it should still always be an error? I don't mind it, but it feels a bit pedantic ;)

@@ -1614,6 +1620,9 @@ impl<'db, 'ast> SemanticIndexBuilder<'db, 'ast> {
&mut self,
nested_bindings: NestedGlobalOrNonlocalDeclarations,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a BTreeMap instead?

let mut interned_ids_by_definition =
FxHashMap::with_capacity_and_hasher(definitions_by_definition.len(), FxBuildHasher);

let mut definitions_by_definition =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a BTreeMap instead?

Base automatically changed from charlie/stabilize-map-codes-output to main June 8, 2026 08:58
@charliermarsh

Copy link
Copy Markdown
Member Author

Lol I literally backed out all the reasons because I thought they were too noisy :D

@charliermarsh

Copy link
Copy Markdown
Member Author

(I will re-add them.)

@charliermarsh charliermarsh force-pushed the charlie/enable-iter-over-hash-type branch from 64b9213 to ec1c351 Compare June 8, 2026 21:21
@charliermarsh charliermarsh force-pushed the charlie/enable-iter-over-hash-type branch from ec1c351 to bcf904d Compare June 9, 2026 12:40
@charliermarsh charliermarsh enabled auto-merge (squash) June 9, 2026 16:30
@charliermarsh charliermarsh merged commit 948359f into main Jun 9, 2026
58 checks passed
@charliermarsh charliermarsh deleted the charlie/enable-iter-over-hash-type branch June 9, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants