Skip to content

Commit 843895c

Browse files
authored
Merge pull request RustPython#2531 from RustPython/clippy-1.51
Fix clippy warnings for 1.51
2 parents a3c5334 + 76f8ed5 commit 843895c

File tree

11 files changed

+34
-31
lines changed

11 files changed

+34
-31
lines changed

parser/src/error.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub enum LexicalErrorType {
2929
UnrecognizedToken { tok: char },
3030
FStringError(FStringErrorType),
3131
LineContinuationError,
32-
EOF,
32+
Eof,
3333
OtherError(String),
3434
}
3535

@@ -64,7 +64,7 @@ impl fmt::Display for LexicalErrorType {
6464
LexicalErrorType::LineContinuationError => {
6565
write!(f, "unexpected character after line continuation character")
6666
}
67-
LexicalErrorType::EOF => write!(f, "unexpected EOF while parsing"),
67+
LexicalErrorType::Eof => write!(f, "unexpected EOF while parsing"),
6868
LexicalErrorType::OtherError(msg) => write!(f, "{}", msg),
6969
}
7070
}
@@ -129,7 +129,7 @@ pub struct ParseError {
129129
#[derive(Debug, PartialEq)]
130130
pub enum ParseErrorType {
131131
/// Parser encountered an unexpected end of input
132-
EOF,
132+
Eof,
133133
/// Parser encountered an extra token
134134
ExtraToken(Tok),
135135
/// Parser encountered an invalid token
@@ -146,7 +146,7 @@ impl From<LalrpopError<Location, Tok, LexicalError>> for ParseError {
146146
match err {
147147
// TODO: Are there cases where this isn't an EOF?
148148
LalrpopError::InvalidToken { location } => ParseError {
149-
error: ParseErrorType::EOF,
149+
error: ParseErrorType::Eof,
150150
location,
151151
},
152152
LalrpopError::ExtraToken { token } => ParseError {
@@ -171,7 +171,7 @@ impl From<LalrpopError<Location, Tok, LexicalError>> for ParseError {
171171
}
172172
}
173173
LalrpopError::UnrecognizedEOF { location, .. } => ParseError {
174-
error: ParseErrorType::EOF,
174+
error: ParseErrorType::Eof,
175175
location,
176176
},
177177
}
@@ -187,7 +187,7 @@ impl fmt::Display for ParseError {
187187
impl fmt::Display for ParseErrorType {
188188
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
189189
match *self {
190-
ParseErrorType::EOF => write!(f, "Got unexpected EOF"),
190+
ParseErrorType::Eof => write!(f, "Got unexpected EOF"),
191191
ParseErrorType::ExtraToken(ref tok) => write!(f, "Got extraneous token: {:?}", tok),
192192
ParseErrorType::InvalidToken => write!(f, "Got invalid token"),
193193
ParseErrorType::UnrecognizedToken(ref tok, ref expected) => {

parser/src/lexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ where
11891189

11901190
if self.chr0.is_none() {
11911191
return Err(LexicalError {
1192-
error: LexicalErrorType::EOF,
1192+
error: LexicalErrorType::Eof,
11931193
location: self.get_pos(),
11941194
});
11951195
}

src/shell.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ fn shell_exec(vm: &VirtualMachine, source: &str, scope: Scope) -> ShellExecResul
2323
Err(err) => ShellExecResult::PyErr(err),
2424
},
2525
Err(CompileError {
26-
error: CompileErrorType::Parse(ParseErrorType::Lexical(LexicalErrorType::EOF)),
26+
error: CompileErrorType::Parse(ParseErrorType::Lexical(LexicalErrorType::Eof)),
2727
..
28-
}) => ShellExecResult::Continue,
29-
Err(CompileError {
30-
error: CompileErrorType::Parse(ParseErrorType::EOF),
28+
})
29+
| Err(CompileError {
30+
error: CompileErrorType::Parse(ParseErrorType::Eof),
3131
..
3232
}) => ShellExecResult::Continue,
3333
Err(err) => ShellExecResult::PyErr(vm.new_syntax_error(&err)),
@@ -108,7 +108,7 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
108108
vm.new_exception_empty(vm.ctx.exceptions.keyboard_interrupt.clone());
109109
Err(keyboard_interrupt)
110110
}
111-
ReadlineResult::EOF => {
111+
ReadlineResult::Eof => {
112112
break;
113113
}
114114
ReadlineResult::EncodingError => {
@@ -119,7 +119,7 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
119119
eprintln!("Readline error: {:?}", err);
120120
break;
121121
}
122-
ReadlineResult::IO(err) => {
122+
ReadlineResult::Io(err) => {
123123
eprintln!("IO error: {:?}", err);
124124
break;
125125
}

vm/src/builtins/complex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl PyComplex {
241241
if mod_val.flatten().is_some() {
242242
Err(vm.new_value_error("complex modulo not allowed".to_owned()))
243243
} else {
244-
self.op(other, |a, b| Ok(inner_pow(a, b, vm)?), vm)
244+
self.op(other, |a, b| inner_pow(a, b, vm), vm)
245245
}
246246
}
247247

@@ -251,7 +251,7 @@ impl PyComplex {
251251
other: PyObjectRef,
252252
vm: &VirtualMachine,
253253
) -> PyResult<PyArithmaticValue<Complex64>> {
254-
self.op(other, |a, b| Ok(inner_pow(b, a, vm)?), vm)
254+
self.op(other, |a, b| inner_pow(b, a, vm), vm)
255255
}
256256

257257
#[pymethod(name = "__bool__")]

vm/src/builtins/make_module.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,13 @@ mod decl {
382382
let mut readline = Readline::new(());
383383
match readline.readline(prompt) {
384384
ReadlineResult::Line(s) => Ok(vm.ctx.new_str(s)),
385-
ReadlineResult::EOF => {
385+
ReadlineResult::Eof => {
386386
Err(vm.new_exception_empty(vm.ctx.exceptions.eof_error.clone()))
387387
}
388388
ReadlineResult::Interrupt => {
389389
Err(vm.new_exception_empty(vm.ctx.exceptions.keyboard_interrupt.clone()))
390390
}
391-
ReadlineResult::IO(e) => Err(vm.new_os_error(e.to_string())),
391+
ReadlineResult::Io(e) => Err(vm.new_os_error(e.to_string())),
392392
ReadlineResult::EncodingError => {
393393
Err(vm.new_unicode_decode_error("Error decoding readline input".to_owned()))
394394
}

vm/src/bytesinner.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ impl<'s> AnyStr<'s> for [u8] {
10131013
{
10141014
let mut splited = Vec::new();
10151015
let mut count = maxsplit;
1016-
let mut haystack = &self[..];
1016+
let mut haystack = self;
10171017
while let Some(offset) = haystack.find_byteset(ASCII_WHITESPACES) {
10181018
if offset != 0 {
10191019
if count == 0 {
@@ -1036,7 +1036,7 @@ impl<'s> AnyStr<'s> for [u8] {
10361036
{
10371037
let mut splited = Vec::new();
10381038
let mut count = maxsplit;
1039-
let mut haystack = &self[..];
1039+
let mut haystack = self;
10401040
while let Some(offset) = haystack.rfind_byteset(ASCII_WHITESPACES) {
10411041
if offset + 1 != haystack.len() {
10421042
if count == 0 {
@@ -1185,7 +1185,7 @@ pub fn bytes_from_object(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult<Vec
11851185
}
11861186

11871187
if let Ok(elements) = vm.map_iterable_object(obj, |x| value_from_object(vm, &x)) {
1188-
return Ok(elements?);
1188+
return elements;
11891189
}
11901190

11911191
Err(vm.new_type_error(

vm/src/frame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ impl ExecutingFrame<'_> {
16531653
haystack: PyObjectRef,
16541654
) -> PyResult<bool> {
16551655
let found = vm._membership(haystack, needle)?;
1656-
Ok(pybool::boolval(vm, found)?)
1656+
pybool::boolval(vm, found)
16571657
}
16581658

16591659
fn _not_in(

vm/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
//! - Base objects
77
88
// for methods like vm.to_str(), not the typical use of 'to' as a method prefix
9-
#![allow(clippy::wrong_self_convention, clippy::implicit_hasher)]
9+
#![allow(clippy::wrong_self_convention)]
1010
// to allow `mod foo {}` in foo.rs; clippy thinks this is a mistake/misunderstanding of
1111
// how `mod` works, but we want this sometimes for pymodule declarations
1212
#![allow(clippy::module_inception)]
1313
// to encourage good API design, see https://github.com/rust-lang/rust-clippy/issues/6726
1414
#![allow(clippy::unnecessary_wraps)]
15+
// we want to mirror python naming conventions when defining python structs, so that does mean
16+
// uppercase acronyms, e.g. TextIOWrapper instead of TextIoWrapper
17+
#![allow(clippy::upper_case_acronyms)]
1518
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/master/logo.png")]
1619
#![doc(html_root_url = "https://docs.rs/rustpython-vm/")]
1720

vm/src/readline.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ type OtherResult<T> = Result<T, OtherError>;
66

77
pub enum ReadlineResult {
88
Line(String),
9-
EOF,
9+
Eof,
1010
Interrupt,
11-
IO(std::io::Error),
11+
Io(std::io::Error),
1212
EncodingError,
1313
Other(OtherError),
1414
}
@@ -45,16 +45,16 @@ mod basic_readline {
4545
use std::io::prelude::*;
4646
print!("{}", prompt);
4747
if let Err(e) = io::stdout().flush() {
48-
return ReadlineResult::IO(e);
48+
return ReadlineResult::Io(e);
4949
}
5050

5151
match io::stdin().lock().lines().next() {
5252
Some(Ok(line)) => ReadlineResult::Line(line),
53-
None => ReadlineResult::EOF,
53+
None => ReadlineResult::Eof,
5454
Some(Err(e)) => match e.kind() {
5555
io::ErrorKind::Interrupted => ReadlineResult::Interrupt,
5656
io::ErrorKind::InvalidData => ReadlineResult::EncodingError,
57-
_ => ReadlineResult::IO(e),
57+
_ => ReadlineResult::Io(e),
5858
},
5959
}
6060
}
@@ -112,8 +112,8 @@ mod rustyline_readline {
112112
match self.repl.readline(prompt) {
113113
Ok(line) => ReadlineResult::Line(line),
114114
Err(ReadlineError::Interrupted) => ReadlineResult::Interrupt,
115-
Err(ReadlineError::Eof) => ReadlineResult::EOF,
116-
Err(ReadlineError::Io(e)) => ReadlineResult::IO(e),
115+
Err(ReadlineError::Eof) => ReadlineResult::Eof,
116+
Err(ReadlineError::Io(e)) => ReadlineResult::Io(e),
117117
#[cfg(unix)]
118118
Err(ReadlineError::Utf8Error) => ReadlineResult::EncodingError,
119119
#[cfg(windows)]

vm/src/stdlib/winreg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ fn reg_to_py(value: RegValue, vm: &VirtualMachine) -> PyResult {
240240
};
241241
i.map(|i| vm.ctx.new_int(i))
242242
}};
243-
};
243+
}
244244
let bytes_to_wide = |b: &[u8]| -> Option<&[u16]> {
245245
if b.len() % 2 == 0 {
246246
Some(unsafe { std::slice::from_raw_parts(b.as_ptr().cast(), b.len() / 2) })

wasm/lib/src/convert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ pub fn syntax_err(err: CompileError) -> SyntaxError {
255255
&"col".into(),
256256
&(err.location.column() as u32).into(),
257257
);
258-
let can_continue = matches!(&err.error, CompileErrorType::Parse(ParseErrorType::EOF));
258+
let can_continue = matches!(&err.error, CompileErrorType::Parse(ParseErrorType::Eof));
259259
let _ = Reflect::set(&js_err, &"canContinue".into(), &can_continue.into());
260260
js_err
261261
}

0 commit comments

Comments
 (0)