Skip to content

Commit 57eedba

Browse files
committed
Convert sort_by to sort_by_cached_key
1 parent 5cd0504 commit 57eedba

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

src/librustc_driver/lib.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![cfg_attr(unix, feature(libc))]
2424
#![feature(quote)]
2525
#![feature(rustc_diagnostic_macros)]
26+
#![feature(slice_sort_by_cached_key)]
2627
#![feature(set_stdio)]
2728
#![feature(rustc_stack_internals)]
2829

@@ -83,7 +84,6 @@ use rustc_trans_utils::trans_crate::TransCrate;
8384
use serialize::json::ToJson;
8485

8586
use std::any::Any;
86-
use std::cmp::Ordering::Equal;
8787
use std::cmp::max;
8888
use std::default::Default;
8989
use std::env::consts::{DLL_PREFIX, DLL_SUFFIX};
@@ -1177,13 +1177,8 @@ Available lint options:
11771177

11781178
fn sort_lints(sess: &Session, lints: Vec<(&'static Lint, bool)>) -> Vec<&'static Lint> {
11791179
let mut lints: Vec<_> = lints.into_iter().map(|(x, _)| x).collect();
1180-
lints.sort_by(|x: &&Lint, y: &&Lint| {
1181-
match x.default_level(sess).cmp(&y.default_level(sess)) {
1182-
// The sort doesn't case-fold but it's doubtful we care.
1183-
Equal => x.name.cmp(y.name),
1184-
r => r,
1185-
}
1186-
});
1180+
// The sort doesn't case-fold but it's doubtful we care.
1181+
lints.sort_by_cached_key(|x: &&Lint| (x.default_level(sess), x.name));
11871182
lints
11881183
}
11891184

src/libsyntax/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#![feature(unicode)]
2424
#![feature(rustc_diagnostic_macros)]
25+
#![feature(slice_sort_by_cached_key)]
2526
#![feature(non_exhaustive)]
2627
#![feature(const_atomic_usize_new)]
2728
#![feature(rustc_attrs)]

src/libsyntax/parse/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ impl<'a> Parser<'a> {
689689
.chain(inedible.iter().map(|x| TokenType::Token(x.clone())))
690690
.chain(self.expected_tokens.iter().cloned())
691691
.collect::<Vec<_>>();
692-
expected.sort_by(|a, b| a.to_string().cmp(&b.to_string()));
692+
expected.sort_by_cached_key(|x| x.to_string());
693693
expected.dedup();
694694
let expect = tokens_to_string(&expected[..]);
695695
let actual = self.this_token_to_string();

0 commit comments

Comments
 (0)