]> git.lizzy.rs Git - rust.git/commitdiff
Improve readability in a few sorts
authorljedrz <ljedrz@gmail.com>
Wed, 25 Jul 2018 08:36:57 +0000 (10:36 +0200)
committerljedrz <ljedrz@gmail.com>
Wed, 25 Jul 2018 10:13:02 +0000 (12:13 +0200)
src/librustc_driver/lib.rs
src/librustc_driver/profile/trace.rs
src/librustc_errors/emitter.rs
src/librustc_mir/monomorphize/mod.rs
src/librustc_mir/util/patch.rs
src/librustc_typeck/collect.rs

index 2100ceea22849713c853d10cf810dd61ae7628b3..000025c49a698a4a230eb93819d370b0254851ad 100644 (file)
@@ -1229,10 +1229,7 @@ fn sort_lints(sess: &Session, lints: Vec<(&'static Lint, bool)>) -> Vec<&'static
     fn sort_lint_groups(lints: Vec<(&'static str, Vec<lint::LintId>, bool)>)
                         -> Vec<(&'static str, Vec<lint::LintId>)> {
         let mut lints: Vec<_> = lints.into_iter().map(|(x, y, _)| (x, y)).collect();
-        lints.sort_by(|&(x, _): &(&'static str, Vec<lint::LintId>),
-                       &(y, _): &(&'static str, Vec<lint::LintId>)| {
-            x.cmp(y)
-        });
+        lints.sort_by_key(|ref l| l.0);
         lints
     }
 
index 5f10c56e8e214cd5f287cd7050a8b54fab2d8a9b..4aaf5eb47f61c8b4bc17bbe64d11f9c10cbdab32 100644 (file)
@@ -202,14 +202,13 @@ fn compute_counts_rec(counts: &mut HashMap<String,QueryMetric>, traces: &Vec<Rec
 
 pub fn write_counts(count_file: &mut File, counts: &mut HashMap<String,QueryMetric>) {
     use rustc::util::common::duration_to_secs_str;
-    use std::cmp::Ordering;
+    use std::cmp::Reverse;
 
     let mut data = vec![];
     for (ref cons, ref qm) in counts.iter() {
         data.push((cons.clone(), qm.count.clone(), qm.dur_total.clone(), qm.dur_self.clone()));
     };
-    data.sort_by(|&(_,_,_,self1),&(_,_,_,self2)|
-                 if self1 > self2 { Ordering::Less } else { Ordering::Greater } );
+    data.sort_by_key(|&k| Reverse(k.3));
     for (cons, count, dur_total, dur_self) in data {
         write!(count_file, "{}, {}, {}, {}\n",
                cons, count,
index c9b6818d5c158497ec48b42dbacabdfd16da9397..6bcf0d9eff6c5b4b8147904a3b5db1f89a525dad 100644 (file)
@@ -22,7 +22,7 @@
 use std::io::prelude::*;
 use std::io;
 use std::collections::HashMap;
-use std::cmp::min;
+use std::cmp::{min, Reverse};
 use termcolor::{StandardStream, ColorChoice, ColorSpec, BufferWriter};
 use termcolor::{WriteColor, Color, Buffer};
 use unicode_width;
@@ -265,9 +265,7 @@ fn add_annotation_to_file(file_vec: &mut Vec<FileWithAnnotatedLines>,
         }
 
         // Find overlapping multiline annotations, put them at different depths
-        multiline_annotations.sort_by(|a, b| {
-            (a.1.line_start, a.1.line_end).cmp(&(b.1.line_start, b.1.line_end))
-        });
+        multiline_annotations.sort_by_key(|&(_, ref ml)| (ml.line_start, ml.line_end));
         for item in multiline_annotations.clone() {
             let ann = item.1;
             for item in multiline_annotations.iter_mut() {
@@ -403,7 +401,7 @@ fn render_source_line(&self,
         // 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_by_key(|a| Reverse(a.start_col));
 
         // First, figure out where each label will be positioned.
         //
index bf544e5120cd81d691e6741c6da186ee4c4db7f8..e148bc3d9460c2f81dca841a1f149c831a902f3c 100644 (file)
@@ -29,9 +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)|{
-        sym1.cmp(sym2)
-    });
+    (&mut symbols[..]).sort_by_key(|&sym| sym.1);
 
     for pair in (&symbols[..]).windows(2) {
         let sym1 = &pair[0].1;
index 21ff7eaa72d9d298be595b11d0a2aca70e980a62..c2a56adc18f5ccf8d4d1efd4aa6fefa842602d38 100644 (file)
@@ -156,7 +156,7 @@ pub fn apply(self, mir: &mut Mir<'tcx>) {
         }
 
         let mut new_statements = self.new_statements;
-        new_statements.sort_by(|u,v| u.0.cmp(&v.0));
+        new_statements.sort_by_key(|s| s.0);
 
         let mut delta = 0;
         let mut last_bb = START_BLOCK;
index 5193113d82c8a4133db12fd50e8a855b0457713a..60f8928255174a361515d3ac83917a133ca73a09 100644 (file)
@@ -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_by_key(|t| t.def_id());
 
     let implicitly_sized = if let SizedByDefault::Yes = sized_by_default {
         !is_unsized(astconv, ast_bounds, span)