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",
_ => 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<()> {

View file

@ -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")
@ -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")

View file

@ -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,
});
@ -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,
});
@ -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,
})
}

View file

@ -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;
@ -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)?;
}
}
@ -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),
@ -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),
@ -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),
@ -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),

View file

@ -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 => {
@ -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}"),
}
}
}
@ -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")
}
@ -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")
}
}
}
@ -198,7 +197,7 @@ 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 {
@ -206,10 +205,10 @@ impl fmt::Display for ParseErrorType {
} 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}"),
}
}
}

View file

@ -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>")
}

View file

@ -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))

View file

@ -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\"")?;
@ -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("\"")