Auto merge of #78623 - m-ou-se:rollup-m6y5j0m, r=m-ou-se
Rollup of 6 pull requests Successful merges: - #78073 (Add #[inline] to some functions in core::str.) - #78596 (Fix doc links to std::fmt) - #78599 (Add note to process::arg[s] that args shouldn't be escaped or quoted) - #78602 (fix various aliasing issues in the standard library) - #78603 (expand: Tweak a comment in implementation of `macro_rules`) - #78621 (Inline Default::default() for atomics) Failed merges: r? `@ghost`
This commit is contained in:
commit
e8cbaf2ae7
13 changed files with 55 additions and 21 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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::<u8>::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,
|
||||
))
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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>(),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -842,13 +842,13 @@ impl<T> MaybeUninit<T> {
|
|||
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
|
||||
#[inline(always)]
|
||||
pub fn slice_as_ptr(this: &[MaybeUninit<T>]) -> *const T {
|
||||
this as *const [MaybeUninit<T>] 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<T>]) -> *mut T {
|
||||
this as *mut [MaybeUninit<T>] as *mut T
|
||||
this.as_mut_ptr() as *mut T
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<usize> {
|
||||
self.error_len.map(|len| len as usize)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 []) }
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue