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 9 pull requests #94152

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c05276a
Stabilize pin_static_ref.
m-ou-se Feb 2, 2022
bc4b0a7
Fix macro reexports duplicates in the sidebar
GuillaumeGomez Feb 14, 2022
d9ea7bc
Add test for duplicated macros in the sidebar
GuillaumeGomez Feb 14, 2022
4b5beae
adapt static-nobundle test to use llvm-nm
krasimirgg Feb 15, 2022
0647e38
add llvm-nm to bootstrap dist bin's
krasimirgg Feb 16, 2022
e5f7239
use BOOL for TCP_NODELAY setsockopt value on Windows
chrisnc Feb 17, 2022
5cf8274
Add module-level docs for `rustc_middle::query`
pierwill Feb 17, 2022
f7448a7
core: Implement trim functions on byte slices
dbrgn Feb 6, 2022
0f14bea
Optimize char_try_from_u32
digama0 Feb 18, 2022
56aba3c
document rustc_middle::mir::Field
MakitaToki Feb 18, 2022
7c3ebec
fix
digama0 Feb 18, 2022
6210208
fix some typos
MakitaToki Feb 18, 2022
b78123c
Fix miniz_oxide types showing up in std
GuillaumeGomez Feb 18, 2022
fd2e631
Rollup merge of #93580 - m-ou-se:stabilize-pin-static-ref, r=scottmcm
matthiaskrgr Feb 19, 2022
c41c187
Rollup merge of #93686 - dbrgn:trim-on-byte-slices, r=joshtriplett
matthiaskrgr Feb 19, 2022
fc8c26f
Rollup merge of #94002 - GuillaumeGomez:duplicated-sidebar-macro, r=n…
matthiaskrgr Feb 19, 2022
149168b
Rollup merge of #94023 - krasimirgg:head-llvm-use-llvm-nm, r=Mark-Sim…
matthiaskrgr Feb 19, 2022
a8cb229
Rollup merge of #94094 - chrisnc:tcp-nodelay-windows-bool, r=dtolnay
matthiaskrgr Feb 19, 2022
5a13f5a
Rollup merge of #94097 - pierwill:doc-rustc-middle-query, r=cjgillot
matthiaskrgr Feb 19, 2022
37a183c
Rollup merge of #94112 - digama0:patch-3, r=scottmcm
matthiaskrgr Feb 19, 2022
b33836f
Rollup merge of #94113 - Mizobrook-kan:issue-94025, r=estebank
matthiaskrgr Feb 19, 2022
25e3b81
Rollup merge of #94122 - GuillaumeGomez:miniz-oxide-std, r=notriddle
matthiaskrgr Feb 19, 2022
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
9 changes: 9 additions & 0 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1841,6 +1841,15 @@ static_assert_size!(PlaceElem<'_>, 24);
pub type ProjectionKind = ProjectionElem<(), ()>;

rustc_index::newtype_index! {
/// A [newtype'd][wrapper] index type in the MIR [control-flow graph][CFG]
///
/// A field (e.g., `f` in `_1.f`) is one variant of [`ProjectionElem`]. Conceptually,
/// rustc can identify that a field projection refers to either two different regions of memory
/// or the same one between the base and the 'projection element'.
/// Read more about projections in the [rustc-dev-guide][mir-datatypes]
/// [wrapper]: https://rustc-dev-guide.rust-lang.org/appendix/glossary.html#newtype
/// [CFG]: https://rustc-dev-guide.rust-lang.org/appendix/background.html#cfg
/// [mir-datatypes]: https://rustc-dev-guide.rust-lang.org/mir/index.html#mir-data-types
pub struct Field {
derive [HashStable]
DEBUG_FORMAT = "field[{}]"
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! Defines the various compiler queries.
//!
//! For more information on the query system, see
//! ["Queries: demand-driven compilation"](https://rustc-dev-guide.rust-lang.org/query.html).
//! This chapter includes instructions for adding new queries.

// Each of these queries corresponds to a function pointer field in the
// `Providers` struct for requesting a value of that type, and a method
// on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
Expand Down
17 changes: 14 additions & 3 deletions library/core/src/char/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use crate::fmt;
use crate::mem::transmute;
use crate::str::FromStr;

use super::MAX;

/// Converts a `u32` to a `char`.
///
/// Note that all [`char`]s are valid [`u32`]s, and can be cast to one with
Expand Down Expand Up @@ -271,7 +269,20 @@ impl FromStr for char {

#[inline]
const fn char_try_from_u32(i: u32) -> Result<char, CharTryFromError> {
if (i > MAX as u32) || (i >= 0xD800 && i <= 0xDFFF) {
// This is an optimized version of the check
// (i > MAX as u32) || (i >= 0xD800 && i <= 0xDFFF),
// which can also be written as
// i >= 0x110000 || (i >= 0xD800 && i < 0xE000).
//
// The XOR with 0xD800 permutes the ranges such that 0xD800..0xE000 is
// mapped to 0x0000..0x0800, while keeping all the high bits outside 0xFFFF the same.
// In particular, numbers >= 0x110000 stay in this range.
//
// Subtracting 0x800 causes 0x0000..0x0800 to wrap, meaning that a single
// unsigned comparison against 0x110000 - 0x800 will detect both the wrapped
// surrogate range as well as the numbers originally larger than 0x110000.
//
if (i ^ 0xD800).wrapping_sub(0x800) >= 0x110000 - 0x800 {
Err(CharTryFromError(()))
} else {
// SAFETY: checked that it's a legal unicode value
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ impl<T: ?Sized> Pin<&'static T> {
///
/// This is safe, because `T` is borrowed for the `'static` lifetime, which
/// never ends.
#[unstable(feature = "pin_static_ref", issue = "78186")]
#[stable(feature = "pin_static_ref", since = "1.60.0")]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
pub const fn static_ref(r: &'static T) -> Pin<&'static T> {
// SAFETY: The 'static borrow guarantees the data will not be
Expand Down Expand Up @@ -858,7 +858,7 @@ impl<T: ?Sized> Pin<&'static mut T> {
///
/// This is safe, because `T` is borrowed for the `'static` lifetime, which
/// never ends.
#[unstable(feature = "pin_static_ref", issue = "78186")]
#[stable(feature = "pin_static_ref", since = "1.60.0")]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
pub const fn static_mut(r: &'static mut T) -> Pin<&'static mut T> {
// SAFETY: The 'static borrow guarantees the data will not be
Expand Down
78 changes: 78 additions & 0 deletions library/core/src/slice/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,84 @@ impl [u8] {
pub fn escape_ascii(&self) -> EscapeAscii<'_> {
EscapeAscii { inner: self.iter().flat_map(EscapeByte) }
}

/// Returns a byte slice with leading ASCII whitespace bytes removed.
///
/// 'Whitespace' refers to the definition used by
/// `u8::is_ascii_whitespace`.
///
/// # Examples
///
/// ```
/// #![feature(byte_slice_trim_ascii)]
///
/// assert_eq!(b" \t hello world\n".trim_ascii_start(), b"hello world\n");
/// assert_eq!(b" ".trim_ascii_start(), b"");
/// assert_eq!(b"".trim_ascii_start(), b"");
/// ```
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
pub const fn trim_ascii_start(&self) -> &[u8] {
let mut bytes = self;
// Note: A pattern matching based approach (instead of indexing) allows
// making the function const.
while let [first, rest @ ..] = bytes {
if first.is_ascii_whitespace() {
bytes = rest;
} else {
break;
}
}
bytes
}

/// Returns a byte slice with trailing ASCII whitespace bytes removed.
///
/// 'Whitespace' refers to the definition used by
/// `u8::is_ascii_whitespace`.
///
/// # Examples
///
/// ```
/// #![feature(byte_slice_trim_ascii)]
///
/// assert_eq!(b"\r hello world\n ".trim_ascii_end(), b"\r hello world");
/// assert_eq!(b" ".trim_ascii_end(), b"");
/// assert_eq!(b"".trim_ascii_end(), b"");
/// ```
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
pub const fn trim_ascii_end(&self) -> &[u8] {
let mut bytes = self;
// Note: A pattern matching based approach (instead of indexing) allows
// making the function const.
while let [rest @ .., last] = bytes {
if last.is_ascii_whitespace() {
bytes = rest;
} else {
break;
}
}
bytes
}

/// Returns a byte slice with leading and trailing ASCII whitespace bytes
/// removed.
///
/// 'Whitespace' refers to the definition used by
/// `u8::is_ascii_whitespace`.
///
/// # Examples
///
/// ```
/// #![feature(byte_slice_trim_ascii)]
///
/// assert_eq!(b"\r hello world\n ".trim_ascii(), b"hello world");
/// assert_eq!(b" ".trim_ascii(), b"");
/// assert_eq!(b"".trim_ascii(), b"");
/// ```
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
pub const fn trim_ascii(&self) -> &[u8] {
self.trim_ascii_start().trim_ascii_end()
}
}

impl_fn_for_zst! {
Expand Down
5 changes: 4 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@
#![feature(panic_internals)]
#![feature(panic_can_unwind)]
#![feature(panic_unwind)]
#![feature(pin_static_ref)]
#![feature(platform_intrinsics)]
#![feature(portable_simd)]
#![feature(prelude_import)]
Expand Down Expand Up @@ -365,6 +364,10 @@ extern crate libc;
#[allow(unused_extern_crates)]
extern crate unwind;

#[doc(masked)]
#[allow(unused_extern_crates)]
extern crate miniz_oxide;

// During testing, this crate is not actually the "real" std library, but rather
// it links to the real std library, which was compiled from this same source
// code. So any lang items std defines are conditionally excluded (or else they
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/windows/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,11 @@ impl Socket {
}

pub fn set_nodelay(&self, nodelay: bool) -> io::Result<()> {
net::setsockopt(self, c::IPPROTO_TCP, c::TCP_NODELAY, nodelay as c::BYTE)
net::setsockopt(self, c::IPPROTO_TCP, c::TCP_NODELAY, nodelay as c::BOOL)
}

pub fn nodelay(&self) -> io::Result<bool> {
let raw: c::BYTE = net::getsockopt(self, c::IPPROTO_TCP, c::TCP_NODELAY)?;
let raw: c::BOOL = net::getsockopt(self, c::IPPROTO_TCP, c::TCP_NODELAY)?;
Ok(raw != 0)
}

Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,7 @@ impl Step for RustDev {
"llvm-bcanalyzer",
"llvm-cov",
"llvm-dwp",
"llvm-nm",
] {
tarball.add_file(src_bindir.join(exe(bin, target)), "bin", 0o755);
}
Expand Down
17 changes: 11 additions & 6 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ impl<'tcx> Context<'tcx> {
fn build_sidebar_items(&self, m: &clean::Module) -> BTreeMap<String, Vec<NameDoc>> {
// BTreeMap instead of HashMap to get a sorted output
let mut map: BTreeMap<_, Vec<_>> = BTreeMap::new();
let mut inserted: FxHashMap<ItemType, FxHashSet<Symbol>> = FxHashMap::default();

for item in &m.items {
if item.is_stripped() {
continue;
Expand All @@ -258,13 +260,16 @@ impl<'tcx> Context<'tcx> {
let short = item.type_();
let myname = match item.name {
None => continue,
Some(ref s) => s.to_string(),
Some(s) => s,
};
let short = short.to_string();
map.entry(short).or_default().push((
myname,
Some(item.doc_value().map_or_else(String::new, |s| plain_text_summary(&s))),
));
if inserted.entry(short).or_default().insert(myname) {
let short = short.to_string();
let myname = myname.to_string();
map.entry(short).or_default().push((
myname,
Some(item.doc_value().map_or_else(String::new, |s| plain_text_summary(&s))),
));
}
}

if self.shared.sort_modules_alphabetically {
Expand Down
6 changes: 4 additions & 2 deletions src/test/run-make-fulldeps/static-nobundle/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ all: $(call NATIVE_STATICLIB,aaa)
$(RUSTC) bbb.rs --crate-type=rlib

# Check that bbb does NOT contain the definition of `native_func`
nm $(TMPDIR)/libbbb.rlib | $(CGREP) -ve "T _*native_func"
nm $(TMPDIR)/libbbb.rlib | $(CGREP) -e "U _*native_func"
# We're using the llvm-nm instead of the system nm to ensure it
# is compatible with the LLVM bitcode generated by rustc.
"$(LLVM_BIN_DIR)/llvm-nm" $(TMPDIR)/libbbb.rlib | $(CGREP) -ve "T _*native_func"
"$(LLVM_BIN_DIR)/llvm-nm" $(TMPDIR)/libbbb.rlib | $(CGREP) -e "U _*native_func"

# Check that aaa gets linked (either as `-l aaa` or `aaa.lib`) when building ccc.
$(RUSTC) ccc.rs -C prefer-dynamic --crate-type=dylib --print link-args | $(CGREP) -e '-l[" ]*aaa|aaa\.lib'
Expand Down
14 changes: 14 additions & 0 deletions src/test/rustdoc-gui/duplicate-macro-reexport.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// This test ensures that there is no macro duplicates in the sidebar.
goto: file://|DOC_PATH|/test_docs/macro.a.html
// Waiting for the elements in the sidebar to be rendered.
wait-for: ".sidebar-elems .others .macro"
// Check there is only one macro named "a" listed in the sidebar.
assert-count: (
"//*[@class='sidebar-elems']//*[@class='others']/*[@class='block macro']//li/a[text()='a']",
1,
)
// Check there is only one macro named "b" listed in the sidebar.
assert-count: (
"//*[@class='sidebar-elems']//*[@class='others']/*[@class='block macro']//li/a[text()='b']",
1,
)
3 changes: 3 additions & 0 deletions src/test/rustdoc-gui/src/test_docs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,6 @@ impl EmptyTrait1 for HasEmptyTraits {}
impl EmptyTrait2 for HasEmptyTraits {}
#[doc(cfg(feature = "some-feature"))]
impl EmptyTrait3 for HasEmptyTraits {}

mod macros;
pub use macros::*;
4 changes: 4 additions & 0 deletions src/test/rustdoc-gui/src/test_docs/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[macro_export]
macro_rules! a{ () => {}}
#[macro_export]
macro_rules! b{ () => {}}