Merge pull request #2531 from RustPython/clippy-1.51

Fix clippy warnings for 1.51
This commit is contained in:
Jeong YunWon authored and GitHub committed 2021-03-28 02:36:20 +09:00
commit 843895c04d
11 files changed
+34 -31

No files matched your search

+6 -6
View File
@@ -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<LalrpopError<Location, Tok, LexicalError>> 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<LalrpopError<Location, Tok, LexicalError>> 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) => {
+1 -1
View File
@@ -1189,7 +1189,7 @@ where
if self.chr0.is_none() {
return Err(LexicalError {
error: LexicalErrorType::EOF,
error: LexicalErrorType::Eof,
location: self.get_pos(),
});
}
+6 -6
View File
@@ -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;
}
+2 -2
View File
@@ -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<PyArithmaticValue<Complex64>> {
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__")]
+2 -2
View File
@@ -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()))
}
+3 -3
View File
@@ -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<Vec
}
if let Ok(elements) = vm.map_iterable_object(obj, |x| value_from_object(vm, &x)) {
return Ok(elements?);
return elements;
}
Err(vm.new_type_error(
+1 -1
View File
@@ -1653,7 +1653,7 @@ impl ExecutingFrame<'_> {
haystack: PyObjectRef,
) -> PyResult<bool> {
let found = vm._membership(haystack, needle)?;
Ok(pybool::boolval(vm, found)?)
pybool::boolval(vm, found)
}
fn _not_in(
+4 -1
View File
@@ -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/")]
+7 -7
View File
@@ -6,9 +6,9 @@ type OtherResult<T> = Result<T, OtherError>;
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)]
+1 -1
View File
@@ -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) })
+1 -1
View File
@@ -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
}