]> git.lizzy.rs Git - rust.git/commitdiff
Improve sorting delegate
authorrobojumper <robojumper@gmail.com>
Sat, 9 Feb 2019 00:57:08 +0000 (01:57 +0100)
committerrobojumper <robojumper@gmail.com>
Sat, 9 Feb 2019 00:57:08 +0000 (01:57 +0100)
crates/ra_assists/src/lib.rs

index ce5ee365e8afc9cc40919749abd95d40b12d8d08..7928b49830b9e6e61bb42364de654b53189e484e 100644 (file)
@@ -65,13 +65,11 @@ pub fn assists<H>(db: &H, range: FileRange) -> Vec<(AssistLabel, AssistAction)>
                 Assist::Unresolved(..) => unreachable!(),
             })
             .collect::<Vec<(AssistLabel, AssistAction)>>();
-        a.sort_by(|a, b| match a {
-            // Some(y) < Some(x) < None for y < x
-            (_, AssistAction { target: Some(a), .. }) => match b {
-                (_, AssistAction { target: Some(b), .. }) => a.len().cmp(&b.len()),
-                _ => Ordering::Less,
-            },
-            _ => Ordering::Greater,
+        a.sort_by(|a, b| match (a.1.target, b.1.target) {
+            (Some(a), Some(b)) => a.len().cmp(&b.len()),
+            (Some(_), None) => Ordering::Less,
+            (None, Some(_)) => Ordering::Greater,
+            (None, None) => Ordering::Equal,
         });
         a
     })