Skip to content

Commit 03ce65b

Browse files
syvbMark-Simulacrum
authored andcommitted
Implement concat_bytes!
The tracking issue for this is rust-lang#87555.
1 parent 7d64540 commit 03ce65b

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

core/src/macros/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,34 @@ pub(crate) mod builtin {
967967
($($e:ident),+ $(,)?) => {{ /* compiler built-in */ }};
968968
}
969969

970+
/// Concatenates literals into a byte slice.
971+
///
972+
/// This macro takes any number of comma-separated literals, and concatenates them all into
973+
/// one, yielding an expression of type `&[u8, _]`, which represents all of the literals
974+
/// concatenated left-to-right. The literals passed can be any combination of:
975+
///
976+
/// - byte literals (`b'r'`)
977+
/// - byte strings (`b"Rust"`)
978+
/// - arrays of bytes/numbers (`[b'A', 66, b'C']`)
979+
///
980+
/// # Examples
981+
///
982+
/// ```
983+
/// #![feature(concat_bytes)]
984+
///
985+
/// # fn main() {
986+
/// let s: &[u8; 6] = concat_bytes!(b'A', b"BC", [68, b'E', 70]);
987+
/// assert_eq!(s, b"ABCDEF");
988+
/// # }
989+
/// ```
990+
#[cfg(not(bootstrap))]
991+
#[unstable(feature = "concat_bytes", issue = "87555")]
992+
#[rustc_builtin_macro]
993+
#[macro_export]
994+
macro_rules! concat_bytes {
995+
($($e:literal),+ $(,)?) => {{ /* compiler built-in */ }};
996+
}
997+
970998
/// Concatenates literals into a static string slice.
971999
///
9721000
/// This macro takes any number of comma-separated literals, yielding an

core/src/prelude/v1.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ pub use crate::{
6060
option_env, stringify, trace_macros,
6161
};
6262

63+
#[unstable(
64+
feature = "concat_bytes",
65+
issue = "87555",
66+
reason = "`concat_bytes` is not stable enough for use and is subject to change"
67+
)]
68+
#[cfg(not(bootstrap))]
69+
#[doc(no_inline)]
70+
pub use crate::concat_bytes;
71+
6372
#[unstable(
6473
feature = "asm",
6574
issue = "72016",

std/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@
250250
#![feature(cfg_target_thread_local)]
251251
#![feature(char_error_internals)]
252252
#![feature(char_internals)]
253+
#![cfg_attr(not(bootstrap), feature(concat_bytes))]
253254
#![feature(concat_idents)]
254255
#![feature(const_cstr_unchecked)]
255256
#![feature(const_fn_floating_point_arithmetic)]
@@ -576,6 +577,14 @@ pub use core::{
576577
log_syntax, module_path, option_env, stringify, trace_macros,
577578
};
578579

580+
#[unstable(
581+
feature = "concat_bytes",
582+
issue = "87555",
583+
reason = "`concat_bytes` is not stable enough for use and is subject to change"
584+
)]
585+
#[cfg(not(bootstrap))]
586+
pub use core::concat_bytes;
587+
579588
#[stable(feature = "core_primitive", since = "1.43.0")]
580589
pub use core::primitive;
581590

std/src/prelude/v1.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ pub use core::prelude::v1::{
4545
PartialOrd,
4646
};
4747

48+
#[unstable(
49+
feature = "concat_bytes",
50+
issue = "87555",
51+
reason = "`concat_bytes` is not stable enough for use and is subject to change"
52+
)]
53+
#[cfg(not(bootstrap))]
54+
#[doc(no_inline)]
55+
pub use core::prelude::v1::concat_bytes;
56+
4857
#[unstable(
4958
feature = "asm",
5059
issue = "72016",

0 commit comments

Comments
 (0)