Skip to content

Fix nightly clippy warnings #4310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ impl Compiler {
NameUsage::Delete if is_forbidden_name(name) => "cannot delete",
_ => return Ok(()),
};
Err(self.error(CodegenErrorType::SyntaxError(format!("{} {}", msg, name))))
Err(self.error(CodegenErrorType::SyntaxError(format!("{msg} {name}"))))
}

fn compile_name(&mut self, name: &str, usage: NameUsage) -> CompileResult<()> {
Expand Down
6 changes: 3 additions & 3 deletions compiler/codegen/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ impl fmt::Display for CodegenErrorType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use CodegenErrorType::*;
match self {
Assign(target) => write!(f, "cannot assign to {}", target),
Delete(target) => write!(f, "cannot delete {}", target),
Assign(target) => write!(f, "cannot assign to {target}"),
Delete(target) => write!(f, "cannot delete {target}"),
SyntaxError(err) => write!(f, "{}", err.as_str()),
MultipleStarArgs => {
write!(f, "two starred expressions in assignment")
Expand All @@ -59,7 +59,7 @@ impl fmt::Display for CodegenErrorType {
"from __future__ imports must occur at the beginning of the file"
),
InvalidFutureFeature(feat) => {
write!(f, "future feature {} is not defined", feat)
write!(f, "future feature {feat} is not defined")
}
FunctionImportStar => {
write!(f, "import * only allowed at module level")
Expand Down
20 changes: 9 additions & 11 deletions compiler/codegen/src/symboltable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,27 +1154,26 @@ impl SymbolTableBuilder {
SymbolUsage::Global if !symbol.is_global() => {
if flags.contains(SymbolFlags::PARAMETER) {
return Err(SymbolTableError {
error: format!("name '{}' is parameter and global", name),
error: format!("name '{name}' is parameter and global"),
location,
});
}
if flags.contains(SymbolFlags::REFERENCED) {
return Err(SymbolTableError {
error: format!("name '{}' is used prior to global declaration", name),
error: format!("name '{name}' is used prior to global declaration"),
location,
});
}
if flags.contains(SymbolFlags::ANNOTATED) {
return Err(SymbolTableError {
error: format!("annotated name '{}' can't be global", name),
error: format!("annotated name '{name}' can't be global"),
location,
});
}
if flags.contains(SymbolFlags::ASSIGNED) {
return Err(SymbolTableError {
error: format!(
"name '{}' is assigned to before global declaration",
name
"name '{name}' is assigned to before global declaration"
),
location,
});
Expand All @@ -1183,27 +1182,26 @@ impl SymbolTableBuilder {
SymbolUsage::Nonlocal => {
if flags.contains(SymbolFlags::PARAMETER) {
return Err(SymbolTableError {
error: format!("name '{}' is parameter and nonlocal", name),
error: format!("name '{name}' is parameter and nonlocal"),
location,
});
}
if flags.contains(SymbolFlags::REFERENCED) {
return Err(SymbolTableError {
error: format!("name '{}' is used prior to nonlocal declaration", name),
error: format!("name '{name}' is used prior to nonlocal declaration"),
location,
});
}
if flags.contains(SymbolFlags::ANNOTATED) {
return Err(SymbolTableError {
error: format!("annotated name '{}' can't be nonlocal", name),
error: format!("annotated name '{name}' can't be nonlocal"),
location,
});
}
if flags.contains(SymbolFlags::ASSIGNED) {
return Err(SymbolTableError {
error: format!(
"name '{}' is assigned to before nonlocal declaration",
name
"name '{name}' is assigned to before nonlocal declaration"
),
location,
});
Expand All @@ -1220,7 +1218,7 @@ impl SymbolTableBuilder {
match role {
SymbolUsage::Nonlocal if scope_depth < 2 => {
return Err(SymbolTableError {
error: format!("cannot define nonlocal '{}' at top level.", name),
error: format!("cannot define nonlocal '{name}' at top level."),
location,
})
}
Expand Down
28 changes: 14 additions & 14 deletions compiler/core/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,15 @@ impl<C: Constant> BorrowedConstant<'_, C> {
// takes `self` because we need to consume the iterator
pub fn fmt_display(self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
BorrowedConstant::Integer { value } => write!(f, "{}", value),
BorrowedConstant::Float { value } => write!(f, "{}", value),
BorrowedConstant::Complex { value } => write!(f, "{}", value),
BorrowedConstant::Integer { value } => write!(f, "{value}"),
BorrowedConstant::Float { value } => write!(f, "{value}"),
BorrowedConstant::Complex { value } => write!(f, "{value}"),
BorrowedConstant::Boolean { value } => {
write!(f, "{}", if value { "True" } else { "False" })
}
BorrowedConstant::Str { value } => write!(f, "{:?}", value),
BorrowedConstant::Str { value } => write!(f, "{value:?}"),
BorrowedConstant::Bytes { value } => write!(f, "b{:?}", value.as_bstr()),
BorrowedConstant::Code { code } => write!(f, "{:?}", code),
BorrowedConstant::Code { code } => write!(f, "{code:?}"),
BorrowedConstant::Tuple { elements } => {
write!(f, "(")?;
let mut first = true;
Expand Down Expand Up @@ -852,7 +852,7 @@ impl<C: Constant> fmt::Display for CodeObject<C> {
self.display_inner(f, false, 1)?;
for constant in &*self.constants {
if let BorrowedConstant::Code { code } = constant.borrow_constant() {
writeln!(f, "\nDisassembly of {:?}", code)?;
writeln!(f, "\nDisassembly of {code:?}")?;
code.fmt(f)?;
}
}
Expand Down Expand Up @@ -1118,14 +1118,14 @@ impl Instruction {
}
}
}
UnaryOperation { op } => w!(UnaryOperation, format_args!("{:?}", op)),
BinaryOperation { op } => w!(BinaryOperation, format_args!("{:?}", op)),
UnaryOperation { op } => w!(UnaryOperation, format_args!("{op:?}")),
BinaryOperation { op } => w!(BinaryOperation, format_args!("{op:?}")),
BinaryOperationInplace { op } => {
w!(BinaryOperationInplace, format_args!("{:?}", op))
w!(BinaryOperationInplace, format_args!("{op:?}"))
}
LoadAttr { idx } => w!(LoadAttr, name(*idx)),
TestOperation { op } => w!(TestOperation, format_args!("{:?}", op)),
CompareOperation { op } => w!(CompareOperation, format_args!("{:?}", op)),
TestOperation { op } => w!(TestOperation, format_args!("{op:?}")),
CompareOperation { op } => w!(CompareOperation, format_args!("{op:?}")),
Pop => w!(Pop),
Rotate2 => w!(Rotate2),
Rotate3 => w!(Rotate3),
Expand All @@ -1139,7 +1139,7 @@ impl Instruction {
JumpIfFalse { target } => w!(JumpIfFalse, target),
JumpIfTrueOrPop { target } => w!(JumpIfTrueOrPop, target),
JumpIfFalseOrPop { target } => w!(JumpIfFalseOrPop, target),
MakeFunction(flags) => w!(MakeFunction, format_args!("{:?}", flags)),
MakeFunction(flags) => w!(MakeFunction, format_args!("{flags:?}")),
CallFunctionPositional { nargs } => w!(CallFunctionPositional, nargs),
CallFunctionKeyword { nargs } => w!(CallFunctionKeyword, nargs),
CallFunctionEx { has_kwargs } => w!(CallFunctionEx, has_kwargs),
Expand All @@ -1163,7 +1163,7 @@ impl Instruction {
BeforeAsyncWith => w!(BeforeAsyncWith),
SetupAsyncWith { end } => w!(SetupAsyncWith, end),
PopBlock => w!(PopBlock),
Raise { kind } => w!(Raise, format_args!("{:?}", kind)),
Raise { kind } => w!(Raise, format_args!("{kind:?}")),
BuildString { size } => w!(BuildString, size),
BuildTuple { size, unpack } => w!(BuildTuple, size, unpack),
BuildList { size, unpack } => w!(BuildList, size, unpack),
Expand All @@ -1182,7 +1182,7 @@ impl Instruction {
LoadBuildClass => w!(LoadBuildClass),
UnpackSequence { size } => w!(UnpackSequence, size),
UnpackEx { before, after } => w!(UnpackEx, before, after),
FormatValue { conversion } => w!(FormatValue, format_args!("{:?}", conversion)),
FormatValue { conversion } => w!(FormatValue, format_args!("{conversion:?}")),
PopException => w!(PopException),
Reverse { amount } => w!(Reverse, amount),
GetAwaitable => w!(GetAwaitable),
Expand Down
21 changes: 10 additions & 11 deletions compiler/parser/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl fmt::Display for LexicalErrorType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
LexicalErrorType::StringError => write!(f, "Got unexpected string"),
LexicalErrorType::FStringError(error) => write!(f, "Got error in f-string: {}", error),
LexicalErrorType::FStringError(error) => write!(f, "Got error in f-string: {error}"),
LexicalErrorType::UnicodeError => write!(f, "Got unexpected unicode"),
LexicalErrorType::NestingError => write!(f, "Got unexpected nesting"),
LexicalErrorType::IndentationError => {
Expand All @@ -56,13 +56,13 @@ impl fmt::Display for LexicalErrorType {
write!(f, "positional argument follows keyword argument")
}
LexicalErrorType::UnrecognizedToken { tok } => {
write!(f, "Got unexpected token {}", tok)
write!(f, "Got unexpected token {tok}")
}
LexicalErrorType::LineContinuationError => {
write!(f, "unexpected character after line continuation character")
}
LexicalErrorType::Eof => write!(f, "unexpected EOF while parsing"),
LexicalErrorType::OtherError(msg) => write!(f, "{}", msg),
LexicalErrorType::OtherError(msg) => write!(f, "{msg}"),
}
}
}
Expand Down Expand Up @@ -97,17 +97,16 @@ impl fmt::Display for FStringErrorType {
FStringErrorType::UnopenedRbrace => write!(f, "Unopened '}}'"),
FStringErrorType::ExpectedRbrace => write!(f, "Expected '}}' after conversion flag."),
FStringErrorType::InvalidExpression(error) => {
write!(f, "{}", error)
write!(f, "{error}")
}
FStringErrorType::InvalidConversionFlag => write!(f, "invalid conversion character"),
FStringErrorType::EmptyExpression => write!(f, "empty expression not allowed"),
FStringErrorType::MismatchedDelimiter(first, second) => write!(
f,
"closing parenthesis '{}' does not match opening parenthesis '{}'",
second, first
"closing parenthesis '{second}' does not match opening parenthesis '{first}'"
),
FStringErrorType::SingleRbrace => write!(f, "single '}}' is not allowed"),
FStringErrorType::Unmatched(delim) => write!(f, "unmatched '{}'", delim),
FStringErrorType::Unmatched(delim) => write!(f, "unmatched '{delim}'"),
FStringErrorType::ExpressionNestedTooDeeply => {
write!(f, "expressions nested too deeply")
}
Expand All @@ -118,7 +117,7 @@ impl fmt::Display for FStringErrorType {
if *c == '\\' {
write!(f, "f-string expression part cannot include a backslash")
} else {
write!(f, "f-string expression part cannot include '{}'s", c)
write!(f, "f-string expression part cannot include '{c}'s")
}
}
}
Expand Down Expand Up @@ -198,18 +197,18 @@ impl fmt::Display for ParseErrorType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
ParseErrorType::Eof => write!(f, "Got unexpected EOF"),
ParseErrorType::ExtraToken(ref tok) => write!(f, "Got extraneous token: {:?}", tok),
ParseErrorType::ExtraToken(ref tok) => write!(f, "Got extraneous token: {tok:?}"),
ParseErrorType::InvalidToken => write!(f, "Got invalid token"),
ParseErrorType::UnrecognizedToken(ref tok, ref expected) => {
if *tok == Tok::Indent {
write!(f, "unexpected indent")
} else if expected.as_deref() == Some("Indent") {
write!(f, "expected an indented block")
} else {
write!(f, "invalid syntax. Got unexpected token {}", tok)
write!(f, "invalid syntax. Got unexpected token {tok}")
}
}
ParseErrorType::Lexical(ref error) => write!(f, "{}", error),
ParseErrorType::Lexical(ref error) => write!(f, "{error}"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/parser/src/fstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl FStringParser {
}

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

Expand Down
2 changes: 1 addition & 1 deletion compiler/parser/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ where
let value_text = self.radix_run(radix);
let end_pos = self.get_pos();
let value = BigInt::from_str_radix(&value_text, radix).map_err(|e| LexicalError {
error: LexicalErrorType::OtherError(format!("{:?}", e)),
error: LexicalErrorType::OtherError(format!("{e:?}")),
location: start_pos,
})?;
Ok((start_pos, Tok::Int { value }, end_pos))
Expand Down
12 changes: 6 additions & 6 deletions compiler/parser/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ impl fmt::Display for Tok {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use Tok::*;
match self {
Name { name } => write!(f, "'{}'", name),
Int { value } => write!(f, "'{}'", value),
Float { value } => write!(f, "'{}'", value),
Complex { real, imag } => write!(f, "{}j{}", real, imag),
Name { name } => write!(f, "'{name}'"),
Int { value } => write!(f, "'{value}'"),
Float { value } => write!(f, "'{value}'"),
Complex { real, imag } => write!(f, "{real}j{imag}"),
String { value, kind } => {
match kind {
StringKind::F => f.write_str("f")?,
StringKind::U => f.write_str("u")?,
StringKind::Normal => {}
}
write!(f, "{:?}", value)
write!(f, "{value:?}")
}
Bytes { value } => {
write!(f, "b\"")?;
Expand All @@ -138,7 +138,7 @@ impl fmt::Display for Tok {
10 => f.write_str("\\n")?,
13 => f.write_str("\\r")?,
32..=126 => f.write_char(*i as char)?,
_ => write!(f, "\\x{:02x}", i)?,
_ => write!(f, "\\x{i:02x}")?,
}
}
f.write_str("\"")
Expand Down
4 changes: 2 additions & 2 deletions examples/dis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn main() {
error!("Error while compiling {:?}: {}", script, e);
}
} else {
eprintln!("{:?} is not a file.", script);
eprintln!("{script:?} is not a file.");
}
}
}
Expand All @@ -90,7 +90,7 @@ fn display_script(
if expand_codeobjects {
println!("{}", code.display_expand_codeobjects());
} else {
println!("{}", code);
println!("{code}");
}
Ok(())
}
2 changes: 1 addition & 1 deletion examples/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ gen()
PyResult::Ok(v)
})?;
match r {
PyIterReturn::Return(value) => println!("{}", value),
PyIterReturn::Return(value) => println!("{value}"),
PyIterReturn::StopIteration(_) => break,
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/package_embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() -> ExitCode {
});
let result = py_main(&interp);
let result = result.map(|result| {
println!("name: {}", result);
println!("name: {result}");
});
ExitCode::from(interp.run(|_vm| result))
}
8 changes: 4 additions & 4 deletions examples/parse_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() {

let folder = Path::new(matches.value_of("folder").unwrap());
if folder.exists() && folder.is_dir() {
println!("Parsing folder of python code: {:?}", folder);
println!("Parsing folder of python code: {folder:?}");
let t1 = Instant::now();
let parsed_files = parse_folder(folder).unwrap();
let t2 = Instant::now();
Expand All @@ -43,7 +43,7 @@ fn main() {
};
statistics(results);
} else {
println!("{:?} is not a folder.", folder);
println!("{folder:?} is not a folder.");
}
}

Expand Down Expand Up @@ -111,13 +111,13 @@ fn statistics(results: ScanResult) {
.iter()
.filter(|p| p.result.is_ok())
.count();
println!("Passed: {} Failed: {} Total: {}", passed, failed, total);
println!("Passed: {passed} Failed: {failed} Total: {total}");
println!(
"That is {} % success rate.",
(passed as f64 * 100.0) / total as f64
);
let duration = results.t2 - results.t1;
println!("Total time spend: {:?}", duration);
println!("Total time spend: {duration:?}");
println!(
"Processed {} files. That's {} files/second",
total,
Expand Down
2 changes: 1 addition & 1 deletion src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ fn get_paths(env_variable_name: &str) -> impl Iterator<Item = String> + '_ {
.map(|path| {
path.into_os_string()
.into_string()
.unwrap_or_else(|_| panic!("{} isn't valid unicode", env_variable_name))
.unwrap_or_else(|_| panic!("{env_variable_name} isn't valid unicode"))
})
.collect::<Vec<_>>()
})
Expand Down
4 changes: 2 additions & 2 deletions src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
break;
}
ReadlineResult::Other(err) => {
eprintln!("Readline error: {:?}", err);
eprintln!("Readline error: {err:?}");
break;
}
ReadlineResult::Io(err) => {
eprintln!("IO error: {:?}", err);
eprintln!("IO error: {err:?}");
break;
}
};
Expand Down
Loading