@ -35,8 +35,6 @@ try:
except ImportError :
except ImportError :
import tomli as tomllib
import tomli as tomllib
STRICT_LINTS = { " unknown_lints " , " warnings " }
class CargoTOML :
class CargoTOML :
tomldata : Mapping [ Any , Any ]
tomldata : Mapping [ Any , Any ]
@ -82,7 +80,7 @@ class LintFlag:
priority : int
priority : int
def generate_lint_flags ( cargo_toml : CargoTOML , strict_lints : bool ) - > Iterable [ str ] :
def generate_lint_flags ( cargo_toml : CargoTOML ) - > Iterable [ str ] :
""" Converts Cargo.toml lints to rustc -A/-D/-F/-W flags. """
""" Converts Cargo.toml lints to rustc -A/-D/-F/-W flags. """
toml_lints = cargo_toml . lints
toml_lints = cargo_toml . lints
@ -103,14 +101,8 @@ def generate_lint_flags(cargo_toml: CargoTOML, strict_lints: bool) -> Iterable[s
flag = " -F "
flag = " -F "
else :
else :
raise Exception ( f " invalid level { level } for { prefix } { lint } " )
raise Exception ( f " invalid level { level } for { prefix } { lint } " )
if not ( strict_lints and lint in STRICT_LINTS ) :
lint_list . append ( LintFlag ( flags = [ flag , prefix + lint ] , priority = priority ) )
lint_list . append ( LintFlag ( flags = [ flag , prefix + lint ] , priority = priority ) )
if strict_lints :
for lint in STRICT_LINTS :
lint_list . append ( LintFlag ( flags = [ " -D " , lint ] , priority = 1000000 ) )
lint_list . sort ( key = lambda x : x . priority )
lint_list . sort ( key = lambda x : x . priority )
for lint in lint_list :
for lint in lint_list :
yield from lint . flags
yield from lint . flags
@ -187,13 +179,6 @@ def main() -> None:
required = False ,
required = False ,
default = " 1.0.0 " ,
default = " 1.0.0 " ,
)
)
parser . add_argument (
" --strict-lints " ,
action = " store_true " ,
dest = " strict_lints " ,
help = " apply stricter checks (for nightly Rust) " ,
default = False ,
)
args = parser . parse_args ( )
args = parser . parse_args ( )
if args . verbose :
if args . verbose :
logging . basicConfig ( level = logging . DEBUG )
logging . basicConfig ( level = logging . DEBUG )
@ -207,7 +192,7 @@ def main() -> None:
cargo_toml = CargoTOML ( args . cargo_toml , None )
cargo_toml = CargoTOML ( args . cargo_toml , None )
if args . lints :
if args . lints :
for tok in generate_lint_flags ( cargo_toml , args . strict_lints ) :
for tok in generate_lint_flags ( cargo_toml ) :
print ( tok )
print ( tok )
if rustc_version > = ( 1 , 80 ) :
if rustc_version > = ( 1 , 80 ) :