From 89feb6d5fd38aa9b493d6fc3ca5b546c373aac31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Romanowski?= Date: Thu, 18 Apr 2019 15:30:50 +0200 Subject: [PATCH 01/15] Clean up unicode.py script --- .gitignore | 1 + src/libcore/unicode/unicode.py | 372 ++++++++++++++++++++++++--------- 2 files changed, 270 insertions(+), 103 deletions(-) diff --git a/.gitignore b/.gitignore index 67e0dd8e795bb..51f3e722ca7d8 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ __pycache__/ /src/libcore/unicode/Scripts.txt /src/libcore/unicode/SpecialCasing.txt /src/libcore/unicode/UnicodeData.txt +/src/libcore/unicode/downloaded /stage[0-9]+/ /target target/ diff --git a/src/libcore/unicode/unicode.py b/src/libcore/unicode/unicode.py index ae356c3ff4459..97c11fb795ea8 100755 --- a/src/libcore/unicode/unicode.py +++ b/src/libcore/unicode/unicode.py @@ -1,35 +1,71 @@ #!/usr/bin/env python -# This script uses the following Unicode tables: -# - DerivedCoreProperties.txt -# - DerivedNormalizationProps.txt -# - EastAsianWidth.txt -# - auxiliary/GraphemeBreakProperty.txt -# - PropList.txt -# - ReadMe.txt -# - Scripts.txt -# - UnicodeData.txt -# +""" +Regenerate Unicode tables (tables.rs). +""" + +# This script uses the Unicode tables as defined +# in the UnicodeFiles class. + # Since this should not require frequent updates, we just store this # out-of-line and check the tables.rs file into git. -import fileinput, re, os, sys, operator, math, datetime +# Note that the "curl" program is required for operation. +# This script is compatible with Python 2.7 and 3.x. + +import argparse +import datetime +import fileinput +import operator +import os +import re +import textwrap +import subprocess + +from collections import namedtuple + + +# we don't use enum.Enum because of Python 2.7 compatibility +class UnicodeFiles(object): + # ReadMe does not contain any unicode data, we + # use it to extract versions. + README = "ReadMe.txt" + + DERIVED_CORE_PROPERTIES = "DerivedCoreProperties.txt" + DERIVED_NORMALIZATION_PROPS = "DerivedNormalizationProps.txt" + SPECIAL_CASING = "SpecialCasing.txt" + SCRIPTS = "Scripts.txt" + PROPS = "PropList.txt" + UNICODE_DATA = "UnicodeData.txt" + + +UnicodeFiles.ALL_FILES = tuple( + getattr(UnicodeFiles, name) for name in dir(UnicodeFiles) + if not name.startswith("_") +) -# The directory in which this file resides. -fdir = os.path.dirname(os.path.realpath(__file__)) + "/" +# The directory this file is located in. +THIS_DIR = os.path.dirname(os.path.realpath(__file__)) -preamble = ''' +# Where to download the Unicode data. The downloaded files +# will be placed in sub-directories named after Unicode version. +FETCH_DIR = os.path.join(THIS_DIR, "downloaded") + +FETCH_URL_LATEST = "ftp://ftp.unicode.org/Public/UNIDATA/{filename}" +FETCH_URL_VERSION = "ftp://ftp.unicode.org/Public/{version}/ucd/{filename}" + +PREAMBLE = """\ // NOTE: The following code was generated by "./unicode.py", do not edit directly #![allow(missing_docs, non_upper_case_globals, non_snake_case)] use unicode::version::UnicodeVersion; use unicode::bool_trie::{{BoolTrie, SmallBoolTrie}}; -'''.format(year = datetime.datetime.now().year) +""".format(year=datetime.datetime.now().year) # Mapping taken from Table 12 from: # http://www.unicode.org/reports/tr44/#General_Category_Values -expanded_categories = { +EXPANDED_CATEGORIES = { 'Lu': ['LC', 'L'], 'Ll': ['LC', 'L'], 'Lt': ['LC', 'L'], 'Lm': ['L'], 'Lo': ['L'], 'Mn': ['M'], 'Mc': ['M'], 'Me': ['M'], @@ -42,22 +78,101 @@ } # these are the surrogate codepoints, which are not valid rust characters -surrogate_codepoints = (0xd800, 0xdfff) +SURROGATE_CODEPOINTS = (0xd800, 0xdfff) + +UnicodeData = namedtuple( + "UnicodeData", ("canon_decomp", "compat_decomp", "gencats", "combines", + "to_upper", "to_lower", "to_title", ) +) + +UnicodeVersion = namedtuple( + "UnicodeVersion", ("major", "minor", "micro", "as_str") +) + + +def fetch_files(version=None): + """ + Fetch all the Unicode files from unicode.org + + :param version: The desired Unicode version, as string. + (If None, defaults to latest final release available). + :return: The version downloaded (UnicodeVersion object). + """ + have_version = should_skip_fetch(version) + if have_version: + return have_version + + if version: + # check if the desired version exists on the server + get_fetch_url = lambda name: FETCH_URL_VERSION.format(version=version, filename=name) + else: + # extract the latest version + get_fetch_url = lambda name: FETCH_URL_LATEST.format(filename=name) + + readme_url = get_fetch_url(UnicodeFiles.README) + + print("Fetching: {}".format(readme_url)) + readme_content = subprocess.check_output(("curl", readme_url)) + + unicode_version = parse_unicode_version( + str(readme_content, "utf8") + ) + + download_dir = os.path.join(FETCH_DIR, unicode_version.as_str) + if not os.path.exists(download_dir): + # for 2.7 compat, we don't use exist_ok=True + os.makedirs(download_dir) + + for filename in UnicodeFiles.ALL_FILES: + file_path = os.path.join(download_dir, filename) + + if filename == UnicodeFiles.README: + with open(file_path, "wb") as fd: + fd.write(readme_content) + elif not os.path.exists(file_path): + url = get_fetch_url(filename) + print("Fetching: {}".format(url)) + subprocess.check_call(("curl", "-o", file_path, url)) + + return unicode_version + + +def should_skip_fetch(version): + if not version: + # should always check latest version + return False + + fetch_dir = os.path.join(FETCH_DIR, version) + + for filename in UnicodeFiles.ALL_FILES: + file_path = os.path.join(fetch_dir, filename) + + if not os.path.exists(file_path): + return False + + with open(os.path.join(fetch_dir, UnicodeFiles.README)) as fd: + return parse_unicode_version(fd.read()) + + +def parse_unicode_version(readme_content): + # "raw string" is necessary for \d not being treated as escape char + # (for the sake of compat with future Python versions) + # see: https://docs.python.org/3.6/whatsnew/3.6.html#deprecated-python-behavior + pattern = r"for Version (\d+)\.(\d+)\.(\d+) of the Unicode" + groups = re.search(pattern, readme_content).groups() + + return UnicodeVersion(*map(int, groups), as_str=".".join(groups)) + -def fetch(f): - path = fdir + os.path.basename(f) - if not os.path.exists(path): - os.system("curl -o {0}{1} ftp://ftp.unicode.org/Public/UNIDATA/{1}".format(fdir, f)) +def get_unicode_file_path(unicode_version, filename): + return os.path.join(FETCH_DIR, unicode_version.as_str, filename) - if not os.path.exists(path): - sys.stderr.write("cannot load %s" % f) - exit(1) def is_surrogate(n): - return surrogate_codepoints[0] <= n <= surrogate_codepoints[1] + return SURROGATE_CODEPOINTS[0] <= n <= SURROGATE_CODEPOINTS[1] -def load_unicode_data(f): - fetch(f) + +def load_unicode_data(file_path): gencats = {} to_lower = {} to_upper = {} @@ -68,8 +183,8 @@ def load_unicode_data(f): udict = {} range_start = -1 - for line in fileinput.input(fdir + f): - data = line.split(';') + for line in fileinput.input(file_path): + data = line.split(";") if len(data) != 15: continue cp = int(data[0], 16) @@ -104,7 +219,7 @@ def load_unicode_data(f): # store decomposition, if given if decomp != "": - if decomp.startswith('<'): + if decomp.startswith("<"): seq = [] for i in decomp.split()[1:]: seq.append(int(i, 16)) @@ -116,7 +231,7 @@ def load_unicode_data(f): canon_decomp[code] = seq # place letter in categories as appropriate - for cat in [gencat, "Assigned"] + expanded_categories.get(gencat, []): + for cat in [gencat, "Assigned"] + EXPANDED_CATEGORIES.get(gencat, []): if cat not in gencats: gencats[cat] = [] gencats[cat].append(code) @@ -136,12 +251,15 @@ def load_unicode_data(f): gencats = group_cats(gencats) combines = to_combines(group_cats(combines)) - return (canon_decomp, compat_decomp, gencats, combines, to_upper, to_lower, to_title) + return UnicodeData( + canon_decomp, compat_decomp, gencats, combines, to_upper, + to_lower, to_title, + ) + -def load_special_casing(f, to_upper, to_lower, to_title): - fetch(f) - for line in fileinput.input(fdir + f): - data = line.split('#')[0].split(';') +def load_special_casing(file_path, unicode_data): + for line in fileinput.input(file_path): + data = line.split("#")[0].split(";") if len(data) == 5: code, lower, title, upper, _comment = data elif len(data) == 6: @@ -155,7 +273,9 @@ def load_special_casing(f, to_upper, to_lower, to_title): title = title.strip() upper = upper.strip() key = int(code, 16) - for (map_, values) in [(to_lower, lower), (to_upper, upper), (to_title, title)]: + for (map_, values) in ((unicode_data.to_lower, lower), + (unicode_data.to_upper, upper), + (unicode_data.to_title, title)): if values != code: values = [int(i, 16) for i in values.split()] for _ in range(len(values), 3): @@ -163,12 +283,14 @@ def load_special_casing(f, to_upper, to_lower, to_title): assert len(values) == 3 map_[key] = values + def group_cats(cats): cats_out = {} for cat in cats: cats_out[cat] = group_cat(cats[cat]) return cats_out + def group_cat(cat): cat_out = [] letters = sorted(set(cat)) @@ -185,6 +307,7 @@ def group_cat(cat): cat_out.append((cur_start, cur_end)) return cat_out + def ungroup_cat(cat): cat_out = [] for (lo, hi) in cat: @@ -193,21 +316,24 @@ def ungroup_cat(cat): lo += 1 return cat_out + def gen_unassigned(assigned): assigned = set(assigned) return ([i for i in range(0, 0xd800) if i not in assigned] + [i for i in range(0xe000, 0x110000) if i not in assigned]) + def to_combines(combs): combs_out = [] for comb in combs: for (lo, hi) in combs[comb]: combs_out.append((lo, hi, comb)) - combs_out.sort(key=lambda comb: comb[0]) + combs_out.sort(key=lambda c: c[0]) return combs_out + def format_table_content(f, content, indent): - line = " "*indent + line = " " * indent first = True for chunk in content.split(","): if len(line) + len(chunk) < 98: @@ -218,16 +344,19 @@ def format_table_content(f, content, indent): first = False else: f.write(line + ",\n") - line = " "*indent + chunk + line = " " * indent + chunk f.write(line) -def load_properties(f, interestingprops): - fetch(f) + +def load_properties(file_path, interestingprops): props = {} - re1 = re.compile("^ *([0-9A-F]+) *; *(\w+)") - re2 = re.compile("^ *([0-9A-F]+)\.\.([0-9A-F]+) *; *(\w+)") + # "raw string" is necessary for \w not to be treated as escape char + # (for the sake of compat with future Python versions) + # see: https://docs.python.org/3.6/whatsnew/3.6.html#deprecated-python-behavior + re1 = re.compile(r"^ *([0-9A-F]+) *; *(\w+)") + re2 = re.compile(r"^ *([0-9A-F]+)\.\.([0-9A-F]+) *; *(\w+)") - for line in fileinput.input(fdir + os.path.basename(f)): + for line in fileinput.input(file_path): prop = None d_lo = 0 d_hi = 0 @@ -258,10 +387,12 @@ def load_properties(f, interestingprops): return props + def escape_char(c): return "'\\u{%x}'" % c if c != 0 else "'\\0'" -def emit_table(f, name, t_data, t_type = "&[(char, char)]", is_pub=True, + +def emit_table(f, name, t_data, t_type="&[(char, char)]", is_pub=True, pfun=lambda x: "(%s,%s)" % (escape_char(x[0]), escape_char(x[1]))): pub_string = "" if is_pub: @@ -277,6 +408,7 @@ def emit_table(f, name, t_data, t_type = "&[(char, char)]", is_pub=True, format_table_content(f, data, 8) f.write("\n ];\n\n") + def compute_trie(rawdata, chunksize): root = [] childmap = {} @@ -288,10 +420,11 @@ def compute_trie(rawdata, chunksize): childmap[child] = len(childmap) child_data.extend(data) root.append(childmap[child]) - return (root, child_data) + return root, child_data + def emit_bool_trie(f, name, t_data, is_pub=True): - CHUNK = 64 + chunk_size = 64 rawdata = [False] * 0x110000 for (lo, hi) in t_data: for cp in range(lo, hi + 1): @@ -299,7 +432,7 @@ def emit_bool_trie(f, name, t_data, is_pub=True): # convert to bitmap chunks of 64 bits each chunks = [] - for i in range(0x110000 // CHUNK): + for i in range(0x110000 // chunk_size): chunk = 0 for j in range(64): if rawdata[i * 64 + j]: @@ -311,12 +444,12 @@ def emit_bool_trie(f, name, t_data, is_pub=True): pub_string = "pub " f.write(" %sconst %s: &super::BoolTrie = &super::BoolTrie {\n" % (pub_string, name)) f.write(" r1: [\n") - data = ','.join('0x%016x' % chunk for chunk in chunks[0:0x800 // CHUNK]) + data = ','.join('0x%016x' % chunk for chunk in chunks[0:0x800 // chunk_size]) format_table_content(f, data, 12) f.write("\n ],\n") # 0x800..0x10000 trie - (r2, r3) = compute_trie(chunks[0x800 // CHUNK : 0x10000 // CHUNK], 64 // CHUNK) + (r2, r3) = compute_trie(chunks[0x800 // chunk_size : 0x10000 // chunk_size], 64 // chunk_size) f.write(" r2: [\n") data = ','.join(str(node) for node in r2) format_table_content(f, data, 12) @@ -327,7 +460,7 @@ def emit_bool_trie(f, name, t_data, is_pub=True): f.write("\n ],\n") # 0x10000..0x110000 trie - (mid, r6) = compute_trie(chunks[0x10000 // CHUNK : 0x110000 // CHUNK], 64 // CHUNK) + (mid, r6) = compute_trie(chunks[0x10000 // chunk_size : 0x110000 // chunk_size], 64 // chunk_size) (r4, r5) = compute_trie(mid, 64) f.write(" r4: [\n") data = ','.join(str(node) for node in r4) @@ -344,6 +477,7 @@ def emit_bool_trie(f, name, t_data, is_pub=True): f.write(" };\n\n") + def emit_small_bool_trie(f, name, t_data, is_pub=True): last_chunk = max(hi // 64 for (lo, hi) in t_data) n_chunks = last_chunk + 1 @@ -374,6 +508,7 @@ def emit_small_bool_trie(f, name, t_data, is_pub=True): f.write(" };\n\n") + def emit_property_module(f, mod, tbl, emit): f.write("pub mod %s {\n" % mod) for cat in sorted(emit): @@ -389,7 +524,8 @@ def emit_property_module(f, mod, tbl, emit): f.write(" }\n\n") f.write("}\n\n") -def emit_conversions_module(f, to_upper, to_lower, to_title): + +def emit_conversions_module(f, unicode_data): f.write("pub mod conversions {") f.write(""" pub fn to_lower(c: char) -> [char; 3] { @@ -414,74 +550,104 @@ def emit_conversions_module(f, to_upper, to_lower, to_title): t_type = "&[(char, [char; 3])]" pfun = lambda x: "(%s,[%s,%s,%s])" % ( escape_char(x[0]), escape_char(x[1][0]), escape_char(x[1][1]), escape_char(x[1][2])) - emit_table(f, "to_lowercase_table", - sorted(to_lower.items(), key=operator.itemgetter(0)), - is_pub=False, t_type = t_type, pfun=pfun) - emit_table(f, "to_uppercase_table", - sorted(to_upper.items(), key=operator.itemgetter(0)), - is_pub=False, t_type = t_type, pfun=pfun) - f.write("}\n\n") -def emit_norm_module(f, canon, compat, combine, norm_props): - canon_keys = sorted(canon.keys()) + emit_table(f, + name="to_lowercase_table", + t_data=sorted(unicode_data.to_lower.items(), key=operator.itemgetter(0)), + t_type=t_type, + is_pub=False, + pfun=pfun) - compat_keys = sorted(compat.keys()) + emit_table(f, + name="to_uppercase_table", + t_data=sorted(unicode_data.to_upper.items(), key=operator.itemgetter(0)), + t_type=t_type, + is_pub=False, + pfun=pfun) + + f.write("}\n") + + +def emit_norm_module(f, unicode_data, norm_props): + canon_keys = sorted(unicode_data.canon_decomp.keys()) canon_comp = {} comp_exclusions = norm_props["Full_Composition_Exclusion"] for char in canon_keys: if any(lo <= char <= hi for lo, hi in comp_exclusions): continue - decomp = canon[char] + decomp = unicode_data.canon_decomp[char] if len(decomp) == 2: if decomp[0] not in canon_comp: canon_comp[decomp[0]] = [] - canon_comp[decomp[0]].append( (decomp[1], char) ) - canon_comp_keys = sorted(canon_comp.keys()) + canon_comp[decomp[0]].append((decomp[1], char)) -if __name__ == "__main__": - r = fdir + "tables.rs" - if os.path.exists(r): - os.remove(r) - with open(r, "w") as rf: + +def parse_args(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("-v", "--version", default=None, type=str, + help="Unicode version to use (if not specified," + " defaults to latest available final release).") + + return parser.parse_args() + + +def main(): + args = parse_args() + + unicode_version = fetch_files(args.version) + print("Using Unicode version: {}".format(unicode_version.as_str)) + + tables_rs_path = os.path.join(THIS_DIR, "tables.rs") + if os.path.exists(tables_rs_path): + os.remove(tables_rs_path) + + with open(tables_rs_path, "w") as rf: # write the file's preamble - rf.write(preamble) - - # download and parse all the data - fetch("ReadMe.txt") - with open(fdir + "ReadMe.txt") as readme: - pattern = "for Version (\d+)\.(\d+)\.(\d+) of the Unicode" - unicode_version = re.search(pattern, readme.read()).groups() - rf.write(""" -/// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of -/// `char` and `str` methods are based on. -#[unstable(feature = "unicode_version", issue = "49726")] -pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion { - major: %s, - minor: %s, - micro: %s, - _priv: (), -}; -""" % unicode_version) - (canon_decomp, compat_decomp, gencats, combines, - to_upper, to_lower, to_title) = load_unicode_data("UnicodeData.txt") - load_special_casing("SpecialCasing.txt", to_upper, to_lower, to_title) + rf.write(PREAMBLE) + + unicode_version_notice = textwrap.dedent(""" + /// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of + /// `char` and `str` methods are based on. + #[unstable(feature = "unicode_version", issue = "49726")] + pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion {{ + major: {version.major}, + minor: {version.minor}, + micro: {version.micro}, + _priv: (), + }}; + """).format(version=unicode_version) + rf.write(unicode_version_notice) + + get_path = lambda f: get_unicode_file_path(unicode_version, f) + + unicode_data = load_unicode_data(get_path(UnicodeFiles.UNICODE_DATA)) + load_special_casing(get_path(UnicodeFiles.SPECIAL_CASING), unicode_data) + want_derived = ["XID_Start", "XID_Continue", "Alphabetic", "Lowercase", "Uppercase", "Cased", "Case_Ignorable", "Grapheme_Extend"] - derived = load_properties("DerivedCoreProperties.txt", want_derived) - scripts = load_properties("Scripts.txt", []) - props = load_properties("PropList.txt", - ["White_Space", "Join_Control", "Noncharacter_Code_Point", "Pattern_White_Space"]) - norm_props = load_properties("DerivedNormalizationProps.txt", - ["Full_Composition_Exclusion"]) + derived = load_properties(get_path(UnicodeFiles.DERIVED_CORE_PROPERTIES), want_derived) + + # TODO scripts not used? + scripts = load_properties(get_path(UnicodeFiles.SCRIPTS), []) + props = load_properties(get_path(UnicodeFiles.PROPS), + ["White_Space", "Join_Control", "Noncharacter_Code_Point", + "Pattern_White_Space"]) + norm_props = load_properties(get_path(UnicodeFiles.DERIVED_NORMALIZATION_PROPS), + ["Full_Composition_Exclusion"]) # category tables - for (name, cat, pfuns) in ("general_category", gencats, ["N", "Cc"]), \ - ("derived_property", derived, want_derived), \ - ("property", props, ["White_Space", "Pattern_White_Space"]): + for (name, cat, pfuns) in (("general_category", unicode_data.gencats, ["N", "Cc"]), + ("derived_property", derived, want_derived), + ("property", props, ["White_Space", "Pattern_White_Space"])): emit_property_module(rf, name, cat, pfuns) # normalizations and conversions module - emit_norm_module(rf, canon_decomp, compat_decomp, combines, norm_props) - emit_conversions_module(rf, to_upper, to_lower, to_title) + emit_norm_module(rf, unicode_data, norm_props) + emit_conversions_module(rf, unicode_data) + print("Regenerated tables.rs.") + + +if __name__ == "__main__": + main() From a580421afbd6ee93aaab0ad01dee3df8343a88dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Romanowski?= Date: Thu, 18 Apr 2019 16:16:34 +0200 Subject: [PATCH 02/15] More cleanups for unicode.py --- src/libcore/unicode/unicode.py | 48 ++++++++++++++++------------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/libcore/unicode/unicode.py b/src/libcore/unicode/unicode.py index 97c11fb795ea8..447f4274c18da 100755 --- a/src/libcore/unicode/unicode.py +++ b/src/libcore/unicode/unicode.py @@ -28,14 +28,14 @@ # we don't use enum.Enum because of Python 2.7 compatibility class UnicodeFiles(object): # ReadMe does not contain any unicode data, we - # use it to extract versions. + # only use it to extract versions. README = "ReadMe.txt" DERIVED_CORE_PROPERTIES = "DerivedCoreProperties.txt" DERIVED_NORMALIZATION_PROPS = "DerivedNormalizationProps.txt" - SPECIAL_CASING = "SpecialCasing.txt" - SCRIPTS = "Scripts.txt" PROPS = "PropList.txt" + SCRIPTS = "Scripts.txt" + SPECIAL_CASING = "SpecialCasing.txt" UNICODE_DATA = "UnicodeData.txt" @@ -66,15 +66,15 @@ class UnicodeFiles(object): # Mapping taken from Table 12 from: # http://www.unicode.org/reports/tr44/#General_Category_Values EXPANDED_CATEGORIES = { - 'Lu': ['LC', 'L'], 'Ll': ['LC', 'L'], 'Lt': ['LC', 'L'], - 'Lm': ['L'], 'Lo': ['L'], - 'Mn': ['M'], 'Mc': ['M'], 'Me': ['M'], - 'Nd': ['N'], 'Nl': ['N'], 'No': ['N'], - 'Pc': ['P'], 'Pd': ['P'], 'Ps': ['P'], 'Pe': ['P'], - 'Pi': ['P'], 'Pf': ['P'], 'Po': ['P'], - 'Sm': ['S'], 'Sc': ['S'], 'Sk': ['S'], 'So': ['S'], - 'Zs': ['Z'], 'Zl': ['Z'], 'Zp': ['Z'], - 'Cc': ['C'], 'Cf': ['C'], 'Cs': ['C'], 'Co': ['C'], 'Cn': ['C'], + "Lu": ["LC", "L"], "Ll": ["LC", "L"], "Lt": ["LC", "L"], + "Lm": ["L"], "Lo": ["L"], + "Mn": ["M"], "Mc": ["M"], "Me": ["M"], + "Nd": ["N"], "Nl": ["N"], "No": ["N"], + "Pc": ["P"], "Pd": ["P"], "Ps": ["P"], "Pe": ["P"], + "Pi": ["P"], "Pf": ["P"], "Po": ["P"], + "Sm": ["S"], "Sc": ["S"], "Sk": ["S"], "So": ["S"], + "Zs": ["Z"], "Zl": ["Z"], "Zp": ["Z"], + "Cc": ["C"], "Cf": ["C"], "Cs": ["C"], "Co": ["C"], "Cn": ["C"], } # these are the surrogate codepoints, which are not valid rust characters @@ -115,7 +115,7 @@ def fetch_files(version=None): readme_content = subprocess.check_output(("curl", readme_url)) unicode_version = parse_unicode_version( - str(readme_content, "utf8") + readme_content.decode("utf8") ) download_dir = os.path.join(FETCH_DIR, unicode_version.as_str) @@ -415,7 +415,7 @@ def compute_trie(rawdata, chunksize): child_data = [] for i in range(len(rawdata) // chunksize): data = rawdata[i * chunksize: (i + 1) * chunksize] - child = '|'.join(map(str, data)) + child = "|".join(map(str, data)) if child not in childmap: childmap[child] = len(childmap) child_data.extend(data) @@ -444,18 +444,18 @@ def emit_bool_trie(f, name, t_data, is_pub=True): pub_string = "pub " f.write(" %sconst %s: &super::BoolTrie = &super::BoolTrie {\n" % (pub_string, name)) f.write(" r1: [\n") - data = ','.join('0x%016x' % chunk for chunk in chunks[0:0x800 // chunk_size]) + data = ",".join("0x%016x" % chunk for chunk in chunks[0:0x800 // chunk_size]) format_table_content(f, data, 12) f.write("\n ],\n") # 0x800..0x10000 trie (r2, r3) = compute_trie(chunks[0x800 // chunk_size : 0x10000 // chunk_size], 64 // chunk_size) f.write(" r2: [\n") - data = ','.join(str(node) for node in r2) + data = ",".join(str(node) for node in r2) format_table_content(f, data, 12) f.write("\n ],\n") f.write(" r3: &[\n") - data = ','.join('0x%016x' % chunk for chunk in r3) + data = ",".join("0x%016x" % chunk for chunk in r3) format_table_content(f, data, 12) f.write("\n ],\n") @@ -463,15 +463,15 @@ def emit_bool_trie(f, name, t_data, is_pub=True): (mid, r6) = compute_trie(chunks[0x10000 // chunk_size : 0x110000 // chunk_size], 64 // chunk_size) (r4, r5) = compute_trie(mid, 64) f.write(" r4: [\n") - data = ','.join(str(node) for node in r4) + data = ",".join(str(node) for node in r4) format_table_content(f, data, 12) f.write("\n ],\n") f.write(" r5: &[\n") - data = ','.join(str(node) for node in r5) + data = ",".join(str(node) for node in r5) format_table_content(f, data, 12) f.write("\n ],\n") f.write(" r6: &[\n") - data = ','.join('0x%016x' % chunk for chunk in r6) + data = ",".join("0x%016x" % chunk for chunk in r6) format_table_content(f, data, 12) f.write("\n ],\n") @@ -497,12 +497,12 @@ def emit_small_bool_trie(f, name, t_data, is_pub=True): (r1, r2) = compute_trie(chunks, 1) f.write(" r1: &[\n") - data = ','.join(str(node) for node in r1) + data = ",".join(str(node) for node in r1) format_table_content(f, data, 12) f.write("\n ],\n") f.write(" r2: &[\n") - data = ','.join('0x%016x' % node for node in r2) + data = ",".join("0x%016x" % node for node in r2) format_table_content(f, data, 12) f.write("\n ],\n") @@ -599,11 +599,9 @@ def main(): print("Using Unicode version: {}".format(unicode_version.as_str)) tables_rs_path = os.path.join(THIS_DIR, "tables.rs") - if os.path.exists(tables_rs_path): - os.remove(tables_rs_path) + # will overwrite the file if it exists with open(tables_rs_path, "w") as rf: - # write the file's preamble rf.write(PREAMBLE) unicode_version_notice = textwrap.dedent(""" From edbc27da2dc5a75f8e0ac70e7a5e07aa6f6f0a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Romanowski?= Date: Thu, 18 Apr 2019 17:14:31 +0200 Subject: [PATCH 03/15] Fix tidy errors --- src/libcore/unicode/unicode.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcore/unicode/unicode.py b/src/libcore/unicode/unicode.py index 447f4274c18da..e645c3f33c84c 100755 --- a/src/libcore/unicode/unicode.py +++ b/src/libcore/unicode/unicode.py @@ -460,7 +460,8 @@ def emit_bool_trie(f, name, t_data, is_pub=True): f.write("\n ],\n") # 0x10000..0x110000 trie - (mid, r6) = compute_trie(chunks[0x10000 // chunk_size : 0x110000 // chunk_size], 64 // chunk_size) + (mid, r6) = compute_trie(chunks[0x10000 // chunk_size : 0x110000 // chunk_size], + 64 // chunk_size) (r4, r5) = compute_trie(mid, 64) f.write(" r4: [\n") data = ",".join(str(node) for node in r4) @@ -626,7 +627,7 @@ def main(): "Cased", "Case_Ignorable", "Grapheme_Extend"] derived = load_properties(get_path(UnicodeFiles.DERIVED_CORE_PROPERTIES), want_derived) - # TODO scripts not used? + # FIXME scripts not used? scripts = load_properties(get_path(UnicodeFiles.SCRIPTS), []) props = load_properties(get_path(UnicodeFiles.PROPS), ["White_Space", "Join_Control", "Noncharacter_Code_Point", From 2c9c978e1d4a3541d8df593346c7520c8ef4d69e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Romanowski?= Date: Fri, 19 Apr 2019 11:42:08 +0200 Subject: [PATCH 04/15] Refactor and document unicode.py script --- src/libcore/unicode/unicode.py | 820 +++++++++++++++++++++------------ 1 file changed, 518 insertions(+), 302 deletions(-) diff --git a/src/libcore/unicode/unicode.py b/src/libcore/unicode/unicode.py index e645c3f33c84c..f66e82299100d 100755 --- a/src/libcore/unicode/unicode.py +++ b/src/libcore/unicode/unicode.py @@ -16,13 +16,31 @@ import argparse import datetime import fileinput -import operator +import itertools import os import re import textwrap import subprocess -from collections import namedtuple +from collections import defaultdict, namedtuple + +try: + # Python 3 + from itertools import zip_longest + from io import StringIO +except ImportError: + # Python 2 compatibility + zip_longest = itertools.izip_longest + from StringIO import StringIO + +try: + # completely optional type hinting + # (Python 2 compatible using comments, + # see: https://mypy.readthedocs.io/en/latest/python2.html) + # This is very helpful in typing-aware IDE like PyCharm. + from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Set, Tuple +except ImportError: + pass # we don't use enum.Enum because of Python 2.7 compatibility @@ -77,12 +95,21 @@ class UnicodeFiles(object): "Cc": ["C"], "Cf": ["C"], "Cs": ["C"], "Co": ["C"], "Cn": ["C"], } -# these are the surrogate codepoints, which are not valid rust characters -SURROGATE_CODEPOINTS = (0xd800, 0xdfff) +# this is the surrogate codepoints range (both ends inclusive) +# - they are not valid Rust characters +SURROGATE_CODEPOINTS_RANGE = (0xd800, 0xdfff) UnicodeData = namedtuple( - "UnicodeData", ("canon_decomp", "compat_decomp", "gencats", "combines", - "to_upper", "to_lower", "to_title", ) + "UnicodeData", ( + # conversions: + "to_upper", "to_lower", "to_title", + + # decompositions: canonical decompositions, compatibility decomp + "canon_decomp", "compat_decomp", + + # grouped: general categories and combining characters + "general_categories", "combines", + ) ) UnicodeVersion = namedtuple( @@ -91,14 +118,19 @@ class UnicodeFiles(object): def fetch_files(version=None): + # type: (str) -> UnicodeVersion """ - Fetch all the Unicode files from unicode.org + Fetch all the Unicode files from unicode.org. + + This will use cached files (stored in FETCH_DIR) if they exist, + creating them if they don't. In any case, the Unicode version + is always returned. :param version: The desired Unicode version, as string. - (If None, defaults to latest final release available). - :return: The version downloaded (UnicodeVersion object). + (If None, defaults to latest final release available, + querying the unicode.org service). """ - have_version = should_skip_fetch(version) + have_version = check_stored_version(version) if have_version: return have_version @@ -114,22 +146,26 @@ def fetch_files(version=None): print("Fetching: {}".format(readme_url)) readme_content = subprocess.check_output(("curl", readme_url)) - unicode_version = parse_unicode_version( + unicode_version = parse_readme_unicode_version( readme_content.decode("utf8") ) - download_dir = os.path.join(FETCH_DIR, unicode_version.as_str) + download_dir = get_unicode_dir(unicode_version) if not os.path.exists(download_dir): # for 2.7 compat, we don't use exist_ok=True os.makedirs(download_dir) for filename in UnicodeFiles.ALL_FILES: - file_path = os.path.join(download_dir, filename) + file_path = get_unicode_file_path(unicode_version, filename) + + if os.path.exists(file_path): + # assume file on the server didn't change if it's been saved before + continue if filename == UnicodeFiles.README: with open(file_path, "wb") as fd: fd.write(readme_content) - elif not os.path.exists(file_path): + else: url = get_fetch_url(filename) print("Fetching: {}".format(url)) subprocess.check_call(("curl", "-o", file_path, url)) @@ -137,10 +173,15 @@ def fetch_files(version=None): return unicode_version -def should_skip_fetch(version): +def check_stored_version(version): + # type: (Optional[str]) -> Optional[UnicodeVersion] + """ + Given desired Unicode version, return the version + if stored files are all present, and None otherwise. + """ if not version: # should always check latest version - return False + return None fetch_dir = os.path.join(FETCH_DIR, version) @@ -148,13 +189,17 @@ def should_skip_fetch(version): file_path = os.path.join(fetch_dir, filename) if not os.path.exists(file_path): - return False + return None with open(os.path.join(fetch_dir, UnicodeFiles.README)) as fd: - return parse_unicode_version(fd.read()) + return parse_readme_unicode_version(fd.read()) -def parse_unicode_version(readme_content): +def parse_readme_unicode_version(readme_content): + # type: (str) -> UnicodeVersion + """ + Parse the Unicode version contained in their ReadMe.txt file. + """ # "raw string" is necessary for \d not being treated as escape char # (for the sake of compat with future Python versions) # see: https://docs.python.org/3.6/whatsnew/3.6.html#deprecated-python-behavior @@ -164,45 +209,78 @@ def parse_unicode_version(readme_content): return UnicodeVersion(*map(int, groups), as_str=".".join(groups)) +def get_unicode_dir(unicode_version): + # type: (UnicodeVersion) -> str + """ + Indicate where the unicode data files should be stored. + + This returns a full, absolute path. + """ + return os.path.join(FETCH_DIR, unicode_version.as_str) + + def get_unicode_file_path(unicode_version, filename): - return os.path.join(FETCH_DIR, unicode_version.as_str, filename) + # type: (UnicodeVersion, str) -> str + """ + Indicate where the unicode data file should be stored. + """ + return os.path.join(get_unicode_dir(unicode_version), filename) def is_surrogate(n): - return SURROGATE_CODEPOINTS[0] <= n <= SURROGATE_CODEPOINTS[1] + # type: (int) -> bool + """ + Tell if given codepoint is a surrogate (not a valid Rust character). + """ + return SURROGATE_CODEPOINTS_RANGE[0] <= n <= SURROGATE_CODEPOINTS_RANGE[1] def load_unicode_data(file_path): - gencats = {} - to_lower = {} - to_upper = {} - to_title = {} - combines = {} - canon_decomp = {} - compat_decomp = {} - - udict = {} + # type: (str) -> UnicodeData + """ + Load main unicode data. + """ + # conversions + to_lower = {} # type: Dict[int, Tuple[int, int, int]] + to_upper = {} # type: Dict[int, Tuple[int, int, int]] + to_title = {} # type: Dict[int, Tuple[int, int, int]] + + # decompositions + compat_decomp = {} # type: Dict[int, List[int]] + canon_decomp = {} # type: Dict[int, List[int]] + + # combining characters + # FIXME: combines are not used + combines = defaultdict(set) # type: Dict[str, Set[int]] + + # categories + general_categories = defaultdict(set) # type: Dict[str, Set[int]] + category_assigned_codepoints = set() # type: Set[int] + + all_codepoints = {} + range_start = -1 + for line in fileinput.input(file_path): data = line.split(";") if len(data) != 15: continue - cp = int(data[0], 16) - if is_surrogate(cp): + codepoint = int(data[0], 16) + if is_surrogate(codepoint): continue if range_start >= 0: - for i in range(range_start, cp): - udict[i] = data + for i in range(range_start, codepoint): + all_codepoints[i] = data range_start = -1 if data[1].endswith(", First>"): - range_start = cp + range_start = codepoint continue - udict[cp] = data + all_codepoints[codepoint] = data - for code in udict: + for code, data in all_codepoints.items(): (code_org, name, gencat, combine, bidi, decomp, deci, digit, num, mirror, - old, iso, upcase, lowcase, titlecase) = udict[code] + old, iso, upcase, lowcase, titlecase) = data # generate char to char direct common and simple conversions # uppercase to lowercase @@ -218,46 +296,47 @@ def load_unicode_data(file_path): to_title[code] = (int(titlecase, 16), 0, 0) # store decomposition, if given - if decomp != "": + if decomp: + decompositions = decomp.split()[1:] + decomp_code_points = [int(i, 16) for i in decompositions] + if decomp.startswith("<"): - seq = [] - for i in decomp.split()[1:]: - seq.append(int(i, 16)) - compat_decomp[code] = seq + # compatibility decomposition + compat_decomp[code] = decomp_code_points else: - seq = [] - for i in decomp.split(): - seq.append(int(i, 16)) - canon_decomp[code] = seq + # canonical decomposition + canon_decomp[code] = decomp_code_points # place letter in categories as appropriate - for cat in [gencat, "Assigned"] + EXPANDED_CATEGORIES.get(gencat, []): - if cat not in gencats: - gencats[cat] = [] - gencats[cat].append(code) + for cat in itertools.chain((gencat, ), EXPANDED_CATEGORIES.get(gencat, [])): + general_categories[cat].add(code) + category_assigned_codepoints.add(code) # record combining class, if any if combine != "0": - if combine not in combines: - combines[combine] = [] - combines[combine].append(code) + combines[combine].add(code) # generate Not_Assigned from Assigned - gencats["Cn"] = gen_unassigned(gencats["Assigned"]) - # Assigned is not a real category - del(gencats["Assigned"]) + general_categories["Cn"] = get_unassigned_codepoints(category_assigned_codepoints) + # Other contains Not_Assigned - gencats["C"].extend(gencats["Cn"]) - gencats = group_cats(gencats) - combines = to_combines(group_cats(combines)) + general_categories["C"].update(general_categories["Cn"]) + + grouped_categories = group_categories(general_categories) + # FIXME: combines are not used return UnicodeData( - canon_decomp, compat_decomp, gencats, combines, to_upper, - to_lower, to_title, + to_lower=to_lower, to_upper=to_upper, to_title=to_title, + compat_decomp=compat_decomp, canon_decomp=canon_decomp, + general_categories=grouped_categories, combines=combines, ) def load_special_casing(file_path, unicode_data): + # type: (str, UnicodeData) -> None + """ + Load special casing data and enrich given unicode data. + """ for line in fileinput.input(file_path): data = line.split("#")[0].split(";") if len(data) == 5: @@ -277,258 +356,395 @@ def load_special_casing(file_path, unicode_data): (unicode_data.to_upper, upper), (unicode_data.to_title, title)): if values != code: - values = [int(i, 16) for i in values.split()] - for _ in range(len(values), 3): - values.append(0) - assert len(values) == 3 - map_[key] = values - - -def group_cats(cats): - cats_out = {} - for cat in cats: - cats_out[cat] = group_cat(cats[cat]) - return cats_out - - -def group_cat(cat): - cat_out = [] - letters = sorted(set(cat)) - cur_start = letters.pop(0) - cur_end = cur_start - for letter in letters: - assert letter > cur_end, \ - "cur_end: %s, letter: %s" % (hex(cur_end), hex(letter)) - if letter == cur_end + 1: - cur_end = letter - else: - cat_out.append((cur_start, cur_end)) - cur_start = cur_end = letter - cat_out.append((cur_start, cur_end)) - return cat_out + split = values.split() + + codepoints = list(itertools.chain( + (int(i, 16) for i in split), + (0 for _ in range(len(split), 3)) + )) + + assert len(codepoints) == 3 + map_[key] = codepoints + + +def group_categories(mapping): + # type: (Dict[Any, Iterable[int]]) -> Dict[str, List[Tuple[int, int]]] + """ + Group codepoints mapped in "categories". + """ + return {category: group_codepoints(codepoints) + for category, codepoints in mapping.items()} + + +def group_codepoints(codepoints): + # type: (Iterable[int]) -> List[Tuple[int, int]] + """ + Group integral values into continuous, disjoint value ranges. + + Performs value deduplication. + + :return: sorted list of pairs denoting start and end of codepoint + group values, both ends inclusive. + + >>> group_codepoints([1, 2, 10, 11, 12, 3, 4]) + [(1, 4), (10, 12)] + >>> group_codepoints([1]) + [(1, 1)] + >>> group_codepoints([1, 5, 6]) + [(1, 1), (5, 6)] + >>> group_codepoints([]) + [] + """ + sorted_codes = sorted(set(codepoints)) + result = [] # type: List[Tuple[int, int]] + if not sorted_codes: + return result -def ungroup_cat(cat): - cat_out = [] - for (lo, hi) in cat: - while lo <= hi: - cat_out.append(lo) - lo += 1 - return cat_out + next_codes = sorted_codes[1:] + start_code = sorted_codes[0] + for code, next_code in zip_longest(sorted_codes, next_codes, fillvalue=None): + if next_code is None or next_code - code != 1: + result.append((start_code, code)) + start_code = next_code -def gen_unassigned(assigned): - assigned = set(assigned) - return ([i for i in range(0, 0xd800) if i not in assigned] + - [i for i in range(0xe000, 0x110000) if i not in assigned]) + return result -def to_combines(combs): - combs_out = [] - for comb in combs: - for (lo, hi) in combs[comb]: - combs_out.append((lo, hi, comb)) - combs_out.sort(key=lambda c: c[0]) - return combs_out +def ungroup_codepoints(codepoint_pairs): + # type: (Iterable[Tuple[int, int]]) -> List[int] + """ + The inverse of group_codepoints -- produce a flat list of values + from value range pairs. + + >>> ungroup_codepoints([(1, 4), (10, 12)]) + [1, 2, 3, 4, 10, 11, 12] + >>> ungroup_codepoints([(1, 1), (5, 6)]) + [1, 5, 6] + >>> ungroup_codepoints(group_codepoints([1, 2, 7, 8])) + [1, 2, 7, 8] + >>> ungroup_codepoints([]) + [] + """ + return list(itertools.chain.from_iterable( + range(lo, hi + 1) for lo, hi in codepoint_pairs + )) + + +def get_unassigned_codepoints(assigned_codepoints): + # type: (Set[int]) -> Set[int] + """ + Given a set of "assigned" codepoints, return a set + of these that are not in assigned and not surrogate. + """ + return {i for i in range(0, 0x110000) + if i not in assigned_codepoints and not is_surrogate(i)} + + +def generate_table_lines(items, indent, wrap=98): + # type: (Iterable[str], int, int) -> Iterator[str] + """ + Given table items, generate wrapped lines of text with comma-separated items. + This is a generator function. -def format_table_content(f, content, indent): + :param wrap: soft wrap limit (characters per line), integer. + """ line = " " * indent first = True - for chunk in content.split(","): - if len(line) + len(chunk) < 98: + for item in items: + if len(line) + len(item) < wrap: if first: - line += chunk + line += item else: - line += ", " + chunk + line += ", " + item first = False else: - f.write(line + ",\n") - line = " " * indent + chunk - f.write(line) + yield line + ",\n" + line = " " * indent + item + yield line -def load_properties(file_path, interestingprops): - props = {} - # "raw string" is necessary for \w not to be treated as escape char + +def load_properties(file_path, interesting_props): + # type: (str, Iterable[str]) -> Dict[str, List[Tuple[int, int]]] + """ + Load properties data and return in grouped form. + """ + props = defaultdict(list) # type: Dict[str, List[Tuple[int, int]]] + # "raw string" is necessary for \. and \w not to be treated as escape chars # (for the sake of compat with future Python versions) # see: https://docs.python.org/3.6/whatsnew/3.6.html#deprecated-python-behavior re1 = re.compile(r"^ *([0-9A-F]+) *; *(\w+)") re2 = re.compile(r"^ *([0-9A-F]+)\.\.([0-9A-F]+) *; *(\w+)") for line in fileinput.input(file_path): - prop = None - d_lo = 0 - d_hi = 0 - m = re1.match(line) - if m: - d_lo = m.group(1) - d_hi = m.group(1) - prop = m.group(2) - else: - m = re2.match(line) - if m: - d_lo = m.group(1) - d_hi = m.group(2) - prop = m.group(3) + match = re1.match(line) or re2.match(line) + if match: + groups = match.groups() + + if len(groups) == 2: + # re1 matched + d_lo, prop = groups + d_hi = d_lo else: - continue - if interestingprops and prop not in interestingprops: + d_lo, d_hi, prop = groups + else: continue - d_lo = int(d_lo, 16) - d_hi = int(d_hi, 16) - if prop not in props: - props[prop] = [] - props[prop].append((d_lo, d_hi)) + + if interesting_props and prop not in interesting_props: + continue + + lo_value = int(d_lo, 16) + hi_value = int(d_hi, 16) + + props[prop].append((lo_value, hi_value)) # optimize if possible for prop in props: - props[prop] = group_cat(ungroup_cat(props[prop])) + props[prop] = group_codepoints(ungroup_codepoints(props[prop])) return props def escape_char(c): - return "'\\u{%x}'" % c if c != 0 else "'\\0'" + # type: (int) -> str + r""" + Escape a codepoint for use as Rust char literal. + Outputs are OK to use as Rust source code as char literals + and they also include necessary quotes. -def emit_table(f, name, t_data, t_type="&[(char, char)]", is_pub=True, - pfun=lambda x: "(%s,%s)" % (escape_char(x[0]), escape_char(x[1]))): + >>> escape_char(97) + "'\\u{61}'" + >>> escape_char(0) + "'\\0'" + """ + return r"'\u{%x}'" % c if c != 0 else r"'\0'" + + +def format_char_pair(pair): + # type: (Tuple[int, int]) -> str + """ + Format a pair of two Rust chars. + """ + return "(%s,%s)" % (escape_char(pair[0]), escape_char(pair[1])) + + +def generate_table( + name, # type: str + items, # type: List[Tuple[int, int]] + decl_type="&[(char, char)]", # type: str + is_pub=True, # type: bool + format_item=format_char_pair, # type: Callable[[Tuple[int, int]], str] +): + # type: (...) -> Iterator[str] + """ + Generate a nicely formatted Rust constant "table" array. + + This generates actual Rust code. + """ pub_string = "" if is_pub: pub_string = "pub " - f.write(" %sconst %s: %s = &[\n" % (pub_string, name, t_type)) - data = "" + + yield " %sconst %s: %s = &[\n" % (pub_string, name, decl_type) + + data = [] first = True - for dat in t_data: + for item in items: if not first: - data += "," + data.append(",") first = False - data += pfun(dat) - format_table_content(f, data, 8) - f.write("\n ];\n\n") + data.extend(format_item(item)) + + for table_line in generate_table_lines("".join(data).split(","), 8): + yield table_line + yield "\n ];\n\n" -def compute_trie(rawdata, chunksize): + +def compute_trie(raw_data, chunk_size): + # type: (List[int], int) -> Tuple[List[int], List[int]] + """ + Compute postfix-compressed trie. + + See: bool_trie.rs for more details. + + >>> compute_trie([1, 2, 3, 1, 2, 3, 4, 5, 6], 3) + ([0, 0, 1], [1, 2, 3, 4, 5, 6]) + >>> compute_trie([1, 2, 3, 1, 2, 4, 4, 5, 6], 3) + ([0, 1, 2], [1, 2, 3, 1, 2, 4, 4, 5, 6]) + """ root = [] - childmap = {} + childmap = {} # type: Dict[Tuple[int, ...], int] child_data = [] - for i in range(len(rawdata) // chunksize): - data = rawdata[i * chunksize: (i + 1) * chunksize] - child = "|".join(map(str, data)) + + assert len(raw_data) % chunk_size == 0, "Chunks must be equally sized" + + for i in range(len(raw_data) // chunk_size): + data = raw_data[i * chunk_size : (i + 1) * chunk_size] + + # postfix compression of child nodes (data chunks) + # (identical child nodes are shared) + + # make a tuple out of the list so it's hashable + child = tuple(data) if child not in childmap: childmap[child] = len(childmap) child_data.extend(data) + root.append(childmap[child]) + return root, child_data -def emit_bool_trie(f, name, t_data, is_pub=True): +def generate_bool_trie(name, codepoint_ranges, is_pub=True): + # type: (str, List[Tuple[int, int]], bool) -> Iterator[str] + """ + Generate Rust code for BoolTrie struct. + + This yields string fragments that should be joined to produce + the final string. + + See: bool_trie.rs + """ chunk_size = 64 rawdata = [False] * 0x110000 - for (lo, hi) in t_data: + for (lo, hi) in codepoint_ranges: for cp in range(lo, hi + 1): rawdata[cp] = True - # convert to bitmap chunks of 64 bits each + # convert to bitmap chunks of chunk_size bits each chunks = [] for i in range(0x110000 // chunk_size): chunk = 0 - for j in range(64): - if rawdata[i * 64 + j]: + for j in range(chunk_size): + if rawdata[i * chunk_size + j]: chunk |= 1 << j chunks.append(chunk) pub_string = "" if is_pub: pub_string = "pub " - f.write(" %sconst %s: &super::BoolTrie = &super::BoolTrie {\n" % (pub_string, name)) - f.write(" r1: [\n") - data = ",".join("0x%016x" % chunk for chunk in chunks[0:0x800 // chunk_size]) - format_table_content(f, data, 12) - f.write("\n ],\n") + yield " %sconst %s: &super::BoolTrie = &super::BoolTrie {\n" % (pub_string, name) + yield " r1: [\n" + data = ("0x%016x" % chunk for chunk in chunks[:0x800 // chunk_size]) + for fragment in generate_table_lines(data, 12): + yield fragment + yield "\n ],\n" # 0x800..0x10000 trie (r2, r3) = compute_trie(chunks[0x800 // chunk_size : 0x10000 // chunk_size], 64 // chunk_size) - f.write(" r2: [\n") - data = ",".join(str(node) for node in r2) - format_table_content(f, data, 12) - f.write("\n ],\n") - f.write(" r3: &[\n") - data = ",".join("0x%016x" % chunk for chunk in r3) - format_table_content(f, data, 12) - f.write("\n ],\n") + yield " r2: [\n" + data = map(str, r2) + for fragment in generate_table_lines(data, 12): + yield fragment + yield "\n ],\n" + + yield " r3: &[\n" + data = ("0x%016x" % node for node in r3) + for fragment in generate_table_lines(data, 12): + yield fragment + yield "\n ],\n" # 0x10000..0x110000 trie (mid, r6) = compute_trie(chunks[0x10000 // chunk_size : 0x110000 // chunk_size], 64 // chunk_size) (r4, r5) = compute_trie(mid, 64) - f.write(" r4: [\n") - data = ",".join(str(node) for node in r4) - format_table_content(f, data, 12) - f.write("\n ],\n") - f.write(" r5: &[\n") - data = ",".join(str(node) for node in r5) - format_table_content(f, data, 12) - f.write("\n ],\n") - f.write(" r6: &[\n") - data = ",".join("0x%016x" % chunk for chunk in r6) - format_table_content(f, data, 12) - f.write("\n ],\n") - - f.write(" };\n\n") - - -def emit_small_bool_trie(f, name, t_data, is_pub=True): - last_chunk = max(hi // 64 for (lo, hi) in t_data) + + yield " r4: [\n" + data = map(str, r4) + for fragment in generate_table_lines(data, 12): + yield fragment + yield "\n ],\n" + + yield " r5: &[\n" + data = map(str, r5) + for fragment in generate_table_lines(data, 12): + yield fragment + yield "\n ],\n" + + yield " r6: &[\n" + data = ("0x%016x" % node for node in r6) + for fragment in generate_table_lines(data, 12): + yield fragment + yield "\n ],\n" + + yield " };\n\n" + + +def generate_small_bool_trie(name, codepoint_ranges, is_pub=True): + # type: (str, List[Tuple[int, int]], bool) -> Iterator[str] + """ + Generate Rust code for SmallBoolTrie struct. + + See: bool_trie.rs + """ + last_chunk = max(hi // 64 for (lo, hi) in codepoint_ranges) n_chunks = last_chunk + 1 chunks = [0] * n_chunks - for (lo, hi) in t_data: + for (lo, hi) in codepoint_ranges: for cp in range(lo, hi + 1): - if cp // 64 >= len(chunks): - print(cp, cp // 64, len(chunks), lo, hi) + assert cp // 64 < len(chunks) chunks[cp // 64] |= 1 << (cp & 63) pub_string = "" if is_pub: pub_string = "pub " - f.write(" %sconst %s: &super::SmallBoolTrie = &super::SmallBoolTrie {\n" - % (pub_string, name)) + + yield (" %sconst %s: &super::SmallBoolTrie = &super::SmallBoolTrie {\n" + % (pub_string, name)) (r1, r2) = compute_trie(chunks, 1) - f.write(" r1: &[\n") - data = ",".join(str(node) for node in r1) - format_table_content(f, data, 12) - f.write("\n ],\n") + yield " r1: &[\n" + data = (str(node) for node in r1) + for fragment in generate_table_lines(data, 12): + yield fragment + yield "\n ],\n" + + yield " r2: &[\n" + data = ("0x%016x" % node for node in r2) + for fragment in generate_table_lines(data, 12): + yield fragment + yield "\n ],\n" - f.write(" r2: &[\n") - data = ",".join("0x%016x" % node for node in r2) - format_table_content(f, data, 12) - f.write("\n ],\n") + yield " };\n\n" - f.write(" };\n\n") +def generate_property_module(mod, grouped_categories, category_subset): + # type: (str, Dict[str, List[Tuple[int, int]]], Iterable[str]) -> Iterator[str] + """ + Generate Rust code for module defining properties. + """ -def emit_property_module(f, mod, tbl, emit): - f.write("pub mod %s {\n" % mod) - for cat in sorted(emit): - if cat in ["Cc", "White_Space", "Pattern_White_Space"]: - emit_small_bool_trie(f, "%s_table" % cat, tbl[cat]) - f.write(" pub fn %s(c: char) -> bool {\n" % cat) - f.write(" %s_table.lookup(c)\n" % cat) - f.write(" }\n\n") + yield "pub mod %s {\n" % mod + for cat in sorted(category_subset): + if cat in ("Cc", "White_Space", "Pattern_White_Space"): + generator = generate_small_bool_trie("%s_table" % cat, grouped_categories[cat]) else: - emit_bool_trie(f, "%s_table" % cat, tbl[cat]) - f.write(" pub fn %s(c: char) -> bool {\n" % cat) - f.write(" %s_table.lookup(c)\n" % cat) - f.write(" }\n\n") - f.write("}\n\n") + generator = generate_bool_trie("%s_table" % cat, grouped_categories[cat]) + + for fragment in generator: + yield fragment + + yield " pub fn %s(c: char) -> bool {\n" % cat + yield " %s_table.lookup(c)\n" % cat + yield " }\n\n" + + yield "}\n\n" + +def generate_conversions_module(unicode_data): + # type: (UnicodeData) -> Iterator[str] + """ + Generate Rust code for module defining conversions. + """ -def emit_conversions_module(f, unicode_data): - f.write("pub mod conversions {") - f.write(""" + yield "pub mod conversions {" + yield """ pub fn to_lower(c: char) -> [char; 3] { match bsearch_case_table(c, to_lowercase_table) { None => [c, '\\0', '\\0'], @@ -545,46 +761,39 @@ def emit_conversions_module(f, unicode_data): fn bsearch_case_table(c: char, table: &[(char, [char; 3])]) -> Option { table.binary_search_by(|&(key, _)| key.cmp(&c)).ok() - } - -""") - t_type = "&[(char, [char; 3])]" - pfun = lambda x: "(%s,[%s,%s,%s])" % ( - escape_char(x[0]), escape_char(x[1][0]), escape_char(x[1][1]), escape_char(x[1][2])) - - emit_table(f, - name="to_lowercase_table", - t_data=sorted(unicode_data.to_lower.items(), key=operator.itemgetter(0)), - t_type=t_type, - is_pub=False, - pfun=pfun) - - emit_table(f, - name="to_uppercase_table", - t_data=sorted(unicode_data.to_upper.items(), key=operator.itemgetter(0)), - t_type=t_type, - is_pub=False, - pfun=pfun) - - f.write("}\n") - - -def emit_norm_module(f, unicode_data, norm_props): - canon_keys = sorted(unicode_data.canon_decomp.keys()) - - canon_comp = {} - comp_exclusions = norm_props["Full_Composition_Exclusion"] - for char in canon_keys: - if any(lo <= char <= hi for lo, hi in comp_exclusions): - continue - decomp = unicode_data.canon_decomp[char] - if len(decomp) == 2: - if decomp[0] not in canon_comp: - canon_comp[decomp[0]] = [] - canon_comp[decomp[0]].append((decomp[1], char)) + }\n\n""" + + decl_type = "&[(char, [char; 3])]" + format_conversion = lambda x: "({},[{},{},{}])".format(*( + escape_char(c) for c in (x[0], x[1][0], x[1][1], x[1][2]) + )) + + for fragment in generate_table( + name="to_lowercase_table", + items=sorted(unicode_data.to_lower.items(), key=lambda x: x[0]), + decl_type=decl_type, + is_pub=False, + format_item=format_conversion + ): + yield fragment + + for fragment in generate_table( + name="to_uppercase_table", + items=sorted(unicode_data.to_upper.items(), key=lambda x: x[0]), + decl_type=decl_type, + is_pub=False, + format_item=format_conversion + ): + yield fragment + + yield "}\n" def parse_args(): + # type: () -> argparse.Namespace + """ + Parse command line arguments. + """ parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("-v", "--version", default=None, type=str, help="Unicode version to use (if not specified," @@ -594,56 +803,63 @@ def parse_args(): def main(): + # type: () -> None + """ + Script entry point. + """ args = parse_args() unicode_version = fetch_files(args.version) print("Using Unicode version: {}".format(unicode_version.as_str)) + # all the writing happens entirely in memory, we only write to file + # once we have generated the file content (it's not very large, <1 MB) + buf = StringIO() + buf.write(PREAMBLE) + + unicode_version_notice = textwrap.dedent(""" + /// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of + /// `char` and `str` methods are based on. + #[unstable(feature = "unicode_version", issue = "49726")] + pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion {{ + major: {version.major}, + minor: {version.minor}, + micro: {version.micro}, + _priv: (), + }}; + """).format(version=unicode_version) + buf.write(unicode_version_notice) + + get_path = lambda f: get_unicode_file_path(unicode_version, f) + + unicode_data = load_unicode_data(get_path(UnicodeFiles.UNICODE_DATA)) + load_special_casing(get_path(UnicodeFiles.SPECIAL_CASING), unicode_data) + + want_derived = {"XID_Start", "XID_Continue", "Alphabetic", "Lowercase", "Uppercase", + "Cased", "Case_Ignorable", "Grapheme_Extend"} + derived = load_properties(get_path(UnicodeFiles.DERIVED_CORE_PROPERTIES), want_derived) + + props = load_properties(get_path(UnicodeFiles.PROPS), + {"White_Space", "Join_Control", "Noncharacter_Code_Point", + "Pattern_White_Space"}) + + # category tables + for (name, categories, category_subset) in ( + ("general_category", unicode_data.general_categories, ["N", "Cc"]), + ("derived_property", derived, want_derived), + ("property", props, ["White_Space", "Pattern_White_Space"]) + ): + for fragment in generate_property_module(name, categories, category_subset): + buf.write(fragment) + + for fragment in generate_conversions_module(unicode_data): + buf.write(fragment) + tables_rs_path = os.path.join(THIS_DIR, "tables.rs") # will overwrite the file if it exists - with open(tables_rs_path, "w") as rf: - rf.write(PREAMBLE) - - unicode_version_notice = textwrap.dedent(""" - /// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of - /// `char` and `str` methods are based on. - #[unstable(feature = "unicode_version", issue = "49726")] - pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion {{ - major: {version.major}, - minor: {version.minor}, - micro: {version.micro}, - _priv: (), - }}; - """).format(version=unicode_version) - rf.write(unicode_version_notice) - - get_path = lambda f: get_unicode_file_path(unicode_version, f) - - unicode_data = load_unicode_data(get_path(UnicodeFiles.UNICODE_DATA)) - load_special_casing(get_path(UnicodeFiles.SPECIAL_CASING), unicode_data) - - want_derived = ["XID_Start", "XID_Continue", "Alphabetic", "Lowercase", "Uppercase", - "Cased", "Case_Ignorable", "Grapheme_Extend"] - derived = load_properties(get_path(UnicodeFiles.DERIVED_CORE_PROPERTIES), want_derived) - - # FIXME scripts not used? - scripts = load_properties(get_path(UnicodeFiles.SCRIPTS), []) - props = load_properties(get_path(UnicodeFiles.PROPS), - ["White_Space", "Join_Control", "Noncharacter_Code_Point", - "Pattern_White_Space"]) - norm_props = load_properties(get_path(UnicodeFiles.DERIVED_NORMALIZATION_PROPS), - ["Full_Composition_Exclusion"]) - - # category tables - for (name, cat, pfuns) in (("general_category", unicode_data.gencats, ["N", "Cc"]), - ("derived_property", derived, want_derived), - ("property", props, ["White_Space", "Pattern_White_Space"])): - emit_property_module(rf, name, cat, pfuns) - - # normalizations and conversions module - emit_norm_module(rf, unicode_data, norm_props) - emit_conversions_module(rf, unicode_data) + with open(tables_rs_path, "w") as fd: + fd.write(buf.getvalue()) print("Regenerated tables.rs.") From 60ccf89693037b3c010b027081d253b9c69a304c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Romanowski?= Date: Mon, 10 Jun 2019 20:45:58 +0200 Subject: [PATCH 05/15] Apply suggestions from code review Co-Authored-By: varkor --- src/libcore/unicode/unicode.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libcore/unicode/unicode.py b/src/libcore/unicode/unicode.py index f66e82299100d..9eaf6eb9baa9e 100755 --- a/src/libcore/unicode/unicode.py +++ b/src/libcore/unicode/unicode.py @@ -36,7 +36,7 @@ try: # completely optional type hinting # (Python 2 compatible using comments, - # see: https://mypy.readthedocs.io/en/latest/python2.html) + # see: https://mypy.readthedocs.io/en/latest/python2.html) # This is very helpful in typing-aware IDE like PyCharm. from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Set, Tuple except ImportError: @@ -95,7 +95,8 @@ class UnicodeFiles(object): "Cc": ["C"], "Cf": ["C"], "Cs": ["C"], "Co": ["C"], "Cn": ["C"], } -# this is the surrogate codepoints range (both ends inclusive) +# This is the (inclusive) range of surrogate codepoints. +# These are not valid Rust characters. # - they are not valid Rust characters SURROGATE_CODEPOINTS_RANGE = (0xd800, 0xdfff) @@ -122,7 +123,7 @@ def fetch_files(version=None): """ Fetch all the Unicode files from unicode.org. - This will use cached files (stored in FETCH_DIR) if they exist, + This will use cached files (stored in `FETCH_DIR`) if they exist, creating them if they don't. In any case, the Unicode version is always returned. @@ -797,7 +798,7 @@ def parse_args(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("-v", "--version", default=None, type=str, help="Unicode version to use (if not specified," - " defaults to latest available final release).") + " defaults to latest release).") return parser.parse_args() From 2b47a085dd418447f1dd79986df94dd051f27c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Romanowski?= Date: Mon, 10 Jun 2019 21:13:01 +0200 Subject: [PATCH 06/15] Address review remarks in unicode.py --- src/libcore/unicode/unicode.py | 116 +++++++++++++++++---------------- 1 file changed, 61 insertions(+), 55 deletions(-) diff --git a/src/libcore/unicode/unicode.py b/src/libcore/unicode/unicode.py index 9eaf6eb9baa9e..a0539cd9ca9b6 100755 --- a/src/libcore/unicode/unicode.py +++ b/src/libcore/unicode/unicode.py @@ -34,7 +34,7 @@ from StringIO import StringIO try: - # completely optional type hinting + # Completely optional type hinting # (Python 2 compatible using comments, # see: https://mypy.readthedocs.io/en/latest/python2.html) # This is very helpful in typing-aware IDE like PyCharm. @@ -43,9 +43,9 @@ pass -# we don't use enum.Enum because of Python 2.7 compatibility +# We don't use enum.Enum because of Python 2.7 compatibility. class UnicodeFiles(object): - # ReadMe does not contain any unicode data, we + # ReadMe does not contain any Unicode data, we # only use it to extract versions. README = "ReadMe.txt" @@ -57,11 +57,15 @@ class UnicodeFiles(object): UNICODE_DATA = "UnicodeData.txt" -UnicodeFiles.ALL_FILES = tuple( - getattr(UnicodeFiles, name) for name in dir(UnicodeFiles) +# The order doesn't really matter (Python < 3.6 won't preserve it), +# we only want to aggregate all the file names. +ALL_UNICODE_FILES = tuple( + value for name, value in UnicodeFiles.__dict__.items() if not name.startswith("_") ) +assert len(ALL_UNICODE_FILES) == 7, "Unexpected number of unicode files" + # The directory this file is located in. THIS_DIR = os.path.dirname(os.path.realpath(__file__)) @@ -97,18 +101,17 @@ class UnicodeFiles(object): # This is the (inclusive) range of surrogate codepoints. # These are not valid Rust characters. -# - they are not valid Rust characters SURROGATE_CODEPOINTS_RANGE = (0xd800, 0xdfff) UnicodeData = namedtuple( "UnicodeData", ( - # conversions: + # Conversions: "to_upper", "to_lower", "to_title", - # decompositions: canonical decompositions, compatibility decomp + # Decompositions: canonical decompositions, compatibility decomp "canon_decomp", "compat_decomp", - # grouped: general categories and combining characters + # Grouped: general categories and combining characters "general_categories", "combines", ) ) @@ -136,10 +139,10 @@ def fetch_files(version=None): return have_version if version: - # check if the desired version exists on the server + # Check if the desired version exists on the server. get_fetch_url = lambda name: FETCH_URL_VERSION.format(version=version, filename=name) else: - # extract the latest version + # Extract the latest version. get_fetch_url = lambda name: FETCH_URL_LATEST.format(filename=name) readme_url = get_fetch_url(UnicodeFiles.README) @@ -153,14 +156,14 @@ def fetch_files(version=None): download_dir = get_unicode_dir(unicode_version) if not os.path.exists(download_dir): - # for 2.7 compat, we don't use exist_ok=True + # For 2.7 compat, we don't use `exist_ok=True`. os.makedirs(download_dir) - for filename in UnicodeFiles.ALL_FILES: + for filename in ALL_UNICODE_FILES: file_path = get_unicode_file_path(unicode_version, filename) if os.path.exists(file_path): - # assume file on the server didn't change if it's been saved before + # Assume file on the server didn't change if it's been saved before. continue if filename == UnicodeFiles.README: @@ -178,15 +181,16 @@ def check_stored_version(version): # type: (Optional[str]) -> Optional[UnicodeVersion] """ Given desired Unicode version, return the version - if stored files are all present, and None otherwise. + if stored files are all present, and `None` otherwise. """ if not version: - # should always check latest version + # If no desired version specified, we should check what's the latest + # version, skipping stored version checks. return None fetch_dir = os.path.join(FETCH_DIR, version) - for filename in UnicodeFiles.ALL_FILES: + for filename in ALL_UNICODE_FILES: file_path = os.path.join(fetch_dir, filename) if not os.path.exists(file_path): @@ -199,11 +203,11 @@ def check_stored_version(version): def parse_readme_unicode_version(readme_content): # type: (str) -> UnicodeVersion """ - Parse the Unicode version contained in their ReadMe.txt file. + Parse the Unicode version contained in their `ReadMe.txt` file. """ - # "raw string" is necessary for \d not being treated as escape char - # (for the sake of compat with future Python versions) - # see: https://docs.python.org/3.6/whatsnew/3.6.html#deprecated-python-behavior + # "Raw string" is necessary for \d not being treated as escape char + # (for the sake of compat with future Python versions). + # See: https://docs.python.org/3.6/whatsnew/3.6.html#deprecated-python-behavior pattern = r"for Version (\d+)\.(\d+)\.(\d+) of the Unicode" groups = re.search(pattern, readme_content).groups() @@ -213,7 +217,7 @@ def parse_readme_unicode_version(readme_content): def get_unicode_dir(unicode_version): # type: (UnicodeVersion) -> str """ - Indicate where the unicode data files should be stored. + Indicate in which parent dir the Unicode data files should be stored. This returns a full, absolute path. """ @@ -223,7 +227,7 @@ def get_unicode_dir(unicode_version): def get_unicode_file_path(unicode_version, filename): # type: (UnicodeVersion, str) -> str """ - Indicate where the unicode data file should be stored. + Indicate where the Unicode data file should be stored. """ return os.path.join(get_unicode_dir(unicode_version), filename) @@ -239,22 +243,22 @@ def is_surrogate(n): def load_unicode_data(file_path): # type: (str) -> UnicodeData """ - Load main unicode data. + Load main Unicode data. """ - # conversions + # Conversions to_lower = {} # type: Dict[int, Tuple[int, int, int]] to_upper = {} # type: Dict[int, Tuple[int, int, int]] to_title = {} # type: Dict[int, Tuple[int, int, int]] - # decompositions + # Decompositions compat_decomp = {} # type: Dict[int, List[int]] canon_decomp = {} # type: Dict[int, List[int]] - # combining characters + # Combining characters # FIXME: combines are not used combines = defaultdict(set) # type: Dict[str, Set[int]] - # categories + # Categories general_categories = defaultdict(set) # type: Dict[str, Set[int]] category_assigned_codepoints = set() # type: Set[int] @@ -283,41 +287,42 @@ def load_unicode_data(file_path): decomp, deci, digit, num, mirror, old, iso, upcase, lowcase, titlecase) = data - # generate char to char direct common and simple conversions - # uppercase to lowercase + # Generate char to char direct common and simple conversions: + + # Uppercase to lowercase if lowcase != "" and code_org != lowcase: to_lower[code] = (int(lowcase, 16), 0, 0) - # lowercase to uppercase + # Lowercase to uppercase if upcase != "" and code_org != upcase: to_upper[code] = (int(upcase, 16), 0, 0) - # title case + # Title case if titlecase.strip() != "" and code_org != titlecase: to_title[code] = (int(titlecase, 16), 0, 0) - # store decomposition, if given + # Store decomposition, if given if decomp: decompositions = decomp.split()[1:] decomp_code_points = [int(i, 16) for i in decompositions] if decomp.startswith("<"): - # compatibility decomposition + # Compatibility decomposition compat_decomp[code] = decomp_code_points else: - # canonical decomposition + # Canonical decomposition canon_decomp[code] = decomp_code_points - # place letter in categories as appropriate + # Place letter in categories as appropriate. for cat in itertools.chain((gencat, ), EXPANDED_CATEGORIES.get(gencat, [])): general_categories[cat].add(code) category_assigned_codepoints.add(code) - # record combining class, if any + # Record combining class, if any. if combine != "0": combines[combine].add(code) - # generate Not_Assigned from Assigned + # Generate Not_Assigned from Assigned. general_categories["Cn"] = get_unassigned_codepoints(category_assigned_codepoints) # Other contains Not_Assigned @@ -336,7 +341,7 @@ def load_unicode_data(file_path): def load_special_casing(file_path, unicode_data): # type: (str, UnicodeData) -> None """ - Load special casing data and enrich given unicode data. + Load special casing data and enrich given Unicode data. """ for line in fileinput.input(file_path): data = line.split("#")[0].split(";") @@ -474,9 +479,9 @@ def load_properties(file_path, interesting_props): Load properties data and return in grouped form. """ props = defaultdict(list) # type: Dict[str, List[Tuple[int, int]]] - # "raw string" is necessary for \. and \w not to be treated as escape chars - # (for the sake of compat with future Python versions) - # see: https://docs.python.org/3.6/whatsnew/3.6.html#deprecated-python-behavior + # "Raw string" is necessary for `\.` and `\w` not to be treated as escape chars + # (for the sake of compat with future Python versions). + # See: https://docs.python.org/3.6/whatsnew/3.6.html#deprecated-python-behavior re1 = re.compile(r"^ *([0-9A-F]+) *; *(\w+)") re2 = re.compile(r"^ *([0-9A-F]+)\.\.([0-9A-F]+) *; *(\w+)") @@ -486,7 +491,7 @@ def load_properties(file_path, interesting_props): groups = match.groups() if len(groups) == 2: - # re1 matched + # `re1` matched (2 groups). d_lo, prop = groups d_hi = d_lo else: @@ -502,7 +507,7 @@ def load_properties(file_path, interesting_props): props[prop].append((lo_value, hi_value)) - # optimize if possible + # Optimize if possible. for prop in props: props[prop] = group_codepoints(ungroup_codepoints(props[prop])) @@ -587,10 +592,10 @@ def compute_trie(raw_data, chunk_size): for i in range(len(raw_data) // chunk_size): data = raw_data[i * chunk_size : (i + 1) * chunk_size] - # postfix compression of child nodes (data chunks) - # (identical child nodes are shared) + # Postfix compression of child nodes (data chunks) + # (identical child nodes are shared). - # make a tuple out of the list so it's hashable + # Make a tuple out of the list so it's hashable. child = tuple(data) if child not in childmap: childmap[child] = len(childmap) @@ -609,7 +614,7 @@ def generate_bool_trie(name, codepoint_ranges, is_pub=True): This yields string fragments that should be joined to produce the final string. - See: bool_trie.rs + See: `bool_trie.rs`. """ chunk_size = 64 rawdata = [False] * 0x110000 @@ -617,7 +622,7 @@ def generate_bool_trie(name, codepoint_ranges, is_pub=True): for cp in range(lo, hi + 1): rawdata[cp] = True - # convert to bitmap chunks of chunk_size bits each + # Convert to bitmap chunks of `chunk_size` bits each. chunks = [] for i in range(0x110000 // chunk_size): chunk = 0 @@ -679,9 +684,9 @@ def generate_bool_trie(name, codepoint_ranges, is_pub=True): def generate_small_bool_trie(name, codepoint_ranges, is_pub=True): # type: (str, List[Tuple[int, int]], bool) -> Iterator[str] """ - Generate Rust code for SmallBoolTrie struct. + Generate Rust code for `SmallBoolTrie` struct. - See: bool_trie.rs + See: `bool_trie.rs`. """ last_chunk = max(hi // 64 for (lo, hi) in codepoint_ranges) n_chunks = last_chunk + 1 @@ -813,8 +818,8 @@ def main(): unicode_version = fetch_files(args.version) print("Using Unicode version: {}".format(unicode_version.as_str)) - # all the writing happens entirely in memory, we only write to file - # once we have generated the file content (it's not very large, <1 MB) + # All the writing happens entirely in memory, we only write to file + # once we have generated the file content (it's not very large, <1 MB). buf = StringIO() buf.write(PREAMBLE) @@ -844,7 +849,7 @@ def main(): {"White_Space", "Join_Control", "Noncharacter_Code_Point", "Pattern_White_Space"}) - # category tables + # Category tables for (name, categories, category_subset) in ( ("general_category", unicode_data.general_categories, ["N", "Cc"]), ("derived_property", derived, want_derived), @@ -858,7 +863,8 @@ def main(): tables_rs_path = os.path.join(THIS_DIR, "tables.rs") - # will overwrite the file if it exists + # Actually write out the file content. + # Will overwrite the file if it exists. with open(tables_rs_path, "w") as fd: fd.write(buf.getvalue()) From 05c1e92787d134c53a38c5eea7100caa7441fccd Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 5 Jul 2019 18:47:55 +0000 Subject: [PATCH 07/15] Correct definition of CONSOLE_SCREEN_BUFFER_INFO --- src/libterm/win.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/libterm/win.rs b/src/libterm/win.rs index 14ea68d378878..f5c60ee352276 100644 --- a/src/libterm/win.rs +++ b/src/libterm/win.rs @@ -20,19 +20,36 @@ pub struct WinConsole { background: color::Color, } +type SHORT = i16; type WORD = u16; type DWORD = u32; type BOOL = i32; type HANDLE = *mut u8; +#[allow(non_snake_case)] +#[repr(C)] +struct SMALL_RECT { + Left: SHORT, + Top: SHORT, + Right: SHORT, + Bottom: SHORT, +} + +#[allow(non_snake_case)] +#[repr(C)] +struct COORD { + X: SHORT, + Y: SHORT, +} + #[allow(non_snake_case)] #[repr(C)] struct CONSOLE_SCREEN_BUFFER_INFO { - dwSize: [libc::c_short; 2], - dwCursorPosition: [libc::c_short; 2], + dwSize: COORD, + dwCursorPosition: COORD, wAttributes: WORD, - srWindow: [libc::c_short; 4], - dwMaximumWindowSize: [libc::c_short; 2], + srWindow: SMALL_RECT, + dwMaximumWindowSize: COORD, } #[allow(non_snake_case)] From 42c3d3714508c9ab51e5c83dd78a37dbc5e2890c Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 5 Jul 2019 18:59:56 +0000 Subject: [PATCH 08/15] Remove use of mem::uninitialized in libterm crate --- src/libterm/win.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libterm/win.rs b/src/libterm/win.rs index f5c60ee352276..e5911de8396c1 100644 --- a/src/libterm/win.rs +++ b/src/libterm/win.rs @@ -2,8 +2,6 @@ // FIXME (#13400): this is only a tiny fraction of the Windows console api -extern crate libc; - use std::io; use std::io::prelude::*; @@ -122,12 +120,17 @@ impl WinConsole { /// Returns `None` whenever the terminal cannot be created for some reason. pub fn new(out: T) -> io::Result> { + use std::mem::MaybeUninit; + let fg; let bg; unsafe { - #[allow(deprecated)] - let mut buffer_info = ::std::mem::uninitialized(); - if GetConsoleScreenBufferInfo(GetStdHandle(-11i32 as DWORD), &mut buffer_info) != 0 { + let mut buffer_info = MaybeUninit::::uninit(); + if GetConsoleScreenBufferInfo( + GetStdHandle(-11i32 as DWORD), + buffer_info.as_mut_ptr() + ) != 0 { + let buffer_info = buffer_info.assume_init() ; fg = bits_to_color(buffer_info.wAttributes); bg = bits_to_color(buffer_info.wAttributes >> 4); } else { From 7646d4935b50c02f97545705af46ab46116db91d Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 5 Jul 2019 19:26:25 +0000 Subject: [PATCH 09/15] Remove use of mem::uninitialized in code_gen crate --- src/librustc_codegen_llvm/common.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs index 9fdc93c3ff0f3..3b2701b893bb1 100644 --- a/src/librustc_codegen_llvm/common.rs +++ b/src/librustc_codegen_llvm/common.rs @@ -170,8 +170,7 @@ impl CodegenCx<'ll, 'tcx> { pub fn const_get_real(&self, v: &'ll Value) -> Option<(f64, bool)> { unsafe { if self.is_const_real(v) { - #[allow(deprecated)] - let mut loses_info: llvm::Bool = ::std::mem::uninitialized(); + let mut loses_info: llvm::Bool = 0; let r = llvm::LLVMConstRealGetDouble(v, &mut loses_info); let loses_info = if loses_info == 1 { true } else { false }; Some((r, loses_info)) From 5eb662f302c881053110470543801f7f1f43188a Mon Sep 17 00:00:00 2001 From: topecongiro Date: Sat, 6 Jul 2019 14:32:56 +0900 Subject: [PATCH 10/15] Update rustfmt to 1.3.2 --- Cargo.lock | 46 ++++++++++++++++------------------------------ src/tools/rustfmt | 2 +- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e6d5d512d6ebe..6451769ad1f62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -327,18 +327,6 @@ dependencies = [ "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "cargo_metadata" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "cargo_metadata" version = "0.8.0" @@ -794,12 +782,11 @@ dependencies = [ [[package]] name = "dirs" -version = "1.0.5" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_users 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "dirs-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2386,7 +2373,7 @@ dependencies = [ "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-workspace-hack 1.0.0", "rustc_tools_util 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustfmt-nightly 1.3.0", + "rustfmt-nightly 1.3.2", "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_ignored 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3212,7 +3199,7 @@ dependencies = [ [[package]] name = "rustfmt-config_proc_macro" -version = "0.1.0" +version = "0.1.2" dependencies = [ "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3222,15 +3209,15 @@ dependencies = [ [[package]] name = "rustfmt-nightly" -version = "1.3.0" +version = "1.3.2" dependencies = [ "annotate-snippets 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "bytecount 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cargo_metadata 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cargo_metadata 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", - "dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "dirs 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3243,10 +3230,10 @@ dependencies = [ "rustc-ap-syntax 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-ap-syntax_pos 491.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-workspace-hack 1.0.0", - "rustfmt-config_proc_macro 0.1.0", + "rustfmt-config_proc_macro 0.1.2", "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", - "structopt 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", + "structopt 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3489,16 +3476,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "structopt" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", - "structopt-derive 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", + "structopt-derive 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "structopt-derive" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4237,7 +4224,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d" "checksum bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "40ade3d27603c2cb345eb0912aec461a6dec7e06a4ae48589904e808335c7afa" "checksum bytesize 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "716960a18f978640f25101b5cbf1c6f6b0d3192fab36a2d98ca96f0ecbe41010" -"checksum cargo_metadata 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "585784cac9b05c93a53b17a0b24a5cdd1dfdda5256f030e089b549d2390cc720" "checksum cargo_metadata 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "929766d993a2fde7a0ae962ee82429069cd7b68839cd9375b98efd719df65d3a" "checksum cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)" = "5e5f3fee5eeb60324c2781f1e41286bdee933850fff9b3c672587fed5ec58c83" "checksum cfg-if 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "89431bba4e6b7092fb5fcd00a6f6ca596c55cc26b2f1e6dcdd08a1f4933f66b2" @@ -4277,7 +4263,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" "checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90" "checksum directories 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ccc83e029c3cebb4c8155c644d34e3a070ccdb4ff90d369c74cd73f7cb3c984" -"checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" +"checksum dirs 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1c4ef5a8b902d393339e2a2c7fe573af92ce7e0ee5a3ff827b4c9ad7e07e4fa1" "checksum dirs-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "937756392ec77d1f2dd9dc3ac9d69867d109a2121479d72c364e42f4cab21e2d" "checksum dlmalloc 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f283302e035e61c23f2b86b3093e8c6273a4c3125742d6087e96ade001ca5e63" "checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0" @@ -4489,8 +4475,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum string_cache_shared 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc" "checksum strip-ansi-escapes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d63676e2abafa709460982ddc02a3bb586b6d15a49b75c212e06edd3933acee" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" -"checksum structopt 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)" = "fa19a5a708e22bb5be31c1b6108a2a902f909c4b9ba85cba44c06632386bc0ff" -"checksum structopt-derive 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)" = "c6d59d0ae8ef8de16e49e3ca7afa16024a3e0dfd974a75ef93fdc5464e34523f" +"checksum structopt 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "16c2cdbf9cc375f15d1b4141bc48aeef444806655cd0e904207edc8d68d86ed7" +"checksum structopt-derive 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "53010261a84b37689f9ed7d395165029f9cc7abb9f56bbfe86bee2597ed25107" "checksum strum 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f6c3a2071519ab6a48f465808c4c1ffdd00dfc8e93111d02b4fc5abab177676e" "checksum strum_macros 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8baacebd7b7c9b864d83a6ba7a246232983e277b86fa5cdec77f565715a4b136" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" diff --git a/src/tools/rustfmt b/src/tools/rustfmt index d33450247b17d..679c8d5f106e8 160000 --- a/src/tools/rustfmt +++ b/src/tools/rustfmt @@ -1 +1 @@ -Subproject commit d33450247b17d92a951d9663822c5a3635a37dde +Subproject commit 679c8d5f106e8442bf8c4a54609a63df9eb3863c From 45dda939ab558b244d9099798047ec6e6376cff1 Mon Sep 17 00:00:00 2001 From: Andrew Xu Date: Mon, 1 Jul 2019 22:18:45 +0800 Subject: [PATCH 11/15] Move async-await tests from run-pass to ui --- src/test/{run-pass => ui}/async-await/async-fn-size.rs | 5 +++-- src/test/{run-pass => ui}/async-await/issue-60709.rs | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) rename src/test/{run-pass => ui}/async-await/async-fn-size.rs (98%) rename src/test/{run-pass => ui}/async-await/issue-60709.rs (98%) diff --git a/src/test/run-pass/async-await/async-fn-size.rs b/src/test/ui/async-await/async-fn-size.rs similarity index 98% rename from src/test/run-pass/async-await/async-fn-size.rs rename to src/test/ui/async-await/async-fn-size.rs index 7396918196c08..e4dfd4d829e69 100644 --- a/src/test/run-pass/async-await/async-fn-size.rs +++ b/src/test/ui/async-await/async-fn-size.rs @@ -1,9 +1,10 @@ +// run-pass + // edition:2018 #![feature(async_await)] -#[path = "../auxiliary/arc_wake.rs"] -mod arc_wake; +extern crate arc_wake; use std::pin::Pin; use std::future::Future; diff --git a/src/test/run-pass/async-await/issue-60709.rs b/src/test/ui/async-await/issue-60709.rs similarity index 98% rename from src/test/run-pass/async-await/issue-60709.rs rename to src/test/ui/async-await/issue-60709.rs index 5ebb18b999ab6..ad0b49fa4a219 100644 --- a/src/test/run-pass/async-await/issue-60709.rs +++ b/src/test/ui/async-await/issue-60709.rs @@ -2,6 +2,8 @@ // handled incorrectly in generators. // compile-flags: -Copt-level=z -Cdebuginfo=2 --edition=2018 +// run-pass + #![feature(async_await)] #![allow(unused)] From b14a2ec400aa58a71a8e69a05f8bb41f3b571c2b Mon Sep 17 00:00:00 2001 From: Andrew Xu Date: Wed, 3 Jul 2019 22:37:33 +0800 Subject: [PATCH 12/15] Remove duplicated arc_wake.rs The auxiliary file arc_wake.rs is in run-pass/auxiliary and also ui/async-await/auxiliary. Remove the former one as their contents are same. Move run-pass/futures-api.rs to ui/async-await/futures-api.rs as it needs to use arc_wake.rs. --- src/test/run-pass/auxiliary/arc_wake.rs | 64 ------------------- .../async-await}/futures-api.rs | 2 + 2 files changed, 2 insertions(+), 64 deletions(-) delete mode 100644 src/test/run-pass/auxiliary/arc_wake.rs rename src/test/{run-pass => ui/async-await}/futures-api.rs (98%) diff --git a/src/test/run-pass/auxiliary/arc_wake.rs b/src/test/run-pass/auxiliary/arc_wake.rs deleted file mode 100644 index c21886f26f467..0000000000000 --- a/src/test/run-pass/auxiliary/arc_wake.rs +++ /dev/null @@ -1,64 +0,0 @@ -// edition:2018 - -use std::sync::Arc; -use std::task::{ - Waker, RawWaker, RawWakerVTable, -}; - -macro_rules! waker_vtable { - ($ty:ident) => { - &RawWakerVTable::new( - clone_arc_raw::<$ty>, - wake_arc_raw::<$ty>, - wake_by_ref_arc_raw::<$ty>, - drop_arc_raw::<$ty>, - ) - }; -} - -pub trait ArcWake { - fn wake(self: Arc); - - fn wake_by_ref(arc_self: &Arc) { - arc_self.clone().wake() - } - - fn into_waker(wake: Arc) -> Waker where Self: Sized - { - let ptr = Arc::into_raw(wake) as *const (); - - unsafe { - Waker::from_raw(RawWaker::new(ptr, waker_vtable!(Self))) - } - } -} - -unsafe fn increase_refcount(data: *const ()) { - // Retain Arc by creating a copy - let arc: Arc = Arc::from_raw(data as *const T); - let arc_clone = arc.clone(); - // Forget the Arcs again, so that the refcount isn't decrased - let _ = Arc::into_raw(arc); - let _ = Arc::into_raw(arc_clone); -} - -unsafe fn clone_arc_raw(data: *const ()) -> RawWaker { - increase_refcount::(data); - RawWaker::new(data, waker_vtable!(T)) -} - -unsafe fn drop_arc_raw(data: *const ()) { - // Drop Arc - let _: Arc = Arc::from_raw(data as *const T); -} - -unsafe fn wake_arc_raw(data: *const ()) { - let arc: Arc = Arc::from_raw(data as *const T); - ArcWake::wake(arc); -} - -unsafe fn wake_by_ref_arc_raw(data: *const ()) { - let arc: Arc = Arc::from_raw(data as *const T); - ArcWake::wake_by_ref(&arc); - let _ = Arc::into_raw(arc); -} diff --git a/src/test/run-pass/futures-api.rs b/src/test/ui/async-await/futures-api.rs similarity index 98% rename from src/test/run-pass/futures-api.rs rename to src/test/ui/async-await/futures-api.rs index ee77053fd5b6a..a7da058de3081 100644 --- a/src/test/run-pass/futures-api.rs +++ b/src/test/ui/async-await/futures-api.rs @@ -1,3 +1,5 @@ +// run-pass + // aux-build:arc_wake.rs extern crate arc_wake; From 73aee89b47972da57b0f0b1c99ba4e2893ad0a20 Mon Sep 17 00:00:00 2001 From: Andrew Xu Date: Wed, 3 Jul 2019 23:10:03 +0800 Subject: [PATCH 13/15] Move the test async-fn-size-moved-locals to ui --- .../{run-pass => ui}/async-await/async-fn-size-moved-locals.rs | 2 ++ 1 file changed, 2 insertions(+) rename src/test/{run-pass => ui}/async-await/async-fn-size-moved-locals.rs (99%) diff --git a/src/test/run-pass/async-await/async-fn-size-moved-locals.rs b/src/test/ui/async-await/async-fn-size-moved-locals.rs similarity index 99% rename from src/test/run-pass/async-await/async-fn-size-moved-locals.rs rename to src/test/ui/async-await/async-fn-size-moved-locals.rs index 139be7fe0132b..8d24ffe7a7c8c 100644 --- a/src/test/run-pass/async-await/async-fn-size-moved-locals.rs +++ b/src/test/ui/async-await/async-fn-size-moved-locals.rs @@ -7,6 +7,8 @@ // // See issue #59123 for a full explanation. +// run-pass + // edition:2018 #![feature(async_await)] From f115147fc481a4431116be526ce4dec315b1f871 Mon Sep 17 00:00:00 2001 From: Andrew Xu Date: Thu, 4 Jul 2019 21:04:20 +0800 Subject: [PATCH 14/15] Add missing aux-build directive --- src/test/ui/async-await/async-fn-size.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/async-await/async-fn-size.rs b/src/test/ui/async-await/async-fn-size.rs index e4dfd4d829e69..c6b2ed13b0a8d 100644 --- a/src/test/ui/async-await/async-fn-size.rs +++ b/src/test/ui/async-await/async-fn-size.rs @@ -1,5 +1,5 @@ // run-pass - +// aux-build:arc_wake.rs // edition:2018 #![feature(async_await)] From 79c760a67bc09926d1b233c4be5ee1fbdf472520 Mon Sep 17 00:00:00 2001 From: Samy Kacimi Date: Sat, 6 Jul 2019 09:48:03 +0200 Subject: [PATCH 15/15] normalize use of backticks/lowercase in compiler messages for librustc_mir https://github.com/rust-lang/rust/issues/60532 r? @alexreg --- src/librustc_mir/build/matches/mod.rs | 2 +- src/librustc_mir/hair/pattern/check_match.rs | 4 +- src/librustc_mir/interpret/place.rs | 2 +- src/librustc_mir/monomorphize/collector.rs | 4 +- src/librustc_mir/transform/check_unsafety.rs | 4 +- src/librustc_mir/transform/copy_prop.rs | 4 +- src/librustc_mir/transform/inline.rs | 12 ++-- src/librustc_mir/transform/instcombine.rs | 4 +- src/librustc_mir/transform/qualify_consts.rs | 2 +- .../bind-by-move-no-guards.stderr | 2 +- .../borrowck/borrowck-mutate-in-guard.stderr | 2 +- src/test/ui/consts/const_let_refutable.stderr | 2 +- .../min_const_fn/allow_const_fn_ptr.stderr | 2 +- .../min_const_fn/bad_const_fn_body_ice.stderr | 2 +- .../ui/consts/min_const_fn/cast_errors.stderr | 10 +-- .../min_const_fn/cmp_fn_pointers.stderr | 2 +- .../ui/consts/min_const_fn/loop_ice.stderr | 2 +- .../consts/min_const_fn/min_const_fn.stderr | 66 +++++++++---------- .../min_const_fn/min_const_fn_dyn.stderr | 4 +- .../min_const_fn/min_const_fn_fn_ptr.stderr | 4 +- .../min_const_fn_libstd_stability.stderr | 8 +-- ...in_const_unsafe_fn_libstd_stability.stderr | 8 +-- ...n_const_unsafe_fn_libstd_stability2.stderr | 6 +- .../consts/min_const_fn/mutable_borrow.stderr | 4 +- .../ui/consts/single_variant_match_ice.stderr | 2 +- .../ui/derives/deriving-with-repr-packed.rs | 8 +-- .../derives/deriving-with-repr-packed.stderr | 8 +-- src/test/ui/error-codes/E0008.stderr | 2 +- src/test/ui/error-codes/E0301.stderr | 2 +- src/test/ui/issues/issue-37550.stderr | 2 +- .../feature-gate.no_gate.stderr | 2 +- src/test/ui/unsafe/ranged_ints2_const.stderr | 4 +- 32 files changed, 96 insertions(+), 96 deletions(-) diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 75c64bb2644c1..dafb8c5f8f706 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -1465,7 +1465,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .map(|b| GuardFrameLocal::new(b.var_id, b.binding_mode)) .collect(), }; - debug!("Entering guard building context: {:?}", guard_frame); + debug!("entering guard building context: {:?}", guard_frame); self.guard_context.push(guard_frame); let re_erased = tcx.lifetimes.re_erased; diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 915ce9f20d07d..1cadd5b0dcc17 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -576,7 +576,7 @@ fn check_legality_of_move_bindings( "cannot bind by-move into a pattern guard"); err.span_label(p.span, "moves value into pattern guard"); if cx.tcx.sess.opts.unstable_features.is_nightly_build() { - err.help("add #![feature(bind_by_move_pattern_guards)] to the \ + err.help("add `#![feature(bind_by_move_pattern_guards)]` to the \ crate attributes to enable"); } err.emit(); @@ -663,7 +663,7 @@ impl<'a, 'tcx> Delegate<'tcx> for MutationChecker<'a, 'tcx> { "cannot mutably borrow in a pattern guard"); err.span_label(span, "borrowed mutably in pattern guard"); if self.cx.tcx.sess.opts.unstable_features.is_nightly_build() { - err.help("add #![feature(bind_by_move_pattern_guards)] to the \ + err.help("add `#![feature(bind_by_move_pattern_guards)]` to the \ crate attributes to enable"); } err.emit(); diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 4f3727fbd8d9a..3dee02989c9f9 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -351,7 +351,7 @@ where if field >= len { // This can be violated because this runs during promotion on code where the // type system has not yet ensured that such things don't happen. - debug!("Tried to access element {} of array/slice with length {}", field, len); + debug!("tried to access element {} of array/slice with length {}", field, len); return err!(BoundsCheck { len, index: field }); } stride * field diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index da8fdb5082a8c..bcc6ad4eac29f 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -289,7 +289,7 @@ pub fn collect_crate_mono_items( collect_roots(tcx, mode) }); - debug!("Building mono item graph, beginning at roots"); + debug!("building mono item graph, beginning at roots"); let mut visited = MTLock::new(FxHashSet::default()); let mut inlining_map = MTLock::new(InliningMap::new()); @@ -316,7 +316,7 @@ pub fn collect_crate_mono_items( // Find all non-generic items by walking the HIR. These items serve as roots to // start monomorphizing from. fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionMode) -> Vec> { - debug!("Collecting roots"); + debug!("collecting roots"); let mut roots = Vec::new(); { diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 9898ba897734d..0c48531e34521 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -552,10 +552,10 @@ fn unsafe_derive_on_repr_packed(tcx: TyCtxt<'_>, def_id: DefId) { // FIXME: when we make this a hard error, this should have its // own error code. let message = if tcx.generics_of(def_id).own_requires_monomorphization() { - "#[derive] can't be used on a #[repr(packed)] struct with \ + "`#[derive]` can't be used on a `#[repr(packed)]` struct with \ type or const parameters (error E0133)".to_string() } else { - "#[derive] can't be used on a #[repr(packed)] struct that \ + "`#[derive]` can't be used on a `#[repr(packed)]` struct that \ does not derive Copy (error E0133)".to_string() }; tcx.lint_hir(SAFE_PACKED_BORROWS, diff --git a/src/librustc_mir/transform/copy_prop.rs b/src/librustc_mir/transform/copy_prop.rs index c850b48e074ab..88a46b1012b61 100644 --- a/src/librustc_mir/transform/copy_prop.rs +++ b/src/librustc_mir/transform/copy_prop.rs @@ -47,7 +47,7 @@ impl MirPass for CopyPropagation { let mut changed = false; for dest_local in body.local_decls.indices() { - debug!("Considering destination local: {:?}", dest_local); + debug!("considering destination local: {:?}", dest_local); let action; let location; @@ -159,7 +159,7 @@ fn eliminate_self_assignments( } else { continue; } - debug!("Deleting a self-assignment for {:?}", dest_local); + debug!("deleting a self-assignment for {:?}", dest_local); body.make_statement_nop(location); changed = true; } diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index dc73e58d15c3d..04ee14f5f59be 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -159,7 +159,7 @@ impl Inliner<'tcx> { // Simplify if we inlined anything. if changed { - debug!("Running simplify cfg on {:?}", self.source); + debug!("running simplify cfg on {:?}", self.source); CfgSimplifier::new(caller_body).simplify(); remove_dead_blocks(caller_body); } @@ -247,7 +247,7 @@ impl Inliner<'tcx> { // need to check for first. attr::InlineAttr::Always => true, attr::InlineAttr::Never => { - debug!("#[inline(never)] present - not inlining"); + debug!("`#[inline(never)]` present - not inlining"); return false } attr::InlineAttr::Hint => true, @@ -397,7 +397,7 @@ impl Inliner<'tcx> { match terminator.kind { // FIXME: Handle inlining of diverging calls TerminatorKind::Call { args, destination: Some(destination), cleanup, .. } => { - debug!("Inlined {:?} into {:?}", callsite.callee, self.source); + debug!("inlined {:?} into {:?}", callsite.callee, self.source); let mut local_map = IndexVec::with_capacity(callee_body.local_decls.len()); let mut scope_map = IndexVec::with_capacity(callee_body.source_scopes.len()); @@ -456,7 +456,7 @@ impl Inliner<'tcx> { } let dest = if dest_needs_borrow(&destination.0) { - debug!("Creating temp for return destination"); + debug!("creating temp for return destination"); let dest = Rvalue::Ref( self.tcx.lifetimes.re_erased, BorrowKind::Mut { allow_two_phase_borrow: false }, @@ -610,7 +610,7 @@ impl Inliner<'tcx> { } } - debug!("Creating temp for argument {:?}", arg); + debug!("creating temp for argument {:?}", arg); // Otherwise, create a temporary for the arg let arg = Rvalue::Use(arg); @@ -659,7 +659,7 @@ struct Integrator<'a, 'tcx> { impl<'a, 'tcx> Integrator<'a, 'tcx> { fn update_target(&self, tgt: BasicBlock) -> BasicBlock { let new = BasicBlock::new(tgt.index() + self.block_idx); - debug!("Updating target `{:?}`, new: `{:?}`", tgt, new); + debug!("updating target `{:?}`, new: `{:?}`", tgt, new); new } } diff --git a/src/librustc_mir/transform/instcombine.rs b/src/librustc_mir/transform/instcombine.rs index c338e1ebe936f..40563ad4167d5 100644 --- a/src/librustc_mir/transform/instcombine.rs +++ b/src/librustc_mir/transform/instcombine.rs @@ -39,7 +39,7 @@ pub struct InstCombineVisitor<'tcx> { impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> { fn visit_rvalue(&mut self, rvalue: &mut Rvalue<'tcx>, location: Location) { if self.optimizations.and_stars.remove(&location) { - debug!("Replacing `&*`: {:?}", rvalue); + debug!("replacing `&*`: {:?}", rvalue); let new_place = match *rvalue { Rvalue::Ref(_, _, Place::Projection(ref mut projection)) => { // Replace with dummy @@ -51,7 +51,7 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> { } if let Some(constant) = self.optimizations.arrays_lengths.remove(&location) { - debug!("Replacing `Len([_; N])`: {:?}", rvalue); + debug!("replacing `Len([_; N])`: {:?}", rvalue); *rvalue = Rvalue::Use(Operand::Constant(box constant)); } diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 3e52d3ee9bbdf..2dffafd6e54c0 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -1545,7 +1545,7 @@ impl MirPass for QualifyAndPromoteConstants { diag.note("for more information, see issue \ https://github.com/rust-lang/rust/issues/57563"); diag.help( - "add #![feature(const_fn)] to the crate attributes to enable", + "add `#![feature(const_fn)]` to the crate attributes to enable", ); diag.emit(); } else { diff --git a/src/test/ui/bind-by-move/bind-by-move-no-guards.stderr b/src/test/ui/bind-by-move/bind-by-move-no-guards.stderr index 5f8b7007f304c..c5f0256c2c92f 100644 --- a/src/test/ui/bind-by-move/bind-by-move-no-guards.stderr +++ b/src/test/ui/bind-by-move/bind-by-move-no-guards.stderr @@ -4,7 +4,7 @@ error[E0008]: cannot bind by-move into a pattern guard LL | Some(z) if z.recv().unwrap() => { panic!() }, | ^ moves value into pattern guard | - = help: add #![feature(bind_by_move_pattern_guards)] to the crate attributes to enable + = help: add `#![feature(bind_by_move_pattern_guards)]` to the crate attributes to enable error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-mutate-in-guard.stderr b/src/test/ui/borrowck/borrowck-mutate-in-guard.stderr index ac6bed6137fa3..d39f535d8e2f7 100644 --- a/src/test/ui/borrowck/borrowck-mutate-in-guard.stderr +++ b/src/test/ui/borrowck/borrowck-mutate-in-guard.stderr @@ -10,7 +10,7 @@ error[E0301]: cannot mutably borrow in a pattern guard LL | Enum::A(_) if { let y = &mut x; *y = Enum::B(false); false } => 1, | ^ borrowed mutably in pattern guard | - = help: add #![feature(bind_by_move_pattern_guards)] to the crate attributes to enable + = help: add `#![feature(bind_by_move_pattern_guards)]` to the crate attributes to enable error[E0302]: cannot assign in a pattern guard --> $DIR/borrowck-mutate-in-guard.rs:15:41 diff --git a/src/test/ui/consts/const_let_refutable.stderr b/src/test/ui/consts/const_let_refutable.stderr index cdd696ee7fbff..a848b20ed98f5 100644 --- a/src/test/ui/consts/const_let_refutable.stderr +++ b/src/test/ui/consts/const_let_refutable.stderr @@ -11,7 +11,7 @@ LL | a + b | ^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable warning[E0381]: use of possibly uninitialized variable: `a` --> $DIR/const_let_refutable.rs:4:5 diff --git a/src/test/ui/consts/min_const_fn/allow_const_fn_ptr.stderr b/src/test/ui/consts/min_const_fn/allow_const_fn_ptr.stderr index e6e1ced6592a2..6228b012dde38 100644 --- a/src/test/ui/consts/min_const_fn/allow_const_fn_ptr.stderr +++ b/src/test/ui/consts/min_const_fn/allow_const_fn_ptr.stderr @@ -5,7 +5,7 @@ LL | const fn error(_: fn()) {} | ^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error: aborting due to previous error diff --git a/src/test/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr b/src/test/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr index ac8d082fc1904..ecfd30e7b4439 100644 --- a/src/test/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr +++ b/src/test/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr @@ -5,7 +5,7 @@ LL | vec![1, 2, 3] | ^^^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/consts/min_const_fn/cast_errors.stderr b/src/test/ui/consts/min_const_fn/cast_errors.stderr index b1a50be99835d..9919c17a04208 100644 --- a/src/test/ui/consts/min_const_fn/cast_errors.stderr +++ b/src/test/ui/consts/min_const_fn/cast_errors.stderr @@ -5,7 +5,7 @@ LL | const fn unsize(x: &[u8; 3]) -> &[u8] { x } | ^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: function pointers in const fn are unstable --> $DIR/cast_errors.rs:5:23 @@ -14,7 +14,7 @@ LL | const fn closure() -> fn() { || {} } | ^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: function pointers in const fn are unstable --> $DIR/cast_errors.rs:8:5 @@ -23,7 +23,7 @@ LL | (|| {}) as fn(); | ^^^^^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: function pointers in const fn are unstable --> $DIR/cast_errors.rs:11:28 @@ -32,7 +32,7 @@ LL | const fn reify(f: fn()) -> unsafe fn() { f } | ^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: function pointers in const fn are unstable --> $DIR/cast_errors.rs:13:21 @@ -41,7 +41,7 @@ LL | const fn reify2() { main as unsafe fn(); } | ^^^^^^^^^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error: aborting due to 5 previous errors diff --git a/src/test/ui/consts/min_const_fn/cmp_fn_pointers.stderr b/src/test/ui/consts/min_const_fn/cmp_fn_pointers.stderr index 7f6132ce9cd5e..82ed1d45226fa 100644 --- a/src/test/ui/consts/min_const_fn/cmp_fn_pointers.stderr +++ b/src/test/ui/consts/min_const_fn/cmp_fn_pointers.stderr @@ -5,7 +5,7 @@ LL | const fn cmp(x: fn(), y: fn()) -> bool { | ^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error: aborting due to previous error diff --git a/src/test/ui/consts/min_const_fn/loop_ice.stderr b/src/test/ui/consts/min_const_fn/loop_ice.stderr index cb85956266b0e..edf983fc56b11 100644 --- a/src/test/ui/consts/min_const_fn/loop_ice.stderr +++ b/src/test/ui/consts/min_const_fn/loop_ice.stderr @@ -5,7 +5,7 @@ LL | loop {} | ^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error: aborting due to previous error diff --git a/src/test/ui/consts/min_const_fn/min_const_fn.stderr b/src/test/ui/consts/min_const_fn/min_const_fn.stderr index 28a5ffb201594..d8ae624009615 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_fn.stderr @@ -11,7 +11,7 @@ LL | const fn get_mut(&mut self) -> &mut T { &mut self.0 } | ^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0493]: destructors cannot be evaluated at compile-time --> $DIR/min_const_fn.rs:44:28 @@ -26,7 +26,7 @@ LL | const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 } | ^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0493]: destructors cannot be evaluated at compile-time --> $DIR/min_const_fn.rs:51:27 @@ -41,7 +41,7 @@ LL | const fn get_mut_s(&mut self) -> &mut T { &mut self.0 } | ^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: mutable references in const fn are unstable --> $DIR/min_const_fn.rs:58:39 @@ -50,7 +50,7 @@ LL | const fn get_mut_sq(&mut self) -> &mut T { &mut self.0 } | ^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable --> $DIR/min_const_fn.rs:76:16 @@ -59,7 +59,7 @@ LL | const fn foo11(t: T) -> T { t } | ^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable --> $DIR/min_const_fn.rs:78:18 @@ -68,7 +68,7 @@ LL | const fn foo11_2(t: T) -> T { t } | ^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: only int, `bool` and `char` operations are stable in const fn --> $DIR/min_const_fn.rs:80:33 @@ -77,7 +77,7 @@ LL | const fn foo19(f: f32) -> f32 { f * 2.0 } | ^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: only int, `bool` and `char` operations are stable in const fn --> $DIR/min_const_fn.rs:82:35 @@ -86,7 +86,7 @@ LL | const fn foo19_2(f: f32) -> f32 { 2.0 - f } | ^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: only int and `bool` operations are stable in const fn --> $DIR/min_const_fn.rs:84:35 @@ -95,7 +95,7 @@ LL | const fn foo19_3(f: f32) -> f32 { -f } | ^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: only int, `bool` and `char` operations are stable in const fn --> $DIR/min_const_fn.rs:86:43 @@ -104,7 +104,7 @@ LL | const fn foo19_4(f: f32, g: f32) -> f32 { f / g } | ^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: cannot access `static` items in const fn --> $DIR/min_const_fn.rs:90:27 @@ -113,7 +113,7 @@ LL | const fn foo25() -> u32 { BAR } | ^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: cannot access `static` items in const fn --> $DIR/min_const_fn.rs:91:36 @@ -122,7 +122,7 @@ LL | const fn foo26() -> &'static u32 { &BAR } | ^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: casting pointers to ints is unstable in const fn --> $DIR/min_const_fn.rs:92:42 @@ -131,7 +131,7 @@ LL | const fn foo30(x: *const u32) -> usize { x as usize } | ^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: casting pointers to ints is unstable in const fn --> $DIR/min_const_fn.rs:94:63 @@ -140,7 +140,7 @@ LL | const fn foo30_with_unsafe(x: *const u32) -> usize { unsafe { x as usize } | ^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: casting pointers to ints is unstable in const fn --> $DIR/min_const_fn.rs:96:42 @@ -149,7 +149,7 @@ LL | const fn foo30_2(x: *mut u32) -> usize { x as usize } | ^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: casting pointers to ints is unstable in const fn --> $DIR/min_const_fn.rs:98:63 @@ -158,7 +158,7 @@ LL | const fn foo30_2_with_unsafe(x: *mut u32) -> usize { unsafe { x as usize } | ^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: loops and conditional expressions are not stable in const fn --> $DIR/min_const_fn.rs:100:38 @@ -167,7 +167,7 @@ LL | const fn foo30_4(b: bool) -> usize { if b { 1 } else { 42 } } | ^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: loops and conditional expressions are not stable in const fn --> $DIR/min_const_fn.rs:102:29 @@ -176,7 +176,7 @@ LL | const fn foo30_5(b: bool) { while b { } } | ^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: loops and conditional expressions are not stable in const fn --> $DIR/min_const_fn.rs:104:44 @@ -185,7 +185,7 @@ LL | const fn foo36(a: bool, b: bool) -> bool { a && b } | ^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: loops and conditional expressions are not stable in const fn --> $DIR/min_const_fn.rs:106:44 @@ -194,7 +194,7 @@ LL | const fn foo37(a: bool, b: bool) -> bool { a || b } | ^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: mutable references in const fn are unstable --> $DIR/min_const_fn.rs:108:14 @@ -203,7 +203,7 @@ LL | const fn inc(x: &mut i32) { *x += 1 } | ^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable --> $DIR/min_const_fn.rs:113:6 @@ -212,7 +212,7 @@ LL | impl Foo { | ^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable --> $DIR/min_const_fn.rs:118:6 @@ -221,7 +221,7 @@ LL | impl Foo { | ^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable --> $DIR/min_const_fn.rs:123:6 @@ -230,7 +230,7 @@ LL | impl Foo { | ^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: `impl Trait` in const fn is unstable --> $DIR/min_const_fn.rs:129:24 @@ -239,7 +239,7 @@ LL | const fn no_rpit2() -> AlanTuring { AlanTuring(0) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable --> $DIR/min_const_fn.rs:131:34 @@ -248,7 +248,7 @@ LL | const fn no_apit2(_x: AlanTuring) {} | ^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable --> $DIR/min_const_fn.rs:133:22 @@ -257,7 +257,7 @@ LL | const fn no_apit(_x: impl std::fmt::Debug) {} | ^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: `impl Trait` in const fn is unstable --> $DIR/min_const_fn.rs:134:23 @@ -266,7 +266,7 @@ LL | const fn no_rpit() -> impl std::fmt::Debug {} | ^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable --> $DIR/min_const_fn.rs:135:23 @@ -275,7 +275,7 @@ LL | const fn no_dyn_trait(_x: &dyn std::fmt::Debug) {} | ^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable --> $DIR/min_const_fn.rs:136:32 @@ -284,7 +284,7 @@ LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable warning[E0515]: cannot return reference to temporary value --> $DIR/min_const_fn.rs:136:63 @@ -306,7 +306,7 @@ LL | const fn really_no_traits_i_mean_it() { (&() as &dyn std::fmt::Debug, ()).1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: function pointers in const fn are unstable --> $DIR/min_const_fn.rs:147:21 @@ -315,7 +315,7 @@ LL | const fn no_fn_ptrs(_x: fn()) {} | ^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: function pointers in const fn are unstable --> $DIR/min_const_fn.rs:149:27 @@ -324,7 +324,7 @@ LL | const fn no_fn_ptrs2() -> fn() { fn foo() {} foo } | ^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error: aborting due to 36 previous errors diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr b/src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr index 9ded93c16727b..02ddb0395296c 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr @@ -5,7 +5,7 @@ LL | x.0.field; | ^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable --> $DIR/min_const_fn_dyn.rs:12:66 @@ -14,7 +14,7 @@ LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) } | ^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable warning[E0716]: temporary value dropped while borrowed --> $DIR/min_const_fn_dyn.rs:12:67 diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_fn_ptr.stderr b/src/test/ui/consts/min_const_fn/min_const_fn_fn_ptr.stderr index 5316d07afa428..085ad1aad3a95 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn_fn_ptr.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_fn_fn_ptr.stderr @@ -5,7 +5,7 @@ LL | x.0.field; | ^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: function pointers in const fn are unstable --> $DIR/min_const_fn_fn_ptr.rs:14:59 @@ -14,7 +14,7 @@ LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasPtr { field }) } | ^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error: aborting due to 2 previous errors diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr b/src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr index c52d7c8511561..0af5bdca815f9 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr @@ -5,7 +5,7 @@ LL | const fn bar() -> u32 { foo() } | ^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2` is not stable as `const fn` --> $DIR/min_const_fn_libstd_stability.rs:22:26 @@ -14,7 +14,7 @@ LL | const fn bar2() -> u32 { foo2() } | ^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: only int, `bool` and `char` operations are stable in const fn --> $DIR/min_const_fn_libstd_stability.rs:26:26 @@ -23,7 +23,7 @@ LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 } | ^^^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2_gated` is not stable as `const fn` --> $DIR/min_const_fn_libstd_stability.rs:34:32 @@ -32,7 +32,7 @@ LL | const fn bar2_gated() -> u32 { foo2_gated() } | ^^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error: aborting due to 4 previous errors diff --git a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr index af39b99e90cc9..bc6f8c596060f 100644 --- a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr @@ -5,7 +5,7 @@ LL | const unsafe fn bar() -> u32 { unsafe { foo() } } | ^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2` is not stable as `const fn` --> $DIR/min_const_unsafe_fn_libstd_stability.rs:22:42 @@ -14,7 +14,7 @@ LL | const unsafe fn bar2() -> u32 { unsafe { foo2() } } | ^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: only int, `bool` and `char` operations are stable in const fn --> $DIR/min_const_unsafe_fn_libstd_stability.rs:26:33 @@ -23,7 +23,7 @@ LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 } | ^^^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2_gated` is not stable as `const fn` --> $DIR/min_const_unsafe_fn_libstd_stability.rs:34:48 @@ -32,7 +32,7 @@ LL | const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } } | ^^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error: aborting due to 4 previous errors diff --git a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr index e4534d9ab98f6..a14fd740c670a 100644 --- a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr @@ -5,7 +5,7 @@ LL | const unsafe fn bar() -> u32 { foo() } | ^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2` is not stable as `const fn` --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:22:33 @@ -14,7 +14,7 @@ LL | const unsafe fn bar2() -> u32 { foo2() } | ^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2_gated` is not stable as `const fn` --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:30:39 @@ -23,7 +23,7 @@ LL | const unsafe fn bar2_gated() -> u32 { foo2_gated() } | ^^^^^^^^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error: aborting due to 3 previous errors diff --git a/src/test/ui/consts/min_const_fn/mutable_borrow.stderr b/src/test/ui/consts/min_const_fn/mutable_borrow.stderr index ed55849124f27..7c121be0d552d 100644 --- a/src/test/ui/consts/min_const_fn/mutable_borrow.stderr +++ b/src/test/ui/consts/min_const_fn/mutable_borrow.stderr @@ -5,7 +5,7 @@ LL | let b = &mut a; | ^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: mutable references in const fn are unstable --> $DIR/mutable_borrow.rs:12:13 @@ -14,7 +14,7 @@ LL | let b = &mut a; | ^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error: aborting due to 2 previous errors diff --git a/src/test/ui/consts/single_variant_match_ice.stderr b/src/test/ui/consts/single_variant_match_ice.stderr index 851733726ac0f..3f37a6c645056 100644 --- a/src/test/ui/consts/single_variant_match_ice.stderr +++ b/src/test/ui/consts/single_variant_match_ice.stderr @@ -17,7 +17,7 @@ LL | match *self { | ^^^^^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error: aborting due to 3 previous errors diff --git a/src/test/ui/derives/deriving-with-repr-packed.rs b/src/test/ui/derives/deriving-with-repr-packed.rs index 66b0f85c85dd1..d354cef66bc06 100644 --- a/src/test/ui/derives/deriving-with-repr-packed.rs +++ b/src/test/ui/derives/deriving-with-repr-packed.rs @@ -6,15 +6,15 @@ // not be aligned. #[derive(Copy, Clone, PartialEq, Eq)] -//~^ ERROR #[derive] can't be used +//~^ ERROR `#[derive]` can't be used //~| hard error -//~^^^ ERROR #[derive] can't be used +//~^^^ ERROR `#[derive]` can't be used //~| hard error #[repr(packed)] pub struct Foo(T, T, T); #[derive(PartialEq, Eq)] -//~^ ERROR #[derive] can't be used +//~^ ERROR `#[derive]` can't be used //~| hard error #[repr(packed)] pub struct Bar(u32, u32, u32); @@ -23,7 +23,7 @@ pub struct Bar(u32, u32, u32); struct Y(usize); #[derive(PartialEq)] -//~^ ERROR #[derive] can't be used +//~^ ERROR `#[derive]` can't be used //~| hard error #[repr(packed)] struct X(Y); diff --git a/src/test/ui/derives/deriving-with-repr-packed.stderr b/src/test/ui/derives/deriving-with-repr-packed.stderr index 9d96908a05620..8093c58a67e42 100644 --- a/src/test/ui/derives/deriving-with-repr-packed.stderr +++ b/src/test/ui/derives/deriving-with-repr-packed.stderr @@ -1,4 +1,4 @@ -error: #[derive] can't be used on a #[repr(packed)] struct with type or const parameters (error E0133) +error: `#[derive]` can't be used on a `#[repr(packed)]` struct with type or const parameters (error E0133) --> $DIR/deriving-with-repr-packed.rs:8:16 | LL | #[derive(Copy, Clone, PartialEq, Eq)] @@ -12,7 +12,7 @@ LL | #![deny(safe_packed_borrows)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #46043 -error: #[derive] can't be used on a #[repr(packed)] struct with type or const parameters (error E0133) +error: `#[derive]` can't be used on a `#[repr(packed)]` struct with type or const parameters (error E0133) --> $DIR/deriving-with-repr-packed.rs:8:23 | LL | #[derive(Copy, Clone, PartialEq, Eq)] @@ -21,7 +21,7 @@ LL | #[derive(Copy, Clone, PartialEq, Eq)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #46043 -error: #[derive] can't be used on a #[repr(packed)] struct that does not derive Copy (error E0133) +error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133) --> $DIR/deriving-with-repr-packed.rs:16:10 | LL | #[derive(PartialEq, Eq)] @@ -30,7 +30,7 @@ LL | #[derive(PartialEq, Eq)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #46043 -error: #[derive] can't be used on a #[repr(packed)] struct that does not derive Copy (error E0133) +error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133) --> $DIR/deriving-with-repr-packed.rs:25:10 | LL | #[derive(PartialEq)] diff --git a/src/test/ui/error-codes/E0008.stderr b/src/test/ui/error-codes/E0008.stderr index 2505c03a148af..6b45439c4b587 100644 --- a/src/test/ui/error-codes/E0008.stderr +++ b/src/test/ui/error-codes/E0008.stderr @@ -4,7 +4,7 @@ error[E0008]: cannot bind by-move into a pattern guard LL | Some(s) if s.len() == 0 => {}, | ^ moves value into pattern guard | - = help: add #![feature(bind_by_move_pattern_guards)] to the crate attributes to enable + = help: add `#![feature(bind_by_move_pattern_guards)]` to the crate attributes to enable error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0301.stderr b/src/test/ui/error-codes/E0301.stderr index 44e823631b592..4f12fd3850e33 100644 --- a/src/test/ui/error-codes/E0301.stderr +++ b/src/test/ui/error-codes/E0301.stderr @@ -4,7 +4,7 @@ error[E0301]: cannot mutably borrow in a pattern guard LL | option if option.take().is_none() => {}, | ^^^^^^ borrowed mutably in pattern guard | - = help: add #![feature(bind_by_move_pattern_guards)] to the crate attributes to enable + = help: add `#![feature(bind_by_move_pattern_guards)]` to the crate attributes to enable error[E0596]: cannot borrow `option` as mutable, as it is immutable for the pattern guard --> $DIR/E0301.rs:4:19 diff --git a/src/test/ui/issues/issue-37550.stderr b/src/test/ui/issues/issue-37550.stderr index 609043942b7d9..c1523e911fd2b 100644 --- a/src/test/ui/issues/issue-37550.stderr +++ b/src/test/ui/issues/issue-37550.stderr @@ -5,7 +5,7 @@ LL | let x = || t; | ^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error: aborting due to previous error diff --git a/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.no_gate.stderr b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.no_gate.stderr index 2a1a04b3f494c..c2f6edee05fa6 100644 --- a/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.no_gate.stderr +++ b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.no_gate.stderr @@ -4,7 +4,7 @@ error[E0008]: cannot bind by-move into a pattern guard LL | A { a: v } if *v == 42 => v, | ^ moves value into pattern guard | - = help: add #![feature(bind_by_move_pattern_guards)] to the crate attributes to enable + = help: add `#![feature(bind_by_move_pattern_guards)]` to the crate attributes to enable error: aborting due to previous error diff --git a/src/test/ui/unsafe/ranged_ints2_const.stderr b/src/test/ui/unsafe/ranged_ints2_const.stderr index 6a47c5b14146b..e99155ee10162 100644 --- a/src/test/ui/unsafe/ranged_ints2_const.stderr +++ b/src/test/ui/unsafe/ranged_ints2_const.stderr @@ -5,7 +5,7 @@ LL | let y = &mut x.0; | ^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0723]: mutable references in const fn are unstable --> $DIR/ranged_ints2_const.rs:18:9 @@ -14,7 +14,7 @@ LL | let y = unsafe { &mut x.0 }; | ^ | = note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 - = help: add #![feature(const_fn)] to the crate attributes to enable + = help: add `#![feature(const_fn)]` to the crate attributes to enable error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block --> $DIR/ranged_ints2_const.rs:11:13