diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 12399413b..869ccb530 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -141,7 +141,7 @@ jobs: if: runner.os == 'macOS' - name: run clippy - run: cargo clippy ${{ env.CARGO_ARGS }} --workspace --exclude rustpython_wasm -- -Dwarnings + run: cargo clippy ${{ env.CARGO_ARGS }} --workspace --all-targets --exclude rustpython_wasm -- -Dwarnings - name: run rust tests run: cargo test --workspace --exclude rustpython_wasm --verbose --features threading ${{ env.CARGO_ARGS }} diff --git a/benches/execution.rs b/benches/execution.rs index 57529bbb3..d38dab089 100644 --- a/benches/execution.rs +++ b/benches/execution.rs @@ -4,8 +4,6 @@ use criterion::{ criterion_main, }; use rustpython_compiler::Mode; -use rustpython_parser::Parse; -use rustpython_parser::ast; use rustpython_vm::{Interpreter, PyResult, Settings}; use std::collections::HashMap; use std::path::Path; @@ -50,7 +48,7 @@ pub fn benchmark_file_execution(group: &mut BenchmarkGroup, name: &str pub fn benchmark_file_parsing(group: &mut BenchmarkGroup, name: &str, contents: &str) { group.throughput(Throughput::Bytes(contents.len() as u64)); group.bench_function(BenchmarkId::new("rustpython", name), |b| { - b.iter(|| ast::Suite::parse(contents, name).unwrap()) + b.iter(|| ruff_python_parser::parse_module(contents).unwrap()) }); group.bench_function(BenchmarkId::new("cpython", name), |b| { use pyo3::types::PyAnyMethods; diff --git a/compiler/codegen/src/compile.rs b/compiler/codegen/src/compile.rs index ccce28953..95d304a0e 100644 --- a/compiler/codegen/src/compile.rs +++ b/compiler/codegen/src/compile.rs @@ -3660,7 +3660,7 @@ mod tests { flags, }), }); - assert_eq!(Compiler::contains_await(not_present), false); + assert!(!Compiler::contains_await(not_present)); // f'{await x}' let expr_await_x = Expr::Await(ExprAwait { @@ -3686,7 +3686,7 @@ mod tests { flags, }), }); - assert_eq!(Compiler::contains_await(present), true); + assert!(Compiler::contains_await(present)); // f'{x:{await y}}' let expr_x = Expr::Name(ExprName { @@ -3727,7 +3727,7 @@ mod tests { flags, }), }); - assert_eq!(Compiler::contains_await(present), true); + assert!(Compiler::contains_await(present)); } } diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index 9df7a2c5a..0ebfbbf41 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -159,7 +159,7 @@ pub fn _compile_symtable( #[test] fn test_compile() { let code = "x = 'abc'"; - let compiled = compile(&code, Mode::Single, "<>", CompileOpts::default()); + let compiled = compile(code, Mode::Single, "<>", CompileOpts::default()); dbg!(compiled.expect("compile error")); } @@ -172,7 +172,7 @@ def main(): if __name__ == '__main__': main() "#; - let compiled = compile(&code, Mode::Exec, "<>", CompileOpts::default()); + let compiled = compile(code, Mode::Exec, "<>", CompileOpts::default()); dbg!(compiled.expect("compile error")); } @@ -188,7 +188,7 @@ elif False: else: pass "#; - let compiled = compile(&code, Mode::Exec, "<>", CompileOpts::default()); + let compiled = compile(code, Mode::Exec, "<>", CompileOpts::default()); dbg!(compiled.expect("compile error")); } @@ -197,7 +197,7 @@ fn test_compile_lambda() { let code = r#" lambda: 'a' "#; - let compiled = compile(&code, Mode::Exec, "<>", CompileOpts::default()); + let compiled = compile(code, Mode::Exec, "<>", CompileOpts::default()); dbg!(compiled.expect("compile error")); } @@ -206,7 +206,7 @@ fn test_compile_lambda2() { let code = r#" (lambda x: f'hello, {x}')('world}') "#; - let compiled = compile(&code, Mode::Exec, "<>", CompileOpts::default()); + let compiled = compile(code, Mode::Exec, "<>", CompileOpts::default()); dbg!(compiled.expect("compile error")); } @@ -223,7 +223,7 @@ def f(): else: return g "#; - let compiled = compile(&code, Mode::Exec, "<>", CompileOpts::default()); + let compiled = compile(code, Mode::Exec, "<>", CompileOpts::default()); dbg!(compiled.expect("compile error")); } @@ -232,7 +232,7 @@ fn test_compile_int() { let code = r#" a = 0xFF "#; - let compiled = compile(&code, Mode::Exec, "<>", CompileOpts::default()); + let compiled = compile(code, Mode::Exec, "<>", CompileOpts::default()); dbg!(compiled.expect("compile error")); } @@ -241,7 +241,7 @@ fn test_compile_bigint() { let code = r#" a = 0xFFFFFFFFFFFFFFFFFFFFFFFF "#; - let compiled = compile(&code, Mode::Exec, "<>", CompileOpts::default()); + let compiled = compile(code, Mode::Exec, "<>", CompileOpts::default()); dbg!(compiled.expect("compile error")); } @@ -250,36 +250,36 @@ fn test_compile_fstring() { let code1 = r#" assert f"1" == '1' "#; - let compiled = compile(&code1, Mode::Exec, "<>", CompileOpts::default()); + let compiled = compile(code1, Mode::Exec, "<>", CompileOpts::default()); dbg!(compiled.expect("compile error")); let code2 = r#" assert f"{1}" == '1' "#; - let compiled = compile(&code2, Mode::Exec, "<>", CompileOpts::default()); + let compiled = compile(code2, Mode::Exec, "<>", CompileOpts::default()); dbg!(compiled.expect("compile error")); let code3 = r#" assert f"{1+1}" == '2' "#; - let compiled = compile(&code3, Mode::Exec, "<>", CompileOpts::default()); + let compiled = compile(code3, Mode::Exec, "<>", CompileOpts::default()); dbg!(compiled.expect("compile error")); let code4 = r#" assert f"{{{(lambda: f'{1}')}" == '{1' "#; - let compiled = compile(&code4, Mode::Exec, "<>", CompileOpts::default()); + let compiled = compile(code4, Mode::Exec, "<>", CompileOpts::default()); dbg!(compiled.expect("compile error")); let code5 = r#" assert f"a{1}" == 'a1' "#; - let compiled = compile(&code5, Mode::Exec, "<>", CompileOpts::default()); + let compiled = compile(code5, Mode::Exec, "<>", CompileOpts::default()); dbg!(compiled.expect("compile error")); let code6 = r#" assert f"{{{(lambda x: f'hello, {x}')('world}')}" == '{hello, world}' "#; - let compiled = compile(&code6, Mode::Exec, "<>", CompileOpts::default()); + let compiled = compile(code6, Mode::Exec, "<>", CompileOpts::default()); dbg!(compiled.expect("compile error")); } @@ -293,6 +293,6 @@ class RegexFlag: DEBUG = 1 print(RegexFlag.NOFLAG & RegexFlag.DEBUG) "#; - let compiled = compile(&code, Mode::Exec, "", CompileOpts::default()); + let compiled = compile(code, Mode::Exec, "", CompileOpts::default()); dbg!(compiled.expect("compile error")); } diff --git a/examples/dis.rs b/examples/dis.rs index 5b8826fdf..c79b5e258 100644 --- a/examples/dis.rs +++ b/examples/dis.rs @@ -1,10 +1,10 @@ -/// This an example usage of the rustpython_compiler crate. -/// This program reads, parses, and compiles a file you provide -/// to RustPython bytecode, and then displays the output in the -/// `dis.dis` format. -/// -/// example usage: -/// $ cargo run --release --example dis demo*.py +//! This an example usage of the rustpython_compiler crate. +//! This program reads, parses, and compiles a file you provide +//! to RustPython bytecode, and then displays the output in the +//! `dis.dis` format. +//! +//! example usage: +//! $ cargo run --release --example dis demo*.py #[macro_use] extern crate log; @@ -53,10 +53,7 @@ fn main() -> Result<(), lexopt::Error> { return Err("expected at least one argument".into()); } - let opts = compiler::CompileOpts { - optimize, - ..Default::default() - }; + let opts = compiler::CompileOpts { optimize }; for script in &scripts { if script.exists() && script.is_file() { diff --git a/examples/mini_repl.rs b/examples/mini_repl.rs index fe3b13dcf..d7baa4692 100644 --- a/examples/mini_repl.rs +++ b/examples/mini_repl.rs @@ -1,8 +1,9 @@ -///! This example show cases a very simple REPL. -///! While a much better REPL can be found in ../src/shell, -///! This much smaller REPL is still a useful example because it showcases inserting -///! values and functions into the Python runtime's scope, and showcases use -///! of the compilation mode "Single". +//! This example show cases a very simple REPL. +//! While a much better REPL can be found in ../src/shell, +//! This much smaller REPL is still a useful example because it showcases inserting +//! values and functions into the Python runtime's scope, and showcases use +//! of the compilation mode "Single". + use rustpython_vm as vm; // these are needed for special memory shenanigans to let us share a variable with Python and Rust use std::sync::atomic::{AtomicBool, Ordering}; diff --git a/examples/parse_folder.rs b/examples/parse_folder.rs index acad76ad7..e05b34c26 100644 --- a/examples/parse_folder.rs +++ b/examples/parse_folder.rs @@ -69,8 +69,6 @@ fn parse_python_file(filename: &Path) -> ParsedFile { info!("Parsing file {:?}", filename); match std::fs::read_to_string(filename) { Err(e) => ParsedFile { - filename: Box::new(filename.to_path_buf()), - code: "".to_owned(), num_lines: 0, result: Err(e.to_string()), }, @@ -79,12 +77,7 @@ fn parse_python_file(filename: &Path) -> ParsedFile { let result = parse_module(&source) .map(|x| x.into_suite()) .map_err(|e| e.to_string()); - ParsedFile { - filename: Box::new(filename.to_path_buf()), - code: source.to_string(), - num_lines, - result, - } + ParsedFile { num_lines, result } } } } @@ -134,8 +127,6 @@ struct ScanResult { } struct ParsedFile { - filename: Box, - code: String, num_lines: usize, result: ParseResult, } diff --git a/vm/sre_engine/tests/tests.rs b/vm/sre_engine/tests/tests.rs index 0946fd64c..5499afa28 100644 --- a/vm/sre_engine/tests/tests.rs +++ b/vm/sre_engine/tests/tests.rs @@ -1,6 +1,7 @@ use rustpython_sre_engine::{Request, State, StrDrive}; struct Pattern { + #[allow(unused)] pattern: &'static str, code: &'static [u32], } @@ -178,6 +179,7 @@ fn test_bigcharset() { #[test] fn test_search_nonascii() { + #[allow(unused)] // pattern p = re.compile('\xe0+') // START GENERATED by generate_tests.py #[rustfmt::skip] let p = Pattern { pattern: "\u{e0}+", code: &[14, 4, 0, 1, 4294967295, 24, 6, 1, 4294967295, 16, 224, 1, 1] };