summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-12-09 05:08:30 +0100
committerGitHub <noreply@github.com>2021-12-09 05:08:30 +0100
commit3fc5bd7abc2878f65a3c3dbc594874bae369cdf8 (patch)
treee34d5a0968600fd8b634636456cc9db7f3800a9c /library/std/src
parent3c857f48ce12d1f98f3ea6d48eb9e33d8d60c985 (diff)
parenteb56693a370df5bb60f58f73586cded6a641b0cc (diff)
downloadrust-3fc5bd7abc2878f65a3c3dbc594874bae369cdf8.tar.gz
rust-3fc5bd7abc2878f65a3c3dbc594874bae369cdf8.zip
Rollup merge of #87599 - Smittyvb:concat_bytes, r=Mark-Simulacrum
Implement concat_bytes!

This implements the unstable `concat_bytes!` macro, which has tracking issue #87555. It can be used like:
```rust
#![feature(concat_bytes)]

fn main() {
    assert_eq!(concat_bytes!(), &[]);
    assert_eq!(concat_bytes!(b'A', b"BC", [68, b'E', 70]), b"ABCDEF");
}
```
If strings or characters are used where byte strings or byte characters are required, it suggests adding a `b` prefix. If a number is used outside of an array it suggests arrayifying it. If a boolean is used it suggests replacing it with the numeric value of that number. Doubly nested arrays of bytes are disallowed.
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/lib.rs9
-rw-r--r--library/std/src/prelude/v1.rs9
2 files changed, 18 insertions, 0 deletions
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs
index 67846e78835..367f072ffc7 100644
--- a/library/std/src/lib.rs
+++ b/library/std/src/lib.rs
@@ -250,6 +250,7 @@
 #![feature(cfg_target_thread_local)]
 #![feature(char_error_internals)]
 #![feature(char_internals)]
+#![cfg_attr(not(bootstrap), feature(concat_bytes))]
 #![feature(concat_idents)]
 #![feature(const_cstr_unchecked)]
 #![feature(const_fn_floating_point_arithmetic)]
@@ -576,6 +577,14 @@ pub use core::{
     log_syntax, module_path, option_env, stringify, trace_macros,
 };
 
+#[unstable(
+    feature = "concat_bytes",
+    issue = "87555",
+    reason = "`concat_bytes` is not stable enough for use and is subject to change"
+)]
+#[cfg(not(bootstrap))]
+pub use core::concat_bytes;
+
 #[stable(feature = "core_primitive", since = "1.43.0")]
 pub use core::primitive;
 
diff --git a/library/std/src/prelude/v1.rs b/library/std/src/prelude/v1.rs
index 772044f0149..9b23aa37e31 100644
--- a/library/std/src/prelude/v1.rs
+++ b/library/std/src/prelude/v1.rs
@@ -46,6 +46,15 @@ pub use core::prelude::v1::{
 };
 
 #[unstable(
+    feature = "concat_bytes",
+    issue = "87555",
+    reason = "`concat_bytes` is not stable enough for use and is subject to change"
+)]
+#[cfg(not(bootstrap))]
+#[doc(no_inline)]
+pub use core::prelude::v1::concat_bytes;
+
+#[unstable(
     feature = "asm",
     issue = "72016",
     reason = "inline assembly is not stable enough for use and is subject to change"