Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary sorts in rustc_hir_analysis #131328

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, trait_def_id: LocalDefId) {
debug!(?required_bounds);
let param_env = tcx.param_env(gat_def_id);

let mut unsatisfied_bounds: Vec<_> = required_bounds
let unsatisfied_bounds: Vec<_> = required_bounds
.into_iter()
.filter(|clause| match clause.kind().skip_binder() {
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
Expand All @@ -552,9 +552,6 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, trait_def_id: LocalDefId) {
.map(|clause| clause.to_string())
.collect();

// We sort so that order is predictable
unsatisfied_bounds.sort();

if !unsatisfied_bounds.is_empty() {
let plural = pluralize!(unsatisfied_bounds.len());
let suggestion = format!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
// List of connected regions is built. Now, run the overlap check
// for each pair of impl blocks in the same connected region.
for region in connected_regions.into_iter().flatten() {
let mut impl_blocks =
region.impl_blocks.into_iter().collect::<SmallVec<[usize; 8]>>();
impl_blocks.sort_unstable();
let impl_blocks = region.impl_blocks.into_iter().collect::<SmallVec<[usize; 8]>>();
Copy link
Contributor

@klensy klensy Oct 6, 2024

Choose a reason for hiding this comment

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

That into_iter().collect() can actually be skipped?
No, there is nested for :-(

Copy link
Contributor

Choose a reason for hiding this comment

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

It might be possible to use the IndexSet::as_slice API

for (i, &impl1_items_idx) in impl_blocks.iter().enumerate() {
let &(&impl1_def_id, impl_items1) = &impls_items[impl1_items_idx];
res = res.and(self.check_for_duplicate_items_in_impl(impl1_def_id));
Expand Down
Loading