1
Fork 0

Deprecates 4 lints

Namely STR_TO_STRING, STRING_TO_STRING, UNSTABLE_AS_SLICE and
UNSTABLE_AS_MUT_SLICE.
This commit is contained in:
mcarton 2016-03-24 19:25:59 +01:00
parent 68b2f12adf
commit 15e55f5df5
11 changed files with 115 additions and 171 deletions

View file

@ -13,14 +13,20 @@ declare_lint_re = re.compile(r'''
pub \s+ (?P<name>[A-Z_][A-Z_0-9]*) \s*,\s*
(?P<level>Forbid|Deny|Warn|Allow) \s*,\s*
" (?P<desc>(?:[^"\\]+|\\.)*) " \s* [})]
''', re.X | re.S)
''', re.VERBOSE | re.DOTALL)
declare_deprecated_lint_re = re.compile(r'''
declare_deprecated_lint! \s* [{(] \s*
pub \s+ (?P<name>[A-Z_][A-Z_0-9]*) \s*,\s*
" (?P<desc>(?:[^"\\]+|\\.)*) " \s* [})]
''', re.VERBOSE | re.DOTALL)
nl_escape_re = re.compile(r'\\\n\s*')
wiki_link = 'https://github.com/Manishearth/rust-clippy/wiki'
def collect(lints, fn):
def collect(lints, deprecated_lints, fn):
"""Collect all lints from a file.
Adds entries to the lints list as `(module, name, level, desc)`.
@ -35,6 +41,13 @@ def collect(lints, fn):
match.group('level').lower(),
desc.replace('\\"', '"')))
for match in declare_deprecated_lint_re.finditer(code):
# remove \-newline escapes from description string
desc = nl_escape_re.sub('', match.group('desc'))
deprecated_lints.append((os.path.splitext(os.path.basename(fn))[0],
match.group('name').lower(),
desc.replace('\\"', '"')))
def gen_table(lints, link=None):
"""Write lint table in Markdown format."""
@ -67,6 +80,13 @@ def gen_mods(lints):
yield 'pub mod %s;\n' % module
def gen_deprecated(lints):
"""Declare deprecated lints"""
for lint in lints:
yield ' store.register_removed("%s", "%s");\n' % (lint[1], lint[2])
def replace_region(fn, region_start, region_end, callback,
replace_start=True, write_back=True):
"""Replace a region in a file delimited by two lines matching regexes.
@ -107,6 +127,7 @@ def replace_region(fn, region_start, region_end, callback,
def main(print_only=False, check=False):
lints = []
deprecated_lints = []
# check directory
if not os.path.isfile('src/lib.rs'):
@ -117,7 +138,7 @@ def main(print_only=False, check=False):
for root, dirs, files in os.walk('src'):
for fn in files:
if fn.endswith('.rs'):
collect(lints, os.path.join(root, fn))
collect(lints, deprecated_lints, os.path.join(root, fn))
if print_only:
sys.stdout.writelines(gen_table(lints))
@ -147,6 +168,13 @@ def main(print_only=False, check=False):
lambda: gen_group(lints, levels=('warn', 'deny')),
replace_start=False, write_back=not check)
# same for "deprecated" lint collection
changed |= replace_region(
'src/lib.rs', r'let mut store', r'end deprecated lints',
lambda: gen_deprecated(deprecated_lints),
replace_start=False,
write_back=not check)
# same for "clippy_pedantic" lint collection
changed |= replace_region(
'src/lib.rs', r'reg.register_lint_group\("clippy_pedantic"', r'\]\);',