Skip to content

Commit

Permalink
Auto merge of rust-lang#71031 - Dylan-DPC:rollup-zr8hh86, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - rust-lang#70644 (Clean up `ModuleConfig` initialization)
 - rust-lang#70937 (Fix staticlib name for *-pc-windows-gnu targets)
 - rust-lang#70996 (Add or_insert_with_key to Entry of HashMap/BTreeMap)
 - rust-lang#71020 (Store UNICODE_VERSION as a tuple)
 - rust-lang#71021 (Use write!-style syntax for MIR assert terminator)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Apr 11, 2020
2 parents e82734e + d8dcdec commit 378901d
Show file tree
Hide file tree
Showing 27 changed files with 254 additions and 223 deletions.
28 changes: 28 additions & 0 deletions src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2361,6 +2361,34 @@ impl<'a, K: Ord, V> Entry<'a, K, V> {
}
}

#[unstable(feature = "or_insert_with_key", issue = "71024")]
/// Ensures a value is in the entry by inserting, if empty, the result of the default function,
/// which takes the key as its argument, and returns a mutable reference to the value in the
/// entry.
///
/// # Examples
///
/// ```
/// #![feature(or_insert_with_key)]
/// use std::collections::BTreeMap;
///
/// let mut map: BTreeMap<&str, usize> = BTreeMap::new();
///
/// map.entry("poneyland").or_insert_with_key(|key| key.chars().count());
///
/// assert_eq!(map["poneyland"], 9);
/// ```
#[inline]
pub fn or_insert_with_key<F: FnOnce(&K) -> V>(self, default: F) -> &'a mut V {
match self {
Occupied(entry) => entry.into_mut(),
Vacant(entry) => {
let value = default(entry.key());
entry.insert(value)
}
}
}

/// Returns a reference to this entry's key.
///
/// # Examples
Expand Down
2 changes: 0 additions & 2 deletions src/libcore/char/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ pub use self::decode::{decode_utf16, DecodeUtf16, DecodeUtf16Error};

// unstable re-exports
#[unstable(feature = "unicode_version", issue = "49726")]
pub use crate::unicode::version::UnicodeVersion;
#[unstable(feature = "unicode_version", issue = "49726")]
pub use crate::unicode::UNICODE_VERSION;

use crate::fmt::{self, Write};
Expand Down
13 changes: 4 additions & 9 deletions src/libcore/unicode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@

pub(crate) mod printable;
mod unicode_data;
pub(crate) mod version;

use version::UnicodeVersion;

/// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of
/// `char` and `str` methods are based on.
///
/// The version numbering scheme is explained in
/// [Unicode 11.0 or later, Section 3.1 Versions of the Unicode Standard](https://www.unicode.org/versions/Unicode11.0.0/ch03.pdf#page=4).
#[unstable(feature = "unicode_version", issue = "49726")]
pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion {
major: unicode_data::UNICODE_VERSION.0,
minor: unicode_data::UNICODE_VERSION.1,
micro: unicode_data::UNICODE_VERSION.2,
_priv: (),
};
pub const UNICODE_VERSION: (u8, u8, u8) = unicode_data::UNICODE_VERSION;

// For use in liballoc, not re-exported in libstd.
pub mod derived_property {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/unicode/unicode_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn skip_search<const SOR: usize, const OFFSETS: usize>(
offset_idx % 2 == 1
}

pub const UNICODE_VERSION: (u32, u32, u32) = (13, 0, 0);
pub const UNICODE_VERSION: (u8, u8, u8) = (13, 0, 0);

#[rustfmt::skip]
pub mod alphabetic {
Expand Down
18 changes: 0 additions & 18 deletions src/libcore/unicode/version.rs

This file was deleted.

Loading

0 comments on commit 378901d

Please sign in to comment.