Skip to content

Commit 415d8fc

Browse files
committed
Auto merge of #103213 - matthiaskrgr:rollup-diloxg3, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #101889 (doc: rewrite doc for uint::{carrying_add,borrowing_sub}) - #102507 (More slice::partition_point examples) - #103164 (rustdoc: remove CSS ``@media` (min-width: 701px)`) - #103189 (Clean up code-color and headers-color rustdoc GUI tests) - #103203 (Retrieve LLVM version from llvm-filecheck binary if it is not set yet) - #103204 (Add some more autolabels) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2efc90e + e0c162f commit 415d8fc

File tree

11 files changed

+232
-191
lines changed

11 files changed

+232
-191
lines changed

Diff for: library/core/src/num/uint_macros.rs

+49-31
Original file line numberDiff line numberDiff line change
@@ -1469,37 +1469,42 @@ macro_rules! uint_impl {
14691469
(a as Self, b)
14701470
}
14711471

1472-
/// Calculates `self + rhs + carry` without the ability to overflow.
1472+
/// Calculates `self` + `rhs` + `carry` and returns a tuple containing
1473+
/// the sum and the output carry.
14731474
///
1474-
/// Performs "ternary addition" which takes in an extra bit to add, and may return an
1475-
/// additional bit of overflow. This allows for chaining together multiple additions
1476-
/// to create "big integers" which represent larger values.
1475+
/// Performs "ternary addition" of two integer operands and a carry-in
1476+
/// bit, and returns an output integer and a carry-out bit. This allows
1477+
/// chaining together multiple additions to create a wider addition, and
1478+
/// can be useful for bignum addition.
14771479
///
14781480
#[doc = concat!("This can be thought of as a ", stringify!($BITS), "-bit \"full adder\", in the electronics sense.")]
14791481
///
1480-
/// # Examples
1482+
/// If the input carry is false, this method is equivalent to
1483+
/// [`overflowing_add`](Self::overflowing_add), and the output carry is
1484+
/// equal to the overflow flag. Note that although carry and overflow
1485+
/// flags are similar for unsigned integers, they are different for
1486+
/// signed integers.
14811487
///
1482-
/// Basic usage
1488+
/// # Examples
14831489
///
14841490
/// ```
14851491
/// #![feature(bigint_helper_methods)]
1486-
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".carrying_add(2, false), (7, false));")]
1487-
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".carrying_add(2, true), (8, false));")]
1488-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.carrying_add(1, false), (0, true));")]
1489-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.carrying_add(0, true), (0, true));")]
1490-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.carrying_add(1, true), (1, true));")]
1491-
#[doc = concat!("assert_eq!(",
1492-
stringify!($SelfT), "::MAX.carrying_add(", stringify!($SelfT), "::MAX, true), ",
1493-
"(", stringify!($SelfT), "::MAX, true));"
1494-
)]
1495-
/// ```
14961492
///
1497-
/// If `carry` is false, this method is equivalent to [`overflowing_add`](Self::overflowing_add):
1493+
#[doc = concat!("// 3 MAX (a = 3 × 2^", stringify!($BITS), " + 2^", stringify!($BITS), " - 1)")]
1494+
#[doc = concat!("// + 5 7 (b = 5 × 2^", stringify!($BITS), " + 7)")]
1495+
/// // ---------
1496+
#[doc = concat!("// 9 6 (sum = 9 × 2^", stringify!($BITS), " + 6)")]
14981497
///
1499-
/// ```
1500-
/// #![feature(bigint_helper_methods)]
1501-
#[doc = concat!("assert_eq!(5_", stringify!($SelfT), ".carrying_add(2, false), 5_", stringify!($SelfT), ".overflowing_add(2));")]
1502-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.carrying_add(1, false), ", stringify!($SelfT), "::MAX.overflowing_add(1));")]
1498+
#[doc = concat!("let (a1, a0): (", stringify!($SelfT), ", ", stringify!($SelfT), ") = (3, ", stringify!($SelfT), "::MAX);")]
1499+
#[doc = concat!("let (b1, b0): (", stringify!($SelfT), ", ", stringify!($SelfT), ") = (5, 7);")]
1500+
/// let carry0 = false;
1501+
///
1502+
/// let (sum0, carry1) = a0.carrying_add(b0, carry0);
1503+
/// assert_eq!(carry1, true);
1504+
/// let (sum1, carry2) = a1.carrying_add(b1, carry1);
1505+
/// assert_eq!(carry2, false);
1506+
///
1507+
/// assert_eq!((sum1, sum0), (9, 6));
15031508
/// ```
15041509
#[unstable(feature = "bigint_helper_methods", issue = "85532")]
15051510
#[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")]
@@ -1563,22 +1568,35 @@ macro_rules! uint_impl {
15631568
(a as Self, b)
15641569
}
15651570

