Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #83664

Merged
merged 20 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
6233f3f
alloc: Added `as_slice` method to `BinaryHeap` collection
frol Feb 20, 2021
dd2b8a0
provide a more realistic example for BinaryHeap::as_slice
frol Mar 13, 2021
3d6bd87
unix: Fix feature(unix_socket_ancillary_data) on macos and other BSDs
reyk Mar 22, 2021
4572e7f
Lint on unknown intra-doc link disambiguators
camelid Mar 27, 2021
c20ba9c
Add escape_default method to u8 and [u8]
clarfonthey Oct 24, 2020
56347a1
Point to disambiguator instead of whole link
camelid Mar 29, 2021
5497f15
Add test for weird backticks placement
camelid Mar 29, 2021
141df6f
Inline `find_suffix` closure that's only used once
camelid Mar 29, 2021
29d4a7d
Add a regression test for issue-82792
JohnTitor Mar 29, 2021
c9562fd
Prefer 4 spaces
JohnTitor Mar 29, 2021
48f9f08
Remove a FIXME resolved by #73578
JohnTitor Mar 29, 2021
79acd5e
:arrow_up: rust-analyzer
lnicola Mar 29, 2021
595f3f2
Updated the tracking issue #
frol Mar 29, 2021
2843baa
Rollup merge of #82331 - frol:feat/std-binary-heap-as-slice, r=Amanieu
Dylan-DPC Mar 29, 2021
68964d1
Rollup merge of #83130 - clarfonthey:escape, r=m-ou-se
Dylan-DPC Mar 29, 2021
772582e
Rollup merge of #83374 - reyk:fix/bsd-ancillary, r=joshtriplett
Dylan-DPC Mar 29, 2021
25ade69
Rollup merge of #83543 - camelid:lint-unknown-disambiguator, r=jyn514
Dylan-DPC Mar 29, 2021
6b5ba53
Rollup merge of #83636 - JohnTitor:const-generics-defualts-regg-test,…
Dylan-DPC Mar 29, 2021
fca8e7d
Rollup merge of #83643 - JohnTitor:is-freeze-no-longer-uses-span, r=R…
Dylan-DPC Mar 29, 2021
6738ee7
Rollup merge of #83644 - lnicola:rust-analyzer-2021-03-29, r=jonas-sc…
Dylan-DPC Mar 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,6 @@ impl<'tcx> ty::TyS<'tcx> {
/// optimization as well as the rules around static values. Note
/// that the `Freeze` trait is not exposed to end users and is
/// effectively an implementation detail.
// FIXME: use `TyCtxtAt` instead of separate `Span`.
pub fn is_freeze(&'tcx self, tcx_at: TyCtxtAt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
self.is_trivially_freeze() || tcx_at.is_freeze_raw(param_env.and(self))
}
Expand Down
21 changes: 21 additions & 0 deletions library/alloc/src/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,27 @@ impl<T> BinaryHeap<T> {
self.data.shrink_to(min_capacity)
}

/// Returns a slice of all values in the underlying vector, in arbitrary
/// order.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(binary_heap_as_slice)]
/// use std::collections::BinaryHeap;
/// use std::io::{self, Write};
///
/// let heap = BinaryHeap::from(vec![1, 2, 3, 4, 5, 6, 7]);
///
/// io::sink().write(heap.as_slice()).unwrap();
/// ```
#[unstable(feature = "binary_heap_as_slice", issue = "83659")]
pub fn as_slice(&self) -> &[T] {
self.data.as_slice()
}

/// Consumes the `BinaryHeap` and returns the underlying vector
/// in arbitrary order.
///
Expand Down
1 change: 1 addition & 0 deletions library/alloc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#![feature(binary_heap_drain_sorted)]
#![feature(slice_ptr_get)]
#![feature(binary_heap_retain)]
#![feature(binary_heap_as_slice)]
#![feature(inplace_iteration)]
#![feature(iter_map_while)]
#![feature(vecdeque_binary_search)]
Expand Down
26 changes: 26 additions & 0 deletions library/core/src/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#![stable(feature = "rust1", since = "1.0.0")]

use crate::ascii;
use crate::intrinsics;
use crate::mem;
use crate::str::FromStr;
Expand Down Expand Up @@ -661,6 +662,31 @@ impl u8 {
pub const fn is_ascii_control(&self) -> bool {
matches!(*self, b'\0'..=b'\x1F' | b'\x7F')
}

/// Returns an iterator that produces an escaped version of a `u8`,
/// treating it as an ASCII character.
///
/// The behavior is identical to [`ascii::escape_default`].
///
/// # Examples
///
/// ```
/// #![feature(inherent_ascii_escape)]
///
/// assert_eq!("0", b'0'.escape_ascii().to_string());
/// assert_eq!("\\t", b'\t'.escape_ascii().to_string());
/// assert_eq!("\\r", b'\r'.escape_ascii().to_string());
/// assert_eq!("\\n", b'\n'.escape_ascii().to_string());
/// assert_eq!("\\'", b'\''.escape_ascii().to_string());
/// assert_eq!("\\\"", b'"'.escape_ascii().to_string());
/// assert_eq!("\\\\", b'\\'.escape_ascii().to_string());
/// assert_eq!("\\x9d", b'\x9d'.escape_ascii().to_string());
/// ```
#[unstable(feature = "inherent_ascii_escape", issue = "77174")]
#[inline]
pub fn escape_ascii(&self) -> ascii::EscapeDefault {
ascii::escape_default(*self)
}
}

#[lang = "u16"]
Expand Down
92 changes: 92 additions & 0 deletions library/core/src/slice/ascii.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Operations on ASCII `[u8]`.

use crate::ascii;
use crate::fmt::{self, Write};
use crate::iter;
use crate::mem;
use crate::ops;

#[lang = "slice_u8"]
#[cfg(not(test))]
Expand Down Expand Up @@ -56,6 +59,95 @@ impl [u8] {
byte.make_ascii_lowercase();
}
}

