Fix nightly clippy warnings

This commit is contained in:
Jeong YunWon 2022-12-05 12:08:16 +09:00
parent 7b9e7e0443
commit 9250260e20
8 changed files with 45 additions and 48 deletions

View file

@ -457,7 +457,7 @@ impl Compiler {
NameUsage::Delete if is_forbidden_name(name) => "cannot delete", NameUsage::Delete if is_forbidden_name(name) => "cannot delete",
_ => return Ok(()), _ => 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<()> { fn compile_name(&mut self, name: &str, usage: NameUsage) -> CompileResult<()> {

View file

@ -37,8 +37,8 @@ impl fmt::Display for CodegenErrorType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use CodegenErrorType::*; use CodegenErrorType::*;
match self { match self {
Assign(target) => write!(f, "cannot assign to {}", target), Assign(target) => write!(f, "cannot assign to {target}"),
Delete(target) => write!(f, "cannot delete {}", target), Delete(target) => write!(f, "cannot delete {target}"),
SyntaxError(err) => write!(f, "{}", err.as_str()), SyntaxError(err) => write!(f, "{}", err.as_str()),
MultipleStarArgs => { MultipleStarArgs => {
write!(f, "two starred expressions in assignment") write!(f, "two starred expressions in assignment")
@ -59,7 +59,7 @@ impl fmt::Display for CodegenErrorType {
"from __future__ imports must occur at the beginning of the file" "from __future__ imports must occur at the beginning of the file"
), ),
InvalidFutureFeature(feat) => { InvalidFutureFeature(feat) => {
write!(f, "future feature {} is not defined", feat) write!(f, "future feature {feat} is not defined")
} }
FunctionImportStar => { FunctionImportStar => {
write!(f, "import * only allowed at module level") write!(f, "import * only allowed at module level")

View file

@ -1154,27 +1154,26 @@ impl SymbolTableBuilder {
SymbolUsage::Global if !symbol.is_global() => { SymbolUsage::Global if !symbol.is_global() => {
if flags.contains(SymbolFlags::PARAMETER) { if flags.contains(SymbolFlags::PARAMETER) {
return Err(SymbolTableError { return Err(SymbolTableError {
error: format!("name '{}' is parameter and global", name), error: format!("name '{name}' is parameter and global"),
location, location,
}); });
} }
if flags.contains(SymbolFlags::REFERENCED) { if flags.contains(SymbolFlags::REFERENCED) {
return Err(SymbolTableError { return Err(SymbolTableError {
error: format!("name '{}' is used prior to global declaration", name), error: format!("name '{name}' is used prior to global declaration"),
location, location,
}); });
} }
if flags.contains(SymbolFlags::ANNOTATED) { if flags.contains(SymbolFlags::ANNOTATED) {
return Err(SymbolTableError { return Err(SymbolTableError {
error: format!("annotated name '{}' can't be global", name), error: format!("annotated name '{name}' can't be global"),
location, location,
}); });
} }
if flags.contains(SymbolFlags::ASSIGNED) { if flags.contains(SymbolFlags::ASSIGNED) {
return Err(SymbolTableError { return Err(SymbolTableError {
error: format!( error: format!(
"name '{}' is assigned to before global declaration", "name '{name}' is assigned to before global declaration"
name
), ),
location, location,
}); });
@ -1183,27 +1182,26 @@ impl SymbolTableBuilder {
SymbolUsage::Nonlocal => { SymbolUsage::Nonlocal => {
if flags.contains(SymbolFlags::PARAMETER) { if flags.contains(SymbolFlags::PARAMETER) {
return Err(SymbolTableError { return Err(SymbolTableError {
error: format!("name '{}' is parameter and nonlocal", name), error: format!("name '{name}' is parameter and nonlocal"),
location, location,
}); });
} }
if flags.contains(SymbolFlags::REFERENCED) { if flags.contains(SymbolFlags::REFERENCED) {
return Err(SymbolTableError { return Err(SymbolTableError {
error: format!("name '{}' is used prior to nonlocal declaration", name), error: format!("name '{name}' is used prior to nonlocal declaration"),
location, location,
}); });
} }
if flags.contains(SymbolFlags::ANNOTATED) { if flags.contains(SymbolFlags::ANNOTATED) {
return Err(SymbolTableError { return Err(SymbolTableError {
error: format!("annotated name '{}' can't be nonlocal", name), error: format!("annotated name '{name}' can't be nonlocal"),
location, location,
}); });
} }
if flags.contains(SymbolFlags::ASSIGNED) { if flags.contains(SymbolFlags::ASSIGNED) {
return Err(SymbolTableError { return Err(SymbolTableError {
error: format!( error: format!(
"name '{}' is assigned to before nonlocal declaration", "name '{name}' is assigned to before nonlocal declaration"
name
), ),
location, location,
}); });
@ -1220,7 +1218,7 @@ impl SymbolTableBuilder {
match role { match role {
SymbolUsage::Nonlocal if scope_depth < 2 => { SymbolUsage::Nonlocal if scope_depth < 2 => {
return Err(SymbolTableError { return Err(SymbolTableError {
error: format!("cannot define nonlocal '{}' at top level.", name), error: format!("cannot define nonlocal '{name}' at top level."),
location, location,
}) })
} }

View file

@ -482,15 +482,15 @@ impl<C: Constant> BorrowedConstant<'_, C> {
// takes `self` because we need to consume the iterator // takes `self` because we need to consume the iterator
pub fn fmt_display(self, f: &mut fmt::Formatter) -> fmt::Result { pub fn fmt_display(self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
BorrowedConstant::Integer { value } => write!(f, "{}", value), BorrowedConstant::Integer { value } => write!(f, "{value}"),
BorrowedConstant::Float { value } => write!(f, "{}", value), BorrowedConstant::Float { value } => write!(f, "{value}"),
BorrowedConstant::Complex { value } => write!(f, "{}", value), BorrowedConstant::Complex { value } => write!(f, "{value}"),
BorrowedConstant::Boolean { value } => { BorrowedConstant::Boolean { value } => {
write!(f, "{}", if value { "True" } else { "False" }) 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::Bytes { value } => write!(f, "b{:?}", value.as_bstr()),
BorrowedConstant::Code { code } => write!(f, "{:?}", code), BorrowedConstant::Code { code } => write!(f, "{code:?}"),
BorrowedConstant::Tuple { elements } => { BorrowedConstant::Tuple { elements } => {
write!(f, "(")?; write!(f, "(")?;
let mut first = true; let mut first = true;
@ -852,7 +852,7 @@ impl<C: Constant> fmt::Display for CodeObject<C> {
self.display_inner(f, false, 1)?; self.display_inner(f, false, 1)?;
for constant in &*self.constants { for constant in &*self.constants {
if let BorrowedConstant::Code { code } = constant.borrow_constant() { if let BorrowedConstant::Code { code } = constant.borrow_constant() {
writeln!(f, "\nDisassembly of {:?}", code)?; writeln!(f, "\nDisassembly of {code:?}")?;
code.fmt(f)?; code.fmt(f)?;
} }
} }
@ -1118,14 +1118,14 @@ impl Instruction {
} }
} }
} }
UnaryOperation { op } => w!(UnaryOperation, format_args!("{:?}", op)), UnaryOperation { op } => w!(UnaryOperation, format_args!("{op:?}")),
BinaryOperation { op } => w!(BinaryOperation, format_args!("{:?}", op)), BinaryOperation { op } => w!(BinaryOperation, format_args!("{op:?}")),
BinaryOperationInplace { op } => { BinaryOperationInplace { op } => {
w!(BinaryOperationInplace, format_args!("{:?}", op)) w!(BinaryOperationInplace, format_args!("{op:?}"))
} }
LoadAttr { idx } => w!(LoadAttr, name(*idx)), LoadAttr { idx } => w!(LoadAttr, name(*idx)),
TestOperation { op } => w!(TestOperation, format_args!("{:?}", op)), TestOperation { op } => w!(TestOperation, format_args!("{op:?}")),
CompareOperation { op } => w!(CompareOperation, format_args!("{:?}", op)), CompareOperation { op } => w!(CompareOperation, format_args!("{op:?}")),
Pop => w!(Pop), Pop => w!(Pop),
Rotate2 => w!(Rotate2), Rotate2 => w!(Rotate2),
Rotate3 => w!(Rotate3), Rotate3 => w!(Rotate3),
@ -1139,7 +1139,7 @@ impl Instruction {
JumpIfFalse { target } => w!(JumpIfFalse, target), JumpIfFalse { target } => w!(JumpIfFalse, target),
JumpIfTrueOrPop { target } => w!(JumpIfTrueOrPop, target), JumpIfTrueOrPop { target } => w!(JumpIfTrueOrPop, target),
JumpIfFalseOrPop { target } => w!(JumpIfFalseOrPop, 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), CallFunctionPositional { nargs } => w!(CallFunctionPositional, nargs),
CallFunctionKeyword { nargs } => w!(CallFunctionKeyword, nargs), CallFunctionKeyword { nargs } => w!(CallFunctionKeyword, nargs),
CallFunctionEx { has_kwargs } => w!(CallFunctionEx, has_kwargs), CallFunctionEx { has_kwargs } => w!(CallFunctionEx, has_kwargs),
@ -1163,7 +1163,7 @@ impl Instruction {
BeforeAsyncWith => w!(BeforeAsyncWith), BeforeAsyncWith => w!(BeforeAsyncWith),
SetupAsyncWith { end } => w!(SetupAsyncWith, end), SetupAsyncWith { end } => w!(SetupAsyncWith, end),
PopBlock => w!(PopBlock), PopBlock => w!(PopBlock),
Raise { kind } => w!(Raise, format_args!("{:?}", kind)), Raise { kind } => w!(Raise, format_args!("{kind:?}")),
BuildString { size } => w!(BuildString, size), BuildString { size } => w!(BuildString, size),
BuildTuple { size, unpack } => w!(BuildTuple, size, unpack), BuildTuple { size, unpack } => w!(BuildTuple, size, unpack),
BuildList { size, unpack } => w!(BuildList, size, unpack), BuildList { size, unpack } => w!(BuildList, size, unpack),
@ -1182,7 +1182,7 @@ impl Instruction {
LoadBuildClass => w!(LoadBuildClass), LoadBuildClass => w!(LoadBuildClass),
UnpackSequence { size } => w!(UnpackSequence, size), UnpackSequence { size } => w!(UnpackSequence, size),
UnpackEx { before, after } => w!(UnpackEx, before, after), UnpackEx { before, after } => w!(UnpackEx, before, after),
FormatValue { conversion } => w!(FormatValue, format_args!("{:?}", conversion)), FormatValue { conversion } => w!(FormatValue, format_args!("{conversion:?}")),
PopException => w!(PopException), PopException => w!(PopException),
Reverse { amount } => w!(Reverse, amount), Reverse { amount } => w!(Reverse, amount),
GetAwaitable => w!(GetAwaitable), GetAwaitable => w!(GetAwaitable),

View file

@ -34,7 +34,7 @@ impl fmt::Display for LexicalErrorType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
LexicalErrorType::StringError => write!(f, "Got unexpected string"), 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::UnicodeError => write!(f, "Got unexpected unicode"),
LexicalErrorType::NestingError => write!(f, "Got unexpected nesting"), LexicalErrorType::NestingError => write!(f, "Got unexpected nesting"),
LexicalErrorType::IndentationError => { LexicalErrorType::IndentationError => {
@ -56,13 +56,13 @@ impl fmt::Display for LexicalErrorType {
write!(f, "positional argument follows keyword argument") write!(f, "positional argument follows keyword argument")
} }
LexicalErrorType::UnrecognizedToken { tok } => { LexicalErrorType::UnrecognizedToken { tok } => {
write!(f, "Got unexpected token {}", tok) write!(f, "Got unexpected token {tok}")
} }
LexicalErrorType::LineContinuationError => { LexicalErrorType::LineContinuationError => {
write!(f, "unexpected character after line continuation character") 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), LexicalErrorType::OtherError(msg) => write!(f, "{msg}"),
} }
} }
} }
@ -97,17 +97,16 @@ impl fmt::Display for FStringErrorType {
FStringErrorType::UnopenedRbrace => write!(f, "Unopened '}}'"), FStringErrorType::UnopenedRbrace => write!(f, "Unopened '}}'"),
FStringErrorType::ExpectedRbrace => write!(f, "Expected '}}' after conversion flag."), FStringErrorType::ExpectedRbrace => write!(f, "Expected '}}' after conversion flag."),
FStringErrorType::InvalidExpression(error) => { FStringErrorType::InvalidExpression(error) => {
write!(f, "{}", error) write!(f, "{error}")
} }
FStringErrorType::InvalidConversionFlag => write!(f, "invalid conversion character"), FStringErrorType::InvalidConversionFlag => write!(f, "invalid conversion character"),
FStringErrorType::EmptyExpression => write!(f, "empty expression not allowed"), FStringErrorType::EmptyExpression => write!(f, "empty expression not allowed"),
FStringErrorType::MismatchedDelimiter(first, second) => write!( FStringErrorType::MismatchedDelimiter(first, second) => write!(
f, f,
"closing parenthesis '{}' does not match opening parenthesis '{}'", "closing parenthesis '{second}' does not match opening parenthesis '{first}'"
second, first
), ),
FStringErrorType::SingleRbrace => write!(f, "single '}}' is not allowed"), FStringErrorType::SingleRbrace => write!(f, "single '}}' is not allowed"),
FStringErrorType::Unmatched(delim) => write!(f, "unmatched '{}'", delim), FStringErrorType::Unmatched(delim) => write!(f, "unmatched '{delim}'"),
FStringErrorType::ExpressionNestedTooDeeply => { FStringErrorType::ExpressionNestedTooDeeply => {
write!(f, "expressions nested too deeply") write!(f, "expressions nested too deeply")
} }
@ -118,7 +117,7 @@ impl fmt::Display for FStringErrorType {
if *c == '\\' { if *c == '\\' {
write!(f, "f-string expression part cannot include a backslash") write!(f, "f-string expression part cannot include a backslash")
} else { } else {
write!(f, "f-string expression part cannot include '{}'s", c) write!(f, "f-string expression part cannot include '{c}'s")
} }
} }
} }
@ -198,7 +197,7 @@ impl fmt::Display for ParseErrorType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self { 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::ExtraToken(ref tok) => write!(f, "Got extraneous token: {tok:?}"),
ParseErrorType::InvalidToken => write!(f, "Got invalid token"), ParseErrorType::InvalidToken => write!(f, "Got invalid token"),
ParseErrorType::UnrecognizedToken(ref tok, ref expected) => { ParseErrorType::UnrecognizedToken(ref tok, ref expected) => {
if *tok == Tok::Indent { if *tok == Tok::Indent {
@ -206,10 +205,10 @@ impl fmt::Display for ParseErrorType {
} else if expected.as_deref() == Some("Indent") { } else if expected.as_deref() == Some("Indent") {
write!(f, "expected an indented block") write!(f, "expected an indented block")
} else { } 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}"),
} }
} }
} }

View file

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

View file

@ -321,7 +321,7 @@ where
let value_text = self.radix_run(radix); let value_text = self.radix_run(radix);
let end_pos = self.get_pos(); let end_pos = self.get_pos();
let value = BigInt::from_str_radix(&value_text, radix).map_err(|e| LexicalError { 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, location: start_pos,
})?; })?;
Ok((start_pos, Tok::Int { value }, end_pos)) Ok((start_pos, Tok::Int { value }, end_pos))

View file

@ -118,17 +118,17 @@ impl fmt::Display for Tok {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use Tok::*; use Tok::*;
match self { match self {
Name { name } => write!(f, "'{}'", name), Name { name } => write!(f, "'{name}'"),
Int { value } => write!(f, "'{}'", value), Int { value } => write!(f, "'{value}'"),
Float { value } => write!(f, "'{}'", value), Float { value } => write!(f, "'{value}'"),
Complex { real, imag } => write!(f, "{}j{}", real, imag), Complex { real, imag } => write!(f, "{real}j{imag}"),
String { value, kind } => { String { value, kind } => {
match kind { match kind {
StringKind::F => f.write_str("f")?, StringKind::F => f.write_str("f")?,
StringKind::U => f.write_str("u")?, StringKind::U => f.write_str("u")?,
StringKind::Normal => {} StringKind::Normal => {}
} }
write!(f, "{:?}", value) write!(f, "{value:?}")
} }
Bytes { value } => { Bytes { value } => {
write!(f, "b\"")?; write!(f, "b\"")?;
@ -138,7 +138,7 @@ impl fmt::Display for Tok {
10 => f.write_str("\\n")?, 10 => f.write_str("\\n")?,
13 => f.write_str("\\r")?, 13 => f.write_str("\\r")?,
32..=126 => f.write_char(*i as char)?, 32..=126 => f.write_char(*i as char)?,
_ => write!(f, "\\x{:02x}", i)?, _ => write!(f, "\\x{i:02x}")?,
} }
} }
f.write_str("\"") f.write_str("\"")