Skip to content

Commit 3d079ab

Browse files
committed
---
yaml --- r: 153047 b: refs/heads/try2 c: 497ecd0 h: refs/heads/master i: 153045: 11646dc 153043: 46adb40 153039: 357a267 v: v3
1 parent 874ec2a commit 3d079ab

File tree

3 files changed

+19
-30
lines changed

3 files changed

+19
-30
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 0aa23ed18a927aad6578d7a23183275239deb2be
8+
refs/heads/try2: 497ecd04585159bf56a6a38315e9adb3877ece04
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libnum/rational.rs

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -274,17 +274,12 @@ impl<T: Clone + Integer + PartialOrd>
274274
Num for Ratio<T> {}
275275

276276
/* String conversions */
277-
impl<T: fmt::Show + Eq + One> fmt::Show for Ratio<T> {
278-
/// Renders as `numer/denom`. If denom=1, renders as numer.
277+
impl<T: fmt::Show> fmt::Show for Ratio<T> {
278+
/// Renders as `numer/denom`.
279279
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
280-
if self.denom == One::one() {
281-
write!(f, "{}", self.numer)
282-
} else {
283-
write!(f, "{}/{}", self.numer, self.denom)
284-
}
280+
write!(f, "{}/{}", self.numer, self.denom)
285281
}
286282
}
287-
288283
impl<T: ToStrRadix> ToStrRadix for Ratio<T> {
289284
/// Renders as `numer/denom` where the numbers are in base `radix`.
290285
fn to_str_radix(&self, radix: uint) -> String {
@@ -296,20 +291,21 @@ impl<T: ToStrRadix> ToStrRadix for Ratio<T> {
296291

297292
impl<T: FromStr + Clone + Integer + PartialOrd>
298293
FromStr for Ratio<T> {
299-
/// Parses `numer/denom` or just `numer`
294+
/// Parses `numer/denom`.
300295
fn from_str(s: &str) -> Option<Ratio<T>> {
301-
let mut split = s.splitn('/', 1);
302-
303-
let num = split.next().and_then(|n| FromStr::from_str(n));
304-
let den = split.next().or(Some("1")).and_then(|d| FromStr::from_str(d));
305-
306-
match (num, den) {
307-
(Some(n), Some(d)) => Some(Ratio::new(n, d)),
308-
_ => None
296+
let split: Vec<&str> = s.splitn('/', 1).collect();
297+
if split.len() < 2 {
298+
return None
309299
}
300+
let a_option: Option<T> = FromStr::from_str(*split.get(0));
301+
a_option.and_then(|a| {
302+
let b_option: Option<T> = FromStr::from_str(*split.get(1));
303+
b_option.and_then(|b| {
304+
Some(Ratio::new(a.clone(), b.clone()))
305+
})
306+
})
310307
}
311308
}
312-
313309
impl<T: FromStrRadix + Clone + Integer + PartialOrd>
314310
FromStrRadix for Ratio<T> {
315311
/// Parses `numer/denom` where the numbers are in base `radix`.
@@ -433,13 +429,6 @@ mod test {
433429
assert!(!_neg1_2.is_integer());
434430
}
435431

436-
#[test]
437-
fn test_show() {
438-
assert_eq!(format!("{}", _2), "2".to_string());
439-
assert_eq!(format!("{}", _1_2), "1/2".to_string());
440-
assert_eq!(format!("{}", _0), "0".to_string());
441-
assert_eq!(format!("{}", Ratio::from_integer(-2i)), "-2".to_string());
442-
}
443432

444433
mod arith {
445434
use super::{_0, _1, _2, _1_2, _3_2, _neg1_2, to_big};
@@ -573,11 +562,11 @@ mod test {
573562
assert_eq!(FromStr::from_str(s.as_slice()), Some(r));
574563
assert_eq!(r.to_str(), s);
575564
}
576-
test(_1, "1".to_string());
577-
test(_0, "0".to_string());
565+
test(_1, "1/1".to_string());
566+
test(_0, "0/1".to_string());
578567
test(_1_2, "1/2".to_string());
579568
test(_3_2, "3/2".to_string());
580-
test(_2, "2".to_string());
569+
test(_2, "2/1".to_string());
581570
test(_neg1_2, "-1/2".to_string());
582571
}
583572
#[test]

branches/try2/src/librustc/middle/trans/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ pub fn trans_unboxing_shim(bcx: &Block,
261261
let function_type =
262262
ty::mk_bare_fn(tcx, method.fty.clone()).subst(tcx, &substs);
263263

264-
let function_name = tcx.map.with_path(method_id.node, |path| {
264+
let function_name = ty::with_path(tcx, method_id, |path| {
265265
link::mangle_internal_name_by_path_and_seq(path, "unboxing_shim")
266266
});
267267
let llfn = decl_internal_rust_fn(ccx,

0 commit comments

Comments
 (0)