(input: DebugPrintfInput)
| 436 | } |
| 437 | |
| 438 | fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream { |
| 439 | let DebugPrintfInput { |
| 440 | format_string, |
| 441 | variables, |
| 442 | span, |
| 443 | } = input; |
| 444 | |
| 445 | fn map_specifier_to_type( |
| 446 | specifier: char, |
| 447 | chars: &mut std::str::Chars<'_>, |
| 448 | ) -> Option<proc_macro2::TokenStream> { |
| 449 | let mut peekable = chars.peekable(); |
| 450 | |
| 451 | Some(match specifier { |
| 452 | 'd' | 'i' => quote::quote! { i32 }, |
| 453 | 'o' | 'x' | 'X' => quote::quote! { u32 }, |
| 454 | 'a' | 'A' | 'e' | 'E' | 'f' | 'F' | 'g' | 'G' => quote::quote! { f32 }, |
| 455 | 'u' => { |
| 456 | if matches!(peekable.peek(), Some('l')) { |
| 457 | chars.next(); |
| 458 | quote::quote! { u64 } |
| 459 | } else { |
| 460 | quote::quote! { u32 } |
| 461 | } |
| 462 | } |
| 463 | 'l' => { |
| 464 | if matches!(peekable.peek(), Some('u' | 'x')) { |
| 465 | chars.next(); |
| 466 | quote::quote! { u64 } |
| 467 | } else { |
| 468 | return None; |
| 469 | } |
| 470 | } |
| 471 | _ => return None, |
| 472 | }) |
| 473 | } |
| 474 | |
| 475 | let mut chars = format_string.chars(); |
| 476 | let mut format_arguments = Vec::new(); |
| 477 | |
| 478 | while let Some(mut ch) = chars.next() { |
| 479 | if ch == '%' { |
| 480 | ch = match chars.next() { |
| 481 | Some('%') => continue, |
| 482 | None => return parsing_error("Unterminated format specifier", span), |
| 483 | Some(ch) => ch, |
| 484 | }; |
| 485 | |
| 486 | let mut has_precision = false; |
| 487 | |
| 488 | while ch.is_ascii_digit() { |
| 489 | ch = match chars.next() { |
| 490 | Some(ch) => ch, |
| 491 | None => { |
| 492 | return parsing_error( |
| 493 | "Unterminated format specifier: missing type after precision", |
| 494 | span, |
| 495 | ); |
no test coverage detected