Skip to content

Commit 002310a

Browse files
committed
format: refactor verify_arg_type
1 parent 8866f68 commit 002310a

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

src/libsyntax_ext/format.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -336,33 +336,30 @@ impl<'a, 'b> Context<'a, 'b> {
336336
Placeholder(_) => {
337337
// record every (position, type) combination only once
338338
let ref mut seen_ty = self.arg_unique_types[arg];
339-
let i = match seen_ty.iter().position(|x| *x == ty) {
340-
Some(i) => i,
341-
None => {
342-
let i = seen_ty.len();
343-
seen_ty.push(ty);
344-
i
345-
}
346-
};
339+
let i = seen_ty.iter().position(|x| *x == ty).unwrap_or_else(|| {
340+
let i = seen_ty.len();
341+
seen_ty.push(ty);
342+
i
343+
});
347344
self.arg_types[arg].push(i);
348345
}
349346
Count => {
350-
match self.count_positions.entry(arg) {
351-
Entry::Vacant(e) => {
352-
let i = self.count_positions_count;
353-
e.insert(i);
354-
self.count_args.push(Exact(arg));
355-
self.count_positions_count += 1;
356-
}
357-
Entry::Occupied(_) => {}
347+
if let Entry::Vacant(e) = self.count_positions.entry(arg) {
348+
let i = self.count_positions_count;
349+
e.insert(i);
350+
self.count_args.push(Exact(arg));
351+
self.count_positions_count += 1;
358352
}
359353
}
360354
}
361355
}
362356

363357
Named(name) => {
364-
let idx = match self.names.get(&name) {
365-
Some(e) => *e,
358+
match self.names.get(&name) {
359+
Some(idx) => {
360+
// Treat as positional arg.
361+
self.verify_arg_type(Exact(*idx), ty)
362+
}
366363
None => {
367364
let msg = format!("there is no argument named `{}`", name);
368365
let sp = if self.is_literal {
@@ -372,11 +369,8 @@ impl<'a, 'b> Context<'a, 'b> {
372369
};
373370
let mut err = self.ecx.struct_span_err(sp, &msg[..]);
374371
err.emit();
375-
return;
376372
}
377-
};
378-
// Treat as positional arg.
379-
self.verify_arg_type(Exact(idx), ty)
373+
}
380374
}
381375
}
382376
}

0 commit comments

Comments
 (0)