Skip to content

Commit 52ed3d8

Browse files
committed
Auto merge of #50191 - kennytm:rollup, r=kennytm
Rollup of 11 pull requests Successful merges: - #49461 (std: Child::kill() returns error if process has already exited) - #49727 (Add Cell::update) - #49812 (Fix revision support for UI tests.) - #49829 (Add doc links to `std::os` extension traits) - #49906 (Stabilize `std::hint::unreachable_unchecked`.) - #49970 (Deprecate Read::chars and char::decode_utf8) - #49985 (don't see issue #0) - #50118 (fix search bar bug) - #50139 (encourage descriptive issue titles) - #50174 (Use FxHashMap in syntax_pos::symbol::Interner::intern.) - #50185 (core: Fix overflow in `int::mod_euc` when `self < 0 && rhs == MIN`) Failed merges:
2 parents f305b02 + 893774e commit 52ed3d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+425
-167
lines changed

CONTRIBUTING.md

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ as it's possible that someone else has already reported your error. This doesn't
4747
always work, and sometimes it's hard to know what to search for, so consider this
4848
extra credit. We won't mind if you accidentally file a duplicate report.
4949

50+
Similarly, to help others who encountered the bug find your issue,
51+
consider filing an issue with with a descriptive title, which contains information that might be unique to it.
52+
This can be the language or compiler feature used, the conditions that trigger the bug,
53+
or part of the error message if there is any.
54+
An example could be: **"impossible case reached" on lifetime inference for impl Trait in return position**.
55+
5056
Opening an issue is as easy as following [this
5157
link](https://github.com/rust-lang/rust/issues/new) and filling out the fields.
5258
Here's a template that you can use to file a bug, though it's not necessary to

src/libcore/cell.rs

+27
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,33 @@ impl<T:Copy> Cell<T> {
256256
pub fn get(&self) -> T {
257257
unsafe{ *self.value.get() }
258258
}
259+
260+
/// Updates the contained value using a function and returns the new value.
261+
///
262+
/// # Examples
263+
///
264+
/// ```
265+
/// #![feature(cell_update)]
266+
///
267+
/// use std::cell::Cell;
268+
///
269+
/// let c = Cell::new(5);
270+
/// let new = c.update(|x| x + 1);
271+
///
272+
/// assert_eq!(new, 6);
273+
/// assert_eq!(c.get(), 6);
274+
/// ```
275+
#[inline]
276+
#[unstable(feature = "cell_update", issue = "50186")]
277+
pub fn update<F>(&self, f: F) -> T
278+
where
279+
F: FnOnce(T) -> T,
280+
{
281+
let old = self.get();
282+
let new = f(old);
283+
self.set(new);
284+
new
285+
}
259286
}
260287

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

src/libcore/char/decode.rs

+11
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,32 @@ use super::from_u32_unchecked;
1717
/// An iterator over an iterator of bytes of the characters the bytes represent
1818
/// as UTF-8
1919
#[unstable(feature = "decode_utf8", issue = "33906")]
20+
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
21+
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
2022
#[derive(Clone, Debug)]
23+
#[allow(deprecated)]
2124
pub struct DecodeUtf8<I: Iterator<Item = u8>>(::iter::Peekable<I>);
2225

2326
/// Decodes an `Iterator` of bytes as UTF-8.
2427
#[unstable(feature = "decode_utf8", issue = "33906")]
28+
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
29+
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
30+
#[allow(deprecated)]
2531
#[inline]
2632
pub fn decode_utf8<I: IntoIterator<Item = u8>>(i: I) -> DecodeUtf8<I::IntoIter> {
2733
DecodeUtf8(i.into_iter().peekable())
2834
}
2935

3036
/// `<DecodeUtf8 as Iterator>::next` returns this for an invalid input sequence.
3137
#[unstable(feature = "decode_utf8", issue = "33906")]
38+
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
39+
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
3240
#[derive(PartialEq, Eq, Debug)]
41+
#[allow(deprecated)]
3342
pub struct InvalidSequence(());
3443

3544
#[unstable(feature = "decode_utf8", issue = "33906")]
45+
#[allow(deprecated)]
3646
impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> {
3747
type Item = Result<char, InvalidSequence>;
3848
#[inline]
@@ -127,6 +137,7 @@ impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> {
127137
}
128138

129139
#[unstable(feature = "decode_utf8", issue = "33906")]
140+
#[allow(deprecated)]
130141
impl<I: FusedIterator<Item = u8>> FusedIterator for DecodeUtf8<I> {}
131142

132143
/// An iterator that decodes UTF-16 encoded code points from an iterator of `u16`s.

src/libcore/char/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ pub use unicode::tables::UNICODE_VERSION;
5151
#[unstable(feature = "unicode_version", issue = "49726")]
5252
pub use unicode::version::UnicodeVersion;
5353
#[unstable(feature = "decode_utf8", issue = "33906")]
54+
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
55+
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
56+
#[allow(deprecated)]
5457
pub use self::decode::{decode_utf8, DecodeUtf8, InvalidSequence};
5558

5659
use fmt::{self, Write};

src/libcore/hint.rs

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![stable(feature = "core_hint", since = "1.27.0")]
12+
13+
//! Hints to compiler that affects how code should be emitted or optimized.
14+
15+
use intrinsics;
16+
17+
/// Informs the compiler that this point in the code is not reachable, enabling
18+
/// further optimizations.
19+
///
20+
/// # Safety
21+
///
22+
/// Reaching this function is completely *undefined behavior* (UB). In
23+
/// particular, the compiler assumes that all UB must never happen, and
24+
/// therefore will eliminate all branches that reach to a call to
25+
/// `unreachable_unchecked()`.
26+
///
27+
/// Like all instances of UB, if this assumption turns out to be wrong, i.e. the
28+
/// `unreachable_unchecked()` call is actually reachable among all possible
29+
/// control flow, the compiler will apply the wrong optimization strategy, and
30+
/// may sometimes even corrupt seemingly unrelated code, causing
31+
/// difficult-to-debug problems.
32+
///
33+
/// Use this function only when you can prove that the code will never call it.
34+
///
35+
/// The [`unreachable!()`] macro is the safe counterpart of this function, which
36+
/// will panic instead when executed.
37+
///
38+
/// [`unreachable!()`]: ../macro.unreachable.html
39+
///
40+
/// # Example
41+
///
42+
/// ```
43+
/// fn div_1(a: u32, b: u32) -> u32 {
44+
/// use std::hint::unreachable_unchecked;
45+
///
46+
/// // `b.saturating_add(1)` is always positive (not zero),
47+
/// // hence `checked_div` will never return None.
48+
/// // Therefore, the else branch is unreachable.
49+
/// a.checked_div(b.saturating_add(1))
50+
/// .unwrap_or_else(|| unsafe { unreachable_unchecked() })
51+
/// }
52+
///
53+
/// assert_eq!(div_1(7, 0), 7);
54+
/// assert_eq!(div_1(9, 1), 4);
55+
/// assert_eq!(div_1(11, std::u32::MAX), 0);
56+
/// ```
57+
#[inline]
58+
#[stable(feature = "unreachable", since = "1.27.0")]
59+
pub unsafe fn unreachable_unchecked() -> ! {
60+
intrinsics::unreachable()
61+
}

src/libcore/intrinsics.rs

+3
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,9 @@ extern "rust-intrinsic" {
638638
/// NB: This is very different from the `unreachable!()` macro: Unlike the
639639
/// macro, which panics when it is executed, it is *undefined behavior* to
640640
/// reach code marked with this function.
641+
///
642+
/// The stabilized version of this intrinsic is
643+
/// [`std::hint::unreachable_unchecked`](../../std/hint/fn.unreachable_unchecked.html).
641644
pub fn unreachable() -> !;
642645

643646
/// Informs the optimizer that a condition is always true.

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ pub mod intrinsics;
163163
pub mod mem;
164164
pub mod nonzero;
165165
pub mod ptr;
166+
pub mod hint;
166167

167168
/* Core language traits */
168169

src/libcore/macros.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,13 @@ macro_rules! writeln {
421421
/// * Iterators that dynamically terminate.
422422
///
423423
/// If the determination that the code is unreachable proves incorrect, the
424-
/// program immediately terminates with a [`panic!`]. The function [`unreachable`],
425-
/// which belongs to the [`std::intrinsics`] module, informs the compilier to
424+
/// program immediately terminates with a [`panic!`]. The function [`unreachable_unchecked`],
425+
/// which belongs to the [`std::hint`] module, informs the compilier to
426426
/// optimize the code out of the release version entirely.
427427
///
428428
/// [`panic!`]: ../std/macro.panic.html
429-
/// [`unreachable`]: ../std/intrinsics/fn.unreachable.html
430-
/// [`std::intrinsics`]: ../std/intrinsics/index.html
429+
/// [`unreachable_unchecked`]: ../std/hint/fn.unreachable_unchecked.html
430+
/// [`std::hint`]: ../std/hint/index.html
431431
///
432432
/// # Panics
433433
///

src/libcore/mem.rs

-12
Original file line numberDiff line numberDiff line change
@@ -1094,18 +1094,6 @@ impl<T: ::hash::Hash> ::hash::Hash for ManuallyDrop<T> {
10941094
}
10951095
}
10961096

1097-
/// Tells LLVM that this point in the code is not reachable, enabling further
1098-
/// optimizations.
1099-
///
1100-
/// NB: This is very different from the `unreachable!()` macro: Unlike the
1101-
/// macro, which panics when it is executed, it is *undefined behavior* to
1102-
/// reach code marked with this function.
1103-
#[inline]
1104-
#[unstable(feature = "unreachable", issue = "43751")]
1105-
pub unsafe fn unreachable() -> ! {
1106-
intrinsics::unreachable()
1107-
}
1108-
11091097
/// A pinned reference.
11101098
///
11111099
/// A pinned reference is a lot like a mutable reference, except that it is not

src/libcore/num/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,11 @@ assert_eq!((-a).mod_euc(-b), 1);
17651765
pub fn mod_euc(self, rhs: Self) -> Self {
17661766
let r = self % rhs;
17671767
if r < 0 {
1768-
r + rhs.abs()
1768+
if rhs < 0 {
1769+
r - rhs
1770+
} else {
1771+
r + rhs
1772+
}
17691773
} else {
17701774
r
17711775
}

src/libcore/tests/cell.rs

+11
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ fn smoketest_cell() {
2626
assert!(y.get() == (30, 40));
2727
}
2828

29+
#[test]
30+
fn cell_update() {
31+
let x = Cell::new(10);
32+
33+
assert_eq!(x.update(|x| x + 5), 15);
34+
assert_eq!(x.get(), 15);
35+
36+
assert_eq!(x.update(|x| x / 3), 5);
37+
assert_eq!(x.get(), 5);
38+
}
39+
2940
#[test]
3041
fn cell_has_sensible_show() {
3142
let x = Cell::new("foo bar");

src/libcore/tests/char.rs

+1
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ fn eu_iterator_specializations() {
364364
}
365365

366366
#[test]
367+
#[allow(deprecated)]
367368
fn test_decode_utf8() {
368369
macro_rules! assert_decode_utf8 {
369370
($input_bytes: expr, $expected_str: expr) => {

src/libcore/tests/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010

1111
#![feature(ascii_ctype)]
1212
#![feature(box_syntax)]
13+
#![feature(cell_update)]
1314
#![feature(core_float)]
1415
#![feature(core_private_bignum)]
1516
#![feature(core_private_diy_float)]
1617
#![feature(dec2flt)]
1718
#![feature(decode_utf8)]
19+
#![feature(euclidean_division)]
1820
#![feature(exact_size_is_empty)]
1921
#![feature(fixed_size_array)]
2022
#![feature(float_internals)]

src/libcore/tests/num/int_macros.rs

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ mod tests {
3030
num::test_num(10 as $T, 2 as $T);
3131
}
3232

33+
#[test]
34+
fn test_mod_euc() {
35+
assert!((-1 as $T).mod_euc(MIN) == MAX);
36+
}
37+
3338
#[test]
3439
pub fn test_abs() {
3540
assert!((1 as $T).abs() == 1 as $T);

src/librustdoc/html/static/main.js

+18-10
Original file line numberDiff line numberDiff line change
@@ -1375,13 +1375,17 @@
13751375

13761376
function search(e) {
13771377
var params = getQueryStringParams();
1378-
var query = getQuery(document.getElementsByClassName('search-input')[0].value.trim());
1378+
var search_input = document.getElementsByClassName('search-input')[0];
1379+
var query = getQuery(search_input.value.trim());
13791380

13801381
if (e) {
13811382
e.preventDefault();
13821383
}
13831384

13841385
if (!query.query || query.id === currentResults) {
1386+
if (query.query.length > 0) {
1387+
putBackSearch(search_input);
1388+
}
13851389
return;
13861390
}
13871391

@@ -2072,19 +2076,23 @@
20722076
};
20732077
});
20742078

2079+
function putBackSearch(search_input) {
2080+
if (search_input.value !== "") {
2081+
addClass(document.getElementById("main"), "hidden");
2082+
removeClass(document.getElementById("search"), "hidden");
2083+
if (browserSupportsHistoryApi()) {
2084+
history.replaceState(search_input.value,
2085+
"",
2086+
"?search=" + encodeURIComponent(search_input.value));
2087+
}
2088+
}
2089+
}
2090+
20752091
var search_input = document.getElementsByClassName("search-input")[0];
20762092

20772093
if (search_input) {
20782094
search_input.onfocus = function() {
2079-
if (search_input.value !== "") {
2080-
addClass(document.getElementById("main"), "hidden");
2081-
removeClass(document.getElementById("search"), "hidden");
2082-
if (browserSupportsHistoryApi()) {
2083-
history.replaceState(search_input.value,
2084-
"",
2085-
"?search=" + encodeURIComponent(search_input.value));
2086-
}
2087-
}
2095+
putBackSearch(this);
20882096
};
20892097
}
20902098

src/libstd/io/buffered.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1251,13 +1251,15 @@ mod tests {
12511251
}
12521252

12531253
#[test]
1254+
#[allow(deprecated)]
12541255
fn read_char_buffered() {
12551256
let buf = [195, 159];
12561257
let reader = BufReader::with_capacity(1, &buf[..]);
12571258
assert_eq!(reader.chars().next().unwrap().unwrap(), 'ß');
12581259
}
12591260

12601261
#[test]
1262+
#[allow(deprecated)]
12611263
fn test_chars() {
12621264
let buf = [195, 159, b'a'];
12631265
let reader = BufReader::with_capacity(1, &buf[..]);

src/libstd/io/cursor.rs

+2
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ mod tests {
566566
}
567567

568568
#[test]
569+
#[allow(deprecated)]
569570
fn test_read_char() {
570571
let b = &b"Vi\xE1\xBB\x87t"[..];
571572
let mut c = Cursor::new(b).chars();
@@ -577,6 +578,7 @@ mod tests {
577578
}
578579

579580
#[test]
581+
#[allow(deprecated)]
580582
fn test_read_bad_char() {
581583
let b = &b"\x80"[..];
582584
let mut c = Cursor::new(b).chars();

0 commit comments

Comments
 (0)