diff options
| author | Yuri Astrakhan <YuriAstrakhan@gmail.com> | 2024-02-14 18:30:24 -0500 |
|---|---|---|
| committer | Yuri Astrakhan <YuriAstrakhan@gmail.com> | 2024-02-20 01:11:16 -0500 |
| commit | 6fa7d6ca16f5f3704bfd48fd3721e8ea329e971b (patch) | |
| tree | 1455955fc398a630c375d9bef690f5a800feb80f | |
| parent | d712e3f4f4b7b002f984336031a13c864bea10b8 (diff) | |
| download | rust-6fa7d6ca16f5f3704bfd48fd3721e8ea329e971b.tar.gz rust-6fa7d6ca16f5f3704bfd48fd3721e8ea329e971b.zip | |
Use intrinsic
| -rw-r--r-- | library/core/src/fmt/mod.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index f95ab8dd5f3..dde8c0c5e2b 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -430,6 +430,19 @@ impl<'a> Arguments<'a> { _ => None, } } + + /// Same as `as_str`, but will only return a `Some` value if it can be determined at compile time. + #[inline] + const fn as_const_str(&self) -> Option<&'static str> { + let s = self.as_str(); + // if unsafe { core::intrinsics::is_val_statically_known(matches!((self.pieces, self.args), ([], []) | ([_], []))) } { + if unsafe { core::intrinsics::is_val_statically_known(s) } { + s + } else { + None + } + + } } #[stable(feature = "rust1", since = "1.0.0")] |
