diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 3b030fc098f41..ca21909e8f51b 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -4803,6 +4803,6 @@ fn body_ids(bodies: &BTreeMap) -> Vec { // Sorting by span ensures that we get things in order within a // file, and also puts the files in a sensible order. let mut body_ids: Vec<_> = bodies.keys().cloned().collect(); - body_ids.sort_by_key(|b| bodies[b].value.span); + body_ids.sort_unstable_by_key(|b| bodies[b].value.span); body_ids } diff --git a/src/librustc/hir/pat_util.rs b/src/librustc/hir/pat_util.rs index 14989f1ff7d8a..88e0a571b8e68 100644 --- a/src/librustc/hir/pat_util.rs +++ b/src/librustc/hir/pat_util.rs @@ -157,7 +157,7 @@ impl hir::Pat { } true }); - variants.sort(); + variants.sort_unstable(); variants.dedup(); variants } diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 4ad60f2f85e2c..fb9e0faa855e9 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -434,7 +434,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { }; // sort the errors by span, for better error message stability. - errors.sort_by_key(|u| match *u { + errors.sort_unstable_by_key(|u| match *u { RegionResolutionError::ConcreteFailure(ref sro, _, _) => sro.span(), RegionResolutionError::GenericBoundFailure(ref sro, _, _) => sro.span(), RegionResolutionError::SubSupConflict(ref rvo, _, _, _, _) => rvo.span(), diff --git a/src/librustc/infer/lexical_region_resolve/mod.rs b/src/librustc/infer/lexical_region_resolve/mod.rs index 120b45ec01e5e..68e9a710d1794 100644 --- a/src/librustc/infer/lexical_region_resolve/mod.rs +++ b/src/librustc/infer/lexical_region_resolve/mod.rs @@ -568,8 +568,8 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> { _ => 2, } } - lower_bounds.sort_by_key(region_order_key); - upper_bounds.sort_by_key(region_order_key); + lower_bounds.sort_unstable_by_key(region_order_key); + upper_bounds.sort_unstable_by_key(region_order_key); for lower_bound in &lower_bounds { for upper_bound in &upper_bounds { diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 1309540717c2b..e95a746abab48 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -1426,7 +1426,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { .collect(); // ensure that we issue lints in a repeatable order - def_ids.sort_by_key(|&def_id| self.tcx.def_path_hash(def_id)); + def_ids.sort_unstable_by_key(|&def_id| self.tcx.def_path_hash(def_id)); for def_id in def_ids { debug!( diff --git a/src/librustc/session/code_stats.rs b/src/librustc/session/code_stats.rs index df4060e71e53e..47b792cfb7565 100644 --- a/src/librustc/session/code_stats.rs +++ b/src/librustc/session/code_stats.rs @@ -100,7 +100,7 @@ impl CodeStats { // Primary sort: large-to-small. // Secondary sort: description (dictionary order) - sorted.sort_by(|info1, info2| { + sorted.sort_unstable_by(|info1, info2| { // (reversing cmp order to get large-to-small ordering) match info2.overall_size.cmp(&info1.overall_size) { Ordering::Equal => info1.type_description.cmp(&info2.type_description), @@ -151,7 +151,7 @@ impl CodeStats { // We want to print fields by increasing offset. let mut fields = fields.clone(); - fields.sort_by_key(|f| f.offset); + fields.sort_unstable_by_key(|f| f.offset); for field in fields.iter() { let FieldInfo { ref name, offset, size, align } = *field; diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 293b5c63cf06a..4900fe4994812 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -2401,7 +2401,7 @@ mod dep_tracking { impl DepTrackingHash for Vec<$t> { fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) { let mut elems: Vec<&$t> = self.iter().collect(); - elems.sort(); + elems.sort_unstable(); Hash::hash(&elems.len(), hasher); for (index, elem) in elems.iter().enumerate() { Hash::hash(&index, hasher); diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index faad32a5d994e..c8cc25906026a 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -288,7 +288,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { match kind { StructKind::AlwaysSized | StructKind::MaybeUnsized => { - optimizing.sort_by_key(|&x| { + optimizing.sort_unstable_by_key(|&x| { // Place ZSTs first to avoid "interesting offsets", // especially with only one or two non-ZST fields. let f = &fields[x as usize]; @@ -296,7 +296,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { }); } StructKind::Prefixed(..) => { - optimizing.sort_by_key(|&x| field_align(&fields[x as usize])); + optimizing.sort_unstable_by_key(|&x| field_align(&fields[x as usize])); } } } diff --git a/src/librustc/util/time_graph.rs b/src/librustc/util/time_graph.rs index a8502682a806b..c24e79ed8a3eb 100644 --- a/src/librustc/util/time_graph.rs +++ b/src/librustc/util/time_graph.rs @@ -127,7 +127,7 @@ impl TimeGraph { let mut threads: Vec = table.values().map(|data| data.clone()).collect(); - threads.sort_by_key(|timeline| timeline.timings[0].start); + threads.sort_unstable_by_key(|timeline| timeline.timings[0].start); let earliest_instant = threads[0].timings[0].start; let latest_instant = threads.iter() diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs index d36142af56c65..effec4e521b09 100644 --- a/src/librustc_codegen_llvm/back/write.rs +++ b/src/librustc_codegen_llvm/back/write.rs @@ -1923,7 +1923,7 @@ fn start_executing_work(tcx: TyCtxt, // Regardless of what order these modules completed in, report them to // the backend in the same order every time to ensure that we're handing // out deterministic results. - compiled_modules.sort_by(|a, b| a.name.cmp(&b.name)); + compiled_modules.sort_unstable_by(|a, b| a.name.cmp(&b.name)); let compiled_metadata_module = compiled_metadata_module .expect("Metadata module not compiled?"); diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs index 223c04f420f3f..6485f6d8fdd44 100644 --- a/src/librustc_codegen_llvm/base.rs +++ b/src/librustc_codegen_llvm/base.rs @@ -925,7 +925,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, println!("n_inlines: {}", all_stats.n_inlines); println!("n_closures: {}", all_stats.n_closures); println!("fn stats:"); - all_stats.fn_stats.sort_by_key(|&(_, insns)| insns); + all_stats.fn_stats.sort_unstable_by_key(|&(_, insns)| insns); for &(ref name, insns) in all_stats.fn_stats.iter() { println!("{} insns, {}", insns, *name); } @@ -1037,7 +1037,7 @@ fn collect_and_partition_mono_items<'a, 'tcx>( output.push_str(" @@"); let mut empty = Vec::new(); let cgus = item_to_cgus.get_mut(i).unwrap_or(&mut empty); - cgus.as_mut_slice().sort_by_key(|&(ref name, _)| name.clone()); + cgus.as_mut_slice().sort_unstable_by_key(|&(ref name, _)| name.clone()); cgus.dedup(); for &(ref cgu_name, (linkage, _)) in cgus.iter() { output.push_str(" "); @@ -1065,7 +1065,7 @@ fn collect_and_partition_mono_items<'a, 'tcx>( }) .collect(); - item_keys.sort(); + item_keys.sort_unstable(); for item in item_keys { println!("MONO_ITEM {}", item); diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index c016a131507e8..f97adf685e186 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -1002,7 +1002,7 @@ where .iter() .cloned() .collect(); - missing_fragment_specifiers.sort(); + missing_fragment_specifiers.sort_unstable(); for span in missing_fragment_specifiers { let lint = lint::builtin::MISSING_FRAGMENT_SPECIFIER; let msg = "missing fragment specifier"; @@ -1520,7 +1520,7 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec CrateDisambiguator { let mut metadata = session.opts.cg.metadata.clone(); // We don't want the crate_disambiguator to dependent on the order // -C metadata arguments, so sort them: - metadata.sort(); + metadata.sort_unstable(); // Every distinct -C metadata value is only incorporated once: metadata.dedup(); diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index f60954ea02166..85f1057a540bc 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1051,7 +1051,7 @@ impl RustcDefaultCalls { match *req { TargetList => { let mut targets = rustc_target::spec::get_targets().collect::>(); - targets.sort(); + targets.sort_unstable(); println!("{}", targets.join("\n")); }, Sysroot => println!("{}", sess.sysroot().display()), @@ -1117,7 +1117,7 @@ impl RustcDefaultCalls { }); } - cfgs.sort(); + cfgs.sort_unstable(); for cfg in cfgs { println!("{}", cfg); } @@ -1229,8 +1229,8 @@ Available lint options: fn sort_lint_groups(lints: Vec<(&'static str, Vec, bool)>) -> Vec<(&'static str, Vec)> { let mut lints: Vec<_> = lints.into_iter().map(|(x, y, _)| (x, y)).collect(); - lints.sort_by(|&(x, _): &(&'static str, Vec), - &(y, _): &(&'static str, Vec)| { + lints.sort_unstable_by(|&(x, _): &(&'static str, Vec), + &(y, _): &(&'static str, Vec)| { x.cmp(y) }); lints diff --git a/src/librustc_driver/profile/trace.rs b/src/librustc_driver/profile/trace.rs index 5f10c56e8e214..9a1a6a002bd6c 100644 --- a/src/librustc_driver/profile/trace.rs +++ b/src/librustc_driver/profile/trace.rs @@ -208,8 +208,8 @@ pub fn write_counts(count_file: &mut File, counts: &mut HashMap self2 { Ordering::Less } else { Ordering::Greater } ); + data.sort_unstable_by(|&(_,_,_,self1),&(_,_,_,self2)| + if self1 > self2 { Ordering::Less } else { Ordering::Greater } ); for (cons, count, dur_total, dur_self) in data { write!(count_file, "{}, {}, {}, {}\n", cons, count, diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index c9b6818d5c158..46d50a8d26447 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -196,7 +196,7 @@ impl EmitterWriter { line_index, annotations: vec![ann], }); - slot.lines.sort(); + slot.lines.sort_unstable(); return; } } @@ -265,7 +265,7 @@ impl EmitterWriter { } // Find overlapping multiline annotations, put them at different depths - multiline_annotations.sort_by(|a, b| { + multiline_annotations.sort_unstable_by(|a, b| { (a.1.line_start, a.1.line_end).cmp(&(b.1.line_start, b.1.line_end)) }); for item in multiline_annotations.clone() { @@ -403,7 +403,7 @@ impl EmitterWriter { // otherwise the lines would end up needing to go over a message. let mut annotations = line.annotations.clone(); - annotations.sort_by(|a,b| b.start_col.cmp(&a.start_col)); + annotations.sort_unstable_by(|a,b| b.start_col.cmp(&a.start_col)); // First, figure out where each label will be positioned. // @@ -681,7 +681,7 @@ impl EmitterWriter { // | | | // | | something about `foo` // | something about `fn foo()` - annotations_position.sort_by(|a, b| { + annotations_position.sort_unstable_by(|a, b| { // Decreasing order a.1.len().cmp(&b.1.len()).reverse() }); diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index c0f07645f496a..bf8972e93e3ca 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -155,7 +155,7 @@ impl CodeSuggestion { self.substitutions.iter().cloned().map(|mut substitution| { // Assumption: all spans are in the same file, and all spans // are disjoint. Sort in ascending order. - substitution.parts.sort_by_key(|part| part.span.lo()); + substitution.parts.sort_unstable_by_key(|part| part.span.lo()); // Find the bounding span. let lo = substitution.parts.iter().map(|part| part.span.lo()).min().unwrap(); @@ -618,7 +618,7 @@ impl Handler { }) .collect::>(); if !error_codes.is_empty() { - error_codes.sort(); + error_codes.sort_unstable(); if error_codes.len() > 1 { let limit = if error_codes.len() > 9 { 9 } else { error_codes.len() }; self.failure(&format!("Some errors occurred: {}{}", diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index e3a7918f8c589..b5b6f2bf15fdf 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -356,7 +356,7 @@ pub fn provide<'tcx>(providers: &mut Providers<'tcx>) { // we believe that libstd is consistently assigned crate // num 1, so it should be enough to resolve #46112. let mut crates: Vec = (*tcx.crates()).clone(); - crates.sort(); + crates.sort_unstable(); for &cnum in crates.iter() { // Ignore crates without a corresponding local `extern crate` item. diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 7ed991e0de3a1..a82ee6beea99d 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -1438,7 +1438,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { }) .collect::>(); - deps.sort_by_key(|&(cnum, _)| cnum); + deps.sort_unstable_by_key(|&(cnum, _)| cnum); { // Sanity-check the crate numbers diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 4aa38fb5f3732..0fe5e4eb7cd11 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -324,7 +324,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { } } - binds_to.sort(); + binds_to.sort_unstable(); binds_to.dedup(); for local in binds_to { let bind_to = &self.mir.local_decls[local]; @@ -344,7 +344,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { GroupedMoveError::MovesFromPattern { mut binds_to, .. } => { // Suggest ref, since there might be a move in // another match arm - binds_to.sort(); + binds_to.sort_unstable(); binds_to.dedup(); for local in binds_to { let bind_to = &self.mir.local_decls[local]; diff --git a/src/librustc_mir/borrow_check/nll/region_infer/dump_mir.rs b/src/librustc_mir/borrow_check/nll/region_infer/dump_mir.rs index 3c73203706dcb..7271503d57e9b 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/dump_mir.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/dump_mir.rs @@ -77,7 +77,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { } let mut constraints: Vec<_> = self.constraints.iter().collect(); - constraints.sort(); + constraints.sort_unstable(); for constraint in &constraints { let OutlivesConstraint { sup, diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs index 131e1defc1f9e..09cda59baa311 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs @@ -227,7 +227,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { debug!("report_error: categorized_path={:?}", categorized_path); // Find what appears to be the most interesting path to report to the user. - categorized_path.sort_by(|p0, p1| p0.0.cmp(&p1.0)); + categorized_path.sort_unstable_by(|p0, p1| p0.0.cmp(&p1.0)); debug!("report_error: sorted_path={:?}", categorized_path); // Get a span diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs index 52f596f61c2e8..30a1dfc4b777d 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs @@ -418,7 +418,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { debug!("propagate_constraints: constraints={:#?}", { let mut constraints: Vec<_> = self.constraints.iter().collect(); - constraints.sort(); + constraints.sort_unstable(); constraints }); diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index f1591535fa1aa..d69cc238e88cb 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -192,7 +192,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let source_info = self.source_info(span); let mut otherwise = otherwise; - otherwise.sort(); + otherwise.sort_unstable(); otherwise.dedup(); // variant switches can introduce duplicate target blocks for block in otherwise { self.cfg.terminate(block, source_info, TerminatorKind::Unreachable); @@ -644,7 +644,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { -> BasicBlock { let source_info = self.source_info(span); - otherwise.sort(); + otherwise.sort_unstable(); otherwise.dedup(); // variant switches can introduce duplicate target blocks if otherwise.len() == 1 { otherwise[0] diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index ac4d1c74b8cc1..8e11512c338a5 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -408,7 +408,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> { return; } use std::fmt::Write; - allocs.sort(); + allocs.sort_unstable(); allocs.dedup(); let mut allocs_to_print = VecDeque::from(allocs); let mut allocs_seen = FxHashSet::default(); diff --git a/src/librustc_mir/monomorphize/mod.rs b/src/librustc_mir/monomorphize/mod.rs index bf544e5120cd8..db93aeefcb4ae 100644 --- a/src/librustc_mir/monomorphize/mod.rs +++ b/src/librustc_mir/monomorphize/mod.rs @@ -29,7 +29,7 @@ pub fn assert_symbols_are_distinct<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mon (mono_item, mono_item.symbol_name(tcx)) }).collect(); - (&mut symbols[..]).sort_by(|&(_, ref sym1), &(_, ref sym2)|{ + (&mut symbols[..]).sort_unstable_by(|&(_, ref sym1), &(_, ref sym2)|{ sym1.cmp(sym2) }); diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index f83ea6fa13b52..ffd632bfdbade 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -262,7 +262,7 @@ pub fn partition<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>, internalization_candidates: _, } = post_inlining; - result.sort_by(|cgu1, cgu2| { + result.sort_unstable_by(|cgu1, cgu2| { cgu1.name().cmp(cgu2.name()) }); @@ -502,7 +502,7 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning< // smallest into each other) we're sure to start off with a deterministic // order (sorted by name). This'll mean that if two cgus have the same size // the stable sort below will keep everything nice and deterministic. - codegen_units.sort_by_key(|cgu| cgu.name().clone()); + codegen_units.sort_unstable_by_key(|cgu| cgu.name().clone()); // Merge the two smallest codegen units until the target size is reached. while codegen_units.len() > target_cgu_count { diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index ab7629eb66118..31816846fff7e 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -501,7 +501,7 @@ pub fn check_unsafety<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) { } let mut unsafe_blocks: Vec<_> = unsafe_blocks.into_iter().collect(); - unsafe_blocks.sort(); + unsafe_blocks.sort_unstable(); let used_unsafe: FxHashSet<_> = unsafe_blocks.iter() .flat_map(|&&(id, used)| if used { Some(id) } else { None }) .collect(); diff --git a/src/librustc_mir/util/patch.rs b/src/librustc_mir/util/patch.rs index 21ff7eaa72d9d..5cfe0b5c027f7 100644 --- a/src/librustc_mir/util/patch.rs +++ b/src/librustc_mir/util/patch.rs @@ -156,7 +156,7 @@ impl<'tcx> MirPatch<'tcx> { } let mut new_statements = self.new_statements; - new_statements.sort_by(|u,v| u.0.cmp(&v.0)); + new_statements.sort_unstable_by(|u,v| u.0.cmp(&v.0)); let mut delta = 0; let mut last_bb = START_BLOCK; diff --git a/src/librustc_resolve/check_unused.rs b/src/librustc_resolve/check_unused.rs index ec067a6477b6d..9f2adf933506c 100644 --- a/src/librustc_resolve/check_unused.rs +++ b/src/librustc_resolve/check_unused.rs @@ -172,7 +172,7 @@ pub fn check_crate(resolver: &mut Resolver, krate: &ast::Crate) { for (id, spans) in &visitor.unused_imports { let len = spans.len(); let mut spans = spans.values().map(|s| *s).collect::>(); - spans.sort(); + spans.sort_unstable(); let ms = MultiSpan::from_spans(spans.clone()); let mut span_snippets = spans.iter() .filter_map(|s| { @@ -181,7 +181,7 @@ pub fn check_crate(resolver: &mut Resolver, krate: &ast::Crate) { _ => None, } }).collect::>(); - span_snippets.sort(); + span_snippets.sort_unstable(); let msg = format!("unused import{}{}", if len > 1 { "s" } else { "" }, if span_snippets.len() > 0 { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 765016fdc4a74..bb14e6728c6d9 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2619,14 +2619,14 @@ impl<'a> Resolver<'a> { } } let mut missing_vars = missing_vars.iter().collect::>(); - missing_vars.sort(); + missing_vars.sort_unstable(); for (_, v) in missing_vars { resolve_error(self, *v.origin.iter().next().unwrap(), ResolutionError::VariableNotBoundInPattern(v)); } let mut inconsistent_vars = inconsistent_vars.iter().collect::>(); - inconsistent_vars.sort(); + inconsistent_vars.sort_unstable(); for (name, v) in inconsistent_vars { resolve_error(self, v.0, ResolutionError::VariableBoundWithDifferentMode(*name, v.1)); } @@ -2934,7 +2934,7 @@ impl<'a> Resolver<'a> { this.lookup_import_candidates(ident.name, ns, is_enum_variant); let mut enum_candidates = enum_candidates.iter() .map(|suggestion| import_candidate_to_paths(&suggestion)).collect::>(); - enum_candidates.sort(); + enum_candidates.sort_unstable(); for (sp, variant_path, enum_path) in enum_candidates { if sp.is_dummy() { let msg = format!("there is an enum variant `{}`, \ @@ -4610,7 +4610,7 @@ fn show_candidates(err: &mut DiagnosticBuilder, // by iterating through a hash map, so make sure they are ordered: let mut path_strings: Vec<_> = candidates.into_iter().map(|c| path_names_to_string(&c.path)).collect(); - path_strings.sort(); + path_strings.sort_unstable(); let better = if better { "better " } else { "" }; let msg_diff = match path_strings.len() { diff --git a/src/librustc_traits/lowering.rs b/src/librustc_traits/lowering.rs index cf61258577619..f8500a189d9bd 100644 --- a/src/librustc_traits/lowering.rs +++ b/src/librustc_traits/lowering.rs @@ -527,7 +527,7 @@ impl<'a, 'tcx> ClauseDumper<'a, 'tcx> { }) .collect(); - strings.sort(); + strings.sort_unstable(); for string in strings { err.note(&string); diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index a2dbf2aaca30e..ad707b0686397 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -719,7 +719,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { } // Dedup auto traits so that `dyn Trait + Send + Send` is the same as `dyn Trait + Send`. - auto_traits.sort(); + auto_traits.sort_unstable(); auto_traits.dedup(); // skip_binder is okay, because the predicates are re-bound. @@ -729,7 +729,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { .chain(existential_projections .map(|x| ty::ExistentialPredicate::Projection(*x.skip_binder()))) .collect::>(); - v.sort_by(|a, b| a.stable_cmp(tcx, b)); + v.sort_unstable_by(|a, b| a.stable_cmp(tcx, b)); let existential_predicates = ty::Binder::bind(tcx.mk_existential_predicates(v.into_iter())); diff --git a/src/librustc_typeck/check/generator_interior.rs b/src/librustc_typeck/check/generator_interior.rs index e20904930792e..3f00c61c7195b 100644 --- a/src/librustc_typeck/check/generator_interior.rs +++ b/src/librustc_typeck/check/generator_interior.rs @@ -102,7 +102,7 @@ pub fn resolve_interior<'a, 'gcx, 'tcx>(fcx: &'a FnCtxt<'a, 'gcx, 'tcx>, let mut types: Vec<_> = visitor.types.drain().collect(); // Sort types by insertion order - types.sort_by_key(|t| t.1); + types.sort_unstable_by_key(|t| t.1); // Extract type components let type_list = fcx.tcx.mk_type_list(types.into_iter().map(|t| t.0)); diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 026a9de5052cb..8148131af8b67 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -88,7 +88,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let report_candidates = |err: &mut DiagnosticBuilder, mut sources: Vec| { - sources.sort(); + sources.sort_unstable(); sources.dedup(); // Dynamic limit to avoid hiding just one candidate, which is silly. let limit = if sources.len() == 5 { 5 } else { 4 }; @@ -538,7 +538,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { valid_out_of_scope_traits: Vec) -> bool { if !valid_out_of_scope_traits.is_empty() { let mut candidates = valid_out_of_scope_traits; - candidates.sort(); + candidates.sort_unstable(); candidates.dedup(); err.help("items from traits can only be used if the trait is in scope"); let msg = format!("the following {traits_are} implemented but not in scope, \ @@ -598,7 +598,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if !candidates.is_empty() { // sort from most relevant to least relevant - candidates.sort_by(|a, b| a.cmp(b).reverse()); + candidates.sort_unstable_by(|a, b| a.cmp(b).reverse()); candidates.dedup(); // FIXME #21673 this help message could be tuned to the case diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 2cfeb2513926b..7f14e71bee132 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3458,7 +3458,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { .map(|ident| ident.as_str()) .collect::>(); - displayable_field_names.sort(); + displayable_field_names.sort_unstable(); let truncated_fields_error = if len <= 3 { "".to_string() diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 5193113d82c8a..bc06ea9370569 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1746,7 +1746,7 @@ pub fn compute_bounds<'gcx: 'tcx, 'tcx>(astconv: &dyn AstConv<'gcx, 'tcx>, astconv.ast_region_to_region(r, None) }).collect(); - trait_bounds.sort_by(|a,b| a.def_id().cmp(&b.def_id())); + trait_bounds.sort_unstable_by(|a,b| a.def_id().cmp(&b.def_id())); let implicitly_sized = if let SizedByDefault::Yes = sized_by_default { !is_unsized(astconv, ast_bounds, span) diff --git a/src/librustc_typeck/outlives/mod.rs b/src/librustc_typeck/outlives/mod.rs index 5801a6ada3f2f..fa3e9b8ec5897 100644 --- a/src/librustc_typeck/outlives/mod.rs +++ b/src/librustc_typeck/outlives/mod.rs @@ -61,7 +61,7 @@ fn inferred_outlives_of<'a, 'tcx>( err => bug!("unexpected predicate {:?}", err), }) .collect(); - pred.sort(); + pred.sort_unstable(); let span = tcx.def_span(item_def_id); let mut err = tcx.sess.struct_span_err(span, "rustc_outlives"); diff --git a/src/libtest/formatters/pretty.rs b/src/libtest/formatters/pretty.rs index f94780682a0c0..394cfcf384e18 100644 --- a/src/libtest/formatters/pretty.rs +++ b/src/libtest/formatters/pretty.rs @@ -113,7 +113,7 @@ impl PrettyFormatter { } self.write_plain("\nsuccesses:\n")?; - successes.sort(); + successes.sort_unstable(); for name in &successes { self.write_plain(&format!(" {}\n", name))?; } @@ -139,7 +139,7 @@ impl PrettyFormatter { } self.write_plain("\nfailures:\n")?; - failures.sort(); + failures.sort_unstable(); for name in &failures { self.write_plain(&format!(" {}\n", name))?; } diff --git a/src/libtest/formatters/terse.rs b/src/libtest/formatters/terse.rs index 22a06b9f605db..85818c744b787 100644 --- a/src/libtest/formatters/terse.rs +++ b/src/libtest/formatters/terse.rs @@ -117,7 +117,7 @@ impl TerseFormatter { } self.write_plain("\nsuccesses:\n")?; - successes.sort(); + successes.sort_unstable(); for name in &successes { self.write_plain(&format!(" {}\n", name))?; } @@ -143,7 +143,7 @@ impl TerseFormatter { } self.write_plain("\nfailures:\n")?; - failures.sort(); + failures.sort_unstable(); for name in &failures { self.write_plain(&format!(" {}\n", name))?; } diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 6b547dff9120e..c503a69471f4d 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -1342,7 +1342,7 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec) -> Vec Ordering { } fn local_sort(v: &mut [f64]) { - v.sort_by(|x: &f64, y: &f64| local_cmp(*x, *y)); + v.sort_unstable_by(|x: &f64, y: &f64| local_cmp(*x, *y)); } /// Trait that provides simple descriptive statistics on a univariate set of numeric samples.