Skip to content

Commit 35884dc

Browse files
committed
Fix nightly clippy warnings
1 parent 4e094ea commit 35884dc

File tree

21 files changed

+38
-49
lines changed

21 files changed

+38
-49
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ fn run_rustpython(vm: &VirtualMachine, run_mode: RunMode) -> PyResult<()> {
197197
}
198198
let res = match run_mode {
199199
RunMode::Command(command) => {
200-
debug!("Running command {}", command);
200+
debug!("Running command {command}");
201201
vm.run_code_string(scope.clone(), &command, "<stdin>".to_owned())
202202
.map(drop)
203203
}
204204
RunMode::Module(module) => {
205-
debug!("Running module {}", module);
205+
debug!("Running module {module}");
206206
vm.run_module(&module)
207207
}
208208
RunMode::InstallPip(installer) => install_pip(installer, scope.clone(), vm),

src/shell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
152152
continuing_line = false;
153153
let result = match repl.readline(prompt) {
154154
ReadlineResult::Line(line) => {
155-
debug!("You entered {:?}", line);
155+
debug!("You entered {line:?}");
156156

157157
repl.add_history_entry(line.trim_end()).unwrap();
158158

stdlib/src/binascii.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,7 @@ impl ToPyException for Base64DecodeError {
756756
InvalidLastSymbol(_, PAD) => "Excess data after padding".to_owned(),
757757
InvalidLastSymbol(length, _) => {
758758
format!(
759-
"Invalid base64-encoded string: number of data characters {} cannot be 1 more than a multiple of 4",
760-
length
759+
"Invalid base64-encoded string: number of data characters {length} cannot be 1 more than a multiple of 4"
761760
)
762761
}
763762
// TODO: clean up errors

stdlib/src/csv.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,8 @@ mod _csv {
347347
let arg_len = rest.args.len();
348348
if arg_len != 1 {
349349
return Err(vm.new_type_error(
350-
format!(
351-
"field_size_limit() takes at most 1 argument ({} given)",
352-
arg_len
353-
)
354-
.to_string(),
350+
format!("field_size_limit() takes at most 1 argument ({arg_len} given)")
351+
.to_string(),
355352
));
356353
}
357354
let Ok(new_size) = rest.args.first().unwrap().try_int(vm) else {
@@ -701,7 +698,7 @@ mod _csv {
701698
if let Some(dialect) = g.get(name) {
702699
Ok(self.update_py_dialect(*dialect))
703700
} else {
704-
Err(new_csv_error(vm, format!("{} is not registered.", name)))
701+
Err(new_csv_error(vm, format!("{name} is not registered.")))
705702
}
706703
// TODO
707704
// Maybe need to update the obj from HashMap

vm/src/buffer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl FormatSpec {
363363
// Loop over all opcodes:
364364
for code in &self.codes {
365365
buffer = &mut buffer[code.pre_padding..];
366-
debug!("code: {:?}", code);
366+
debug!("code: {code:?}");
367367
match code.code {
368368
FormatType::Str => {
369369
let (buf, rest) = buffer.split_at_mut(code.repeat);
@@ -407,7 +407,7 @@ impl FormatSpec {
407407
let mut items = Vec::with_capacity(self.arg_count);
408408
for code in &self.codes {
409409
data = &data[code.pre_padding..];
410-
debug!("unpack code: {:?}", code);
410+
debug!("unpack code: {code:?}");
411411
match code.code {
412412
FormatType::Pad => {
413413
data = &data[code.repeat..];

vm/src/builtins/complex.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ impl PyObjectRef {
6666
warnings::warn(
6767
vm.ctx.exceptions.deprecation_warning,
6868
format!(
69-
"__complex__ returned non-complex (type {}). \
69+
"__complex__ returned non-complex (type {ret_class}). \
7070
The ability to return an instance of a strict subclass of complex \
71-
is deprecated, and may be removed in a future version of Python.",
72-
ret_class
71+
is deprecated, and may be removed in a future version of Python."
7372
),
7473
1,
7574
vm,

vm/src/builtins/object.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,12 @@ impl Constructor for PyBaseObject {
5353
0 => {}
5454
1 => {
5555
return Err(vm.new_type_error(format!(
56-
"class {} without an implementation for abstract method '{}'",
57-
name, methods
56+
"class {name} without an implementation for abstract method '{methods}'"
5857
)));
5958
}
6059
2.. => {
6160
return Err(vm.new_type_error(format!(
62-
"class {} without an implementation for abstract methods '{}'",
63-
name, methods
61+
"class {name} without an implementation for abstract methods '{methods}'"
6462
)));
6563
}
6664
// TODO: remove `allow` when redox build doesn't complain about it

vm/src/builtins/property.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ impl PyProperty {
132132
let func_args_len = func_args.args.len();
133133
let (_owner, name): (PyObjectRef, PyObjectRef) = func_args.bind(vm).map_err(|_e| {
134134
vm.new_type_error(format!(
135-
"__set_name__() takes 2 positional arguments but {} were given",
136-
func_args_len
135+
"__set_name__() takes 2 positional arguments but {func_args_len} were given"
137136
))
138137
})?;
139138

vm/src/builtins/super.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// cspell:ignore cmeth
12
/*! Python `super` class.
23
34
See also [CPython source code.](https://github.com/python/cpython/blob/50b48572d9a90c5bb36e2bef6179548ea927a35a/Objects/typeobject.c#L7663)
@@ -125,8 +126,8 @@ impl Initializer for PySuper {
125126
(typ, obj)
126127
};
127128

128-
let mut inner = PySuperInner::new(typ, obj, vm)?;
129-
std::mem::swap(&mut inner, &mut zelf.inner.write());
129+
let inner = PySuperInner::new(typ, obj, vm)?;
130+
*zelf.inner.write() = inner;
130131

131132
Ok(())
132133
}

vm/src/codecs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl StandardEncoding {
419419
match encoding {
420420
"be" => Some(Self::Utf32Be),
421421
"le" => Some(Self::Utf32Le),
422-
_ => return None,
422+
_ => None,
423423
}
424424
} else {
425425
None
@@ -1116,7 +1116,7 @@ fn replace_errors(err: PyObjectRef, vm: &VirtualMachine) -> PyResult<(PyObjectRe
11161116
let replace = replacement_char.repeat(range.end - range.start);
11171117
Ok((replace.to_pyobject(vm), range.end))
11181118
} else {
1119-
return Err(bad_err_type(err, vm));
1119+
Err(bad_err_type(err, vm))
11201120
}
11211121
}
11221122

vm/src/eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{PyResult, VirtualMachine, compiler, scope::Scope};
33
pub fn eval(vm: &VirtualMachine, source: &str, scope: Scope, source_path: &str) -> PyResult {
44
match vm.compile(source, compiler::Mode::Eval, source_path.to_owned()) {
55
Ok(bytecode) => {
6-
debug!("Code object: {:?}", bytecode);
6+
debug!("Code object: {bytecode:?}");
77
vm.run_code_obj(bytecode, scope)
88
}
99
Err(err) => Err(vm.new_syntax_error(&err, Some(source))),

vm/src/exceptions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl VirtualMachine {
206206
lineno
207207
)?;
208208
} else if let Some(filename) = maybe_filename {
209-
filename_suffix = format!(" ({})", filename);
209+
filename_suffix = format!(" ({filename})");
210210
}
211211

212212
if let Some(text) = maybe_text {
@@ -215,7 +215,7 @@ impl VirtualMachine {
215215
let l_text = r_text.trim_start_matches([' ', '\n', '\x0c']); // \x0c is \f
216216
let spaces = (r_text.len() - l_text.len()) as isize;
217217

218-
writeln!(output, " {}", l_text)?;
218+
writeln!(output, " {l_text}")?;
219219

220220
let maybe_offset: Option<isize> =
221221
getattr("offset").and_then(|obj| obj.try_to_value::<isize>(vm).ok());
@@ -1615,7 +1615,7 @@ pub(super) mod types {
16151615
format!("{} ({}, line {})", msg, basename(filename.as_str()), lineno)
16161616
}
16171617
(Some(lineno), None) => {
1618-
format!("{} (line {})", msg, lineno)
1618+
format!("{msg} (line {lineno})")
16191619
}
16201620
(None, Some(filename)) => {
16211621
format!("{} ({})", msg, basename(filename.as_str()))

vm/src/frame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ impl ExecutingFrame<'_> {
16671667
.topmost_exception()
16681668
.ok_or_else(|| vm.new_runtime_error("No active exception to reraise".to_owned()))?,
16691669
};
1670-
debug!("Exception raised: {:?} with cause: {:?}", exception, cause);
1670+
debug!("Exception raised: {exception:?} with cause: {cause:?}");
16711671
if let Some(cause) = cause {
16721672
exception.set_cause(cause);
16731673
}

vm/src/protocol/number.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ impl PyObject {
5151
Err(err) => return err,
5252
};
5353
vm.new_value_error(format!(
54-
"invalid literal for int() with base {}: {}",
55-
base, repr,
54+
"invalid literal for int() with base {base}: {repr}",
5655
))
5756
})?;
5857
Ok(PyInt::from(i).into_ref(&vm.ctx))
@@ -475,10 +474,9 @@ impl PyNumber<'_> {
475474
warnings::warn(
476475
vm.ctx.exceptions.deprecation_warning,
477476
format!(
478-
"__int__ returned non-int (type {}). \
477+
"__int__ returned non-int (type {ret_class}). \
479478
The ability to return an instance of a strict subclass of int \
480479
is deprecated, and may be removed in a future version of Python.",
481-
ret_class
482480
),
483481
1,
484482
vm,
@@ -509,10 +507,9 @@ impl PyNumber<'_> {
509507
warnings::warn(
510508
vm.ctx.exceptions.deprecation_warning,
511509
format!(
512-
"__index__ returned non-int (type {}). \
510+
"__index__ returned non-int (type {ret_class}). \
513511
The ability to return an instance of a strict subclass of int \
514512
is deprecated, and may be removed in a future version of Python.",
515-
ret_class
516513
),
517514
1,
518515
vm,
@@ -543,10 +540,9 @@ impl PyNumber<'_> {
543540
warnings::warn(
544541
vm.ctx.exceptions.deprecation_warning,
545542
format!(
546-
"__float__ returned non-float (type {}). \
543+
"__float__ returned non-float (type {ret_class}). \
547544
The ability to return an instance of a strict subclass of float \
548545
is deprecated, and may be removed in a future version of Python.",
549-
ret_class
550546
),
551547
1,
552548
vm,

vm/src/stdlib/ctypes/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl PyCSimple {
251251
#[pyclassmethod]
252252
fn repeat(cls: PyTypeRef, n: isize, vm: &VirtualMachine) -> PyResult {
253253
if n < 0 {
254-
return Err(vm.new_value_error(format!("Array length must be >= 0, not {}", n)));
254+
return Err(vm.new_value_error(format!("Array length must be >= 0, not {n}")));
255255
}
256256
Ok(PyCArrayType {
257257
inner: PyCArray {

vm/src/stdlib/ctypes/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl Function {
7777
}
7878
})
7979
.collect::<PyResult<Vec<Type>>>()?;
80-
let terminated = format!("{}\0", function);
80+
let terminated = format!("{function}\0");
8181
let pointer: Symbol<'_, FP> = unsafe {
8282
library
8383
.get(terminated.as_bytes())

vm/src/stdlib/ctypes/structure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl GetAttr for PyCStructure {
5353
let data = zelf.data.read();
5454
match data.get(&name) {
5555
Some(value) => Ok(value.clone()),
56-
None => Err(vm.new_attribute_error(format!("No attribute named {}", name))),
56+
None => Err(vm.new_attribute_error(format!("No attribute named {name}"))),
5757
}
5858
}
5959
}

vm/src/stdlib/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ mod _io {
11751175
vm.call_method(self.raw.as_ref().unwrap(), "readinto", (mem_obj.clone(),));
11761176

11771177
mem_obj.release();
1178-
std::mem::swap(v, &mut read_buf.take());
1178+
*v = read_buf.take();
11791179

11801180
res?
11811181
}

vm/src/stdlib/posix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,7 @@ pub mod module {
19891989
let pathname = vm.ctx.new_dict();
19901990
for variant in PathconfVar::iter() {
19911991
// get the name of variant as a string to use as the dictionary key
1992-
let key = vm.ctx.new_str(format!("{:?}", variant));
1992+
let key = vm.ctx.new_str(format!("{variant:?}"));
19931993
// get the enum from the string and convert it to an integer for the dictionary value
19941994
let value = vm.ctx.new_int(variant as u8);
19951995
pathname
@@ -2185,7 +2185,7 @@ pub mod module {
21852185
let names = vm.ctx.new_dict();
21862186
for variant in SysconfVar::iter() {
21872187
// get the name of variant as a string to use as the dictionary key
2188-
let key = vm.ctx.new_str(format!("{:?}", variant));
2188+
let key = vm.ctx.new_str(format!("{variant:?}"));
21892189
// get the enum from the string and convert it to an integer for the dictionary value
21902190
let value = vm.ctx.new_int(variant as u8);
21912191
names

vm/src/stdlib/sys.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,9 @@ mod sys {
317317
let mut source = String::new();
318318
handle
319319
.read_to_string(&mut source)
320-
.map_err(|e| vm.new_os_error(format!("Error reading from stdin: {}", e)))?;
320+
.map_err(|e| vm.new_os_error(format!("Error reading from stdin: {e}")))?;
321321
vm.compile(&source, crate::compiler::Mode::Single, "<stdin>".to_owned())
322-
.map_err(|e| vm.new_os_error(format!("Error running stdin: {}", e)))?;
322+
.map_err(|e| vm.new_os_error(format!("Error running stdin: {e}")))?;
323323
Ok(())
324324
}
325325

@@ -723,7 +723,7 @@ mod sys {
723723
vm.state.int_max_str_digits.store(maxdigits);
724724
Ok(())
725725
} else {
726-
let error = format!("maxdigits must be 0 or larger than {:?}", threshold);
726+
let error = format!("maxdigits must be 0 or larger than {threshold:?}");
727727
Err(vm.new_value_error(error))
728728
}
729729
}

vm/src/vm/compile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl VirtualMachine {
4949
self.run_code_string(scope, &source, path.to_owned())?;
5050
}
5151
Err(err) => {
52-
error!("Failed reading file '{}': {}", path, err);
52+
error!("Failed reading file '{path}': {err}");
5353
// TODO: Need to change to ExitCode or Termination
5454
std::process::exit(1);
5555
}

0 commit comments

Comments
 (0)