Skip to content

Commit 1e5f311

Browse files
author
Jorge Aparicio
committed
Fix fallout of DSTifying PartialEq, PartialOrd, Eq, Ord
1 parent 2896278 commit 1e5f311

File tree

9 files changed

+172
-0
lines changed

9 files changed

+172
-0
lines changed

src/libcollections/str.rs

+7
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,17 @@ impl<'a> PartialOrd for MaybeOwned<'a> {
532532
}
533533

534534
impl<'a> Ord for MaybeOwned<'a> {
535+
// NOTE(stage0): remove method after a snapshot
536+
#[cfg(stage0)]
535537
#[inline]
536538
fn cmp(&self, other: &MaybeOwned) -> Ordering {
537539
self.as_slice().cmp(&other.as_slice())
538540
}
541+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
542+
#[inline]
543+
fn cmp(&self, other: &MaybeOwned) -> Ordering {
544+
self.as_slice().cmp(other.as_slice())
545+
}
539546
}
540547

541548
impl<'a, S: Str> Equiv<S> for MaybeOwned<'a> {

src/libcollections/vec.rs

+14
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,17 @@ impl<T: PartialEq> PartialEq for Vec<T> {
506506

507507
#[unstable = "waiting on PartialOrd stability"]
508508
impl<T: PartialOrd> PartialOrd for Vec<T> {
509+
// NOTE(stage0): remove method after a snapshot
510+
#[cfg(stage0)]
509511
#[inline]
510512
fn partial_cmp(&self, other: &Vec<T>) -> Option<Ordering> {
511513
self.as_slice().partial_cmp(&other.as_slice())
512514
}
515+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
516+
#[inline]
517+
fn partial_cmp(&self, other: &Vec<T>) -> Option<Ordering> {
518+
self.as_slice().partial_cmp(other.as_slice())
519+
}
513520
}
514521

515522
#[unstable = "waiting on Eq stability"]
@@ -523,10 +530,17 @@ impl<T: PartialEq, V: AsSlice<T>> Equiv<V> for Vec<T> {
523530

524531
#[unstable = "waiting on Ord stability"]
525532
impl<T: Ord> Ord for Vec<T> {
533+
// NOTE(stage0): remove method after a snapshot
534+
#[cfg(stage0)]
526535
#[inline]
527536
fn cmp(&self, other: &Vec<T>) -> Ordering {
528537
self.as_slice().cmp(&other.as_slice())
529538
}
539+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
540+
#[inline]
541+
fn cmp(&self, other: &Vec<T>) -> Ordering {
542+
self.as_slice().cmp(other.as_slice())
543+
}
530544
}
531545

532546
// FIXME: #13996: need a way to mark the return value as `noalias`

src/libgraphviz/maybe_owned_vec.rs

+12
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,27 @@ impl<'a, T: PartialEq> PartialEq for MaybeOwnedVector<'a, T> {
7676
impl<'a, T: Eq> Eq for MaybeOwnedVector<'a, T> {}
7777

7878
impl<'a, T: PartialOrd> PartialOrd for MaybeOwnedVector<'a, T> {
79+
// NOTE(stage0): remove method after a snapshot
80+
#[cfg(stage0)]
7981
fn partial_cmp(&self, other: &MaybeOwnedVector<T>) -> Option<Ordering> {
8082
self.as_slice().partial_cmp(&other.as_slice())
8183
}
84+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
85+
fn partial_cmp(&self, other: &MaybeOwnedVector<T>) -> Option<Ordering> {
86+
self.as_slice().partial_cmp(other.as_slice())
87+
}
8288
}
8389

8490
impl<'a, T: Ord> Ord for MaybeOwnedVector<'a, T> {
91+
// NOTE(stage0): remove method after a snapshot
92+
#[cfg(stage0)]
8593
fn cmp(&self, other: &MaybeOwnedVector<T>) -> Ordering {
8694
self.as_slice().cmp(&other.as_slice())
8795
}
96+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
97+
fn cmp(&self, other: &MaybeOwnedVector<T>) -> Ordering {
98+
self.as_slice().cmp(other.as_slice())
99+
}
88100
}
89101

90102
impl<'a, T: PartialEq, V: AsSlice<T>> Equiv<V> for MaybeOwnedVector<'a, T> {

src/libregex/parse.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1020,13 +1020,23 @@ fn is_valid_cap(c: char) -> bool {
10201020
|| (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
10211021
}
10221022

1023+
// NOTE(stage0): remove function after a snapshot
1024+
#[cfg(stage0)]
10231025
fn find_class(classes: NamedClasses, name: &str) -> Option<Vec<(char, char)>> {
10241026
match classes.binary_search(|&(s, _)| s.cmp(&name)) {
10251027
slice::Found(i) => Some(classes[i].val1().to_vec()),
10261028
slice::NotFound(_) => None,
10271029
}
10281030
}
10291031

1032+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
1033+
fn find_class(classes: NamedClasses, name: &str) -> Option<Vec<(char, char)>> {
1034+
match classes.binary_search(|&(s, _)| s.cmp(name)) {
1035+
slice::Found(i) => Some(classes[i].val1().to_vec()),
1036+
slice::NotFound(_) => None,
1037+
}
1038+
}
1039+
10301040
type Class = &'static [(char, char)];
10311041
type NamedClasses = &'static [(&'static str, &'static Class)];
10321042

src/librustc/driver/mod.rs

+28
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ Available lint options:
182182
183183
");
184184

185+
// NOTE(stage0): remove function after a snapshot
186+
#[cfg(stage0)]
185187
fn sort_lints(lints: Vec<(&'static Lint, bool)>) -> Vec<&'static Lint> {
186188
let mut lints: Vec<_> = lints.into_iter().map(|(x, _)| x).collect();
187189
lints.sort_by(|x: &&Lint, y: &&Lint| {
@@ -194,6 +196,21 @@ Available lint options:
194196
lints
195197
}
196198

199+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
200+
fn sort_lints(lints: Vec<(&'static Lint, bool)>) -> Vec<&'static Lint> {
201+
let mut lints: Vec<_> = lints.into_iter().map(|(x, _)| x).collect();
202+
lints.sort_by(|x: &&Lint, y: &&Lint| {
203+
match x.default_level.cmp(&y.default_level) {
204+
// The sort doesn't case-fold but it's doubtful we care.
205+
Equal => x.name.cmp(y.name),
206+
r => r,
207+
}
208+
});
209+
lints
210+
}
211+
212+
// NOTE(stage0): remove function after a snapshot
213+
#[cfg(stage0)]
197214
fn sort_lint_groups(lints: Vec<(&'static str, Vec<lint::LintId>, bool)>)
198215
-> Vec<(&'static str, Vec<lint::LintId>)> {
199216
let mut lints: Vec<_> = lints.into_iter().map(|(x, y, _)| (x, y)).collect();
@@ -204,6 +221,17 @@ Available lint options:
204221
lints
205222
}
206223

224+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
225+
fn sort_lint_groups(lints: Vec<(&'static str, Vec<lint::LintId>, bool)>)
226+
-> Vec<(&'static str, Vec<lint::LintId>)> {
227+
let mut lints: Vec<_> = lints.into_iter().map(|(x, y, _)| (x, y)).collect();
228+
lints.sort_by(|&(x, _): &(&'static str, Vec<lint::LintId>),
229+
&(y, _): &(&'static str, Vec<lint::LintId>)| {
230+
x.cmp(y)
231+
});
232+
lints
233+
}
234+
207235
let (plugin, builtin) = lint_store.get_lints().partitioned(|&(_, p)| p);
208236
let plugin = sort_lints(plugin);
209237
let builtin = sort_lints(builtin);

src/librustrt/c_str.rs

+7
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,17 @@ impl PartialEq for CString {
121121
}
122122

123123
impl PartialOrd for CString {
124+
// NOTE(stage0): remove method after a snapshot
125+
#[cfg(stage0)]
124126
#[inline]
125127
fn partial_cmp(&self, other: &CString) -> Option<Ordering> {
126128
self.as_bytes().partial_cmp(&other.as_bytes())
127129
}
130+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
131+
#[inline]
132+
fn partial_cmp(&self, other: &CString) -> Option<Ordering> {
133+
self.as_bytes().partial_cmp(other.as_bytes())
134+
}
128135
}
129136

130137
impl Eq for CString {}

src/libserialize/json.rs

+38
Original file line numberDiff line numberDiff line change
@@ -890,13 +890,25 @@ impl Json {
890890

891891
/// If the Json value is an Object, returns the value associated with the provided key.
892892
/// Otherwise, returns None.
893+
// NOTE(stage0): remove function after a snapshot
894+
#[cfg(stage0)]
893895
pub fn find<'a>(&'a self, key: &str) -> Option<&'a Json>{
894896
match self {
895897
&Object(ref map) => map.find_with(|s| key.cmp(&s.as_slice())),
896898
_ => None
897899
}
898900
}
899901

902+
/// If the Json value is an Object, returns the value associated with the provided key.
903+
/// Otherwise, returns None.
904+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
905+
pub fn find<'a>(&'a self, key: &str) -> Option<&'a Json>{
906+
match self {
907+
&Object(ref map) => map.find_with(|s| key.cmp(s.as_slice())),
908+
_ => None
909+
}
910+
}
911+
900912
/// Attempts to get a nested Json Object for each key in `keys`.
901913
/// If any key is found not to exist, find_path will return None.
902914
/// Otherwise, it will return the Json value associated with the final key.
@@ -914,6 +926,8 @@ impl Json {
914926
/// If the Json value is an Object, performs a depth-first search until
915927
/// a value associated with the provided key is found. If no value is found
916928
/// or the Json value is not an Object, returns None.
929+
// NOTE(stage0): remove function after a snapshot
930+
#[cfg(stage0)]
917931
pub fn search<'a>(&'a self, key: &str) -> Option<&'a Json> {
918932
match self {
919933
&Object(ref map) => {
@@ -934,6 +948,30 @@ impl Json {
934948
}
935949
}
936950

951+
/// If the Json value is an Object, performs a depth-first search until
952+
/// a value associated with the provided key is found. If no value is found
953+
/// or the Json value is not an Object, returns None.
954+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
955+
pub fn search<'a>(&'a self, key: &str) -> Option<&'a Json> {
956+
match self {
957+
&Object(ref map) => {
958+
match map.find_with(|s| key.cmp(s.as_slice())) {
959+
Some(json_value) => Some(json_value),
960+
None => {
961+
for (_, v) in map.iter() {
962+
match v.search(key) {
963+
x if x.is_some() => return x,
964+
_ => ()
965+
}
966+
}
967+
None
968+
}
969+
}
970+
},
971+
_ => None
972+
}
973+
}
974+
937975
/// Returns true if the Json value is an Object. Returns false otherwise.
938976
pub fn is_object<'a>(&'a self) -> bool {
939977
self.as_object().is_some()

src/libsyntax/util/interner.rs

+6
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,15 @@ pub struct RcStr {
9797
impl Eq for RcStr {}
9898

9999
impl Ord for RcStr {
100+
// NOTE(stage0): remove method after a snapshot
101+
#[cfg(stage0)]
100102
fn cmp(&self, other: &RcStr) -> Ordering {
101103
self.as_slice().cmp(&other.as_slice())
102104
}
105+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
106+
fn cmp(&self, other: &RcStr) -> Ordering {
107+
self.as_slice().cmp(other.as_slice())
108+
}
103109
}
104110

105111
impl Str for RcStr {

src/libtest/lib.rs

+50
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,8 @@ fn get_concurrency() -> uint {
973973
}
974974
}
975975

976+
// NOTE(stage0): remove function after a snapshot
977+
#[cfg(stage0)]
976978
pub fn filter_tests(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> Vec<TestDescAndFn> {
977979
let mut filtered = tests;
978980

@@ -1020,6 +1022,54 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> Vec<TestDescA
10201022
}
10211023
}
10221024

1025+
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
1026+
pub fn filter_tests(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> Vec<TestDescAndFn> {
1027+
let mut filtered = tests;
1028+
1029+
// Remove tests that don't match the test filter
1030+
filtered = match opts.filter {
1031+
None => filtered,
1032+
Some(ref re) => {
1033+
filtered.into_iter()
1034+
.filter(|test| re.is_match(test.desc.name.as_slice())).collect()
1035+
}
1036+
};
1037+
1038+
// Maybe pull out the ignored test and unignore them
1039+
filtered = if !opts.run_ignored {
1040+
filtered
1041+
} else {
1042+
fn filter(test: TestDescAndFn) -> Option<TestDescAndFn> {
1043+
if test.desc.ignore {
1044+
let TestDescAndFn {desc, testfn} = test;
1045+
Some(TestDescAndFn {
1046+
desc: TestDesc {ignore: false, ..desc},
1047+
testfn: testfn
1048+
})
1049+
} else {
1050+
None
1051+
}
1052+
};
1053+
filtered.into_iter().filter_map(|x| filter(x)).collect()
1054+
};
1055+
1056+
// Sort the tests alphabetically
1057+
filtered.sort_by(|t1, t2| t1.desc.name.as_slice().cmp(t2.desc.name.as_slice()));
1058+
1059+
// Shard the remaining tests, if sharding requested.
1060+
match opts.test_shard {
1061+
None => filtered,
1062+
Some((a,b)) => {
1063+
filtered.into_iter().enumerate()
1064+
// note: using a - 1 so that the valid shards, for example, are
1065+
// 1.2 and 2.2 instead of 0.2 and 1.2
1066+
.filter(|&(i,_)| i % b == (a - 1))
1067+
.map(|(_,t)| t)
1068+
.collect()
1069+
}
1070+
}
1071+
}
1072+
10231073
pub fn run_test(opts: &TestOpts,
10241074
force_ignore: bool,
10251075
test: TestDescAndFn,

0 commit comments

Comments
 (0)