Skip to content

Commit

Permalink
Rollup merge of #71020 - pyfisch:unicode-version, r=sfackler
Browse files Browse the repository at this point in the history
Store UNICODE_VERSION as a tuple

Remove the UnicodeVersion struct containing
major, minor and update fields and replace it with
a 3-tuple containing the version number.
As the value of each field is limited to 255
use u8 to store them.
  • Loading branch information
Dylan-DPC committed Apr 11, 2020
2 parents 03a724b + 7f4048c commit b794cb2
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 33 deletions.
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.

4 changes: 2 additions & 2 deletions src/test/ui/char_unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ pub fn main() {
check(std::char::UNICODE_VERSION);
}

pub fn check(unicode_version: std::char::UnicodeVersion) {
assert!(unicode_version.major >= 10);
pub fn check(unicode_version: (u8, u8, u8)) {
assert!(unicode_version.0 >= 10);
}
2 changes: 1 addition & 1 deletion src/tools/unicode-table-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ fn main() {

fn version() -> String {
let mut out = String::new();
out.push_str("pub const UNICODE_VERSION: (u32, u32, u32) = ");
out.push_str("pub const UNICODE_VERSION: (u8, u8, u8) = ");

let readme =
std::fs::read_to_string(std::path::Path::new(UNICODE_DIRECTORY).join("ReadMe.txt"))
Expand Down

0 comments on commit b794cb2

Please sign in to comment.