diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2025-05-07 17:41:26 +0200 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2025-06-18 10:20:20 +0200 |
| commit | 5b763fb1b7a06393c5dc21502ac0b28776ce058f (patch) | |
| tree | 272334a1da0db299c2c836ae1f5daae1900126dd /library/coretests | |
| parent | 8ff2c1a97ed9dab37bca913fab0e4cce783e521c (diff) | |
| download | rust-5b763fb1b7a06393c5dc21502ac0b28776ce058f.tar.gz rust-5b763fb1b7a06393c5dc21502ac0b28776ce058f.zip | |
Add test for new format_args!() temporary lifetimes.
Diffstat (limited to 'library/coretests')
| -rw-r--r-- | library/coretests/tests/fmt/mod.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/library/coretests/tests/fmt/mod.rs b/library/coretests/tests/fmt/mod.rs index d9060fe903d..16f116d2590 100644 --- a/library/coretests/tests/fmt/mod.rs +++ b/library/coretests/tests/fmt/mod.rs @@ -3,6 +3,21 @@ mod float; mod num; #[test] +fn test_lifetime() { + // Trigger all different forms of expansion, + // and check that each of them can be stored as a variable. + let a = format_args!("hello"); + let a = format_args!("hello {a}"); + let a = format_args!("hello {a:1}"); + let a = format_args!("hello {a} {a:?}"); + assert_eq!(a.to_string(), "hello hello hello hello hello hello hello"); + + // Without arguments, it should also work in consts. + const A: std::fmt::Arguments<'static> = format_args!("hello"); + assert_eq!(A.to_string(), "hello"); +} + +#[test] fn test_format_flags() { // No residual flags left by pointer formatting let p = "".as_ptr(); |
