Skip to content

Commit 9fcac4e

Browse files
committed
apply requested changes in review
1 parent b6f1d6b commit 9fcac4e

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

compiler/rustc_builtin_macros/src/format_foreign.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,7 @@ pub(crate) mod printf {
265265
impl Num {
266266
fn from_str(s: &str, arg: Option<&str>) -> Option<Self> {
267267
if let Some(arg) = arg {
268-
Some(Num::Arg(
269-
arg.parse().unwrap_or_else(|_| panic!("invalid format arg `{arg:?}`")),
270-
))
268+
arg.parse().ok().map(|arg| Num::Arg(arg))
271269
} else if s == "*" {
272270
Some(Num::Next)
273271
} else {
@@ -423,7 +421,7 @@ pub(crate) mod printf {
423421
state = Prec;
424422
parameter = None;
425423
flags = "";
426-
width = Num::from_str(at.slice_between(end).unwrap(), None);
424+
width = at.slice_between(end).map(|num| Num::from_str(num, None));
427425
if width.is_none() {
428426
return fallback();
429427
}
@@ -457,7 +455,7 @@ pub(crate) mod printf {
457455
'1'..='9' => {
458456
let end = at_next_cp_while(next, char::is_ascii_digit);
459457
state = Prec;
460-
width = Num::from_str(at.slice_between(end).unwrap(), None);
458+
width = at.slice_between(end).map(|num| Num::from_str(num, None));
461459
if width.is_none() {
462460
return fallback();
463461
}
@@ -476,7 +474,7 @@ pub(crate) mod printf {
476474
match end.next_cp() {
477475
Some(('$', end2)) => {
478476
state = Prec;
479-
width = Some(Num::from_str("", Some(at.slice_between(end).unwrap())).unwrap());
477+
width = Num::from_str("", at.slice_between(end));
480478
move_to!(end2);
481479
}
482480
_ => {
@@ -508,7 +506,7 @@ pub(crate) mod printf {
508506
match end.next_cp() {
509507
Some(('$', end2)) => {
510508
state = Length;
511-
precision = Some(Num::from_str("*", next.slice_between(end)).unwrap());
509+
precision = Num::from_str("*", next.slice_between(end));
512510
move_to!(end2);
513511
}
514512
_ => {
@@ -521,7 +519,7 @@ pub(crate) mod printf {
521519
'0'..='9' => {
522520
let end = at_next_cp_while(next, char::is_ascii_digit);
523521
state = Length;
524-
precision = Some(Num::from_str(at.slice_between(end).unwrap(), None).unwrap());
522+
precision = at.slice_between(end).map(|num| Num::from_str(num, None));
525523
move_to!(end);
526524
}
527525
_ => return fallback(),

0 commit comments

Comments
 (0)