Skip to content

Commit e8cbaf2

Browse files
committed
Auto merge of rust-lang#78623 - m-ou-se:rollup-m6y5j0m, r=m-ou-se
Rollup of 6 pull requests Successful merges: - rust-lang#78073 (Add #[inline] to some functions in core::str.) - rust-lang#78596 (Fix doc links to std::fmt) - rust-lang#78599 (Add note to process::arg[s] that args shouldn't be escaped or quoted) - rust-lang#78602 (fix various aliasing issues in the standard library) - rust-lang#78603 (expand: Tweak a comment in implementation of `macro_rules`) - rust-lang#78621 (Inline Default::default() for atomics) Failed merges: r? `@ghost`
2 parents 1e37ba7 + 97678b8 commit e8cbaf2

File tree

13 files changed

+55
-21
lines changed

13 files changed

+55
-21
lines changed

compiler/rustc_expand/src/mbe/transcribe.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,19 @@ pub(super) fn transcribe<'a>(
232232
// the meta-var.
233233
let ident = MacroRulesNormalizedIdent::new(orignal_ident);
234234
if let Some(cur_matched) = lookup_cur_matched(ident, interp, &repeats) {
235-
if let MatchedNonterminal(ref nt) = cur_matched {
236-
// FIXME #2887: why do we apply a mark when matching a token tree meta-var
237-
// (e.g. `$x:tt`), but not when we are matching any other type of token
238-
// tree?
239-
if let NtTT(ref tt) = **nt {
240-
result.push(tt.clone().into());
235+
if let MatchedNonterminal(nt) = cur_matched {
236+
let token = if let NtTT(tt) = &**nt {
237+
// `tt`s are emitted into the output stream directly as "raw tokens",
238+
// without wrapping them into groups.
239+
tt.clone()
241240
} else {
241+
// Other variables are emitted into the output stream as groups with
242+
// `Delimiter::None` to maintain parsing priorities.
243+
// `Interpolated` is currenty used for such groups in rustc parser.
242244
marker.visit_span(&mut sp);
243-
let token = TokenTree::token(token::Interpolated(nt.clone()), sp);
244-
result.push(token.into());
245-
}
245+
TokenTree::token(token::Interpolated(nt.clone()), sp)
246+
};
247+
result.push(token.into());
246248
} else {
247249
// We were unable to descend far enough. This is an error.
248250
return Err(cx.struct_span_err(

library/alloc/src/collections/binary_heap.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1036,8 +1036,9 @@ impl<'a, T> Hole<'a, T> {
10361036
debug_assert!(index != self.pos);
10371037
debug_assert!(index < self.data.len());
10381038
unsafe {
1039-
let index_ptr: *const _ = self.data.get_unchecked(index);
1040-
let hole_ptr = self.data.get_unchecked_mut(self.pos);
1039+
let ptr = self.data.as_mut_ptr();
1040+
let index_ptr: *const _ = ptr.add(index);
1041+
let hole_ptr = ptr.add(self.pos);
10411042
ptr::copy_nonoverlapping(index_ptr, hole_ptr, 1);
10421043
}
10431044
self.pos = index;

library/alloc/src/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ macro_rules! vec {
7171
///
7272
/// Additional parameters passed to `format!` replace the `{}`s within the
7373
/// formatting string in the order given unless named or positional parameters
74-
/// are used; see [`std::fmt`][fmt] for more information.
74+
/// are used; see [`std::fmt`] for more information.
7575
///
7676
/// A common use for `format!` is concatenation and interpolation of strings.
7777
/// The same convention is used with [`print!`] and [`write!`] macros,
@@ -80,7 +80,7 @@ macro_rules! vec {
8080
/// To convert a single value to a string, use the [`to_string`] method. This
8181
/// will use the [`Display`] formatting trait.
8282
///
83-
/// [fmt]: core::fmt
83+
/// [`std::fmt`]: ../std/fmt/index.html
8484
/// [`print!`]: ../std/macro.print.html
8585
/// [`write!`]: core::write
8686
/// [`to_string`]: crate::string::ToString

library/core/src/fmt/num.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,6 @@ fn fmt_u128(n: u128, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::R
595595
// 2^128 is about 3*10^38, so 39 gives an extra byte of space
596596
let mut buf = [MaybeUninit::<u8>::uninit(); 39];
597597
let mut curr = buf.len() as isize;
598-
let buf_ptr = MaybeUninit::slice_as_mut_ptr(&mut buf);
599598

600599
let (n, rem) = udiv_1e19(n);
601600
parse_u64_into(rem, &mut buf, &mut curr);
@@ -606,7 +605,11 @@ fn fmt_u128(n: u128, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::R
606605
// SAFETY: Guaranteed that we wrote at most 19 bytes, and there must be space
607606
// remaining since it has length 39
608607
unsafe {
609-
ptr::write_bytes(buf_ptr.offset(target), b'0', (curr - target) as usize);
608+
ptr::write_bytes(
609+
MaybeUninit::slice_as_mut_ptr(&mut buf).offset(target),
610+
b'0',
611+
(curr - target) as usize,
612+
);
610613
}
611614
curr = target;
612615

@@ -615,6 +618,9 @@ fn fmt_u128(n: u128, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::R
615618
// Should this following branch be annotated with unlikely?
616619
if n != 0 {
617620
let target = (buf.len() - 38) as isize;
621+
// The raw `buf_ptr` pointer is only valid until `buf` is used the next time,
622+
// buf `buf` is not used in this scope so we are good.
623+
let buf_ptr = MaybeUninit::slice_as_mut_ptr(&mut buf);
618624
// SAFETY: At this point we wrote at most 38 bytes, pad up to that point,
619625
// There can only be at most 1 digit remaining.
620626
unsafe {
@@ -629,7 +635,7 @@ fn fmt_u128(n: u128, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::R
629635
// UTF-8 since `DEC_DIGITS_LUT` is
630636
let buf_slice = unsafe {
631637
str::from_utf8_unchecked(slice::from_raw_parts(
632-
buf_ptr.offset(curr),
638+
MaybeUninit::slice_as_mut_ptr(&mut buf).offset(curr),
633639
buf.len() - curr as usize,
634640
))
635641
};

library/core/src/hash/sip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ macro_rules! load_int_le {
111111
debug_assert!($i + mem::size_of::<$int_ty>() <= $buf.len());
112112
let mut data = 0 as $int_ty;
113113
ptr::copy_nonoverlapping(
114-
$buf.get_unchecked($i),
114+
$buf.as_ptr().add($i),
115115
&mut data as *mut _ as *mut u8,
116116
mem::size_of::<$int_ty>(),
117117
);

library/core/src/macros/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ macro_rules! r#try {
327327
///
328328
/// See [`std::fmt`] for more information on the format string syntax.
329329
///
330-
/// [`std::fmt`]: crate::fmt
330+
/// [`std::fmt`]: ../std/fmt/index.html
331331
/// [`fmt::Write`]: crate::fmt::Write
332332
/// [`io::Write`]: ../std/io/trait.Write.html
333333
/// [`fmt::Result`]: crate::fmt::Result

library/core/src/mem/maybe_uninit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -842,13 +842,13 @@ impl<T> MaybeUninit<T> {
842842
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
843843
#[inline(always)]
844844
pub fn slice_as_ptr(this: &[MaybeUninit<T>]) -> *const T {
845-
this as *const [MaybeUninit<T>] as *const T
845+
this.as_ptr() as *const T
846846
}
847847

848848
/// Gets a mutable pointer to the first element of the array.
849849
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
850850
#[inline(always)]
851851
pub fn slice_as_mut_ptr(this: &mut [MaybeUninit<T>]) -> *mut T {
852-
this as *mut [MaybeUninit<T>] as *mut T
852+
this.as_mut_ptr() as *mut T
853853
}
854854
}

library/core/src/str/error.rs

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl Utf8Error {
7272
/// assert_eq!(1, error.valid_up_to());
7373
/// ```
7474
#[stable(feature = "utf8_error", since = "1.5.0")]
75+
#[inline]
7576
pub fn valid_up_to(&self) -> usize {
7677
self.valid_up_to
7778
}
@@ -92,6 +93,7 @@ impl Utf8Error {
9293
///
9394
/// [U+FFFD]: ../../std/char/constant.REPLACEMENT_CHARACTER.html
9495
#[stable(feature = "utf8_error_error_len", since = "1.20.0")]
96+
#[inline]
9597
pub fn error_len(&self) -> Option<usize> {
9698
self.error_len.map(|len| len as usize)
9799
}

library/core/src/str/iter.rs

+1
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ unsafe impl TrustedLen for Bytes<'_> {}
326326
#[doc(hidden)]
327327
#[unstable(feature = "trusted_random_access", issue = "none")]
328328
unsafe impl TrustedRandomAccess for Bytes<'_> {
329+
#[inline]
329330
fn may_have_side_effect() -> bool {
330331
false
331332
}

library/core/src/str/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,7 @@ impl str {
17121712
///
17131713
/// assert_eq!("Hello\tworld", s.trim());
17141714
/// ```
1715+
#[inline]
17151716
#[must_use = "this returns the trimmed string as a slice, \
17161717
without modifying the original"]
17171718
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1749,6 +1750,7 @@ impl str {
17491750
/// let s = " עברית ";
17501751
/// assert!(Some('ע') == s.trim_start().chars().next());
17511752
/// ```
1753+
#[inline]
17521754
#[must_use = "this returns the trimmed string as a new slice, \
17531755
without modifying the original"]
17541756
#[stable(feature = "trim_direction", since = "1.30.0")]
@@ -1786,6 +1788,7 @@ impl str {
17861788
/// let s = " עברית ";
17871789
/// assert!(Some('ת') == s.trim_end().chars().rev().next());
17881790
/// ```
1791+
#[inline]
17891792
#[must_use = "this returns the trimmed string as a new slice, \
17901793
without modifying the original"]
17911794
#[stable(feature = "trim_direction", since = "1.30.0")]
@@ -1824,6 +1827,7 @@ impl str {
18241827
/// let s = " עברית";
18251828
/// assert!(Some('ע') == s.trim_left().chars().next());
18261829
/// ```
1830+
#[inline]
18271831
#[stable(feature = "rust1", since = "1.0.0")]
18281832
#[rustc_deprecated(
18291833
since = "1.33.0",
@@ -1865,6 +1869,7 @@ impl str {
18651869
/// let s = "עברית ";
18661870
/// assert!(Some('ת') == s.trim_right().chars().rev().next());
18671871
/// ```
1872+
#[inline]
18681873
#[stable(feature = "rust1", since = "1.0.0")]
18691874
#[rustc_deprecated(
18701875
since = "1.33.0",
@@ -2260,6 +2265,7 @@ impl str {
22602265
/// assert_eq!("GRüßE, JüRGEN ❤", s);
22612266
/// ```
22622267
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
2268+
#[inline]
22632269
pub fn make_ascii_uppercase(&mut self) {
22642270
// SAFETY: safe because we transmute two types with the same layout.
22652271
let me = unsafe { self.as_bytes_mut() };
@@ -2286,6 +2292,7 @@ impl str {
22862292
/// assert_eq!("grÜße, jÜrgen ❤", s);
22872293
/// ```
22882294
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
2295+
#[inline]
22892296
pub fn make_ascii_lowercase(&mut self) {
22902297
// SAFETY: safe because we transmute two types with the same layout.
22912298
let me = unsafe { self.as_bytes_mut() };
@@ -2423,6 +2430,7 @@ impl AsRef<[u8]> for str {
24232430
#[stable(feature = "rust1", since = "1.0.0")]
24242431
impl Default for &str {
24252432
/// Creates an empty str
2433+
#[inline]
24262434
fn default() -> Self {
24272435
""
24282436
}
@@ -2431,6 +2439,7 @@ impl Default for &str {
24312439
#[stable(feature = "default_mut_str", since = "1.28.0")]
24322440
impl Default for &mut str {
24332441
/// Creates an empty mutable str
2442+
#[inline]
24342443
fn default() -> Self {
24352444
// SAFETY: The empty string is valid UTF-8.
24362445
unsafe { from_utf8_unchecked_mut(&mut []) }

library/core/src/sync/atomic.rs

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ pub struct AtomicBool {
155155
#[stable(feature = "rust1", since = "1.0.0")]
156156
impl Default for AtomicBool {
157157
/// Creates an `AtomicBool` initialized to `false`.
158+
#[inline]
158159
fn default() -> Self {
159160
Self::new(false)
160161
}
@@ -1212,6 +1213,7 @@ macro_rules! atomic_int {
12121213

12131214
#[$stable]
12141215
impl Default for $atomic_type {
1216+
#[inline]
12151217
fn default() -> Self {
12161218
Self::new(Default::default())
12171219
}

library/std/src/process.rs

+10
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,11 @@ impl Command {
557557
///
558558
/// [`args`]: Command::args
559559
///
560+
/// Note that the argument is not passed through a shell, but given
561+
/// literally to the program. This means that shell syntax like quotes,
562+
/// escaped characters, word splitting, glob patterns, substitution, etc.
563+
/// have no effect.
564+
///
560565
/// # Examples
561566
///
562567
/// Basic usage:
@@ -582,6 +587,11 @@ impl Command {
582587
///
583588
/// [`arg`]: Command::arg
584589
///
590+
/// Note that the arguments are not passed through a shell, but given
591+
/// literally to the program. This means that shell syntax like quotes,
592+
/// escaped characters, word splitting, glob patterns, substitution, etc.
593+
/// have no effect.
594+
///
585595
/// # Examples
586596
///
587597
/// Basic usage:

library/std/src/sys/unix/thread.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ impl Thread {
178178
tv_nsec: nsecs,
179179
};
180180
secs -= ts.tv_sec as u64;
181-
if libc::nanosleep(&ts, &mut ts) == -1 {
181+
let ts_ptr = &mut ts as *mut _;
182+
if libc::nanosleep(ts_ptr, ts_ptr) == -1 {
182183
assert_eq!(os::errno(), libc::EINTR);
183184
secs += ts.tv_sec as u64;
184185
nsecs = ts.tv_nsec;

0 commit comments

Comments
 (0)