From 5807be7ccb2c14df9db87a54038221bbf5ae00fa Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 5 Apr 2018 17:09:28 +0200 Subject: [PATCH] Move contents of libstd_unicode into libcore --- src/libcore/lib.rs | 2 ++ .../unicode}/bool_trie.rs | 0 .../unicode}/char.rs | 24 +++++++------- src/libcore/unicode/mod.rs | 29 +++++++++++++++++ .../u_str.rs => libcore/unicode/str.rs} | 6 ++-- .../unicode}/tables.rs | 7 ++-- .../unicode}/unicode.py | 7 ++-- .../unicode}/version.rs | 0 src/libstd_unicode/lib.rs | 32 ++----------------- .../single-primitive-inherent-impl.rs | 8 ++--- 10 files changed, 56 insertions(+), 59 deletions(-) rename src/{libstd_unicode => libcore/unicode}/bool_trie.rs (100%) rename src/{libstd_unicode => libcore/unicode}/char.rs (98%) create mode 100644 src/libcore/unicode/mod.rs rename src/{libstd_unicode/u_str.rs => libcore/unicode/str.rs} (98%) rename src/{libstd_unicode => libcore/unicode}/tables.rs (99%) rename src/{libstd_unicode => libcore/unicode}/unicode.py (99%) rename src/{libstd_unicode => libcore/unicode}/version.rs (100%) diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index e194b173aa71..7cb635a299ae 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -180,6 +180,8 @@ pub mod hash; pub mod fmt; pub mod time; +pub mod unicode; + /* Heap memory allocator trait */ #[allow(missing_docs)] pub mod heap; diff --git a/src/libstd_unicode/bool_trie.rs b/src/libcore/unicode/bool_trie.rs similarity index 100% rename from src/libstd_unicode/bool_trie.rs rename to src/libcore/unicode/bool_trie.rs diff --git a/src/libstd_unicode/char.rs b/src/libcore/unicode/char.rs similarity index 98% rename from src/libstd_unicode/char.rs rename to src/libcore/unicode/char.rs index 460f83d875a7..0e8b09f621a0 100644 --- a/src/libstd_unicode/char.rs +++ b/src/libcore/unicode/char.rs @@ -28,30 +28,30 @@ #![stable(feature = "rust1", since = "1.0.0")] -use core::char::CharExt as C; -use core::iter::FusedIterator; -use core::fmt::{self, Write}; -use tables::{conversions, derived_property, general_category, property}; +use char::CharExt as C; +use iter::FusedIterator; +use fmt::{self, Write}; +use unicode::tables::{conversions, derived_property, general_category, property}; // stable re-exports #[stable(feature = "rust1", since = "1.0.0")] -pub use core::char::{MAX, from_digit, from_u32, from_u32_unchecked}; +pub use char::{MAX, from_digit, from_u32, from_u32_unchecked}; #[stable(feature = "rust1", since = "1.0.0")] -pub use core::char::{EscapeDebug, EscapeDefault, EscapeUnicode}; +pub use char::{EscapeDebug, EscapeDefault, EscapeUnicode}; #[stable(feature = "decode_utf16", since = "1.9.0")] -pub use core::char::REPLACEMENT_CHARACTER; +pub use char::REPLACEMENT_CHARACTER; #[stable(feature = "char_from_str", since = "1.20.0")] -pub use core::char::ParseCharError; +pub use char::ParseCharError; // unstable re-exports #[stable(feature = "try_from", since = "1.26.0")] -pub use core::char::CharTryFromError; +pub use char::CharTryFromError; #[unstable(feature = "decode_utf8", issue = "33906")] -pub use core::char::{DecodeUtf8, decode_utf8}; +pub use char::{DecodeUtf8, decode_utf8}; #[unstable(feature = "unicode", issue = "27783")] -pub use tables::{UNICODE_VERSION}; +pub use unicode::tables::{UNICODE_VERSION}; #[unstable(feature = "unicode", issue = "27783")] -pub use version::UnicodeVersion; +pub use unicode::version::UnicodeVersion; /// Returns an iterator that yields the lowercase equivalent of a `char`. /// diff --git a/src/libcore/unicode/mod.rs b/src/libcore/unicode/mod.rs new file mode 100644 index 000000000000..aaf8081799f0 --- /dev/null +++ b/src/libcore/unicode/mod.rs @@ -0,0 +1,29 @@ +// Copyright 2012-2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![unstable(feature = "unicode", issue = "27783")] +#![allow(missing_docs)] + +mod bool_trie; +mod tables; +mod version; + +pub mod str; +pub mod char; + +// For use in liballoc, not re-exported in libstd. +pub mod derived_property { + pub use unicode::tables::derived_property::{Case_Ignorable, Cased}; +} + +// For use in libsyntax +pub mod property { + pub use unicode::tables::property::Pattern_White_Space; +} diff --git a/src/libstd_unicode/u_str.rs b/src/libcore/unicode/str.rs similarity index 98% rename from src/libstd_unicode/u_str.rs rename to src/libcore/unicode/str.rs index a72e1210d93f..18581bf4d580 100644 --- a/src/libstd_unicode/u_str.rs +++ b/src/libcore/unicode/str.rs @@ -13,9 +13,9 @@ //! This module provides functionality to `str` that requires the Unicode //! methods provided by the unicode parts of the CharExt trait. -use core::char; -use core::iter::{Filter, FusedIterator}; -use core::str::Split; +use char; +use iter::{Filter, FusedIterator}; +use str::Split; /// An iterator over the non-whitespace substrings of a string, /// separated by any amount of whitespace. diff --git a/src/libstd_unicode/tables.rs b/src/libcore/unicode/tables.rs similarity index 99% rename from src/libstd_unicode/tables.rs rename to src/libcore/unicode/tables.rs index b53953b62a7a..7e8e925bda32 100644 --- a/src/libstd_unicode/tables.rs +++ b/src/libcore/unicode/tables.rs @@ -12,8 +12,8 @@ #![allow(missing_docs, non_upper_case_globals, non_snake_case)] -use version::UnicodeVersion; -use bool_trie::{BoolTrie, SmallBoolTrie}; +use unicode::version::UnicodeVersion; +use unicode::bool_trie::{BoolTrie, SmallBoolTrie}; /// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of /// `CharExt` and `UnicodeStrPrelude` traits are based on. @@ -1138,9 +1138,6 @@ pub mod property { } pub mod conversions { - use core::option::Option; - use core::option::Option::{Some, None}; - pub fn to_lower(c: char) -> [char; 3] { match bsearch_case_table(c, to_lowercase_table) { None => [c, '\0', '\0'], diff --git a/src/libstd_unicode/unicode.py b/src/libcore/unicode/unicode.py similarity index 99% rename from src/libstd_unicode/unicode.py rename to src/libcore/unicode/unicode.py index a86294930861..39b68dc7d9b6 100755 --- a/src/libstd_unicode/unicode.py +++ b/src/libcore/unicode/unicode.py @@ -39,8 +39,8 @@ preamble = '''// Copyright 2012-2016 The Rust Project Developers. See the COPYRI #![allow(missing_docs, non_upper_case_globals, non_snake_case)] -use version::UnicodeVersion; -use bool_trie::{BoolTrie, SmallBoolTrie}; +use unicode::version::UnicodeVersion; +use unicode::bool_trie::{BoolTrie, SmallBoolTrie}; ''' # Mapping taken from Table 12 from: @@ -408,9 +408,6 @@ def emit_property_module(f, mod, tbl, emit): def emit_conversions_module(f, to_upper, to_lower, to_title): f.write("pub mod conversions {") f.write(""" - use core::option::Option; - use core::option::Option::{Some, None}; - pub fn to_lower(c: char) -> [char; 3] { match bsearch_case_table(c, to_lowercase_table) { None => [c, '\\0', '\\0'], diff --git a/src/libstd_unicode/version.rs b/src/libcore/unicode/version.rs similarity index 100% rename from src/libstd_unicode/version.rs rename to src/libcore/unicode/version.rs diff --git a/src/libstd_unicode/lib.rs b/src/libstd_unicode/lib.rs index 106a2c0f0c51..8cdeb6c8ad18 100644 --- a/src/libstd_unicode/lib.rs +++ b/src/libstd_unicode/lib.rs @@ -27,37 +27,9 @@ html_playground_url = "https://play.rust-lang.org/", issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/", test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))] -#![deny(missing_debug_implementations)] #![no_std] -#![feature(ascii_ctype)] -#![feature(core_char_ext)] -#![feature(str_internals)] -#![feature(decode_utf8)] -#![feature(fn_traits)] -#![feature(lang_items)] -#![feature(non_exhaustive)] +#![feature(unicode)] #![feature(staged_api)] -#![feature(unboxed_closures)] -mod bool_trie; -mod tables; -mod u_str; -mod version; -pub mod char; - -#[allow(deprecated)] -pub mod str { - pub use u_str::{SplitWhitespace, UnicodeStr}; - pub use u_str::Utf16Encoder; -} - -// For use in liballoc, not re-exported in libstd. -pub mod derived_property { - pub use tables::derived_property::{Case_Ignorable, Cased}; -} - -// For use in libsyntax -pub mod property { - pub use tables::property::Pattern_White_Space; -} +pub use core::unicode::*; diff --git a/src/test/compile-fail/single-primitive-inherent-impl.rs b/src/test/compile-fail/single-primitive-inherent-impl.rs index 5ceb870528a6..365387c3e5e2 100644 --- a/src/test/compile-fail/single-primitive-inherent-impl.rs +++ b/src/test/compile-fail/single-primitive-inherent-impl.rs @@ -15,9 +15,9 @@ #![no_std] // OK -#[lang = "char"] -impl char {} +#[lang = "str"] +impl str {} -impl char { -//~^ error: only a single inherent implementation marked with `#[lang = "char"]` is allowed for the `char` primitive +impl str { +//~^ error: only a single inherent implementation marked with `#[lang = "str"]` is allowed for the `str` primitive }