1566-
/// Calculates `self - rhs - borrow` without the ability to overflow.
1571+
/// Calculates `self` − `rhs` − `borrow` and returns a tuple
1572+
/// containing the difference and the output borrow.
15671573
///
1568-
/// Performs "ternary subtraction" which takes in an extra bit to subtract, and may return
1569-
/// an additional bit of overflow. This allows for chaining together multiple subtractions
1570-
/// to create "big integers" which represent larger values.
1574+
/// Performs "ternary subtraction" by subtracting both an integer
1575+
/// operand and a borrow-in bit from `self`, and returns an output
1576+
/// integer and a borrow-out bit. This allows chaining together multiple
1577+
/// subtractions to create a wider subtraction, and can be useful for
1578+
/// bignum subtraction.
15711579
///
15721580
/// # Examples
15731581
///
1574-
/// Basic usage
1575-
///
15761582
/// ```
15771583
/// #![feature(bigint_helper_methods)]
1578-
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".borrowing_sub(2, false), (3, false));")]
1579-
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".borrowing_sub(2, true), (2, false));")]
1580-
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".borrowing_sub(1, false), (", stringify!($SelfT), "::MAX, true));")]
1581-
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".borrowing_sub(1, true), (", stringify!($SelfT), "::MAX - 1, true));")]
1584+
///
1585+
#[doc = concat!("// 9 6 (a = 9 × 2^", stringify!($BITS), " + 6)")]
1586+
#[doc = concat!("// - 5 7 (b = 5 × 2^", stringify!($BITS), " + 7)")]
1587+
/// // ---------
1588+
#[doc = concat!("// 3 MAX (diff = 3 × 2^", stringify!($BITS), " + 2^", stringify!($BITS), " - 1)")]
1589+
///
1590+
#[doc = concat!("let (a1, a0): (", stringify!($SelfT), ", ", stringify!($SelfT), ") = (9, 6);")]
1591+
#[doc = concat!("let (b1, b0): (", stringify!($SelfT), ", ", stringify!($SelfT), ") = (5, 7);")]
1592+
/// let borrow0 = false;
1593+
///
1594+
/// let (diff0, borrow1) = a0.borrowing_sub(b0, borrow0);
1595+
/// assert_eq!(borrow1, true);
1596+
/// let (diff1, borrow2) = a1.borrowing_sub(b1, borrow1);
1597+
/// assert_eq!(borrow2, false);
1598+
///
1599+
#[doc = concat!("assert_eq!((diff1, diff0), (3, ", stringify!($SelfT), "::MAX));")]
15821600
/// ```
15831601
#[unstable(feature = "bigint_helper_methods", issue = "85532")]
15841602
#[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")]

Diff for: library/core/src/slice/mod.rs

