From 1e5f311d1615ab4bca5b23d09dd678c2662022e6 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 29 Oct 2014 20:21:37 -0500 Subject: [PATCH] Fix fallout of DSTifying PartialEq, PartialOrd, Eq, Ord --- src/libcollections/str.rs | 7 +++++ src/libcollections/vec.rs | 14 +++++++++ src/libgraphviz/maybe_owned_vec.rs | 12 +++++++ src/libregex/parse.rs | 10 ++++++ src/librustc/driver/mod.rs | 28 +++++++++++++++++ src/librustrt/c_str.rs | 7 +++++ src/libserialize/json.rs | 38 +++++++++++++++++++++++ src/libsyntax/util/interner.rs | 6 ++++ src/libtest/lib.rs | 50 ++++++++++++++++++++++++++++++ 9 files changed, 172 insertions(+) diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index ff756a8eef3..79c1f720794 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -532,10 +532,17 @@ impl<'a> PartialOrd for MaybeOwned<'a> { } impl<'a> Ord for MaybeOwned<'a> { + // NOTE(stage0): remove method after a snapshot + #[cfg(stage0)] #[inline] fn cmp(&self, other: &MaybeOwned) -> Ordering { self.as_slice().cmp(&other.as_slice()) } + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot + #[inline] + fn cmp(&self, other: &MaybeOwned) -> Ordering { + self.as_slice().cmp(other.as_slice()) + } } impl<'a, S: Str> Equiv for MaybeOwned<'a> { diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 40e7c949972..4b6921ed0c0 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -506,10 +506,17 @@ impl PartialEq for Vec { #[unstable = "waiting on PartialOrd stability"] impl PartialOrd for Vec { + // NOTE(stage0): remove method after a snapshot + #[cfg(stage0)] #[inline] fn partial_cmp(&self, other: &Vec) -> Option { self.as_slice().partial_cmp(&other.as_slice()) } + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot + #[inline] + fn partial_cmp(&self, other: &Vec) -> Option { + self.as_slice().partial_cmp(other.as_slice()) + } } #[unstable = "waiting on Eq stability"] @@ -523,10 +530,17 @@ impl> Equiv for Vec { #[unstable = "waiting on Ord stability"] impl Ord for Vec { + // NOTE(stage0): remove method after a snapshot + #[cfg(stage0)] #[inline] fn cmp(&self, other: &Vec) -> Ordering { self.as_slice().cmp(&other.as_slice()) } + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot + #[inline] + fn cmp(&self, other: &Vec) -> Ordering { + self.as_slice().cmp(other.as_slice()) + } } // FIXME: #13996: need a way to mark the return value as `noalias` diff --git a/src/libgraphviz/maybe_owned_vec.rs b/src/libgraphviz/maybe_owned_vec.rs index d465d140751..3a89d8b3f81 100644 --- a/src/libgraphviz/maybe_owned_vec.rs +++ b/src/libgraphviz/maybe_owned_vec.rs @@ -76,15 +76,27 @@ impl<'a, T: PartialEq> PartialEq for MaybeOwnedVector<'a, T> { impl<'a, T: Eq> Eq for MaybeOwnedVector<'a, T> {} impl<'a, T: PartialOrd> PartialOrd for MaybeOwnedVector<'a, T> { + // NOTE(stage0): remove method after a snapshot + #[cfg(stage0)] fn partial_cmp(&self, other: &MaybeOwnedVector) -> Option { self.as_slice().partial_cmp(&other.as_slice()) } + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot + fn partial_cmp(&self, other: &MaybeOwnedVector) -> Option { + self.as_slice().partial_cmp(other.as_slice()) + } } impl<'a, T: Ord> Ord for MaybeOwnedVector<'a, T> { + // NOTE(stage0): remove method after a snapshot + #[cfg(stage0)] fn cmp(&self, other: &MaybeOwnedVector) -> Ordering { self.as_slice().cmp(&other.as_slice()) } + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot + fn cmp(&self, other: &MaybeOwnedVector) -> Ordering { + self.as_slice().cmp(other.as_slice()) + } } impl<'a, T: PartialEq, V: AsSlice> Equiv for MaybeOwnedVector<'a, T> { diff --git a/src/libregex/parse.rs b/src/libregex/parse.rs index 3115161682f..6723ea725a3 100644 --- a/src/libregex/parse.rs +++ b/src/libregex/parse.rs @@ -1020,6 +1020,8 @@ fn is_valid_cap(c: char) -> bool { || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') } +// NOTE(stage0): remove function after a snapshot +#[cfg(stage0)] fn find_class(classes: NamedClasses, name: &str) -> Option> { match classes.binary_search(|&(s, _)| s.cmp(&name)) { slice::Found(i) => Some(classes[i].val1().to_vec()), @@ -1027,6 +1029,14 @@ fn find_class(classes: NamedClasses, name: &str) -> Option> { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +fn find_class(classes: NamedClasses, name: &str) -> Option> { + match classes.binary_search(|&(s, _)| s.cmp(name)) { + slice::Found(i) => Some(classes[i].val1().to_vec()), + slice::NotFound(_) => None, + } +} + type Class = &'static [(char, char)]; type NamedClasses = &'static [(&'static str, &'static Class)]; diff --git a/src/librustc/driver/mod.rs b/src/librustc/driver/mod.rs index 7715f0e10f5..8753795d9e2 100644 --- a/src/librustc/driver/mod.rs +++ b/src/librustc/driver/mod.rs @@ -182,6 +182,8 @@ Available lint options: "); + // NOTE(stage0): remove function after a snapshot + #[cfg(stage0)] fn sort_lints(lints: Vec<(&'static Lint, bool)>) -> Vec<&'static Lint> { let mut lints: Vec<_> = lints.into_iter().map(|(x, _)| x).collect(); lints.sort_by(|x: &&Lint, y: &&Lint| { @@ -194,6 +196,21 @@ Available lint options: lints } + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot + fn sort_lints(lints: Vec<(&'static Lint, bool)>) -> Vec<&'static Lint> { + let mut lints: Vec<_> = lints.into_iter().map(|(x, _)| x).collect(); + lints.sort_by(|x: &&Lint, y: &&Lint| { + match x.default_level.cmp(&y.default_level) { + // The sort doesn't case-fold but it's doubtful we care. + Equal => x.name.cmp(y.name), + r => r, + } + }); + lints + } + + // NOTE(stage0): remove function after a snapshot + #[cfg(stage0)] 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(); @@ -204,6 +221,17 @@ Available lint options: lints } + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot + 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)| { + x.cmp(y) + }); + lints + } + let (plugin, builtin) = lint_store.get_lints().partitioned(|&(_, p)| p); let plugin = sort_lints(plugin); let builtin = sort_lints(builtin); diff --git a/src/librustrt/c_str.rs b/src/librustrt/c_str.rs index b15cdb88b67..b7a2c8f9473 100644 --- a/src/librustrt/c_str.rs +++ b/src/librustrt/c_str.rs @@ -121,10 +121,17 @@ impl PartialEq for CString { } impl PartialOrd for CString { + // NOTE(stage0): remove method after a snapshot + #[cfg(stage0)] #[inline] fn partial_cmp(&self, other: &CString) -> Option { self.as_bytes().partial_cmp(&other.as_bytes()) } + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot + #[inline] + fn partial_cmp(&self, other: &CString) -> Option { + self.as_bytes().partial_cmp(other.as_bytes()) + } } impl Eq for CString {} diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index e0d436f5e0e..dbdfa17bfc2 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -890,6 +890,8 @@ impl Json { /// If the Json value is an Object, returns the value associated with the provided key. /// Otherwise, returns None. + // NOTE(stage0): remove function after a snapshot + #[cfg(stage0)] pub fn find<'a>(&'a self, key: &str) -> Option<&'a Json>{ match self { &Object(ref map) => map.find_with(|s| key.cmp(&s.as_slice())), @@ -897,6 +899,16 @@ impl Json { } } + /// If the Json value is an Object, returns the value associated with the provided key. + /// Otherwise, returns None. + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot + pub fn find<'a>(&'a self, key: &str) -> Option<&'a Json>{ + match self { + &Object(ref map) => map.find_with(|s| key.cmp(s.as_slice())), + _ => None + } + } + /// Attempts to get a nested Json Object for each key in `keys`. /// If any key is found not to exist, find_path will return None. /// Otherwise, it will return the Json value associated with the final key. @@ -914,6 +926,8 @@ impl Json { /// If the Json value is an Object, performs a depth-first search until /// a value associated with the provided key is found. If no value is found /// or the Json value is not an Object, returns None. + // NOTE(stage0): remove function after a snapshot + #[cfg(stage0)] pub fn search<'a>(&'a self, key: &str) -> Option<&'a Json> { match self { &Object(ref map) => { @@ -934,6 +948,30 @@ impl Json { } } + /// If the Json value is an Object, performs a depth-first search until + /// a value associated with the provided key is found. If no value is found + /// or the Json value is not an Object, returns None. + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot + pub fn search<'a>(&'a self, key: &str) -> Option<&'a Json> { + match self { + &Object(ref map) => { + match map.find_with(|s| key.cmp(s.as_slice())) { + Some(json_value) => Some(json_value), + None => { + for (_, v) in map.iter() { + match v.search(key) { + x if x.is_some() => return x, + _ => () + } + } + None + } + } + }, + _ => None + } + } + /// Returns true if the Json value is an Object. Returns false otherwise. pub fn is_object<'a>(&'a self) -> bool { self.as_object().is_some() diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 105118ff76a..e6c98a9e3d0 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -97,9 +97,15 @@ pub struct RcStr { impl Eq for RcStr {} impl Ord for RcStr { + // NOTE(stage0): remove method after a snapshot + #[cfg(stage0)] fn cmp(&self, other: &RcStr) -> Ordering { self.as_slice().cmp(&other.as_slice()) } + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot + fn cmp(&self, other: &RcStr) -> Ordering { + self.as_slice().cmp(other.as_slice()) + } } impl Str for RcStr { diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 81d0bb76d14..74bead9e5f2 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -973,6 +973,8 @@ fn get_concurrency() -> uint { } } +// NOTE(stage0): remove function after a snapshot +#[cfg(stage0)] pub fn filter_tests(opts: &TestOpts, tests: Vec) -> Vec { let mut filtered = tests; @@ -1020,6 +1022,54 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec) -> Vec) -> Vec { + let mut filtered = tests; + + // Remove tests that don't match the test filter + filtered = match opts.filter { + None => filtered, + Some(ref re) => { + filtered.into_iter() + .filter(|test| re.is_match(test.desc.name.as_slice())).collect() + } + }; + + // Maybe pull out the ignored test and unignore them + filtered = if !opts.run_ignored { + filtered + } else { + fn filter(test: TestDescAndFn) -> Option { + if test.desc.ignore { + let TestDescAndFn {desc, testfn} = test; + Some(TestDescAndFn { + desc: TestDesc {ignore: false, ..desc}, + testfn: testfn + }) + } else { + None + } + }; + filtered.into_iter().filter_map(|x| filter(x)).collect() + }; + + // Sort the tests alphabetically + filtered.sort_by(|t1, t2| t1.desc.name.as_slice().cmp(t2.desc.name.as_slice())); + + // Shard the remaining tests, if sharding requested. + match opts.test_shard { + None => filtered, + Some((a,b)) => { + filtered.into_iter().enumerate() + // note: using a - 1 so that the valid shards, for example, are + // 1.2 and 2.2 instead of 0.2 and 1.2 + .filter(|&(i,_)| i % b == (a - 1)) + .map(|(_,t)| t) + .collect() + } + } +} + pub fn run_test(opts: &TestOpts, force_ignore: bool, test: TestDescAndFn,