diff --git a/Cargo.lock b/Cargo.lock index 8ed396c815..2631b2b0c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,6 +37,15 @@ version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c794e162a5eff65c72ef524dfe393eb923c354e350bb78b9c7383df13f3bc142" +[[package]] +name = "ascii-canvas" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" +dependencies = [ + "term", +] + [[package]] name = "async-channel" version = "1.7.0" @@ -197,6 +206,21 @@ dependencies = [ "serde", ] +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + [[package]] name = "bitflags" version = "1.3.2" @@ -247,6 +271,17 @@ dependencies = [ "once_cell", ] +[[package]] +name = "bstr" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata", +] + [[package]] name = "bumpalo" version = "3.10.0" @@ -491,6 +526,12 @@ dependencies = [ "syn", ] +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + [[package]] name = "digest" version = "0.8.1" @@ -528,6 +569,16 @@ dependencies = [ "dirs-sys", ] +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if 1.0.0", + "dirs-sys-next", +] + [[package]] name = "dirs-sys" version = "0.3.7" @@ -539,12 +590,32 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi 0.3.9", +] + [[package]] name = "either" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" +[[package]] +name = "ena" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7402b94a93c24e742487327a7cd839dc9d36fec9de9fb25b09f2dae459f36c3" +dependencies = [ + "log", +] + [[package]] name = "event-listener" version = "2.5.3" @@ -587,6 +658,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + [[package]] name = "fnv" version = "1.0.7" @@ -885,6 +962,15 @@ dependencies = [ "libc", ] +[[package]] +name = "itertools" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.3" @@ -919,11 +1005,37 @@ dependencies = [ "log", ] +[[package]] +name = "lalrpop" +version = "0.19.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b30455341b0e18f276fa64540aff54deafb54c589de6aca68659c63dd2d5d823" +dependencies = [ + "ascii-canvas", + "atty", + "bit-set", + "diff", + "ena", + "itertools", + "lalrpop-util", + "petgraph", + "pico-args", + "regex", + "regex-syntax", + "string_cache", + "term", + "tiny-keccak", + "unicode-xid", +] + [[package]] name = "lalrpop-util" version = "0.19.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcf796c978e9b4d983414f4caedc9273aa33ee214c5b887bd55fde84c85d2dc4" +dependencies = [ + "regex", +] [[package]] name = "lazy_static" @@ -963,6 +1075,15 @@ dependencies = [ "value-bag", ] +[[package]] +name = "lz4_flex" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c038063f7a78126c539d666a0323a2032de5e7366012cd14a6eafc5ba290bbd6" +dependencies = [ + "twox-hash", +] + [[package]] name = "memchr" version = "2.5.0" @@ -1041,6 +1162,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "new_debug_unreachable" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" + [[package]] name = "nix" version = "0.24.2" @@ -1089,6 +1216,17 @@ dependencies = [ "autocfg", "num-integer", "num-traits", + "serde", +] + +[[package]] +name = "num-complex" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ae39348c8bc5fbd7f40c727a9925f03517afd2ab27d46702108b6a7e5414c19" +dependencies = [ + "num-traits", + "serde", ] [[package]] @@ -1173,6 +1311,16 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "petgraph" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5014253a1331579ce62aa67443b4a658c5e7dd03d4bc6d302b94474888143" +dependencies = [ + "fixedbitset", + "indexmap", +] + [[package]] name = "phf" version = "0.8.0" @@ -1249,6 +1397,12 @@ dependencies = [ "siphasher", ] +[[package]] +name = "pico-args" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468" + [[package]] name = "pin-project-lite" version = "0.2.9" @@ -1280,6 +1434,12 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -1517,6 +1677,12 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" + [[package]] name = "regex-syntax" version = "0.6.27" @@ -1561,17 +1727,37 @@ dependencies = [ [[package]] name = "rustpython-ast" version = "0.1.0" -source = "git+https://github.com/RustPython/RustPython.git?rev=dff916d45c5d13074d21ad329a5ab68a6499426a#dff916d45c5d13074d21ad329a5ab68a6499426a" +source = "git+https://github.com/RustPython/RustPython.git?rev=f1c7aebfad707526602c8162c8094a67129b6731#f1c7aebfad707526602c8162c8094a67129b6731" dependencies = [ "num-bigint", + "rustpython-bytecode", +] + +[[package]] +name = "rustpython-bytecode" +version = "0.1.2" +source = "git+https://github.com/RustPython/RustPython.git?rev=f1c7aebfad707526602c8162c8094a67129b6731#f1c7aebfad707526602c8162c8094a67129b6731" +dependencies = [ + "bincode", + "bitflags", + "bstr", + "itertools", + "lz4_flex", + "num-bigint", + "num-complex", + "serde", + "static_assertions", ] [[package]] name = "rustpython-parser" version = "0.1.2" -source = "git+https://github.com/RustPython/RustPython.git?rev=dff916d45c5d13074d21ad329a5ab68a6499426a#dff916d45c5d13074d21ad329a5ab68a6499426a" +source = "git+https://github.com/RustPython/RustPython.git?rev=f1c7aebfad707526602c8162c8094a67129b6731#f1c7aebfad707526602c8162c8094a67129b6731" dependencies = [ "ahash", + "anyhow", + "itertools", + "lalrpop", "lalrpop-util", "log", "num-bigint", @@ -1585,6 +1771,12 @@ dependencies = [ "unicode_names2", ] +[[package]] +name = "rustversion" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" + [[package]] name = "ryu" version = "1.0.11" @@ -1752,6 +1944,25 @@ dependencies = [ "thiserror", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "string_cache" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213494b7a2b503146286049378ce02b482200519accc31872ee8be91fa820a08" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", +] + [[package]] name = "strsim" version = "0.10.0" @@ -1789,6 +2000,17 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "term" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +dependencies = [ + "dirs-next", + "rustversion", + "winapi 0.3.9", +] + [[package]] name = "termcolor" version = "1.1.3" @@ -1866,6 +2088,16 @@ dependencies = [ "serde", ] +[[package]] +name = "twox-hash" +version = "1.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" +dependencies = [ + "cfg-if 0.1.10", + "static_assertions", +] + [[package]] name = "typenum" version = "1.15.0" @@ -1930,6 +2162,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +[[package]] +name = "unicode-xid" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" + [[package]] name = "unicode_names2" version = "0.5.0" diff --git a/Cargo.toml b/Cargo.toml index 03741c8e3b..03f3f1905d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ notify = { version = "4.0.17" } pyo3 = { version = "0.16.5", features = ["extension-module", "abi3-py37"] } rayon = { version = "1.5.3" } regex = { version = "1.6.0" } -rustpython-parser = { git = "https://github.com/RustPython/RustPython.git", rev = "dff916d45c5d13074d21ad329a5ab68a6499426a" } +rustpython-parser = { features=["lalrpop"], git = "https://github.com/RustPython/RustPython.git", rev = "f1c7aebfad707526602c8162c8094a67129b6731" } serde = { version = "1.0.143", features = ["derive"] } serde_json = { version = "1.0.83" } toml = { version = "0.5.9"} diff --git a/src/check_ast.rs b/src/check_ast.rs index 07e30a49c2..185c11f85e 100644 --- a/src/check_ast.rs +++ b/src/check_ast.rs @@ -67,7 +67,7 @@ impl Visitor for Checker<'_> { .contains(CheckKind::ImportStarUsage.code()) { for alias in names { - if alias.name == "*" { + if alias.node.name == "*" { self.checks.push(Check { kind: CheckKind::ImportStarUsage, location: stmt.location, @@ -218,7 +218,7 @@ pub fn check_ast(python_ast: &Suite, settings: &Settings) -> Vec { mod tests { use std::collections::BTreeSet; - use rustpython_parser::ast::{Alias, Location, Stmt, StmtKind}; + use rustpython_parser::ast::{Alias, AliasData, Location, Stmt, StmtKind}; use crate::check_ast::Checker; use crate::checks::CheckKind::ImportStarUsage; @@ -239,11 +239,14 @@ mod tests { custom: (), node: StmtKind::ImportFrom { module: Some("bar".to_string()), - names: vec![Alias { - name: "*".to_string(), - asname: None, - }], - level: 0, + names: vec![Alias::new( + Default::default(), + AliasData { + name: "*".to_string(), + asname: None, + }, + )], + level: None, }, }); diff --git a/src/visitor.rs b/src/visitor.rs index 0cbddba3eb..4631190e63 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -230,6 +230,10 @@ pub fn walk_stmt(visitor: &mut V, stmt: &Stmt) { visitor.visit_stmt(stmt) } } + StmtKind::Match { subject, .. } => { + // TODO(charlie): Handle `cases`. + visitor.visit_expr(subject); + } StmtKind::Raise { exc, cause } => { if let Some(expr) = exc { visitor.visit_expr(expr) @@ -326,7 +330,7 @@ pub fn walk_expr(visitor: &mut V, expr: &Expr) { visitor.visit_expr(orelse); } ExprKind::Dict { keys, values } => { - for expr in keys.iter().flatten() { + for expr in keys { visitor.visit_expr(expr) } for expr in values { @@ -505,7 +509,7 @@ pub fn walk_arguments(visitor: &mut V, arguments: &Argument for arg in &arguments.kwonlyargs { visitor.visit_arg(arg); } - for expr in arguments.kw_defaults.iter().flatten() { + for expr in &arguments.kw_defaults { visitor.visit_expr(expr) } if let Some(arg) = &arguments.kwarg {