diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index 0e5c5fe4d4473..3d8a4bbff1833 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -232,17 +232,19 @@ pub(super) fn transcribe<'a>( // the meta-var. let ident = MacroRulesNormalizedIdent::new(orignal_ident); if let Some(cur_matched) = lookup_cur_matched(ident, interp, &repeats) { - if let MatchedNonterminal(ref nt) = cur_matched { - // FIXME #2887: why do we apply a mark when matching a token tree meta-var - // (e.g. `$x:tt`), but not when we are matching any other type of token - // tree? - if let NtTT(ref tt) = **nt { - result.push(tt.clone().into()); + if let MatchedNonterminal(nt) = cur_matched { + let token = if let NtTT(tt) = &**nt { + // `tt`s are emitted into the output stream directly as "raw tokens", + // without wrapping them into groups. + tt.clone() } else { + // Other variables are emitted into the output stream as groups with + // `Delimiter::None` to maintain parsing priorities. + // `Interpolated` is currenty used for such groups in rustc parser. marker.visit_span(&mut sp); - let token = TokenTree::token(token::Interpolated(nt.clone()), sp); - result.push(token.into()); - } + TokenTree::token(token::Interpolated(nt.clone()), sp) + }; + result.push(token.into()); } else { // We were unable to descend far enough. This is an error. return Err(cx.struct_span_err( diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index f2852b1cc2b80..b67c72d7136a6 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -1036,8 +1036,9 @@ impl<'a, T> Hole<'a, T> { debug_assert!(index != self.pos); debug_assert!(index < self.data.len()); unsafe { - let index_ptr: *const _ = self.data.get_unchecked(index); - let hole_ptr = self.data.get_unchecked_mut(self.pos); + let ptr = self.data.as_mut_ptr(); + let index_ptr: *const _ = ptr.add(index); + let hole_ptr = ptr.add(self.pos); ptr::copy_nonoverlapping(index_ptr, hole_ptr, 1); } self.pos = index; diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index 2f744618d6936..a992d768d6314 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -71,7 +71,7 @@ macro_rules! vec { /// /// Additional parameters passed to `format!` replace the `{}`s within the /// formatting string in the order given unless named or positional parameters -/// are used; see [`std::fmt`][fmt] for more information. +/// are used; see [`std::fmt`] for more information. /// /// A common use for `format!` is concatenation and interpolation of strings. /// The same convention is used with [`print!`] and [`write!`] macros, @@ -80,7 +80,7 @@ macro_rules! vec { /// To convert a single value to a string, use the [`to_string`] method. This /// will use the [`Display`] formatting trait. /// -/// [fmt]: core::fmt +/// [`std::fmt`]: ../std/fmt/index.html /// [`print!`]: ../std/macro.print.html /// [`write!`]: core::write /// [`to_string`]: crate::string::ToString diff --git a/library/core/src/fmt/num.rs b/library/core/src/fmt/num.rs index 795cbf5fbbd44..7a98210995ec7 100644 --- a/library/core/src/fmt/num.rs +++ b/library/core/src/fmt/num.rs @@ -595,7 +595,6 @@ fn fmt_u128(n: u128, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::R // 2^128 is about 3*10^38, so 39 gives an extra byte of space let mut buf = [MaybeUninit::::uninit(); 39]; let mut curr = buf.len() as isize; - let buf_ptr = MaybeUninit::slice_as_mut_ptr(&mut buf); let (n, rem) = udiv_1e19(n); 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 // SAFETY: Guaranteed that we wrote at most 19 bytes, and there must be space // remaining since it has length 39 unsafe { - ptr::write_bytes(buf_ptr.offset(target), b'0', (curr - target) as usize); + ptr::write_bytes( + MaybeUninit::slice_as_mut_ptr(&mut buf).offset(target), + b'0', + (curr - target) as usize, + ); } curr = target; @@ -615,6 +618,9 @@ fn fmt_u128(n: u128, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::R // Should this following branch be annotated with unlikely? if n != 0 { let target = (buf.len() - 38) as isize; + // The raw `buf_ptr` pointer is only valid until `buf` is used the next time, + // buf `buf` is not used in this scope so we are good. + let buf_ptr = MaybeUninit::slice_as_mut_ptr(&mut buf); // SAFETY: At this point we wrote at most 38 bytes, pad up to that point, // There can only be at most 1 digit remaining. unsafe { @@ -629,7 +635,7 @@ fn fmt_u128(n: u128, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::R // UTF-8 since `DEC_DIGITS_LUT` is let buf_slice = unsafe { str::from_utf8_unchecked(slice::from_raw_parts( - buf_ptr.offset(curr), + MaybeUninit::slice_as_mut_ptr(&mut buf).offset(curr), buf.len() - curr as usize, )) }; diff --git a/library/core/src/hash/sip.rs b/library/core/src/hash/sip.rs index a9882d54de4f1..6178b0af137e8 100644 --- a/library/core/src/hash/sip.rs +++ b/library/core/src/hash/sip.rs @@ -111,7 +111,7 @@ macro_rules! load_int_le { debug_assert!($i + mem::size_of::<$int_ty>() <= $buf.len()); let mut data = 0 as $int_ty; ptr::copy_nonoverlapping( - $buf.get_unchecked($i), + $buf.as_ptr().add($i), &mut data as *mut _ as *mut u8, mem::size_of::<$int_ty>(), ); diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index bce8a70e92f31..079d9f6006a32 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -327,7 +327,7 @@ macro_rules! r#try { /// /// See [`std::fmt`] for more information on the format string syntax. /// -/// [`std::fmt`]: crate::fmt +/// [`std::fmt`]: ../std/fmt/index.html /// [`fmt::Write`]: crate::fmt::Write /// [`io::Write`]: ../std/io/trait.Write.html /// [`fmt::Result`]: crate::fmt::Result diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index 862c452a43480..660b7db70be92 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -842,13 +842,13 @@ impl MaybeUninit { #[unstable(feature = "maybe_uninit_slice", issue = "63569")] #[inline(always)] pub fn slice_as_ptr(this: &[MaybeUninit]) -> *const T { - this as *const [MaybeUninit] as *const T + this.as_ptr() as *const T } /// Gets a mutable pointer to the first element of the array. #[unstable(feature = "maybe_uninit_slice", issue = "63569")] #[inline(always)] pub fn slice_as_mut_ptr(this: &mut [MaybeUninit]) -> *mut T { - this as *mut [MaybeUninit] as *mut T + this.as_mut_ptr() as *mut T } } diff --git a/library/core/src/str/error.rs b/library/core/src/str/error.rs index 427f720d68cdb..ccf7b20285cb3 100644 --- a/library/core/src/str/error.rs +++ b/library/core/src/str/error.rs @@ -72,6 +72,7 @@ impl Utf8Error { /// assert_eq!(1, error.valid_up_to()); /// ``` #[stable(feature = "utf8_error", since = "1.5.0")] + #[inline] pub fn valid_up_to(&self) -> usize { self.valid_up_to } @@ -92,6 +93,7 @@ impl Utf8Error { /// /// [U+FFFD]: ../../std/char/constant.REPLACEMENT_CHARACTER.html #[stable(feature = "utf8_error_error_len", since = "1.20.0")] + #[inline] pub fn error_len(&self) -> Option { self.error_len.map(|len| len as usize) } diff --git a/library/core/src/str/iter.rs b/library/core/src/str/iter.rs index bee86df520c80..28cd350019ebf 100644 --- a/library/core/src/str/iter.rs +++ b/library/core/src/str/iter.rs @@ -326,6 +326,7 @@ unsafe impl TrustedLen for Bytes<'_> {} #[doc(hidden)] #[unstable(feature = "trusted_random_access", issue = "none")] unsafe impl TrustedRandomAccess for Bytes<'_> { + #[inline] fn may_have_side_effect() -> bool { false } diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index b36d9f5c38841..ab0c873933030 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -1712,6 +1712,7 @@ impl str { /// /// assert_eq!("Hello\tworld", s.trim()); /// ``` + #[inline] #[must_use = "this returns the trimmed string as a slice, \ without modifying the original"] #[stable(feature = "rust1", since = "1.0.0")] @@ -1749,6 +1750,7 @@ impl str { /// let s = " עברית "; /// assert!(Some('ע') == s.trim_start().chars().next()); /// ``` + #[inline] #[must_use = "this returns the trimmed string as a new slice, \ without modifying the original"] #[stable(feature = "trim_direction", since = "1.30.0")] @@ -1786,6 +1788,7 @@ impl str { /// let s = " עברית "; /// assert!(Some('ת') == s.trim_end().chars().rev().next()); /// ``` + #[inline] #[must_use = "this returns the trimmed string as a new slice, \ without modifying the original"] #[stable(feature = "trim_direction", since = "1.30.0")] @@ -1824,6 +1827,7 @@ impl str { /// let s = " עברית"; /// assert!(Some('ע') == s.trim_left().chars().next()); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_deprecated( since = "1.33.0", @@ -1865,6 +1869,7 @@ impl str { /// let s = "עברית "; /// assert!(Some('ת') == s.trim_right().chars().rev().next()); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_deprecated( since = "1.33.0", @@ -2260,6 +2265,7 @@ impl str { /// assert_eq!("GRüßE, JüRGEN ❤", s); /// ``` #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] + #[inline] pub fn make_ascii_uppercase(&mut self) { // SAFETY: safe because we transmute two types with the same layout. let me = unsafe { self.as_bytes_mut() }; @@ -2286,6 +2292,7 @@ impl str { /// assert_eq!("grÜße, jÜrgen ❤", s); /// ``` #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] + #[inline] pub fn make_ascii_lowercase(&mut self) { // SAFETY: safe because we transmute two types with the same layout. let me = unsafe { self.as_bytes_mut() }; @@ -2423,6 +2430,7 @@ impl AsRef<[u8]> for str { #[stable(feature = "rust1", since = "1.0.0")] impl Default for &str { /// Creates an empty str + #[inline] fn default() -> Self { "" } @@ -2431,6 +2439,7 @@ impl Default for &str { #[stable(feature = "default_mut_str", since = "1.28.0")] impl Default for &mut str { /// Creates an empty mutable str + #[inline] fn default() -> Self { // SAFETY: The empty string is valid UTF-8. unsafe { from_utf8_unchecked_mut(&mut []) } diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index 5c9cfe27101f0..a3d93d7074b69 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -155,6 +155,7 @@ pub struct AtomicBool { #[stable(feature = "rust1", since = "1.0.0")] impl Default for AtomicBool { /// Creates an `AtomicBool` initialized to `false`. + #[inline] fn default() -> Self { Self::new(false) } @@ -1212,6 +1213,7 @@ macro_rules! atomic_int { #[$stable] impl Default for $atomic_type { + #[inline] fn default() -> Self { Self::new(Default::default()) } diff --git a/library/std/src/process.rs b/library/std/src/process.rs index a149946774404..2c7ed4614bce9 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -557,6 +557,11 @@ impl Command { /// /// [`args`]: Command::args /// + /// Note that the argument is not passed through a shell, but given + /// literally to the program. This means that shell syntax like quotes, + /// escaped characters, word splitting, glob patterns, substitution, etc. + /// have no effect. + /// /// # Examples /// /// Basic usage: @@ -582,6 +587,11 @@ impl Command { /// /// [`arg`]: Command::arg /// + /// Note that the arguments are not passed through a shell, but given + /// literally to the program. This means that shell syntax like quotes, + /// escaped characters, word splitting, glob patterns, substitution, etc. + /// have no effect. + /// /// # Examples /// /// Basic usage: diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs index fdf114d6df6fe..f1ab302d30e1e 100644 --- a/library/std/src/sys/unix/thread.rs +++ b/library/std/src/sys/unix/thread.rs @@ -178,7 +178,8 @@ impl Thread { tv_nsec: nsecs, }; secs -= ts.tv_sec as u64; - if libc::nanosleep(&ts, &mut ts) == -1 { + let ts_ptr = &mut ts as *mut _; + if libc::nanosleep(ts_ptr, ts_ptr) == -1 { assert_eq!(os::errno(), libc::EINTR); secs += ts.tv_sec as u64; nsecs = ts.tv_nsec;