Skip to content

Commit 6ad3611

Browse files
committed
Auto merge of rust-lang#91692 - matthiaskrgr:rollup-u7dvh0n, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#87599 (Implement concat_bytes!) - rust-lang#89999 (Update std::env::temp_dir to use GetTempPath2 on Windows when available.) - rust-lang#90796 (Remove the reg_thumb register class for asm! on ARM) - rust-lang#91042 (Use Vec extend instead of repeated pushes on several places) - rust-lang#91634 (Do not attempt to suggest help for overly malformed struct/function call) - rust-lang#91685 (Install llvm tools to sysroot when assembling local toolchain) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents dbe7829 + b2daf44 commit 6ad3611

File tree

7 files changed

+71
-13
lines changed

7 files changed

+71
-13
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/env.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -583,28 +583,25 @@ pub fn home_dir() -> Option<PathBuf> {
583583
/// may result in "insecure temporary file" security vulnerabilities. Consider
584584
/// using a crate that securely creates temporary files or directories.
585585
///
586-
/// # Unix
586+
/// # Platform-specific behavior
587587
///
588-
/// Returns the value of the `TMPDIR` environment variable if it is
588+
/// On Unix, returns the value of the `TMPDIR` environment variable if it is
589589
/// set, otherwise for non-Android it returns `/tmp`. If Android, since there
590590
/// is no global temporary folder (it is usually allocated per-app), it returns
591591
/// `/data/local/tmp`.
592+
/// On Windows, the behavior is equivalent to that of [`GetTempPath2`][GetTempPath2] /
593+
/// [`GetTempPath`][GetTempPath], which this function uses internally.
594+
/// Note that, this [may change in the future][changes].
592595
///
593-
/// # Windows
594-
///
595-
/// Returns the value of, in order, the `TMP`, `TEMP`,
596-
/// `USERPROFILE` environment variable if any are set and not the empty
597-
/// string. Otherwise, `temp_dir` returns the path of the Windows directory.
598-
/// This behavior is identical to that of [`GetTempPath`][msdn], which this
599-
/// function uses internally.
600-
///
601-
/// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppatha
596+
/// [changes]: io#platform-specific-behavior
597+
/// [GetTempPath2]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2a
598+
/// [GetTempPath]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppatha
602599
///
603600
/// ```no_run
604601
/// use std::env;
605602
///
606603
/// fn main() {
607-
/// let mut dir = env::temp_dir();
604+
/// let dir = env::temp_dir();
608605
/// println!("Temporary directory: {}", dir.display());
609606
/// }
610607
/// ```

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",

std/src/sys/windows/c.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,12 @@ compat_fn! {
11101110
-> () {
11111111
GetSystemTimeAsFileTime(lpSystemTimeAsFileTime)
11121112
}
1113+
1114+
// >= Win11 / Server 2022
1115+
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2a
1116+
pub fn GetTempPath2W(nBufferLength: DWORD, lpBuffer: LPCWSTR) -> DWORD {
1117+
GetTempPathW(nBufferLength, lpBuffer)
1118+
}
11131119
}
11141120

11151121
compat_fn! {

std/src/sys/windows/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> {
275275
}
276276

277277
pub fn temp_dir() -> PathBuf {
278-
super::fill_utf16_buf(|buf, sz| unsafe { c::GetTempPathW(sz, buf) }, super::os2path).unwrap()
278+
super::fill_utf16_buf(|buf, sz| unsafe { c::GetTempPath2W(sz, buf) }, super::os2path).unwrap()
279279
}
280280

281281
#[cfg(not(target_vendor = "uwp"))]

0 commit comments

Comments
 (0)