diff options
| author | ljedrz <ljedrz@gmail.com> | 2018-12-14 14:40:05 +0100 |
|---|---|---|
| committer | ljedrz <ljedrz@gmail.com> | 2018-12-14 14:40:05 +0100 |
| commit | 959313aad0a7d2eb68bd15894b5e6f94580f4582 (patch) | |
| tree | f25a6f737e55e0a45d56a8148dc8529f6678d177 | |
| parent | 002310a496e92315b3544dbd1a40f8fff190881e (diff) | |
| download | rust-959313aad0a7d2eb68bd15894b5e6f94580f4582.tar.gz rust-959313aad0a7d2eb68bd15894b5e6f94580f4582.zip | |
format: minor stylistic improvements
| -rw-r--r-- | src/libsyntax_ext/format.rs | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index 2e5698c1a6c..41799eede9e 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -413,12 +413,10 @@ impl<'a, 'b> Context<'a, 'b> { parse::CountIs(i) => count("Is", Some(self.ecx.expr_usize(sp, i))), parse::CountIsParam(i) => { // This needs mapping too, as `i` is referring to a macro - // argument. - let i = match self.count_positions.get(&i) { - Some(&i) => i, - None => 0, // error already emitted elsewhere - }; - let i = i + self.count_args_index_offset; + // argument. If `i` is not found in `count_positions` then + // the error had already been emitted elsewhere. + let i = self.count_positions.get(&i).cloned().unwrap_or(0) + + self.count_args_index_offset; count("Param", Some(self.ecx.expr_usize(sp, i))) } parse::CountImplied => count("Implied", None), @@ -503,10 +501,7 @@ impl<'a, 'b> Context<'a, 'b> { }, }; - let fill = match arg.format.fill { - Some(c) => c, - None => ' ', - }; + let fill = arg.format.fill.unwrap_or(' '); if *arg != simple_arg || fill != ' ' { self.all_pieces_simple = false; @@ -805,8 +800,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, if !parser.errors.is_empty() { let err = parser.errors.remove(0); let sp = fmt.span.from_inner_byte_pos(err.start, err.end); - let mut e = ecx.struct_span_err(sp, &format!("invalid format string: {}", - err.description)); + let mut e = ecx.struct_span_err(sp, &format!("invalid format string: {}", err.description)); e.span_label(sp, err.label + " in format string"); if let Some(note) = err.note { e.note(¬e); |