/// Returns an iterator that produces an escaped version of this slice,
/// treating it as an ASCII string.
///
/// # Examples
///
/// ```
/// #![feature(inherent_ascii_escape)]
///
/// let s = b"0\t\r\n'\"\\\x9d";
/// let escaped = s.escape_ascii().to_string();
/// assert_eq!(escaped, "0\\t\\r\\n\\'\\\"\\\\\\x9d");
/// ```
#[unstable(feature = "inherent_ascii_escape", issue = "77174")]
pub fn escape_ascii(&self) -> EscapeAscii<'_> {
EscapeAscii { inner: self.iter().flat_map(EscapeByte) }
}
}

impl_fn_for_zst! {
#[derive(Clone)]
struct EscapeByte impl Fn = |byte: &u8| -> ascii::EscapeDefault {
ascii::escape_default(*byte)
};
}

/// An iterator over the escaped version of a byte slice.
///
/// This `struct` is created by the [`slice::escape_ascii`] method. See its
/// documentation for more information.
#[unstable(feature = "inherent_ascii_escape", issue = "77174")]
#[derive(Clone)]
pub struct EscapeAscii<'a> {
inner: iter::FlatMap<super::Iter<'a, u8>, ascii::EscapeDefault, EscapeByte>,
}

#[unstable(feature = "inherent_ascii_escape", issue = "77174")]
impl<'a> iter::Iterator for EscapeAscii<'a> {
type Item = u8;
#[inline]
fn next(&mut self) -> Option<u8> {
self.inner.next()
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}
#[inline]
fn try_fold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R
where
Fold: FnMut(Acc, Self::Item) -> R,
R: ops::Try<Ok = Acc>,
{
self.inner.try_fold(init, fold)
}
#[inline]
fn fold<Acc, Fold>(self, init: Acc, fold: Fold) -> Acc
where
Fold: FnMut(Acc, Self::Item) -> Acc,
{
self.inner.fold(init, fold)
}
#[inline]
fn last(mut self) -> Option<u8> {
self.next_back()
}
}

#[unstable(feature = "inherent_ascii_escape", issue = "77174")]
impl<'a> iter::DoubleEndedIterator for EscapeAscii<'a> {
fn next_back(&mut self) -> Option<u8> {
self.inner.next_back()
}
}
#[unstable(feature = "inherent_ascii_escape", issue = "77174")]
impl<'a> iter::ExactSizeIterator for EscapeAscii<'a> {}
#[unstable(feature = "inherent_ascii_escape", issue = "77174")]
impl<'a> iter::FusedIterator for EscapeAscii<'a> {}
#[unstable(feature = "inherent_ascii_escape", issue = "77174")]
impl<'a> fmt::Display for EscapeAscii<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.clone().try_for_each(|b| f.write_char(b as char))
}
}
#[unstable(feature = "inherent_ascii_escape", issue = "77174")]
impl<'a> fmt::Debug for EscapeAscii<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("EscapeAscii { .. }")
}
}

/// Returns `true` if any byte in the word `v` is nonascii (>= 128). Snarfed
Expand Down
3 changes: 3 additions & 0 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ pub use index::SliceIndex;
#[unstable(feature = "slice_range", issue = "76393")]
pub use index::range;

#[unstable(feature = "inherent_ascii_escape", issue = "77174")]
pub use ascii::EscapeAscii;

