Skip to content

Commit

Permalink
Rollup merge of #79325 - LingMan:try_op, r=jonas-schievink
Browse files Browse the repository at this point in the history
Reduce boilerplate with the `?` operator

`@rustbot` modify labels to +C-cleanup.
  • Loading branch information
jonas-schievink authored Nov 23, 2020
2 parents 32be3ae + e0871cc commit b4db342
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
16 changes: 6 additions & 10 deletions compiler/rustc_builtin_macros/src/format_foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,17 +649,13 @@ pub mod shell {
impl<'a> Iterator for Substitutions<'a> {
type Item = Substitution<'a>;
fn next(&mut self) -> Option<Self::Item> {
match parse_next_substitution(self.s) {
Some((mut sub, tail)) => {
self.s = tail;
if let Some(InnerSpan { start, end }) = sub.position() {
sub.set_position(start + self.pos, end + self.pos);
self.pos += end;
}
Some(sub)
}
None => None,
let (mut sub, tail) = parse_next_substitution(self.s)?;
self.s = tail;
if let Some(InnerSpan { start, end }) = sub.position() {
sub.set_position(start + self.pos, end + self.pos);
self.pos += end;
}
Some(sub)
}

fn size_hint(&self) -> (usize, Option<usize>) {
Expand Down
10 changes: 3 additions & 7 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2372,13 +2372,9 @@ impl<'o, 'tcx> Iterator for TraitObligationStackList<'o, 'tcx> {
type Item = &'o TraitObligationStack<'o, 'tcx>;

fn next(&mut self) -> Option<&'o TraitObligationStack<'o, 'tcx>> {
match self.head {
Some(o) => {
*self = o.previous;
Some(o)
}
None => None,
}
let o = self.head?;
*self = o.previous;
Some(o)
}
}

Expand Down

0 comments on commit b4db342

Please sign in to comment.