Skip to content

Commit 4c2dd75

Browse files
author
Yuki Okushi
authored
Rollup merge of rust-lang#106008 - uweigand:s390x-lintgroup-order, r=Nilstrieb
Sort lint_groups in no_lint_suggestion The no_lint_suggestion routine passes a vector of lint group names to find_best_match_for_name. That routine depends on the sort order of its input vector, which matters in case multiple inputs are at the same Levenshtein distance to the target name. However, no_lint_suggestion currently just passes lint_groups.keys() as input vector - this is sorted in hash value order, which is not guaranteed to be stable, and in fact differs between big- and little-endian host platforms, causing test failures on s390x. To fix this, always sort the lint groups before using their names as input to find_best_match_for_name. In doing so, prefer non- deprecated lint group names over deprecated ones, and then use alphabetical order. Fixes rust-lang#105379
2 parents 6c0dedb + 30fbfd5 commit 4c2dd75

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

compiler/rustc_lint/src/context.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,16 @@ impl LintStore {
483483
return CheckLintNameResult::NoLint(Some(Symbol::intern(&name_lower)));
484484
}
485485
// ...if not, search for lints with a similar name
486-
let groups = self.lint_groups.keys().copied().map(Symbol::intern);
486+
// Note: find_best_match_for_name depends on the sort order of its input vector.
487+
// To ensure deterministic output, sort elements of the lint_groups hash map.
488+
// Also, never suggest deprecated lint groups.
489+
let mut groups: Vec<_> = self
490+
.lint_groups
491+
.iter()
492+
.filter_map(|(k, LintGroup { depr, .. })| if depr.is_none() { Some(k) } else { None })
493+
.collect();
494+
groups.sort();
495+
let groups = groups.iter().map(|k| Symbol::intern(k));
487496
let lints = self.lints.iter().map(|l| Symbol::intern(&l.name_lower()));
488497
let names: Vec<Symbol> = groups.chain(lints).collect();
489498
let suggestion = find_best_match_for_name(&names, Symbol::intern(&name_lower), None);

0 commit comments

Comments
 (0)