Skip to content

Commit 4f3ab49

Browse files
committed
libstd: Prefer Option::map/etc over match where applicable
1 parent 8dbbd81 commit 4f3ab49

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

src/libstd/net/parser.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ impl<'a> Parser<'a> {
5353
F: FnOnce(&mut Parser) -> Option<T>,
5454
{
5555
self.read_atomically(move |p| {
56-
match cb(p) {
57-
Some(x) => if p.is_eof() {Some(x)} else {None},
58-
None => None,
59-
}
56+
cb(p).filter(|_| p.is_eof())
6057
})
6158
}
6259

src/libstd/path.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1065,10 +1065,7 @@ impl<'a> Iterator for Ancestors<'a> {
10651065

10661066
fn next(&mut self) -> Option<Self::Item> {
10671067
let next = self.next;
1068-
self.next = match next {
1069-
Some(path) => path.parent(),
1070-
None => None,
1071-
};
1068+
self.next = next.and_then(Path::parent);
10721069
next
10731070
}
10741071
}

src/libstd/sys_common/backtrace.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,15 @@ pub fn log_enabled() -> Option<PrintFormat> {
156156
_ => return Some(PrintFormat::Full),
157157
}
158158

159-
let val = match env::var_os("RUST_BACKTRACE") {
160-
Some(x) => if &x == "0" {
159+
let val = env::var_os("RUST_BACKTRACE").and_then(|x|
160+
if &x == "0" {
161161
None
162162
} else if &x == "full" {
163163
Some(PrintFormat::Full)
164164
} else {
165165
Some(PrintFormat::Short)
166-
},
167-
None => None,
168-
};
166+
}
167+
);
169168
ENABLED.store(match val {
170169
Some(v) => v as isize,
171170
None => 1,

0 commit comments

Comments
 (0)