Skip to content

Commit 28eb31f

Browse files
committed
Make libcore/unicode/tables.rs compatible with rustfmt
1 parent f4cff27 commit 28eb31f

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

src/libcore/unicode/tables.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@
22

33
#![allow(missing_docs, non_upper_case_globals, non_snake_case, clippy::unreadable_literal)]
44

5-
use crate::unicode::version::UnicodeVersion;
65
use crate::unicode::bool_trie::{BoolTrie, SmallBoolTrie};
6+
use crate::unicode::version::UnicodeVersion;
77

88
/// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of
99
/// `char` and `str` methods are based on.
1010
#[unstable(feature = "unicode_version", issue = "49726")]
11-
pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion {
12-
major: 12,
13-
minor: 1,
14-
micro: 0,
15-
_priv: (),
16-
};
11+
pub const UNICODE_VERSION: UnicodeVersion =
12+
UnicodeVersion { major: 12, minor: 1, micro: 0, _priv: () };
1713
pub(crate) mod general_category {
14+
#[rustfmt::skip]
1815
const Cc_table: &super::SmallBoolTrie = &super::SmallBoolTrie {
1916
r1: &[
2017
0, 1, 0
@@ -28,6 +25,7 @@ pub(crate) mod general_category {
2825
Cc_table.lookup(c)
2926
}
3027

28+
#[rustfmt::skip]
3129
const N_table: &super::BoolTrie = &super::BoolTrie {
3230
r1: [
3331
0x03ff000000000000, 0x0000000000000000, 0x720c000000000000, 0x0000000000000000,
@@ -138,10 +136,10 @@ pub(crate) mod general_category {
138136
pub fn N(c: char) -> bool {
139137
N_table.lookup(c)
140138
}
141-
142139
}
143140

144141
pub(crate) mod derived_property {
142+
#[rustfmt::skip]
145143
const Alphabetic_table: &super::BoolTrie = &super::BoolTrie {
146144
r1: [
147145
0x0000000000000000, 0x07fffffe07fffffe, 0x0420040000000000, 0xff7fffffff7fffff,
@@ -327,6 +325,7 @@ pub(crate) mod derived_property {
327325
Alphabetic_table.lookup(c)
328326
}
329327

328+
#[rustfmt::skip]
330329
const Case_Ignorable_table: &super::BoolTrie = &super::BoolTrie {
331330
r1: [
332331
0x0400408000000000, 0x0000000140000000, 0x0190a10000000000, 0x0000000000000000,
@@ -464,6 +463,7 @@ pub(crate) mod derived_property {
464463
Case_Ignorable_table.lookup(c)
465464
}
466465

466+
#[rustfmt::skip]
467467
const Cased_table: &super::BoolTrie = &super::BoolTrie {
468468
r1: [
469469
0x0000000000000000, 0x07fffffe07fffffe, 0x0420040000000000, 0xff7fffffff7fffff,
@@ -565,6 +565,7 @@ pub(crate) mod derived_property {
565565
Cased_table.lookup(c)
566566
}
567567

568+
#[rustfmt::skip]
568569
const Grapheme_Extend_table: &super::BoolTrie = &super::BoolTrie {
569570
r1: [
570571
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
@@ -689,6 +690,7 @@ pub(crate) mod derived_property {
689690
Grapheme_Extend_table.lookup(c)
690691
}
691692

693+
#[rustfmt::skip]
692694
const Lowercase_table: &super::BoolTrie = &super::BoolTrie {
693695
r1: [
694696
0x0000000000000000, 0x07fffffe00000000, 0x0420040000000000, 0xff7fffff80000000,
@@ -789,6 +791,7 @@ pub(crate) mod derived_property {
789791
Lowercase_table.lookup(c)
790792
}
791793

794+
#[rustfmt::skip]
792795
const Uppercase_table: &super::BoolTrie = &super::BoolTrie {
793796
r1: [
794797
0x0000000000000000, 0x0000000007fffffe, 0x0000000000000000, 0x000000007f7fffff,
@@ -889,10 +892,10 @@ pub(crate) mod derived_property {
889892
pub fn Uppercase(c: char) -> bool {
890893
Uppercase_table.lookup(c)
891894
}
892-
893895
}
894896

895897
pub(crate) mod property {
898+
#[rustfmt::skip]
896899
const White_Space_table: &super::SmallBoolTrie = &super::SmallBoolTrie {
897900
r1: &[
898901
0, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -912,20 +915,19 @@ pub(crate) mod property {
912915
pub fn White_Space(c: char) -> bool {
913916
White_Space_table.lookup(c)
914917
}
915-
916918
}
917919

918920
pub(crate) mod conversions {
919921
pub fn to_lower(c: char) -> [char; 3] {
920922
match bsearch_case_table(c, to_lowercase_table) {
921-
None => [c, '\0', '\0'],
923+
None => [c, '\0', '\0'],
922924
Some(index) => to_lowercase_table[index].1,
923925
}
924926
}
925927

926928
pub fn to_upper(c: char) -> [char; 3] {
927929
match bsearch_case_table(c, to_uppercase_table) {
928-
None => [c, '\0', '\0'],
930+
None => [c, '\0', '\0'],
929931
Some(index) => to_uppercase_table[index].1,
930932
}
931933
}
@@ -934,6 +936,7 @@ pub(crate) mod conversions {
934936
table.binary_search_by(|&(key, _)| key.cmp(&c)).ok()
935937
}
936938

939+
#[rustfmt::skip]
937940
const to_lowercase_table: &[(char, [char; 3])] = &[
938941
('\u{41}', ['\u{61}', '\0', '\0']), ('\u{42}', ['\u{62}', '\0', '\0']), ('\u{43}',
939942
['\u{63}', '\0', '\0']), ('\u{44}', ['\u{64}', '\0', '\0']), ('\u{45}', ['\u{65}', '\0',
@@ -1558,6 +1561,7 @@ pub(crate) mod conversions {
15581561
('\u{1e920}', ['\u{1e942}', '\0', '\0']), ('\u{1e921}', ['\u{1e943}', '\0', '\0'])
15591562
];
15601563

1564+
#[rustfmt::skip]
15611565
const to_uppercase_table: &[(char, [char; 3])] = &[
15621566
('\u{61}', ['\u{41}', '\0', '\0']), ('\u{62}', ['\u{42}', '\0', '\0']), ('\u{63}',
15631567
['\u{43}', '\0', '\0']), ('\u{64}', ['\u{44}', '\0', '\0']), ('\u{65}', ['\u{45}', '\0',
@@ -2228,5 +2232,4 @@ pub(crate) mod conversions {
22282232
('\u{1e940}', ['\u{1e91e}', '\0', '\0']), ('\u{1e941}', ['\u{1e91f}', '\0', '\0']),
22292233
('\u{1e942}', ['\u{1e920}', '\0', '\0']), ('\u{1e943}', ['\u{1e921}', '\0', '\0'])
22302234
];
2231-
22322235
}

src/libcore/unicode/unicode.py

+20-16
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class UnicodeFiles(object):
8181
8282
#![allow(missing_docs, non_upper_case_globals, non_snake_case, clippy::unreadable_literal)]
8383
84-
use crate::unicode::version::UnicodeVersion;
8584
use crate::unicode::bool_trie::{{BoolTrie, SmallBoolTrie}};
85+
use crate::unicode::version::UnicodeVersion;
8686
""".format(year=datetime.datetime.now().year)
8787

8888
# Mapping taken from Table 12 from:
@@ -555,6 +555,8 @@ def generate_table(
555555
if is_pub:
556556
pub_string = "pub "
557557

558+
yield "\n"
559+
yield " #[rustfmt::skip]\n"
558560
yield " %sconst %s: %s = &[\n" % (pub_string, name, decl_type)
559561

560562
data = []
@@ -568,7 +570,7 @@ def generate_table(
568570
for table_line in generate_table_lines("".join(data).split(","), 8):
569571
yield table_line
570572

571-
yield "\n ];\n\n"
573+
yield "\n ];\n"
572574

573575

574576
def compute_trie(raw_data, chunk_size):
@@ -634,6 +636,9 @@ def generate_bool_trie(name, codepoint_ranges, is_pub=False):
634636
pub_string = ""
635637
if is_pub:
636638
pub_string = "pub "
639+
640+
yield "\n"
641+
yield " #[rustfmt::skip]\n"
637642
yield " %sconst %s: &super::BoolTrie = &super::BoolTrie {\n" % (pub_string, name)
638643
yield " r1: [\n"
639644
data = ("0x%016x" % chunk for chunk in chunks[:0x800 // chunk_size])
@@ -678,7 +683,7 @@ def generate_bool_trie(name, codepoint_ranges, is_pub=False):
678683
yield fragment
679684
yield "\n ],\n"
680685

681-
yield " };\n\n"
686+
yield " };\n"
682687

683688

684689
def generate_small_bool_trie(name, codepoint_ranges, is_pub=False):
@@ -700,6 +705,8 @@ def generate_small_bool_trie(name, codepoint_ranges, is_pub=False):
700705
if is_pub:
701706
pub_string = "pub "
702707

708+
yield "\n"
709+
yield " #[rustfmt::skip]\n"
703710
yield (" %sconst %s: &super::SmallBoolTrie = &super::SmallBoolTrie {\n"
704711
% (pub_string, name))
705712

@@ -717,7 +724,7 @@ def generate_small_bool_trie(name, codepoint_ranges, is_pub=False):
717724
yield fragment
718725
yield "\n ],\n"
719726

720-
yield " };\n\n"
727+
yield " };\n"
721728

722729

723730
def generate_property_module(mod, grouped_categories, category_subset):
@@ -726,7 +733,7 @@ def generate_property_module(mod, grouped_categories, category_subset):
726733
Generate Rust code for module defining properties.
727734
"""
728735

729-
yield "pub(crate) mod %s {\n" % mod
736+
yield "pub(crate) mod %s {" % mod
730737
for cat in sorted(category_subset):
731738
if cat in ("Cc", "White_Space"):
732739
generator = generate_small_bool_trie("%s_table" % cat, grouped_categories[cat])
@@ -736,9 +743,10 @@ def generate_property_module(mod, grouped_categories, category_subset):
736743
for fragment in generator:
737744
yield fragment
738745

746+
yield "\n"
739747
yield " pub fn %s(c: char) -> bool {\n" % cat
740748
yield " %s_table.lookup(c)\n" % cat
741-
yield " }\n\n"
749+
yield " }\n"
742750

743751
yield "}\n\n"
744752

@@ -753,21 +761,21 @@ def generate_conversions_module(unicode_data):
753761
yield """
754762
pub fn to_lower(c: char) -> [char; 3] {
755763
match bsearch_case_table(c, to_lowercase_table) {
756-
None => [c, '\\0', '\\0'],
764+
None => [c, '\\0', '\\0'],
757765
Some(index) => to_lowercase_table[index].1,
758766
}
759767
}
760768
761769
pub fn to_upper(c: char) -> [char; 3] {
762770
match bsearch_case_table(c, to_uppercase_table) {
763-
None => [c, '\\0', '\\0'],
771+
None => [c, '\\0', '\\0'],
764772
Some(index) => to_uppercase_table[index].1,
765773
}
766774
}
767775
768776
fn bsearch_case_table(c: char, table: &[(char, [char; 3])]) -> Option<usize> {
769777
table.binary_search_by(|&(key, _)| key.cmp(&c)).ok()
770-
}\n\n"""
778+
}\n"""
771779

772780
decl_type = "&[(char, [char; 3])]"
773781
format_conversion = lambda x: "({},[{},{},{}])".format(*(
@@ -827,13 +835,9 @@ def main():
827835
/// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of
828836
/// `char` and `str` methods are based on.
829837
#[unstable(feature = "unicode_version", issue = "49726")]
830-
pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion {{
831-
major: {version.major},
832-
minor: {version.minor},
833-
micro: {version.micro},
834-
_priv: (),
835-
}};
836-
""").format(version=unicode_version)
838+
pub const UNICODE_VERSION: UnicodeVersion =
839+
UnicodeVersion {{ major: {v.major}, minor: {v.minor}, micro: {v.micro}, _priv: () }};
840+
""").format(v=unicode_version)
837841
buf.write(unicode_version_notice)
838842

839843
get_path = lambda f: get_unicode_file_path(unicode_version, f)

0 commit comments

Comments
 (0)