Skip to content

Commit e0871cc

Browse files
committed
Reduce boilerplate with the ? operator
1 parent c643dd2 commit e0871cc

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

compiler/rustc_builtin_macros/src/format_foreign.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -649,17 +649,13 @@ pub mod shell {
649649
impl<'a> Iterator for Substitutions<'a> {
650650
type Item = Substitution<'a>;
651651
fn next(&mut self) -> Option<Self::Item> {
652-
match parse_next_substitution(self.s) {
653-
Some((mut sub, tail)) => {
654-
self.s = tail;
655-
if let Some(InnerSpan { start, end }) = sub.position() {
656-
sub.set_position(start + self.pos, end + self.pos);
657-
self.pos += end;
658-
}
659-
Some(sub)
660-
}
661-
None => None,
652+
let (mut sub, tail) = parse_next_substitution(self.s)?;
653+
self.s = tail;
654+
if let Some(InnerSpan { start, end }) = sub.position() {
655+
sub.set_position(start + self.pos, end + self.pos);
656+
self.pos += end;
662657
}
658+
Some(sub)
663659
}
664660

665661
fn size_hint(&self) -> (usize, Option<usize>) {

compiler/rustc_trait_selection/src/traits/select/mod.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -2364,13 +2364,9 @@ impl<'o, 'tcx> Iterator for TraitObligationStackList<'o, 'tcx> {
23642364
type Item = &'o TraitObligationStack<'o, 'tcx>;
23652365

23662366
fn next(&mut self) -> Option<&'o TraitObligationStack<'o, 'tcx>> {
2367-
match self.head {
2368-
Some(o) => {
2369-
*self = o.previous;
2370-
Some(o)
2371-
}
2372-
None => None,
2373-
}
2367+
let o = self.head?;
2368+
*self = o.previous;
2369+
Some(o)
23742370
}
23752371
}
23762372

0 commit comments

Comments
 (0)