+32
Original file line numberDiff line numberDiff line change
@@ -2359,6 +2359,28 @@ impl<T> [T] {
23592359
/// assert!(match r { Ok(1..=4) => true, _ => false, });
23602360
/// ```
23612361
///
2362+
/// If you want to find that whole *range* of matching items, rather than
2363+
/// an arbitrary matching one, that can be done using [`partition_point`]:
2364+
/// ```
2365+
/// let s = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
2366+
///
2367+
/// let low = s.partition_point(|x| x < &1);
2368+
/// assert_eq!(low, 1);
2369+
/// let high = s.partition_point(|x| x <= &1);
2370+
/// assert_eq!(high, 5);
2371+
/// let r = s.binary_search(&1);
2372+
/// assert!((low..high).contains(&r.unwrap()));
2373+
///
2374+
/// assert!(s[..low].iter().all(|&x| x < 1));
2375+
/// assert!(s[low..high].iter().all(|&x| x == 1));
2376+
/// assert!(s[high..].iter().all(|&x| x > 1));
2377+
///
2378+
/// // For something not found, the "range" of equal items is empty
2379+
/// assert_eq!(s.partition_point(|x| x < &11), 9);
2380+
/// assert_eq!(s.partition_point(|x| x <= &11), 9);
2381+
/// assert_eq!(s.binary_search(&11), Err(9));
2382+
/// ```
2383+
///
23622384
/// If you want to insert an item to a sorted vector, while maintaining
23632385
/// sort order, consider using [`partition_point`]:
23642386
///
@@ -3787,6 +3809,16 @@ impl<T> [T] {
37873809
/// assert!(v[i..].iter().all(|&x| !(x < 5)));
37883810
/// ```
37893811
///
3812+
/// If all elements of the slice match the predicate, including if the slice
3813+
/// is empty, then the length of the slice will be returned:
3814+
///
3815+
/// ```
3816+
/// let a = [2, 4, 8];
3817+
/// assert_eq!(a.partition_point(|x| x < &100), a.len());
3818+
/// let a: [i32; 0] = [];
3819+
/// assert_eq!(a.partition_point(|x| x < &100), 0);
3820+
/// ```
3821+
///
37903822
/// If you want to insert an item to a sorted vector, while maintaining
37913823
/// sort order:
37923824
///

Diff for: src/librustdoc/html/static/css/rustdoc.css

+10-20
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ img {
437437

438438
.source-sidebar-expanded .source .sidebar {
439439
overflow-y: auto;
440+
width: 300px;
440441
}
441442

442443
.source-sidebar-expanded .source .sidebar > *:not(#sidebar-toggle) {
@@ -1692,31 +1693,20 @@ details.rustdoc-toggle[open] > summary.hideme::after {
16921693
display: inline-block;
16931694
}
16941695

1695-
/* Media Queries */
1696-
1697-
/*
1698-
WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY;
1699-
If you update this line, then you also need to update the line with the same warning
1700-
in storage.js plus the media query with (max-width: 700px)
1701-
*/
1702-
@media (min-width: 701px) {
1703-
/* In case there is no documentation before a code block, we need to add some margin at the top
1704-
to prevent an overlay between the "collapse toggle" and the information tooltip.
1705-
However, it's not needed with smaller screen width because the doc/code block is always put
1706-
"one line" below. */
1707-
.docblock > .example-wrap:first-child .tooltip {
1708-
margin-top: 16px;
1709-
}
1710-
1711-
.source-sidebar-expanded .source .sidebar {
1712-
width: 300px;
1713-
}
1696+
/* In case there is no documentation before a code block, we need to add some margin at the top
1697+
to prevent an overlay between the "collapse toggle" and the information tooltip.
1698+
However, it's not needed with smaller screen width because the doc/code block is always put
1699+
"one line" below. */
1700+
.docblock > .example-wrap:first-child .tooltip {
1701+
margin-top: 16px;
17141702
}
17151703

1704+
/* Media Queries */
1705+
17161706
/*
17171707
WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
17181708
If you update this line, then you also need to update the line with the same warning
1719-
in storage.js plus the media query with (min-width: 701px)
1709+
in storage.js
17201710
*/
17211711
@media (max-width: 700px) {
17221712
/* When linking to an item with an `id` (for instance, by clicking a link in the sidebar,

Diff for: src/librustdoc/html/static/js/main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ function loadCss(cssFileName) {
737737

738738
window.rustdocMobileScrollLock = function() {
739739
const mobile_topbar = document.querySelector(".mobile-topbar");
740-
if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT) {
740+
if (window.innerWidth <= window.RUSTDOC_MOBILE_BREAKPOINT) {
741741
// This is to keep the scroll position on mobile.
742742
oldSidebarScrollPosition = window.scrollY;
743743
document.body.style.width = `${document.body.offsetWidth}px`;
@@ -783,7 +783,7 @@ function loadCss(cssFileName) {
783783
}
784784

785785
window.addEventListener("resize", () => {
786-
if (window.innerWidth >= window.RUSTDOC_MOBILE_BREAKPOINT &&
786+
if (window.innerWidth > window.RUSTDOC_MOBILE_BREAKPOINT &&
787787
oldSidebarScrollPosition !== null) {
788788
// If the user opens the sidebar in "mobile" mode, and then grows the browser window,
789789
// we need to switch away from mobile mode and make the main content area scrollable.

Diff for: src/librustdoc/html/static/js/storage.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ window.currentTheme = document.getElementById("themeStyle");
1010
window.mainTheme = document.getElementById("mainThemeStyle");
1111

1212
// WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
13-
// If you update this line, then you also need to update the two media queries with the same
13+
// If you update this line, then you also need to update the media query with the same
1414
// warning in rustdoc.css
15-
window.RUSTDOC_MOBILE_BREAKPOINT = 701;
15+
window.RUSTDOC_MOBILE_BREAKPOINT = 700;
1616

1717
const settingsDataset = (function() {
1818
const settingsElement = document.getElementById("default-settings");

Diff for: src/test/rustdoc-gui/code-color.goml

+15-21
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,20 @@
55
goto: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html"
66
// If the text isn't displayed, the browser doesn't compute color style correctly...
77
show-text: true
8-
// Set the theme to dark.
9-
local-storage: {"rustdoc-theme": "dark", "rustdoc-preferred-dark-theme": "dark", "rustdoc-use-system-theme": "false"}
10-
// We reload the page so the local storage settings are being used.
11-
reload:
128

13-
assert-css: (".docblock pre > code", {"color": "rgb(221, 221, 221)"}, ALL)
14-
assert-css: (".docblock > p > code", {"color": "rgb(221, 221, 221)"}, ALL)
9+
define-function: (
10+
"check-colors",
11+
(theme, doc_code_color, doc_inline_code_color),
12+
[
13+
// Set the theme.
14+
("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
15+
// We reload the page so the local storage settings are being used.
16+
("reload"),
17+
("assert-css", (".docblock pre > code", {"color": |doc_code_color|}, ALL)),
18+
("assert-css", (".docblock > p > code", {"color": |doc_inline_code_color|}, ALL)),
19+
],
20+
)
1521

16-
// Set the theme to ayu.
17-
local-storage: {"rustdoc-theme": "ayu", "rustdoc-preferred-dark-theme": "ayu", "rustdoc-use-system-theme": "false"}
18-
// We reload the page so the local storage settings are being used.
19-
reload:
20-
21-
assert-css: (".docblock pre > code", {"color": "rgb(230, 225, 207)"}, ALL)
22-
assert-css: (".docblock > p > code", {"color": "rgb(255, 180, 84)"}, ALL)
23-
24-
// Set the theme to light.
25-
local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
26-
// We reload the page so the local storage settings are being used.
27-
reload:
28-
29-
assert-css: (".docblock pre > code", {"color": "rgb(0, 0, 0)"}, ALL)
30-
assert-css: (".docblock > p > code", {"color": "rgb(0, 0, 0)"}, ALL)
22+
call-function: ("check-colors", ("ayu", "rgb(230, 225, 207)", "rgb(255, 180, 84)"))
23+
call-function: ("check-colors", ("dark", "rgb(221, 221, 221)", "rgb(221, 221, 221)"))
24+
call-function: ("check-colors", ("light", "rgb(0, 0, 0)", "rgb(0, 0, 0)"))

0 commit comments

Comments
 (0)