Skip to content

Commit 378901d

Browse files
committed
Auto merge of rust-lang#71031 - Dylan-DPC:rollup-zr8hh86, r=Dylan-DPC
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
2 parents e82734e + d8dcdec commit 378901d

File tree

27 files changed

+254
-223
lines changed

27 files changed

+254
-223
lines changed

src/liballoc/collections/btree/map.rs

+28
Original file line numberDiff line numberDiff line change
@@ -2361,6 +2361,34 @@ impl<'a, K: Ord, V> Entry<'a, K, V> {
23612361
}
23622362
}
23632363

2364+
#[unstable(feature = "or_insert_with_key", issue = "71024")]
2365+
/// Ensures a value is in the entry by inserting, if empty, the result of the default function,
2366+
/// which takes the key as its argument, and returns a mutable reference to the value in the
2367+
/// entry.
2368+
///
2369+
/// # Examples
2370+
///
2371+
/// ```
2372+
/// #![feature(or_insert_with_key)]
2373+
/// use std::collections::BTreeMap;
2374+
///
2375+
/// let mut map: BTreeMap<&str, usize> = BTreeMap::new();
2376+
///
2377+
/// map.entry("poneyland").or_insert_with_key(|key| key.chars().count());
2378+
///
2379+
/// assert_eq!(map["poneyland"], 9);
2380+
/// ```
2381+
#[inline]
2382+
pub fn or_insert_with_key<F: FnOnce(&K) -> V>(self, default: F) -> &'a mut V {
2383+
match self {
2384+
Occupied(entry) => entry.into_mut(),
2385+
Vacant(entry) => {
2386+
let value = default(entry.key());
2387+
entry.insert(value)
2388+
}
2389+
}
2390+
}
2391+
23642392
/// Returns a reference to this entry's key.
23652393
///
23662394
/// # Examples

src/libcore/char/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ pub use self::decode::{decode_utf16, DecodeUtf16, DecodeUtf16Error};
3737

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

4442
use crate::fmt::{self, Write};

src/libcore/unicode/mod.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@
33

44
pub(crate) mod printable;
55
mod unicode_data;
6-
pub(crate) mod version;
7-
8-
use version::UnicodeVersion;
96

107
/// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of
118
/// `char` and `str` methods are based on.
9+
///
10+
/// The version numbering scheme is explained in
11+
/// [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).
1212
#[unstable(feature = "unicode_version", issue = "49726")]
13-
pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion {
14-
major: unicode_data::UNICODE_VERSION.0,
15-
minor: unicode_data::UNICODE_VERSION.1,
16-
micro: unicode_data::UNICODE_VERSION.2,
17-
_priv: (),
18-
};
13+
pub const UNICODE_VERSION: (u8, u8, u8) = unicode_data::UNICODE_VERSION;
1914

2015
// For use in liballoc, not re-exported in libstd.
2116
pub mod derived_property {

src/libcore/unicode/unicode_data.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn skip_search<const SOR: usize, const OFFSETS: usize>(
9494
offset_idx % 2 == 1
9595
}
9696

97-
pub const UNICODE_VERSION: (u32, u32, u32) = (13, 0, 0);
97+
pub const UNICODE_VERSION: (u8, u8, u8) = (13, 0, 0);
9898

9999
#[rustfmt::skip]
100100
pub mod alphabetic {

src/libcore/unicode/version.rs

-18
This file was deleted.

0 commit comments

Comments
 (0)