Skip to content

Commit

Permalink
Auto merge of #50191 - kennytm:rollup, r=kennytm
Browse files Browse the repository at this point in the history
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:
  • Loading branch information
bors committed Apr 24, 2018
2 parents f305b02 + 893774e commit 52ed3d8
Show file tree
Hide file tree
Showing 51 changed files with 425 additions and 167 deletions.
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ as it's possible that someone else has already reported your error. This doesn't
always work, and sometimes it's hard to know what to search for, so consider this
extra credit. We won't mind if you accidentally file a duplicate report.

Similarly, to help others who encountered the bug find your issue,
consider filing an issue with with a descriptive title, which contains information that might be unique to it.
This can be the language or compiler feature used, the conditions that trigger the bug,
or part of the error message if there is any.
An example could be: **"impossible case reached" on lifetime inference for impl Trait in return position**.

Opening an issue is as easy as following [this
link](https://github.com/rust-lang/rust/issues/new) and filling out the fields.
Here's a template that you can use to file a bug, though it's not necessary to
Expand Down
27 changes: 27 additions & 0 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,33 @@ impl<T:Copy> Cell<T> {
pub fn get(&self) -> T {
unsafe{ *self.value.get() }
}

/// Updates the contained value using a function and returns the new value.
///
/// # Examples
///
/// ```
/// #![feature(cell_update)]
///
/// use std::cell::Cell;
///
/// let c = Cell::new(5);
/// let new = c.update(|x| x + 1);
///
/// assert_eq!(new, 6);
/// assert_eq!(c.get(), 6);
/// ```
#[inline]
#[unstable(feature = "cell_update", issue = "50186")]
pub fn update<F>(&self, f: F) -> T
where
F: FnOnce(T) -> T,
{
let old = self.get();
let new = f(old);
self.set(new);
new
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
11 changes: 11 additions & 0 deletions src/libcore/char/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,32 @@ use super::from_u32_unchecked;
/// An iterator over an iterator of bytes of the characters the bytes represent
/// as UTF-8
#[unstable(feature = "decode_utf8", issue = "33906")]
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
#[derive(Clone, Debug)]
#[allow(deprecated)]
pub struct DecodeUtf8<I: Iterator<Item = u8>>(::iter::Peekable<I>);

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

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

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

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

/// An iterator that decodes UTF-16 encoded code points from an iterator of `u16`s.
Expand Down
3 changes: 3 additions & 0 deletions src/libcore/char/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ pub use unicode::tables::UNICODE_VERSION;
#[unstable(feature = "unicode_version", issue = "49726")]
pub use unicode::version::UnicodeVersion;
#[unstable(feature = "decode_utf8", issue = "33906")]
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
#[allow(deprecated)]
pub use self::decode::{decode_utf8, DecodeUtf8, InvalidSequence};

use fmt::{self, Write};
Expand Down
61 changes: 61 additions & 0 deletions src/libcore/hint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![stable(feature = "core_hint", since = "1.27.0")]

//! Hints to compiler that affects how code should be emitted or optimized.

use intrinsics;

/// Informs the compiler that this point in the code is not reachable, enabling
/// further optimizations.
///
/// # Safety
///
/// Reaching this function is completely *undefined behavior* (UB). In
/// particular, the compiler assumes that all UB must never happen, and
/// therefore will eliminate all branches that reach to a call to
/// `unreachable_unchecked()`.
///
/// Like all instances of UB, if this assumption turns out to be wrong, i.e. the
/// `unreachable_unchecked()` call is actually reachable among all possible
/// control flow, the compiler will apply the wrong optimization strategy, and
/// may sometimes even corrupt seemingly unrelated code, causing
/// difficult-to-debug problems.
///
/// Use this function only when you can prove that the code will never call it.
///
/// The [`unreachable!()`] macro is the safe counterpart of this function, which
/// will panic instead when executed.
///
/// [`unreachable!()`]: ../macro.unreachable.html
///
/// # Example
///
/// ```
/// fn div_1(a: u32, b: u32) -> u32 {
/// use std::hint::unreachable_unchecked;
///
/// // `b.saturating_add(1)` is always positive (not zero),
/// // hence `checked_div` will never return None.
/// // Therefore, the else branch is unreachable.
/// a.checked_div(b.saturating_add(1))
/// .unwrap_or_else(|| unsafe { unreachable_unchecked() })
/// }
///
/// assert_eq!(div_1(7, 0), 7);
/// assert_eq!(div_1(9, 1), 4);
/// assert_eq!(div_1(11, std::u32::MAX), 0);
/// ```
#[inline]
#[stable(feature = "unreachable", since = "1.27.0")]
pub unsafe fn unreachable_unchecked() -> ! {
intrinsics::unreachable()
}
3 changes: 3 additions & 0 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,9 @@ extern "rust-intrinsic" {
/// NB: This is very different from the `unreachable!()` macro: Unlike the
/// macro, which panics when it is executed, it is *undefined behavior* to
/// reach code marked with this function.
///
/// The stabilized version of this intrinsic is
/// [`std::hint::unreachable_unchecked`](../../std/hint/fn.unreachable_unchecked.html).
pub fn unreachable() -> !;

/// Informs the optimizer that a condition is always true.
Expand Down
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ pub mod intrinsics;
pub mod mem;
pub mod nonzero;
pub mod ptr;
pub mod hint;

/* Core language traits */

Expand Down
8 changes: 4 additions & 4 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,13 @@ macro_rules! writeln {
/// * Iterators that dynamically terminate.
///
/// If the determination that the code is unreachable proves incorrect, the
/// program immediately terminates with a [`panic!`]. The function [`unreachable`],
/// which belongs to the [`std::intrinsics`] module, informs the compilier to
/// program immediately terminates with a [`panic!`]. The function [`unreachable_unchecked`],
/// which belongs to the [`std::hint`] module, informs the compilier to
/// optimize the code out of the release version entirely.
///
/// [`panic!`]: ../std/macro.panic.html
/// [`unreachable`]: ../std/intrinsics/fn.unreachable.html
/// [`std::intrinsics`]: ../std/intrinsics/index.html
/// [`unreachable_unchecked`]: ../std/hint/fn.unreachable_unchecked.html
/// [`std::hint`]: ../std/hint/index.html
///
/// # Panics
///
Expand Down
12 changes: 0 additions & 12 deletions src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,18 +1094,6 @@ impl<T: ::hash::Hash> ::hash::Hash for ManuallyDrop<T> {
}
}

/// Tells LLVM that this point in the code is not reachable, enabling further
/// optimizations.
///
/// NB: This is very different from the `unreachable!()` macro: Unlike the
/// macro, which panics when it is executed, it is *undefined behavior* to
/// reach code marked with this function.
#[inline]
#[unstable(feature = "unreachable", issue = "43751")]
pub unsafe fn unreachable() -> ! {
intrinsics::unreachable()
}

/// A pinned reference.
///
/// A pinned reference is a lot like a mutable reference, except that it is not
Expand Down
6 changes: 5 additions & 1 deletion src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,11 @@ assert_eq!((-a).mod_euc(-b), 1);
pub fn mod_euc(self, rhs: Self) -> Self {
let r = self % rhs;
if r < 0 {
r + rhs.abs()
if rhs < 0 {
r - rhs
} else {
r + rhs
}
} else {
r
}
Expand Down
11 changes: 11 additions & 0 deletions src/libcore/tests/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ fn smoketest_cell() {
assert!(y.get() == (30, 40));
}

#[test]
fn cell_update() {
let x = Cell::new(10);

assert_eq!(x.update(|x| x + 5), 15);
assert_eq!(x.get(), 15);

assert_eq!(x.update(|x| x / 3), 5);
assert_eq!(x.get(), 5);
}

#[test]
fn cell_has_sensible_show() {
let x = Cell::new("foo bar");
Expand Down
1 change: 1 addition & 0 deletions src/libcore/tests/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ fn eu_iterator_specializations() {
}

#[test]
#[allow(deprecated)]
fn test_decode_utf8() {
macro_rules! assert_decode_utf8 {
($input_bytes: expr, $expected_str: expr) => {
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

#![feature(ascii_ctype)]
#![feature(box_syntax)]
#![feature(cell_update)]
#![feature(core_float)]
#![feature(core_private_bignum)]
#![feature(core_private_diy_float)]
#![feature(dec2flt)]
#![feature(decode_utf8)]
#![feature(euclidean_division)]
#![feature(exact_size_is_empty)]
#![feature(fixed_size_array)]
#![feature(float_internals)]
Expand Down
5 changes: 5 additions & 0 deletions src/libcore/tests/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ mod tests {
num::test_num(10 as $T, 2 as $T);
}

#[test]
fn test_mod_euc() {
assert!((-1 as $T).mod_euc(MIN) == MAX);
}

#[test]
pub fn test_abs() {
assert!((1 as $T).abs() == 1 as $T);
Expand Down
28 changes: 18 additions & 10 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1375,13 +1375,17 @@

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

if (e) {
e.preventDefault();
}

if (!query.query || query.id === currentResults) {
if (query.query.length > 0) {
putBackSearch(search_input);
}
return;
}

Expand Down Expand Up @@ -2072,19 +2076,23 @@
};
});

function putBackSearch(search_input) {
if (search_input.value !== "") {
addClass(document.getElementById("main"), "hidden");
removeClass(document.getElementById("search"), "hidden");
if (browserSupportsHistoryApi()) {
history.replaceState(search_input.value,
"",
"?search=" + encodeURIComponent(search_input.value));
}
}
}

var search_input = document.getElementsByClassName("search-input")[0];

if (search_input) {
search_input.onfocus = function() {
if (search_input.value !== "") {
addClass(document.getElementById("main"), "hidden");
removeClass(document.getElementById("search"), "hidden");
if (browserSupportsHistoryApi()) {
history.replaceState(search_input.value,
"",
"?search=" + encodeURIComponent(search_input.value));
}
}
putBackSearch(this);
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/libstd/io/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,13 +1251,15 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn read_char_buffered() {
let buf = [195, 159];
let reader = BufReader::with_capacity(1, &buf[..]);
assert_eq!(reader.chars().next().unwrap().unwrap(), 'ß');
}

#[test]
#[allow(deprecated)]
fn test_chars() {
let buf = [195, 159, b'a'];
let reader = BufReader::with_capacity(1, &buf[..]);
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/io/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ mod tests {
}

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

#[test]
#[allow(deprecated)]
fn test_read_bad_char() {
let b = &b"\x80"[..];
let mut c = Cursor::new(b).chars();
Expand Down
Loading

0 comments on commit 52ed3d8

Please sign in to comment.