]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/fmt/format-args-capture.rs
2 #![feature(format_args_capture)]
6 named_argument_takes_precedence_to_captured();
7 formatting_parameters_can_be_captured();
9 #[cfg(panic = "unwind")]
11 panic_with_single_argument_does_not_get_formatted();
12 panic_with_multiple_arguments_is_formatted();
16 fn named_argument_takes_precedence_to_captured() {
18 let s
= format
!("{foo}", foo
="named");
19 assert_eq
!(&s
, "named");
21 let s
= format
!("{foo}-{foo}-{foo}", foo
="named");
22 assert_eq
!(&s
, "named-named-named");
24 let s
= format
!("{}-{bar}-{foo}", "positional", bar
="named");
25 assert_eq
!(&s
, "positional-named-captured");
28 #[cfg(panic = "unwind")]
29 fn panic_with_single_argument_does_not_get_formatted() {
30 // panic! with a single argument does not perform string formatting.
31 // RFC #2795 suggests that this may need to change so that captured arguments are formatted.
32 // For stability reasons this will need to part of an edition change.
34 #[allow(non_fmt_panic)]
35 let msg
= std
::panic
::catch_unwind(|| {
39 assert_eq
!(msg
.downcast_ref
::<&str>(), Some(&"{foo}"))
42 #[cfg(panic = "unwind")]
43 fn panic_with_multiple_arguments_is_formatted() {
46 let msg
= std
::panic
::catch_unwind(|| {
47 panic
!("{}-{bar}-{foo}", "positional", bar
="named");
50 assert_eq
!(msg
.downcast_ref
::<String
>(), Some(&"positional-named-captured".to_string()))
53 fn formatting_parameters_can_be_captured() {
59 let s
= format
!("{x:width$}");
62 let s
= format
!("{x:<width$}");
65 let s
= format
!("{x:-^width$}");
66 assert_eq
!(&s
, "----7----");
68 let s
= format
!("{x:-^width$.precision$}");
69 assert_eq
!(&s
, "--7.000--");