Skip to content

Commit ad6ee5f

Browse files
committed
Use four-space indentation, add trailing commas, and remove unnecessary uses of the return keyword
1 parent 60ea6d6 commit ad6ee5f

File tree

3 files changed

+95
-80
lines changed

3 files changed

+95
-80
lines changed

src/libcore/either.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ pub enum Either<T, U> {
3535
pub fn either<T, U, V>(f_left: &fn(&T) -> V,
3636
f_right: &fn(&U) -> V, value: &Either<T, U>) -> V {
3737
match *value {
38-
Left(ref l) => f_left(l),
39-
Right(ref r) => f_right(r)
38+
Left(ref l) => f_left(l),
39+
Right(ref r) => f_right(r)
4040
}
4141
}
4242

@@ -73,8 +73,8 @@ pub fn partition<T, U>(eithers: ~[Either<T, U>]) -> (~[T], ~[U]) {
7373
let mut rights: ~[U] = ~[];
7474
do vec::consume(eithers) |_i, elt| {
7575
match elt {
76-
Left(l) => lefts.push(l),
77-
Right(r) => rights.push(r)
76+
Left(l) => lefts.push(l),
77+
Right(r) => rights.push(r)
7878
}
7979
}
8080
return (lefts, rights);
@@ -84,8 +84,8 @@ pub fn partition<T, U>(eithers: ~[Either<T, U>]) -> (~[T], ~[U]) {
8484
#[inline(always)]
8585
pub fn flip<T, U>(eith: Either<T, U>) -> Either<U, T> {
8686
match eith {
87-
Right(r) => Left(r),
88-
Left(l) => Right(l)
87+
Right(r) => Left(r),
88+
Left(l) => Right(l)
8989
}
9090
}
9191

@@ -96,21 +96,27 @@ pub fn flip<T, U>(eith: Either<T, U>) -> Either<U, T> {
9696
#[inline(always)]
9797
pub fn to_result<T, U>(eith: Either<T, U>) -> Result<U, T> {
9898
match eith {
99-
Right(r) => result::Ok(r),
100-
Left(l) => result::Err(l)
99+
Right(r) => result::Ok(r),
100+
Left(l) => result::Err(l)
101101
}
102102
}
103103

104104
/// Checks whether the given value is a left
105105
#[inline(always)]
106106
pub fn is_left<T, U>(eith: &Either<T, U>) -> bool {
107-
match *eith { Left(_) => true, _ => false }
107+
match *eith {
108+
Left(_) => true,
109+
_ => false
110+
}
108111
}
109112

110113
/// Checks whether the given value is a right
111114
#[inline(always)]
112115
pub fn is_right<T, U>(eith: &Either<T, U>) -> bool {
113-
match *eith { Right(_) => true, _ => false }
116+
match *eith {
117+
Right(_) => true,
118+
_ => false
119+
}
114120
}
115121

116122
/// Retrieves the value in the left branch. Fails if the either is Right.

src/libcore/option.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ impl<T:Ord> Ord for Option<T> {
8989
}
9090

9191
fn ge(&self, other: &Option<T>) -> bool {
92-
! (self < other)
92+
!(self < other)
9393
}
9494

9595
fn gt(&self, other: &Option<T>) -> bool {
96-
! (self <= other)
96+
!(self <= other)
9797
}
9898
}
9999

src/libcore/path.rs

+77-68
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,10 @@ impl GenericPath for PosixPath {
452452
components.push(s.to_owned())
453453
}
454454
let is_absolute = (s.len() != 0 && s[0] == '/' as u8);
455-
return PosixPath { is_absolute: is_absolute,
456-
components: components }
455+
PosixPath {
456+
is_absolute: is_absolute,
457+
components: components,
458+
}
457459
}
458460

459461
fn dirname(&self) -> ~str {
@@ -466,40 +468,40 @@ impl GenericPath for PosixPath {
466468

467469
fn filename(&self) -> Option<~str> {
468470
match self.components.len() {
469-
0 => None,
470-
n => Some(copy self.components[n - 1])
471+
0 => None,
472+
n => Some(copy self.components[n - 1]),
471473
}
472474
}
473475

474476
fn filestem(&self) -> Option<~str> {
475477
match self.filename() {
476-
None => None,
477-
Some(ref f) => {
478-
match str::rfind_char(*f, '.') {
479-
Some(p) => Some(f.slice(0, p).to_owned()),
480-
None => Some(copy *f)
478+
None => None,
479+
Some(ref f) => {
480+
match str::rfind_char(*f, '.') {
481+
Some(p) => Some(f.slice(0, p).to_owned()),
482+
None => Some(copy *f),
483+
}
481484
}
482-
}
483485
}
484486
}
485487

486488
fn filetype(&self) -> Option<~str> {
487489
match self.filename() {
488-
None => None,
489-
Some(ref f) => {
490-
match str::rfind_char(*f, '.') {
491-
Some(p) if p < f.len() => Some(f.slice(p, f.len()).to_owned()),
492-
_ => None
490+
None => None,
491+
Some(ref f) => {
492+
match str::rfind_char(*f, '.') {
493+
Some(p) if p < f.len() => Some(f.slice(p, f.len()).to_owned()),
494+
_ => None,
495+
}
493496
}
494-
}
495497
}
496498
}
497499

498500
fn with_dirname(&self, d: &str) -> PosixPath {
499501
let dpath = PosixPath(d);
500502
match self.filename() {
501-
Some(ref f) => dpath.push(*f),
502-
None => dpath
503+
Some(ref f) => dpath.push(*f),
504+
None => dpath,
503505
}
504506
}
505507

@@ -510,8 +512,8 @@ impl GenericPath for PosixPath {
510512

511513
fn with_filestem(&self, s: &str) -> PosixPath {
512514
match self.filetype() {
513-
None => self.with_filename(s),
514-
Some(ref t) => self.with_filename(str::to_owned(s) + *t)
515+
None => self.with_filename(s),
516+
Some(ref t) => self.with_filename(str::to_owned(s) + *t),
515517
}
516518
}
517519

@@ -536,8 +538,10 @@ impl GenericPath for PosixPath {
536538
None => ~[],
537539
Some(ref f) => ~[copy *f]
538540
};
539-
return PosixPath { is_absolute: false,
540-
components: cs }
541+
PosixPath {
542+
is_absolute: false,
543+
components: cs,
544+
}
541545
}
542546

543547
fn push_rel(&self, other: &PosixPath) -> PosixPath {
@@ -547,8 +551,10 @@ impl GenericPath for PosixPath {
547551

548552
fn unsafe_join(&self, other: &PosixPath) -> PosixPath {
549553
if other.is_absolute {
550-
PosixPath { is_absolute: true,
551-
components: copy other.components }
554+
PosixPath {
555+
is_absolute: true,
556+
components: copy other.components,
557+
}
552558
} else {
553559
self.push_rel(other)
554560
}
@@ -567,8 +573,10 @@ impl GenericPath for PosixPath {
567573
}
568574
v.push_all_move(ss);
569575
}
570-
PosixPath { is_absolute: self.is_absolute,
571-
components: v }
576+
PosixPath {
577+
is_absolute: self.is_absolute,
578+
components: v,
579+
}
572580
}
573581

574582
fn push(&self, s: &str) -> PosixPath {
@@ -586,19 +594,17 @@ impl GenericPath for PosixPath {
586594
if cs.len() != 0 {
587595
cs.pop();
588596
}
589-
return PosixPath {
597+
PosixPath {
590598
is_absolute: self.is_absolute,
591-
components: cs
592-
}
593-
//..self }
599+
components: cs,
600+
} //..self }
594601
}
595602

596603
fn normalize(&self) -> PosixPath {
597-
return PosixPath {
604+
PosixPath {
598605
is_absolute: self.is_absolute,
599-
components: normalize(self.components)
600-
// ..self
601-
}
606+
components: normalize(self.components),
607+
} // ..self }
602608
}
603609

604610
fn is_absolute(&self) -> bool {
@@ -658,10 +664,12 @@ impl GenericPath for WindowsPath {
658664
components.push(s.to_owned())
659665
}
660666
let is_absolute = (rest.len() != 0 && windows::is_sep(rest[0]));
661-
return WindowsPath { host: host,
662-
device: device,
663-
is_absolute: is_absolute,
664-
components: components }
667+
WindowsPath {
668+
host: host,
669+
device: device,
670+
is_absolute: is_absolute,
671+
components: components,
672+
}
665673
}
666674

667675
fn dirname(&self) -> ~str {
@@ -674,20 +682,20 @@ impl GenericPath for WindowsPath {
674682

675683
fn filename(&self) -> Option<~str> {
676684
match self.components.len() {
677-
0 => None,
678-
n => Some(copy self.components[n - 1])
685+
0 => None,
686+
n => Some(copy self.components[n - 1]),
679687
}
680688
}
681689

682690
fn filestem(&self) -> Option<~str> {
683691
match self.filename() {
684-
None => None,
685-
Some(ref f) => {
686-
match str::rfind_char(*f, '.') {
687-
Some(p) => Some(f.slice(0, p).to_owned()),
688-
None => Some(copy *f)
692+
None => None,
693+
Some(ref f) => {
694+
match str::rfind_char(*f, '.') {
695+
Some(p) => Some(f.slice(0, p).to_owned()),
696+
None => Some(copy *f),
697+
}
689698
}
690-
}
691699
}
692700
}
693701

@@ -696,8 +704,8 @@ impl GenericPath for WindowsPath {
696704
None => None,
697705
Some(ref f) => {
698706
match str::rfind_char(*f, '.') {
699-
Some(p) if p < f.len() => Some(f.slice(p, f.len()).to_owned()),
700-
_ => None
707+
Some(p) if p < f.len() => Some(f.slice(p, f.len()).to_owned()),
708+
_ => None,
701709
}
702710
}
703711
}
@@ -706,8 +714,8 @@ impl GenericPath for WindowsPath {
706714
fn with_dirname(&self, d: &str) -> WindowsPath {
707715
let dpath = WindowsPath(d);
708716
match self.filename() {
709-
Some(ref f) => dpath.push(*f),
710-
None => dpath
717+
Some(ref f) => dpath.push(*f),
718+
None => dpath,
711719
}
712720
}
713721

@@ -718,8 +726,8 @@ impl GenericPath for WindowsPath {
718726

719727
fn with_filestem(&self, s: &str) -> WindowsPath {
720728
match self.filetype() {
721-
None => self.with_filename(s),
722-
Some(ref t) => self.with_filename(str::to_owned(s) + *t)
729+
None => self.with_filename(s),
730+
Some(ref t) => self.with_filename(str::to_owned(s) + *t),
723731
}
724732
}
725733

@@ -740,14 +748,15 @@ impl GenericPath for WindowsPath {
740748
}
741749

742750
fn file_path(&self) -> WindowsPath {
743-
let cs = match self.filename() {
744-
None => ~[],
745-
Some(ref f) => ~[copy *f]
746-
};
747-
return WindowsPath { host: None,
748-
device: None,
749-
is_absolute: false,
750-
components: cs }
751+
WindowsPath {
752+
host: None,
753+
device: None,
754+
is_absolute: false,
755+
components: match self.filename() {
756+
None => ~[],
757+
Some(ref f) => ~[copy *f],
758+
}
759+
}
751760
}
752761

753762
fn push_rel(&self, other: &WindowsPath) -> WindowsPath {
@@ -768,7 +777,7 @@ impl GenericPath for WindowsPath {
768777
host: Some(host),
769778
device: copy other.device,
770779
is_absolute: true,
771-
components: copy other.components
780+
components: copy other.components,
772781
};
773782
}
774783
_ => {}
@@ -781,7 +790,7 @@ impl GenericPath for WindowsPath {
781790
host: None,
782791
device: Some(device),
783792
is_absolute: true,
784-
components: copy other.components
793+
components: copy other.components,
785794
};
786795
}
787796
_ => {}
@@ -793,7 +802,7 @@ impl GenericPath for WindowsPath {
793802
host: copy self.host,
794803
device: copy self.device,
795804
is_absolute: self.is_absolute || other.is_absolute,
796-
components: copy other.components
805+
components: copy other.components,
797806
}
798807
}
799808

@@ -822,7 +831,7 @@ impl GenericPath for WindowsPath {
822831
v.push_all_move(ss);
823832
}
824833
// tedious, but as-is, we can't use ..self
825-
return WindowsPath {
834+
WindowsPath {
826835
host: copy self.host,
827836
device: copy self.device,
828837
is_absolute: self.is_absolute,
@@ -837,24 +846,24 @@ impl GenericPath for WindowsPath {
837846
ss.push(s.to_owned())
838847
}
839848
v.push_all_move(ss);
840-
return WindowsPath { components: v, ..copy *self }
849+
WindowsPath { components: v, ..copy *self }
841850
}
842851

843852
fn pop(&self) -> WindowsPath {
844853
let mut cs = copy self.components;
845854
if cs.len() != 0 {
846855
cs.pop();
847856
}
848-
return WindowsPath {
857+
WindowsPath {
849858
host: copy self.host,
850859
device: copy self.device,
851860
is_absolute: self.is_absolute,
852-
components: cs
861+
components: cs,
853862
}
854863
}
855864

856865
fn normalize(&self) -> WindowsPath {
857-
return WindowsPath {
866+
WindowsPath {
858867
host: copy self.host,
859868
device: match self.device {
860869
None => None,

0 commit comments

Comments
 (0)