#[lang = "slice"]
#[cfg(not(test))]
impl<T> [T] {
Expand Down
57 changes: 34 additions & 23 deletions library/std/src/sys/unix/ext/net/ancillary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use crate::marker::PhantomData;
use crate::mem::{size_of, zeroed};
use crate::os::unix::io::RawFd;
use crate::path::Path;
#[cfg(target_os = "android")]
use crate::ptr::eq;
use crate::ptr::read_unaligned;
use crate::ptr::{eq, read_unaligned};
use crate::slice::from_raw_parts;
use crate::sys::net::Socket;

Expand All @@ -30,12 +28,10 @@ pub(super) fn recv_vectored_with_ancillary_from(
) -> io::Result<(usize, bool, io::Result<SocketAddr>)> {
unsafe {
let mut msg_name: libc::sockaddr_un = zeroed();

let mut msg: libc::msghdr = zeroed();
msg.msg_name = &mut msg_name as *mut _ as *mut _;
msg.msg_namelen = size_of::<libc::sockaddr_un>() as libc::socklen_t;
msg.msg_iov = bufs.as_mut_ptr().cast();
msg.msg_control = ancillary.buffer.as_mut_ptr().cast();
cfg_if::cfg_if! {
if #[cfg(any(target_os = "android", all(target_os = "linux", target_env = "gnu")))] {
msg.msg_iovlen = bufs.len() as libc::size_t;
Expand All @@ -45,13 +41,18 @@ pub(super) fn recv_vectored_with_ancillary_from(
target_os = "emscripten",
target_os = "freebsd",
all(target_os = "linux", target_env = "musl",),
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
))] {
msg.msg_iovlen = bufs.len() as libc::c_int;
msg.msg_controllen = ancillary.buffer.len() as libc::socklen_t;
}
}
// macos requires that the control pointer is NULL when the len is 0.
if msg.msg_controllen > 0 {
msg.msg_control = ancillary.buffer.as_mut_ptr().cast();
}

let count = socket.recv_msg(&mut msg)?;

Expand Down Expand Up @@ -79,7 +80,6 @@ pub(super) fn send_vectored_with_ancillary_to(
msg.msg_name = &mut msg_name as *mut _ as *mut _;
msg.msg_namelen = msg_namelen;
msg.msg_iov = bufs.as_ptr() as *mut _;
msg.msg_control = ancillary.buffer.as_mut_ptr().cast();
cfg_if::cfg_if! {
if #[cfg(any(target_os = "android", all(target_os = "linux", target_env = "gnu")))] {
msg.msg_iovlen = bufs.len() as libc::size_t;
Expand All @@ -89,13 +89,18 @@ pub(super) fn send_vectored_with_ancillary_to(
target_os = "emscripten",
target_os = "freebsd",
all(target_os = "linux", target_env = "musl",),
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
))] {
msg.msg_iovlen = bufs.len() as libc::c_int;
msg.msg_controllen = ancillary.length as libc::socklen_t;
}
}
// macos requires that the control pointer is NULL when the len is 0.
if msg.msg_controllen > 0 {
msg.msg_control = ancillary.buffer.as_mut_ptr().cast();
}

ancillary.truncated = false;

Expand Down Expand Up @@ -147,6 +152,7 @@ fn add_to_ancillary_data<T>(
target_os = "emscripten",
target_os = "freebsd",
all(target_os = "linux", target_env = "musl",),
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
))] {
Expand All @@ -159,14 +165,12 @@ fn add_to_ancillary_data<T>(
while !cmsg.is_null() {
previous_cmsg = cmsg;
cmsg = libc::CMSG_NXTHDR(&msg, cmsg);
cfg_if::cfg_if! {
// Android return the same pointer if it is the last cmsg.
// Therefore, check it if the previous pointer is the same as the current one.
if #[cfg(target_os = "android")] {
if cmsg == previous_cmsg {
break;
}
}

// Most operating systems, but not Linux or emscripten, return the previous pointer
// when its length is zero. Therefore, check if the previous pointer is the same as
// the current one.
if eq(cmsg, previous_cmsg) {
break;
}
}

Expand All @@ -184,6 +188,7 @@ fn add_to_ancillary_data<T>(
target_os = "emscripten",
target_os = "freebsd",
all(target_os = "linux", target_env = "musl",),
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
))] {
Expand Down Expand Up @@ -371,6 +376,7 @@ impl<'a> AncillaryData<'a> {
target_os = "emscripten",
target_os = "freebsd",
all(target_os = "linux", target_env = "musl",),
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
))] {
Expand Down Expand Up @@ -421,6 +427,7 @@ impl<'a> Iterator for Messages<'a> {
target_os = "emscripten",
target_os = "freebsd",
all(target_os = "linux", target_env = "musl",),
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
))] {
Expand All @@ -435,15 +442,13 @@ impl<'a> Iterator for Messages<'a> {
};

let cmsg = cmsg.as_ref()?;
cfg_if::cfg_if! {
// Android return the same pointer if it is the last cmsg.
// Therefore, check it if the previous pointer is the same as the current one.
if #[cfg(target_os = "android")] {
if let Some(current) = self.current {
if eq(current, cmsg) {
return None;
}
}

// Most operating systems, but not Linux or emscripten, return the previous pointer
// when its length is zero. Therefore, check if the previous pointer is the same as
// the current one.
if let Some(current) = self.current {
if eq(current, cmsg) {
return None;
}
}

Expand Down Expand Up @@ -514,6 +519,12 @@ impl<'a> SocketAncillary<'a> {
self.buffer.len()
}

/// Returns `true` if the ancillary data is empty.
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
pub fn is_empty(&self) -> bool {
self.length == 0
}

/// Returns the number of used bytes.
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
pub fn len(&self) -> usize {
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ crate fn plain_text_summary(md: &str) -> String {
s
}

#[derive(Debug)]
crate struct MarkdownLink {
pub kind: LinkType,
pub link: String,
Expand Down
Loading