Skip to content

Commit d935fbc

Browse files
committed
Fix nightly clippy warnings
1 parent 39bed0d commit d935fbc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+226
-284
lines changed

compiler/codegen/src/compile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ impl Compiler {
457457
NameUsage::Delete if is_forbidden_name(name) => "cannot delete",
458458
_ => return Ok(()),
459459
};
460-
Err(self.error(CodegenErrorType::SyntaxError(format!("{} {}", msg, name))))
460+
Err(self.error(CodegenErrorType::SyntaxError(format!("{msg} {name}"))))
461461
}
462462

463463
fn compile_name(&mut self, name: &str, usage: NameUsage) -> CompileResult<()> {

compiler/codegen/src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ impl fmt::Display for CodegenErrorType {
3737
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3838
use CodegenErrorType::*;
3939
match self {
40-
Assign(target) => write!(f, "cannot assign to {}", target),
41-
Delete(target) => write!(f, "cannot delete {}", target),
40+
Assign(target) => write!(f, "cannot assign to {target}"),
41+
Delete(target) => write!(f, "cannot delete {target}"),
4242
SyntaxError(err) => write!(f, "{}", err.as_str()),
4343
MultipleStarArgs => {
4444
write!(f, "two starred expressions in assignment")
@@ -59,7 +59,7 @@ impl fmt::Display for CodegenErrorType {
5959
"from __future__ imports must occur at the beginning of the file"
6060
),
6161
InvalidFutureFeature(feat) => {
62-
write!(f, "future feature {} is not defined", feat)
62+
write!(f, "future feature {feat} is not defined")
6363
}
6464
FunctionImportStar => {
6565
write!(f, "import * only allowed at module level")

compiler/codegen/src/symboltable.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,27 +1154,26 @@ impl SymbolTableBuilder {
11541154
SymbolUsage::Global if !symbol.is_global() => {
11551155
if flags.contains(SymbolFlags::PARAMETER) {
11561156
return Err(SymbolTableError {
1157-
error: format!("name '{}' is parameter and global", name),
1157+
error: format!("name '{name}' is parameter and global"),
11581158
location,
11591159
});
11601160
}
11611161
if flags.contains(SymbolFlags::REFERENCED) {
11621162
return Err(SymbolTableError {
1163-
error: format!("name '{}' is used prior to global declaration", name),
1163+
error: format!("name '{name}' is used prior to global declaration"),
11641164
location,
11651165
});
11661166
}
11671167
if flags.contains(SymbolFlags::ANNOTATED) {
11681168
return Err(SymbolTableError {
1169-
error: format!("annotated name '{}' can't be global", name),
1169+
error: format!("annotated name '{name}' can't be global"),
11701170
location,
11711171
});
11721172
}
11731173
if flags.contains(SymbolFlags::ASSIGNED) {
11741174
return Err(SymbolTableError {
11751175
error: format!(
1176-
"name '{}' is assigned to before global declaration",
1177-
name
1176+
"name '{name}' is assigned to before global declaration"
11781177
),
11791178
location,
11801179
});
@@ -1183,27 +1182,26 @@ impl SymbolTableBuilder {
11831182
SymbolUsage::Nonlocal => {
11841183
if flags.contains(SymbolFlags::PARAMETER) {
11851184
return Err(SymbolTableError {
1186-
error: format!("name '{}' is parameter and nonlocal", name),
1185+
error: format!("name '{name}' is parameter and nonlocal"),
11871186
location,
11881187
});
11891188
}
11901189
if flags.contains(SymbolFlags::REFERENCED) {
11911190
return Err(SymbolTableError {
1192-
error: format!("name '{}' is used prior to nonlocal declaration", name),
1191+
error: format!("name '{name}' is used prior to nonlocal declaration"),
11931192
location,
11941193
});
11951194
}
11961195
if flags.contains(SymbolFlags::ANNOTATED) {
11971196
return Err(SymbolTableError {
1198-
error: format!("annotated name '{}' can't be nonlocal", name),
1197+
error: format!("annotated name '{name}' can't be nonlocal"),
11991198
location,
12001199
});
12011200
}
12021201
if flags.contains(SymbolFlags::ASSIGNED) {
12031202
return Err(SymbolTableError {
12041203
error: format!(
1205-
"name '{}' is assigned to before nonlocal declaration",
1206-
name
1204+
"name '{name}' is assigned to before nonlocal declaration"
12071205
),
12081206
location,
12091207
});
@@ -1220,7 +1218,7 @@ impl SymbolTableBuilder {
12201218
match role {
12211219
SymbolUsage::Nonlocal if scope_depth < 2 => {
12221220
return Err(SymbolTableError {
1223-
error: format!("cannot define nonlocal '{}' at top level.", name),
1221+
error: format!("cannot define nonlocal '{name}' at top level."),
12241222
location,
12251223
})
12261224
}

compiler/core/src/bytecode.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -482,15 +482,15 @@ impl<C: Constant> BorrowedConstant<'_, C> {
482482
// takes `self` because we need to consume the iterator
483483
pub fn fmt_display(self, f: &mut fmt::Formatter) -> fmt::Result {
484484
match self {
485-
BorrowedConstant::Integer { value } => write!(f, "{}", value),
486-
BorrowedConstant::Float { value } => write!(f, "{}", value),
487-
BorrowedConstant::Complex { value } => write!(f, "{}", value),
485+
BorrowedConstant::Integer { value } => write!(f, "{value}"),
486+
BorrowedConstant::Float { value } => write!(f, "{value}"),
487+
BorrowedConstant::Complex { value } => write!(f, "{value}"),
488488
BorrowedConstant::Boolean { value } => {
489489
write!(f, "{}", if value { "True" } else { "False" })
490490
}
491-
BorrowedConstant::Str { value } => write!(f, "{:?}", value),
491+
BorrowedConstant::Str { value } => write!(f, "{value:?}"),
492492
BorrowedConstant::Bytes { value } => write!(f, "b{:?}", value.as_bstr()),
493-
BorrowedConstant::Code { code } => write!(f, "{:?}", code),
493+
BorrowedConstant::Code { code } => write!(f, "{code:?}"),
494494
BorrowedConstant::Tuple { elements } => {
495495
write!(f, "(")?;
496496
let mut first = true;
@@ -852,7 +852,7 @@ impl<C: Constant> fmt::Display for CodeObject<C> {
852852
self.display_inner(f, false, 1)?;
853853
for constant in &*self.constants {
854854
if let BorrowedConstant::Code { code } = constant.borrow_constant() {
855-
writeln!(f, "\nDisassembly of {:?}", code)?;
855+
writeln!(f, "\nDisassembly of {code:?}")?;
856856
code.fmt(f)?;
857857
}
858858
}
@@ -1118,14 +1118,14 @@ impl Instruction {
11181118
}
11191119
}
11201120
}
1121-
UnaryOperation { op } => w!(UnaryOperation, format_args!("{:?}", op)),
1122-
BinaryOperation { op } => w!(BinaryOperation, format_args!("{:?}", op)),
1121+
UnaryOperation { op } => w!(UnaryOperation, format_args!("{op:?}")),
1122+
BinaryOperation { op } => w!(BinaryOperation, format_args!("{op:?}")),
11231123
BinaryOperationInplace { op } => {
1124-
w!(BinaryOperationInplace, format_args!("{:?}", op))
1124+
w!(BinaryOperationInplace, format_args!("{op:?}"))
11251125
}
11261126
LoadAttr { idx } => w!(LoadAttr, name(*idx)),
1127-
TestOperation { op } => w!(TestOperation, format_args!("{:?}", op)),
1128-
CompareOperation { op } => w!(CompareOperation, format_args!("{:?}", op)),
1127+
TestOperation { op } => w!(TestOperation, format_args!("{op:?}")),
1128+
CompareOperation { op } => w!(CompareOperation, format_args!("{op:?}")),
11291129
Pop => w!(Pop),
11301130
Rotate2 => w!(Rotate2),
11311131
Rotate3 => w!(Rotate3),
@@ -1139,7 +1139,7 @@ impl Instruction {
11391139
JumpIfFalse { target } => w!(JumpIfFalse, target),
11401140
JumpIfTrueOrPop { target } => w!(JumpIfTrueOrPop, target),
11411141
JumpIfFalseOrPop { target } => w!(JumpIfFalseOrPop, target),
1142-
MakeFunction(flags) => w!(MakeFunction, format_args!("{:?}", flags)),
1142+
MakeFunction(flags) => w!(MakeFunction, format_args!("{flags:?}")),
11431143
CallFunctionPositional { nargs } => w!(CallFunctionPositional, nargs),
11441144
CallFunctionKeyword { nargs } => w!(CallFunctionKeyword, nargs),
11451145
CallFunctionEx { has_kwargs } => w!(CallFunctionEx, has_kwargs),
@@ -1163,7 +1163,7 @@ impl Instruction {
11631163
BeforeAsyncWith => w!(BeforeAsyncWith),
11641164
SetupAsyncWith { end } => w!(SetupAsyncWith, end),
11651165
PopBlock => w!(PopBlock),
1166-
Raise { kind } => w!(Raise, format_args!("{:?}", kind)),
1166+
Raise { kind } => w!(Raise, format_args!("{kind:?}")),
11671167
BuildString { size } => w!(BuildString, size),
11681168
BuildTuple { size, unpack } => w!(BuildTuple, size, unpack),
11691169
BuildList { size, unpack } => w!(BuildList, size, unpack),
@@ -1182,7 +1182,7 @@ impl Instruction {
11821182
LoadBuildClass => w!(LoadBuildClass),
11831183
UnpackSequence { size } => w!(UnpackSequence, size),
11841184
UnpackEx { before, after } => w!(UnpackEx, before, after),
1185-
FormatValue { conversion } => w!(FormatValue, format_args!("{:?}", conversion)),
1185+
FormatValue { conversion } => w!(FormatValue, format_args!("{conversion:?}")),
11861186
PopException => w!(PopException),
11871187
Reverse { amount } => w!(Reverse, amount),
11881188
GetAwaitable => w!(GetAwaitable),

compiler/parser/src/error.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl fmt::Display for LexicalErrorType {
3434
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3535
match self {
3636
LexicalErrorType::StringError => write!(f, "Got unexpected string"),
37-
LexicalErrorType::FStringError(error) => write!(f, "Got error in f-string: {}", error),
37+
LexicalErrorType::FStringError(error) => write!(f, "Got error in f-string: {error}"),
3838
LexicalErrorType::UnicodeError => write!(f, "Got unexpected unicode"),
3939
LexicalErrorType::NestingError => write!(f, "Got unexpected nesting"),
4040
LexicalErrorType::IndentationError => {
@@ -56,13 +56,13 @@ impl fmt::Display for LexicalErrorType {
5656
write!(f, "positional argument follows keyword argument")
5757
}
5858
LexicalErrorType::UnrecognizedToken { tok } => {
59-
write!(f, "Got unexpected token {}", tok)
59+
write!(f, "Got unexpected token {tok}")
6060
}
6161
LexicalErrorType::LineContinuationError => {
6262
write!(f, "unexpected character after line continuation character")
6363
}
6464
LexicalErrorType::Eof => write!(f, "unexpected EOF while parsing"),
65-
LexicalErrorType::OtherError(msg) => write!(f, "{}", msg),
65+
LexicalErrorType::OtherError(msg) => write!(f, "{msg}"),
6666
}
6767
}
6868
}
@@ -97,17 +97,16 @@ impl fmt::Display for FStringErrorType {
9797
FStringErrorType::UnopenedRbrace => write!(f, "Unopened '}}'"),
9898
FStringErrorType::ExpectedRbrace => write!(f, "Expected '}}' after conversion flag."),
9999
FStringErrorType::InvalidExpression(error) => {
100-
write!(f, "{}", error)
100+
write!(f, "{error}")
101101
}
102102
FStringErrorType::InvalidConversionFlag => write!(f, "invalid conversion character"),
103103
FStringErrorType::EmptyExpression => write!(f, "empty expression not allowed"),
104104
FStringErrorType::MismatchedDelimiter(first, second) => write!(
105105
f,
106-
"closing parenthesis '{}' does not match opening parenthesis '{}'",
107-
second, first
106+
"closing parenthesis '{second}' does not match opening parenthesis '{first}'"
108107
),
109108
FStringErrorType::SingleRbrace => write!(f, "single '}}' is not allowed"),
110-
FStringErrorType::Unmatched(delim) => write!(f, "unmatched '{}'", delim),
109+
FStringErrorType::Unmatched(delim) => write!(f, "unmatched '{delim}'"),
111110
FStringErrorType::ExpressionNestedTooDeeply => {
112111
write!(f, "expressions nested too deeply")
113112
}
@@ -118,7 +117,7 @@ impl fmt::Display for FStringErrorType {
118117
if *c == '\\' {
119118
write!(f, "f-string expression part cannot include a backslash")
120119
} else {
121-
write!(f, "f-string expression part cannot include '{}'s", c)
120+
write!(f, "f-string expression part cannot include '{c}'s")
122121
}
123122
}
124123
}
@@ -198,18 +197,18 @@ impl fmt::Display for ParseErrorType {
198197
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
199198
match *self {
200199
ParseErrorType::Eof => write!(f, "Got unexpected EOF"),
201-
ParseErrorType::ExtraToken(ref tok) => write!(f, "Got extraneous token: {:?}", tok),
200+
ParseErrorType::ExtraToken(ref tok) => write!(f, "Got extraneous token: {tok:?}"),
202201
ParseErrorType::InvalidToken => write!(f, "Got invalid token"),
203202
ParseErrorType::UnrecognizedToken(ref tok, ref expected) => {
204203
if *tok == Tok::Indent {
205204
write!(f, "unexpected indent")
206205
} else if expected.as_deref() == Some("Indent") {
207206
write!(f, "expected an indented block")
208207
} else {
209-
write!(f, "invalid syntax. Got unexpected token {}", tok)
208+
write!(f, "invalid syntax. Got unexpected token {tok}")
210209
}
211210
}
212-
ParseErrorType::Lexical(ref error) => write!(f, "{}", error),
211+
ParseErrorType::Lexical(ref error) => write!(f, "{error}"),
213212
}
214213
}
215214
}

compiler/parser/src/fstring.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl FStringParser {
344344
}
345345

346346
fn parse_fstring_expr(source: &str) -> Result<Expr, ParseError> {
347-
let fstring_body = format!("({})", source);
347+
let fstring_body = format!("({source})");
348348
parse_expression(&fstring_body, "<fstring>")
349349
}
350350

compiler/parser/src/lexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ where
321321
let value_text = self.radix_run(radix);
322322
let end_pos = self.get_pos();
323323
let value = BigInt::from_str_radix(&value_text, radix).map_err(|e| LexicalError {
324-
error: LexicalErrorType::OtherError(format!("{:?}", e)),
324+
error: LexicalErrorType::OtherError(format!("{e:?}")),
325325
location: start_pos,
326326
})?;
327327
Ok((start_pos, Tok::Int { value }, end_pos))

compiler/parser/src/token.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@ impl fmt::Display for Tok {
118118
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
119119
use Tok::*;
120120
match self {
121-
Name { name } => write!(f, "'{}'", name),
122-
Int { value } => write!(f, "'{}'", value),
123-
Float { value } => write!(f, "'{}'", value),
124-
Complex { real, imag } => write!(f, "{}j{}", real, imag),
121+
Name { name } => write!(f, "'{name}'"),
122+
Int { value } => write!(f, "'{value}'"),
123+
Float { value } => write!(f, "'{value}'"),
124+
Complex { real, imag } => write!(f, "{real}j{imag}"),
125125
String { value, kind } => {
126126
match kind {
127127
StringKind::F => f.write_str("f")?,
128128
StringKind::U => f.write_str("u")?,
129129
StringKind::Normal => {}
130130
}
131-
write!(f, "{:?}", value)
131+
write!(f, "{value:?}")
132132
}
133133
Bytes { value } => {
134134
write!(f, "b\"")?;
@@ -138,7 +138,7 @@ impl fmt::Display for Tok {
138138
10 => f.write_str("\\n")?,
139139
13 => f.write_str("\\r")?,
140140
32..=126 => f.write_char(*i as char)?,
141-
_ => write!(f, "\\x{:02x}", i)?,
141+
_ => write!(f, "\\x{i:02x}")?,
142142
}
143143
}
144144
f.write_str("\"")

examples/dis.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn main() {
7373
error!("Error while compiling {:?}: {}", script, e);
7474
}
7575
} else {
76-
eprintln!("{:?} is not a file.", script);
76+
eprintln!("{script:?} is not a file.");
7777
}
7878
}
7979
}
@@ -90,7 +90,7 @@ fn display_script(
9090
if expand_codeobjects {
9191
println!("{}", code.display_expand_codeobjects());
9292
} else {
93-
println!("{}", code);
93+
println!("{code}");
9494
}
9595
Ok(())
9696
}

examples/generator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ gen()
3333
PyResult::Ok(v)
3434
})?;
3535
match r {
36-
PyIterReturn::Return(value) => println!("{}", value),
36+
PyIterReturn::Return(value) => println!("{value}"),
3737
PyIterReturn::StopIteration(_) => break,
3838
}
3939
}

examples/package_embed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn main() -> ExitCode {
2020
});
2121
let result = py_main(&interp);
2222
let result = result.map(|result| {
23-
println!("name: {}", result);
23+
println!("name: {result}");
2424
});
2525
ExitCode::from(interp.run(|_vm| result))
2626
}

examples/parse_folder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn main() {
3232

3333
let folder = Path::new(matches.value_of("folder").unwrap());
3434
if folder.exists() && folder.is_dir() {
35-
println!("Parsing folder of python code: {:?}", folder);
35+
println!("Parsing folder of python code: {folder:?}");
3636
let t1 = Instant::now();
3737
let parsed_files = parse_folder(folder).unwrap();
3838
let t2 = Instant::now();
@@ -43,7 +43,7 @@ fn main() {
4343
};
4444
statistics(results);
4545
} else {
46-
println!("{:?} is not a folder.", folder);
46+
println!("{folder:?} is not a folder.");
4747
}
4848
}
4949

@@ -111,13 +111,13 @@ fn statistics(results: ScanResult) {
111111
.iter()
112112
.filter(|p| p.result.is_ok())
113113
.count();
114-
println!("Passed: {} Failed: {} Total: {}", passed, failed, total);
114+
println!("Passed: {passed} Failed: {failed} Total: {total}");
115115
println!(
116116
"That is {} % success rate.",
117117
(passed as f64 * 100.0) / total as f64
118118
);
119119
let duration = results.t2 - results.t1;
120-
println!("Total time spend: {:?}", duration);
120+
println!("Total time spend: {duration:?}");
121121
println!(
122122
"Processed {} files. That's {} files/second",
123123
total,

src/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ fn get_paths(env_variable_name: &str) -> impl Iterator<Item = String> + '_ {
344344
.map(|path| {
345345
path.into_os_string()
346346
.into_string()
347-
.unwrap_or_else(|_| panic!("{} isn't valid unicode", env_variable_name))
347+
.unwrap_or_else(|_| panic!("{env_variable_name} isn't valid unicode"))
348348
})
349349
.collect::<Vec<_>>()
350350
})

src/shell.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
121121
break;
122122
}
123123
ReadlineResult::Other(err) => {
124-
eprintln!("Readline error: {:?}", err);
124+
eprintln!("Readline error: {err:?}");
125125
break;
126126
}
127127
ReadlineResult::Io(err) => {
128-
eprintln!("IO error: {:?}", err);
128+
eprintln!("IO error: {err:?}");
129129
break;
130130
}
131131
};

0 commit comments

Comments
 (0)