Skip to content

Commit 64371f1

Browse files
authoredDec 5, 2018
Rollup merge of rust-lang#56119 - frewsxcv:frewsxcv-option-carrier, r=TimNN
Utilize `?` instead of `return None`. None

File tree

12 files changed

+26
-68
lines changed

12 files changed

+26
-68
lines changed
 

‎src/libcore/str/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,9 @@ fn next_code_point_reverse<'a, I>(bytes: &mut I) -> Option<u32>
536536
where I: DoubleEndedIterator<Item = &'a u8>,
537537
{
538538
// Decode UTF-8
539-
let w = match bytes.next_back() {
540-
None => return None,
541-
Some(&next_byte) if next_byte < 128 => return Some(next_byte as u32),
542-
Some(&back_byte) => back_byte,
539+
let w = match *bytes.next_back()? {
540+
next_byte if next_byte < 128 => return Some(next_byte as u32),
541+
back_byte => back_byte,
543542
};
544543

545544
// Multibyte case follows

‎src/librustc/middle/region.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,7 @@ impl<'tcx> ScopeTree {
592592
return Some(scope.item_local_id());
593593
}
594594

595-
match self.opt_encl_scope(scope) {
596-
None => return None,
597-
Some(parent) => scope = parent,
598-
}
595+
scope = self.opt_encl_scope(scope)?;
599596
}
600597
}
601598

