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 8 pull requests #90592

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
fdb6bda
Add note about x86 instruction prefixes in asm!
syvb Nov 3, 2021
3f496b5
Simplify js tester a bit
GuillaumeGomez Nov 3, 2021
9057936
Demote metadata load warning to "info".
ehuss Nov 3, 2021
754455e
Clean up some `-Z unstable-options` in tests.
ehuss Nov 4, 2021
dc2c260
Add more text and examples to `carrying_{add|mul}"
scottmcm Nov 4, 2021
056af9d
rustbot: Allow applying relnotes label
joshtriplett Nov 4, 2021
7e02934
rustbot: Allow applying needs-fcp label
joshtriplett Nov 4, 2021
773cc4f
Mention possible future rejections
syvb Nov 4, 2021
aa17e1c
Fix missing bottom border for headings in sidebar
GuillaumeGomez Nov 4, 2021
3ad6d12
Sort scraped call locations before serializing
willcrichton Nov 4, 2021
4846d10
Fix ICE when rustdoc is scraping examples inside of a proc macro
willcrichton Nov 4, 2021
869b826
Rollup merge of #90530 - GuillaumeGomez:simplify-js-tester, r=notriddle
matthiaskrgr Nov 4, 2021
cb27ba3
Rollup merge of #90533 - Smittyvb:patch-1, r=joshtriplett
matthiaskrgr Nov 4, 2021
7448b8f
Rollup merge of #90544 - ehuss:demote-locator-warn, r=petrochenkov
matthiaskrgr Nov 4, 2021
3036d63
Rollup merge of #90554 - ehuss:unstable-options-cleanup, r=joshtriplett
matthiaskrgr Nov 4, 2021
664129b
Rollup merge of #90556 - scottmcm:carrying_comments, r=joshtriplett
matthiaskrgr Nov 4, 2021
4694114
Rollup merge of #90563 - joshtriplett:rustbot-allow-labels, r=Mark-Si…
matthiaskrgr Nov 4, 2021
7dc54bf
Rollup merge of #90571 - GuillaumeGomez:missing-bottom-border-sidebar…
matthiaskrgr Nov 4, 2021
ad03584
Rollup merge of #90583 - willcrichton:example-analyzer, r=jyn514
matthiaskrgr Nov 4, 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
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ use std::fmt::Write as _;
use std::io::{Read, Result as IoResult, Write};
use std::path::{Path, PathBuf};
use std::{cmp, fmt, fs};
use tracing::{debug, info, warn};
use tracing::{debug, info};

#[derive(Clone)]
crate struct CrateLocator<'a> {
Expand Down Expand Up @@ -549,7 +549,7 @@ impl<'a> CrateLocator<'a> {
}
}
Err(err) => {
warn!("no metadata found: {}", err);
info!("no metadata found: {}", err);
continue;
}
};
Expand Down
63 changes: 48 additions & 15 deletions library/core/src/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ depending on the target pointer size.
}

macro_rules! widening_impl {
($SelfT:ty, $WideT:ty, $BITS:literal) => {
($SelfT:ty, $WideT:ty, $BITS:literal, unsigned) => {
widening_impl!($SelfT, $WideT, $BITS, "");
};
($SelfT:ty, $WideT:ty, $BITS:literal, signed) => {
widening_impl!($SelfT, $WideT, $BITS, "# //");
};
($SelfT:ty, $WideT:ty, $BITS:literal, $AdaptiveTestPrefix:literal) => {
/// Calculates the complete product `self * rhs` without the possibility to overflow.
///
/// This returns the low-order (wrapping) bits and the high-order (overflow) bits
Expand Down Expand Up @@ -148,6 +154,33 @@ macro_rules! widening_impl {
/// assert_eq!(5u32.carrying_mul(2, 10), (20, 0));
/// assert_eq!(1_000_000_000u32.carrying_mul(10, 0), (1410065408, 2));
/// assert_eq!(1_000_000_000u32.carrying_mul(10, 10), (1410065418, 2));
#[doc = concat!($AdaptiveTestPrefix, "assert_eq!(",
stringify!($SelfT), "::MAX.carrying_mul(", stringify!($SelfT), "::MAX, ", stringify!($SelfT), "::MAX), ",
"(0, ", stringify!($SelfT), "::MAX));"
)]
/// ```
///
/// If `carry` is zero, this is similar to [`overflowing_mul`](Self::overflowing_mul),
/// except that it gives the value of the overflow instead of just whether one happened:
///
/// ```
/// #![feature(bigint_helper_methods)]
/// let r = u8::carrying_mul(7, 13, 0);
/// assert_eq!((r.0, r.1 != 0), u8::overflowing_mul(7, 13));
/// let r = u8::carrying_mul(13, 42, 0);
/// assert_eq!((r.0, r.1 != 0), u8::overflowing_mul(13, 42));
/// ```
///
/// The value of the first field in the returned tuple matches what you'd get
/// by combining the [`wrapping_mul`](Self::wrapping_mul) and
/// [`wrapping_add`](Self::wrapping_add) methods:
///
/// ```
/// #![feature(bigint_helper_methods)]
/// assert_eq!(
/// 789_u16.carrying_mul(456, 123).0,
/// 789_u16.wrapping_mul(456).wrapping_add(123),
/// );
/// ```
#[unstable(feature = "bigint_helper_methods", issue = "85532")]
#[rustc_const_unstable(feature = "bigint_helper_methods", issue = "85532")]
Expand All @@ -168,29 +201,29 @@ macro_rules! widening_impl {

#[lang = "i8"]
impl i8 {
widening_impl! { i8, i16, 8 }
widening_impl! { i8, i16, 8, signed }
int_impl! { i8, i8, u8, 8, 7, -128, 127, 2, "-0x7e", "0xa", "0x12", "0x12", "0x48",
"[0x12]", "[0x12]", "", "" }
}

#[lang = "i16"]
impl i16 {
widening_impl! { i16, i32, 16 }
widening_impl! { i16, i32, 16, signed }
int_impl! { i16, i16, u16, 16, 15, -32768, 32767, 4, "-0x5ffd", "0x3a", "0x1234", "0x3412",
"0x2c48", "[0x34, 0x12]", "[0x12, 0x34]", "", "" }
}

#[lang = "i32"]
impl i32 {
widening_impl! { i32, i64, 32 }
widening_impl! { i32, i64, 32, signed }
int_impl! { i32, i32, u32, 32, 31, -2147483648, 2147483647, 8, "0x10000b3", "0xb301",
"0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78]", "", "" }
}

#[lang = "i64"]
impl i64 {
widening_impl! { i64, i128, 64 }
widening_impl! { i64, i128, 64, signed }
int_impl! { i64, i64, u64, 64, 63, -9223372036854775808, 9223372036854775807, 12,
"0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412",
"0x6a2c48091e6a2c48", "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
Expand All @@ -212,7 +245,7 @@ impl i128 {
#[cfg(target_pointer_width = "16")]
#[lang = "isize"]
impl isize {
widening_impl! { isize, i32, 16 }
widening_impl! { isize, i32, 16, signed }
int_impl! { isize, i16, usize, 16, 15, -32768, 32767, 4, "-0x5ffd", "0x3a", "0x1234",
"0x3412", "0x2c48", "[0x34, 0x12]", "[0x12, 0x34]",
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
Expand All @@ -221,7 +254,7 @@ impl isize {
#[cfg(target_pointer_width = "32")]
#[lang = "isize"]
impl isize {
widening_impl! { isize, i64, 32 }
widening_impl! { isize, i64, 32, signed }
int_impl! { isize, i32, usize, 32, 31, -2147483648, 2147483647, 8, "0x10000b3", "0xb301",
"0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78]",
Expand All @@ -231,7 +264,7 @@ impl isize {
#[cfg(target_pointer_width = "64")]
#[lang = "isize"]
impl isize {
widening_impl! { isize, i128, 64 }
widening_impl! { isize, i128, 64, signed }
int_impl! { isize, i64, usize, 64, 63, -9223372036854775808, 9223372036854775807,
12, "0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412",
"0x6a2c48091e6a2c48", "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
Expand All @@ -244,7 +277,7 @@ const ASCII_CASE_MASK: u8 = 0b0010_0000;

#[lang = "u8"]
impl u8 {
widening_impl! { u8, u16, 8 }
widening_impl! { u8, u16, 8, unsigned }
uint_impl! { u8, u8, i8, 8, 255, 2, "0x82", "0xa", "0x12", "0x12", "0x48", "[0x12]",
"[0x12]", "", "" }

Expand Down Expand Up @@ -793,21 +826,21 @@ impl u8 {

#[lang = "u16"]
impl u16 {
widening_impl! { u16, u32, 16 }
widening_impl! { u16, u32, 16, unsigned }
uint_impl! { u16, u16, i16, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48",
"[0x34, 0x12]", "[0x12, 0x34]", "", "" }
}

#[lang = "u32"]
impl u32 {
widening_impl! { u32, u64, 32 }
widening_impl! { u32, u64, 32, unsigned }
uint_impl! { u32, u32, i32, 32, 4294967295, 8, "0x10000b3", "0xb301", "0x12345678",
"0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78]", "", "" }
}

#[lang = "u64"]
impl u64 {
widening_impl! { u64, u128, 64 }
widening_impl! { u64, u128, 64, unsigned }
uint_impl! { u64, u64, i64, 64, 18446744073709551615, 12, "0xaa00000000006e1", "0x6e10aa",
"0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48",
"[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
Expand All @@ -830,15 +863,15 @@ impl u128 {
#[cfg(target_pointer_width = "16")]
#[lang = "usize"]
impl usize {
widening_impl! { usize, u32, 16 }
widening_impl! { usize, u32, 16, unsigned }
uint_impl! { usize, u16, isize, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48",
"[0x34, 0x12]", "[0x12, 0x34]",
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
}
#[cfg(target_pointer_width = "32")]
#[lang = "usize"]
impl usize {
widening_impl! { usize, u64, 32 }
widening_impl! { usize, u64, 32, unsigned }
uint_impl! { usize, u32, isize, 32, 4294967295, 8, "0x10000b3", "0xb301", "0x12345678",
"0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78]",
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
Expand All @@ -847,7 +880,7 @@ impl usize {
#[cfg(target_pointer_width = "64")]
#[lang = "usize"]
impl usize {
widening_impl! { usize, u128, 64 }
widening_impl! { usize, u128, 64, unsigned }
uint_impl! { usize, u64, isize, 64, 18446744073709551615, 12, "0xaa00000000006e1", "0x6e10aa",
"0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48",
"[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
Expand Down
15 changes: 15 additions & 0 deletions library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,8 @@ macro_rules! uint_impl {
/// additional bit of overflow. This allows for chaining together multiple additions
/// to create "big integers" which represent larger values.
///
#[doc = concat!("This can be thought of as a ", stringify!($BITS), "-bit \"full adder\", in the electronics sense.")]
///
/// # Examples
///
/// Basic usage
Expand All @@ -1513,7 +1515,20 @@ macro_rules! uint_impl {
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".carrying_add(2, false), (7, false));")]
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".carrying_add(2, true), (8, false));")]
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.carrying_add(1, false), (0, true));")]
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.carrying_add(0, true), (0, true));")]
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.carrying_add(1, true), (1, true));")]
#[doc = concat!("assert_eq!(",
stringify!($SelfT), "::MAX.carrying_add(", stringify!($SelfT), "::MAX, true), ",
"(", stringify!($SelfT), "::MAX, true));"
)]
/// ```
///
/// If `carry` is false, this method is equivalent to [`overflowing_add`](Self::overflowing_add):
///
/// ```
/// #![feature(bigint_helper_methods)]
#[doc = concat!("assert_eq!(5_", stringify!($SelfT), ".carrying_add(2, false), 5_", stringify!($SelfT), ".overflowing_add(2));")]
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.carrying_add(1, false), ", stringify!($SelfT), "::MAX.overflowing_add(1));")]
/// ```
#[unstable(feature = "bigint_helper_methods", issue = "85532")]
#[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")]
Expand Down
2 changes: 2 additions & 0 deletions src/doc/unstable-book/src/library-features/asm.md
Original file line number Diff line number Diff line change
Expand Up @@ -885,5 +885,7 @@ The compiler performs some additional checks on options:
- You are responsible for switching any target-specific state (e.g. thread-local storage, stack bounds).
- The set of memory locations that you may access is the intersection of those allowed by the `asm!` blocks you entered and exited.
- You cannot assume that an `asm!` block will appear exactly once in the output binary. The compiler is allowed to instantiate multiple copies of the `asm!` block, for example when the function containing it is inlined in multiple places.
- On x86, inline assembly must not end with an instruction prefix (such as `LOCK`) that would apply to instructions generated by the compiler.
- The compiler is currently unable to detect this due to the way inline assembly is compiled, but may catch and reject this in the future.

> **Note**: As a general rule, the flags covered by `preserves_flags` are those which are *not* preserved when performing a function call.
8 changes: 7 additions & 1 deletion src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,18 @@ struct Decorations {

impl Decorations {
fn new(info: DecorationInfo) -> Self {
let (starts, ends) = info
// Extract tuples (start, end, kind) into separate sequences of (start, kind) and (end).
let (mut starts, mut ends): (Vec<_>, Vec<_>) = info
.0
.into_iter()
.map(|(kind, ranges)| ranges.into_iter().map(move |(lo, hi)| ((lo, kind), hi)))
.flatten()
.unzip();

// Sort the sequences in document order.
starts.sort_by_key(|(lo, _)| *lo);
ends.sort();

Decorations { starts, ends }
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ h1.fqn > .in-band > a:hover {
section hierarchies. */
h2,
.top-doc h3,
.top-doc h4 {
.top-doc h4,
.sidebar .others h3 {
border-bottom: 1px solid;
}
h3.code-header {
Expand Down
9 changes: 7 additions & 2 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ function hideThemeButtonState() {
// delayed sidebar rendering.
window.initSidebarItems = function(items) {
var sidebar = document.getElementsByClassName("sidebar-elems")[0];
var others;
var current = window.sidebarCurrent;

function addSidebarCrates(crates) {
Expand Down Expand Up @@ -594,7 +595,7 @@ function hideThemeButtonState() {
li.appendChild(link);
ul.appendChild(li);
}
sidebar.appendChild(div);
others.appendChild(div);
}

function block(shortty, longty) {
Expand Down Expand Up @@ -635,10 +636,14 @@ function hideThemeButtonState() {
ul.appendChild(li);
}
div.appendChild(ul);
sidebar.appendChild(div);
others.appendChild(div);
}

if (sidebar) {
others = document.createElement("div");
others.className = "others";
sidebar.appendChild(others);

var isModule = hasClass(document.body, "mod");
if (!isModule) {
block("primitive", "Primitive Types");
Expand Down
36 changes: 27 additions & 9 deletions src/librustdoc/scrape_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_hir::{
self as hir,
intravisit::{self, Visitor},
HirId,
};
use rustc_interface::interface;
use rustc_macros::{Decodable, Encodable};
Expand Down Expand Up @@ -83,15 +82,10 @@ crate struct CallLocation {

impl CallLocation {
fn new(
tcx: TyCtxt<'_>,
expr_span: rustc_span::Span,
expr_id: HirId,
enclosing_item_span: rustc_span::Span,
source_file: &SourceFile,
) -> Self {
let enclosing_item_span =
tcx.hir().span_with_body(tcx.hir().get_parent_item(expr_id)).source_callsite();
assert!(enclosing_item_span.contains(expr_span));

CallLocation {
call_expr: SyntaxRange::new(expr_span, source_file),
enclosing_item: SyntaxRange::new(enclosing_item_span, source_file),
Expand Down Expand Up @@ -168,13 +162,29 @@ where
// If this span comes from a macro expansion, then the source code may not actually show
// a use of the given item, so it would be a poor example. Hence, we skip all uses in macros.
if span.from_expansion() {
trace!("Rejecting expr from macro: {:?}", span);
return;
}

// If the enclosing item has a span coming from a proc macro, then we also don't want to include
// the example.
let enclosing_item_span = tcx.hir().span_with_body(tcx.hir().get_parent_item(ex.hir_id));
if enclosing_item_span.from_expansion() {
trace!("Rejecting expr ({:?}) from macro item: {:?}", span, enclosing_item_span);
return;
}

assert!(
enclosing_item_span.contains(span),
"Attempted to scrape call at [{:?}] whose enclosing item [{:?}] doesn't contain the span of the call.",
span,
enclosing_item_span
);

// Save call site if the function resolves to a concrete definition
if let ty::FnDef(def_id, _) = ty.kind() {
// Ignore functions not from the crate being documented
if self.target_crates.iter().all(|krate| *krate != def_id.krate) {
trace!("Rejecting expr from crate not being documented: {:?}", span);
return;
}

Expand All @@ -198,7 +208,8 @@ where
let fn_key = tcx.def_path_hash(*def_id);
let fn_entries = self.calls.entry(fn_key).or_default();

let location = CallLocation::new(tcx, span, ex.hir_id, &file);
trace!("Including expr: {:?}", span);
let location = CallLocation::new(span, enclosing_item_span, &file);
fn_entries.entry(abs_path).or_insert_with(mk_call_data).locations.push(location);
}
}
Expand Down Expand Up @@ -240,6 +251,13 @@ crate fn run(
let mut finder = FindCalls { calls: &mut calls, tcx, map: tcx.hir(), cx, target_crates };
tcx.hir().visit_all_item_likes(&mut finder.as_deep_visitor());

// Sort call locations within a given file in document order
for fn_calls in calls.values_mut() {
for file_calls in fn_calls.values_mut() {
file_calls.locations.sort_by_key(|loc| loc.call_expr.byte_span.0);
}
}

// Save output to provided path
let mut encoder = FileEncoder::new(options.output_path).map_err(|e| e.to_string())?;
calls.encode(&mut encoder).map_err(|e| e.to_string())?;
Expand Down
17 changes: 17 additions & 0 deletions src/test/run-make/rustdoc-scrape-examples-macros/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-include ../../run-make-fulldeps/tools.mk

OUTPUT_DIR := "$(TMPDIR)/rustdoc"

all:
$(RUSTC) src/proc.rs --crate-name foobar_macro --edition=2021 --crate-type proc-macro --emit=dep-info,link

$(RUSTC) src/lib.rs --crate-name foobar --edition=2021 --crate-type lib --emit=dep-info,link

$(RUSTDOC) examples/ex.rs --crate-name ex --crate-type bin --output $(OUTPUT_DIR) \
--extern foobar=$(TMPDIR)/libfoobar.rlib --extern foobar_macro=$(TMPDIR)/libfoobar_macro.so \
-Z unstable-options --scrape-examples-output-path $(TMPDIR)/ex.calls --scrape-examples-target-crate foobar

$(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib --output $(OUTPUT_DIR) \
-Z unstable-options --with-examples $(TMPDIR)/ex.calls

$(HTMLDOCCK) $(OUTPUT_DIR) src/lib.rs
Loading