diff --git a/Cargo.lock b/Cargo.lock index 9bd778381..bb8f35758 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1078,13 +1078,13 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lexical-core" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db65c6da02e61f55dae90a0ae427b2a5f6b3e8db09f58d10efab23af92592616" +checksum = "21f866863575d0e1d654fbeeabdc927292fdf862873dc3c96c6f753357e13374" dependencies = [ "arrayvec", "bitflags", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "ryu", "static_assertions", ] diff --git a/parser/src/error.rs b/parser/src/error.rs index 3fee075ec..21497c45c 100644 --- a/parser/src/error.rs +++ b/parser/src/error.rs @@ -29,7 +29,7 @@ pub enum LexicalErrorType { UnrecognizedToken { tok: char }, FStringError(FStringErrorType), LineContinuationError, - EOF, + Eof, OtherError(String), } @@ -64,7 +64,7 @@ impl fmt::Display for LexicalErrorType { LexicalErrorType::LineContinuationError => { write!(f, "unexpected character after line continuation character") } - LexicalErrorType::EOF => write!(f, "unexpected EOF while parsing"), + LexicalErrorType::Eof => write!(f, "unexpected EOF while parsing"), LexicalErrorType::OtherError(msg) => write!(f, "{}", msg), } } @@ -129,7 +129,7 @@ pub struct ParseError { #[derive(Debug, PartialEq)] pub enum ParseErrorType { /// Parser encountered an unexpected end of input - EOF, + Eof, /// Parser encountered an extra token ExtraToken(Tok), /// Parser encountered an invalid token @@ -146,7 +146,7 @@ impl From> for ParseError { match err { // TODO: Are there cases where this isn't an EOF? LalrpopError::InvalidToken { location } => ParseError { - error: ParseErrorType::EOF, + error: ParseErrorType::Eof, location, }, LalrpopError::ExtraToken { token } => ParseError { @@ -171,7 +171,7 @@ impl From> for ParseError { } } LalrpopError::UnrecognizedEOF { location, .. } => ParseError { - error: ParseErrorType::EOF, + error: ParseErrorType::Eof, location, }, } @@ -187,7 +187,7 @@ impl fmt::Display for ParseError { impl fmt::Display for ParseErrorType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - ParseErrorType::EOF => write!(f, "Got unexpected EOF"), + ParseErrorType::Eof => write!(f, "Got unexpected EOF"), ParseErrorType::ExtraToken(ref tok) => write!(f, "Got extraneous token: {:?}", tok), ParseErrorType::InvalidToken => write!(f, "Got invalid token"), ParseErrorType::UnrecognizedToken(ref tok, ref expected) => { diff --git a/parser/src/lexer.rs b/parser/src/lexer.rs index 9885fd5fd..ebfaa0a17 100644 --- a/parser/src/lexer.rs +++ b/parser/src/lexer.rs @@ -1189,7 +1189,7 @@ where if self.chr0.is_none() { return Err(LexicalError { - error: LexicalErrorType::EOF, + error: LexicalErrorType::Eof, location: self.get_pos(), }); } diff --git a/src/shell.rs b/src/shell.rs index 1987e0834..7bab4b7dd 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -23,11 +23,11 @@ fn shell_exec(vm: &VirtualMachine, source: &str, scope: Scope) -> ShellExecResul Err(err) => ShellExecResult::PyErr(err), }, Err(CompileError { - error: CompileErrorType::Parse(ParseErrorType::Lexical(LexicalErrorType::EOF)), + error: CompileErrorType::Parse(ParseErrorType::Lexical(LexicalErrorType::Eof)), .. - }) => ShellExecResult::Continue, - Err(CompileError { - error: CompileErrorType::Parse(ParseErrorType::EOF), + }) + | Err(CompileError { + error: CompileErrorType::Parse(ParseErrorType::Eof), .. }) => ShellExecResult::Continue, Err(err) => ShellExecResult::PyErr(vm.new_syntax_error(&err)), @@ -108,7 +108,7 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> { vm.new_exception_empty(vm.ctx.exceptions.keyboard_interrupt.clone()); Err(keyboard_interrupt) } - ReadlineResult::EOF => { + ReadlineResult::Eof => { break; } ReadlineResult::EncodingError => { @@ -119,7 +119,7 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> { eprintln!("Readline error: {:?}", err); break; } - ReadlineResult::IO(err) => { + ReadlineResult::Io(err) => { eprintln!("IO error: {:?}", err); break; } diff --git a/vm/src/builtins/complex.rs b/vm/src/builtins/complex.rs index a1817a586..bc3ca8ae2 100644 --- a/vm/src/builtins/complex.rs +++ b/vm/src/builtins/complex.rs @@ -241,7 +241,7 @@ impl PyComplex { if mod_val.flatten().is_some() { Err(vm.new_value_error("complex modulo not allowed".to_owned())) } else { - self.op(other, |a, b| Ok(inner_pow(a, b, vm)?), vm) + self.op(other, |a, b| inner_pow(a, b, vm), vm) } } @@ -251,7 +251,7 @@ impl PyComplex { other: PyObjectRef, vm: &VirtualMachine, ) -> PyResult> { - self.op(other, |a, b| Ok(inner_pow(b, a, vm)?), vm) + self.op(other, |a, b| inner_pow(b, a, vm), vm) } #[pymethod(name = "__bool__")] diff --git a/vm/src/builtins/make_module.rs b/vm/src/builtins/make_module.rs index 87fdf5559..c62a5d09c 100644 --- a/vm/src/builtins/make_module.rs +++ b/vm/src/builtins/make_module.rs @@ -382,13 +382,13 @@ mod decl { let mut readline = Readline::new(()); match readline.readline(prompt) { ReadlineResult::Line(s) => Ok(vm.ctx.new_str(s)), - ReadlineResult::EOF => { + ReadlineResult::Eof => { Err(vm.new_exception_empty(vm.ctx.exceptions.eof_error.clone())) } ReadlineResult::Interrupt => { Err(vm.new_exception_empty(vm.ctx.exceptions.keyboard_interrupt.clone())) } - ReadlineResult::IO(e) => Err(vm.new_os_error(e.to_string())), + ReadlineResult::Io(e) => Err(vm.new_os_error(e.to_string())), ReadlineResult::EncodingError => { Err(vm.new_unicode_decode_error("Error decoding readline input".to_owned())) } diff --git a/vm/src/bytesinner.rs b/vm/src/bytesinner.rs index 215c0bdf7..c1b3d3b48 100644 --- a/vm/src/bytesinner.rs +++ b/vm/src/bytesinner.rs @@ -1013,7 +1013,7 @@ impl<'s> AnyStr<'s> for [u8] { { let mut splited = Vec::new(); let mut count = maxsplit; - let mut haystack = &self[..]; + let mut haystack = self; while let Some(offset) = haystack.find_byteset(ASCII_WHITESPACES) { if offset != 0 { if count == 0 { @@ -1036,7 +1036,7 @@ impl<'s> AnyStr<'s> for [u8] { { let mut splited = Vec::new(); let mut count = maxsplit; - let mut haystack = &self[..]; + let mut haystack = self; while let Some(offset) = haystack.rfind_byteset(ASCII_WHITESPACES) { if offset + 1 != haystack.len() { if count == 0 { @@ -1185,7 +1185,7 @@ pub fn bytes_from_object(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult { haystack: PyObjectRef, ) -> PyResult { let found = vm._membership(haystack, needle)?; - Ok(pybool::boolval(vm, found)?) + pybool::boolval(vm, found) } fn _not_in( diff --git a/vm/src/lib.rs b/vm/src/lib.rs index c511b73b1..eb53518da 100644 --- a/vm/src/lib.rs +++ b/vm/src/lib.rs @@ -6,12 +6,15 @@ //! - Base objects // for methods like vm.to_str(), not the typical use of 'to' as a method prefix -#![allow(clippy::wrong_self_convention, clippy::implicit_hasher)] +#![allow(clippy::wrong_self_convention)] // to allow `mod foo {}` in foo.rs; clippy thinks this is a mistake/misunderstanding of // how `mod` works, but we want this sometimes for pymodule declarations #![allow(clippy::module_inception)] // to encourage good API design, see https://github.com/rust-lang/rust-clippy/issues/6726 #![allow(clippy::unnecessary_wraps)] +// we want to mirror python naming conventions when defining python structs, so that does mean +// uppercase acronyms, e.g. TextIOWrapper instead of TextIoWrapper +#![allow(clippy::upper_case_acronyms)] #![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/master/logo.png")] #![doc(html_root_url = "https://docs.rs/rustpython-vm/")] diff --git a/vm/src/readline.rs b/vm/src/readline.rs index 8a6fb9dfe..8844b3788 100644 --- a/vm/src/readline.rs +++ b/vm/src/readline.rs @@ -6,9 +6,9 @@ type OtherResult = Result; pub enum ReadlineResult { Line(String), - EOF, + Eof, Interrupt, - IO(std::io::Error), + Io(std::io::Error), EncodingError, Other(OtherError), } @@ -45,16 +45,16 @@ mod basic_readline { use std::io::prelude::*; print!("{}", prompt); if let Err(e) = io::stdout().flush() { - return ReadlineResult::IO(e); + return ReadlineResult::Io(e); } match io::stdin().lock().lines().next() { Some(Ok(line)) => ReadlineResult::Line(line), - None => ReadlineResult::EOF, + None => ReadlineResult::Eof, Some(Err(e)) => match e.kind() { io::ErrorKind::Interrupted => ReadlineResult::Interrupt, io::ErrorKind::InvalidData => ReadlineResult::EncodingError, - _ => ReadlineResult::IO(e), + _ => ReadlineResult::Io(e), }, } } @@ -112,8 +112,8 @@ mod rustyline_readline { match self.repl.readline(prompt) { Ok(line) => ReadlineResult::Line(line), Err(ReadlineError::Interrupted) => ReadlineResult::Interrupt, - Err(ReadlineError::Eof) => ReadlineResult::EOF, - Err(ReadlineError::Io(e)) => ReadlineResult::IO(e), + Err(ReadlineError::Eof) => ReadlineResult::Eof, + Err(ReadlineError::Io(e)) => ReadlineResult::Io(e), #[cfg(unix)] Err(ReadlineError::Utf8Error) => ReadlineResult::EncodingError, #[cfg(windows)] diff --git a/vm/src/stdlib/winreg.rs b/vm/src/stdlib/winreg.rs index f869fb633..d5520a5dd 100644 --- a/vm/src/stdlib/winreg.rs +++ b/vm/src/stdlib/winreg.rs @@ -240,7 +240,7 @@ fn reg_to_py(value: RegValue, vm: &VirtualMachine) -> PyResult { }; i.map(|i| vm.ctx.new_int(i)) }}; - }; + } let bytes_to_wide = |b: &[u8]| -> Option<&[u16]> { if b.len() % 2 == 0 { Some(unsafe { std::slice::from_raw_parts(b.as_ptr().cast(), b.len() / 2) }) diff --git a/wasm/lib/src/convert.rs b/wasm/lib/src/convert.rs index b07838fb9..bdf78cc15 100644 --- a/wasm/lib/src/convert.rs +++ b/wasm/lib/src/convert.rs @@ -255,7 +255,7 @@ pub fn syntax_err(err: CompileError) -> SyntaxError { &"col".into(), &(err.location.column() as u32).into(), ); - let can_continue = matches!(&err.error, CompileErrorType::Parse(ParseErrorType::EOF)); + let can_continue = matches!(&err.error, CompileErrorType::Parse(ParseErrorType::Eof)); let _ = Reflect::set(&js_err, &"canContinue".into(), &can_continue.into()); js_err }