‎src/librustc/session/search_paths.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ impl<'a> Iterator for Iter<'a> {
6767

6868
fn next(&mut self) -> Option<(&'a Path, PathKind)> {
6969
loop {
70-
match self.iter.next() {
71-
Some(&(kind, ref p)) if self.kind == PathKind::All ||
72-
kind == PathKind::All ||
73-
kind == self.kind => {
70+
match *self.iter.next()? {
71+
(kind, ref p) if self.kind == PathKind::All ||
72+
kind == PathKind::All ||
73+
kind == self.kind => {
7474
return Some((p, kind))
7575
}
76-
Some(..) => {}
77-
None => return None,
76+
_ => {}
7877
}
7978
}
8079
}

‎src/librustc_incremental/persist/work_product.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
2929
return None
3030
}
3131

32-
let saved_files: Option<Vec<_>> =
32+
let saved_files =
3333
files.iter()
3434
.map(|&(kind, ref path)| {
3535
let extension = match kind {
@@ -51,11 +51,7 @@ pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
5151
}
5252
}
5353
})
54-
.collect();
55-
let saved_files = match saved_files {
56-
None => return None,
57-
Some(v) => v,
58-
};
54+
.collect::<Option<Vec<_>>>()?;
5955

6056
let work_product = WorkProduct {
6157
cgu_name: cgu_name.to_string(),

‎src/librustc_mir/borrow_check/prefixes.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
8787
impl<'cx, 'gcx, 'tcx> Iterator for Prefixes<'cx, 'gcx, 'tcx> {
8888
type Item = &'cx Place<'tcx>;
8989
fn next(&mut self) -> Option<Self::Item> {
90-
let mut cursor = match self.next {
91-
None => return None,
92-
Some(place) => place,
93-
};
90+
let mut cursor = self.next?;
9491

9592
// Post-processing `place`: Enqueue any remaining
9693
// work. Also, `place` may not be a prefix itself, but

‎src/librustdoc/clean/mod.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -3948,10 +3948,7 @@ pub fn path_to_def_local(tcx: &TyCtxt, path: &[&str]) -> Option<DefId> {
39483948
let mut path_it = path.iter().peekable();
39493949

39503950
loop {
3951-
let segment = match path_it.next() {
3952-
Some(segment) => segment,
3953-
None => return None,
3954-
};
3951+
let segment = path_it.next()?;
39553952

39563953
for item_id in mem::replace(&mut items, HirVec::new()).iter() {
39573954
let item = tcx.hir.expect_item(item_id.id);
@@ -3986,10 +3983,7 @@ pub fn path_to_def(tcx: &TyCtxt, path: &[&str]) -> Option<DefId> {
39863983
let mut path_it = path.iter().skip(1).peekable();
39873984

39883985
loop {
3989-
let segment = match path_it.next() {
3990-
Some(segment) => segment,
3991-
None => return None,
3992-
};
3986+
let segment = path_it.next()?;
39933987

39943988
for item in mem::replace(&mut items, Lrc::new(vec![])).iter() {
39953989
if item.ident.name == *segment {

‎src/librustdoc/html/render.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2220,13 +2220,13 @@ impl<'a> Item<'a> {
22202220
return None;
22212221
}
22222222
} else {
2223-
let (krate, src_root) = match cache.extern_locations.get(&self.item.def_id.krate) {
2224-
Some(&(ref name, ref src, Local)) => (name, src),
2225-
Some(&(ref name, ref src, Remote(ref s))) => {
2223+
let (krate, src_root) = match *cache.extern_locations.get(&self.item.def_id.krate)? {
2224+
(ref name, ref src, Local) => (name, src),
2225+
(ref name, ref src, Remote(ref s)) => {
22262226
root = s.to_string();
22272227
(name, src)
22282228
}
2229-
Some(&(_, _, Unknown)) | None => return None,
2229+
(_, _, Unknown) => return None,
22302230
};
22312231

22322232
clean_srcpath(&src_root, file, false, |component| {

‎src/libstd/sys/windows/path.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ pub fn parse_prefix<'a>(path: &'a OsStr) -> Option<Prefix> {
9191
}
9292

9393
fn parse_two_comps(mut path: &[u8], f: fn(u8) -> bool) -> Option<(&[u8], &[u8])> {
94-
let first = match path.iter().position(|x| f(*x)) {
95-
None => return None,
96-
Some(x) => &path[..x],
97-
};
94+
let first = &path[..path.iter().position(|x| f(*x))?];
9895
path = &path[(first.len() + 1)..];
9996
let idx = path.iter().position(|x| f(*x));
10097
let second = &path[..idx.unwrap_or(path.len())];

‎src/test/run-pass/impl-trait/example-calendar.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -753,10 +753,7 @@ where It: Iterator {
753753
type Item = Vec<It::Item>;
754754

755755
fn next(&mut self) -> Option<Vec<It::Item>> {
756-
let first = match self.it.next() {
757-
Some(e) => e,
758-
None => return None
759-
};
756+
let first = self.it.next()?;
760757

761758
let mut result = Vec::with_capacity(self.n);
762759
result.push(first);

‎src/tools/compiletest/src/errors.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ fn parse_expected(
119119
line: &str,
120120
tag: &str,
121121
) -> Option<(WhichLine, Error)> {
122-
let start = match line.find(tag) {
123-
Some(i) => i,
124-
None => return None,
125-
};
122+
let start = line.find(tag)?;
126123
let (follow, adjusts) = if line[start + tag.len()..].chars().next().unwrap() == '|' {
127124
(true, 0)
128125
} else {

‎src/tools/compiletest/src/header.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -707,14 +707,8 @@ impl Config {
707707

708708
fn parse_custom_normalization(&self, mut line: &str, prefix: &str) -> Option<(String, String)> {
709709
if self.parse_cfg_name_directive(line, prefix) == ParsedNameDirective::Match {
710-
let from = match parse_normalization_string(&mut line) {
711-
Some(s) => s,
712-
None => return None,
713-
};
714-
let to = match parse_normalization_string(&mut line) {
715-
Some(s) => s,
716-
None => return None,
717-
};
710+
let from = parse_normalization_string(&mut line)?;
711+
let to = parse_normalization_string(&mut line)?;
718712
Some((from, to))
719713
} else {
720714
None
@@ -873,14 +867,8 @@ fn expand_variables(mut value: String, config: &Config) -> String {
873867
/// ```
874868
fn parse_normalization_string(line: &mut &str) -> Option<String> {
875869
// FIXME support escapes in strings.
876-
let begin = match line.find('"') {
877-
Some(i) => i + 1,
878-
None => return None,
879-
};
880-
let end = match line[begin..].find('"') {
881-
Some(i) => i + begin,
882-
None => return None,
883-
};
870+
let begin = line.find('"')? + 1;
871+
let end = line[begin..].find('"')? + begin;
884872
let result = line[begin..end].to_owned();
885873
*line = &line[end + 1..];
886874
Some(result)

‎src/tools/linkchecker/main.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,7 @@ fn maybe_redirect(source: &str) -> Option<String> {
332332
const REDIRECT: &'static str = "<p>Redirecting to <a href=";
333333

334334
let mut lines = source.lines();
335-
let redirect_line = match lines.nth(6) {
336-
Some(l) => l,
337-
None => return None,
338-
};
335+
let redirect_line = lines.nth(6)?;
339336

340337
redirect_line.find(REDIRECT).map(|i| {
341338
let rest = &redirect_line[(i + REDIRECT.len() + 1)..];

0 commit comments

Comments
 (0)
Please sign in to comment.