Fix nightly clippy warnings

This commit is contained in:
Jeong YunWon committed 2023-01-07 21:07:10 +09:00
1 parent ba427c8690
commit 8d36fe68e7
14 files changed
+59 -60

No files matched your search

+2 -2
View File
@@ -706,12 +706,12 @@ impl<T> std::error::Error for CapacityError<T> {}
impl<T> fmt::Display for CapacityError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", CAPERROR)
write!(f, "{CAPERROR}")
}
}
impl<T> fmt::Debug for CapacityError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "capacity error: {}", CAPERROR)
write!(f, "capacity error: {CAPERROR}")
}
}
+1 -1
View File
@@ -51,7 +51,7 @@ pub fn repr_with(b: &[u8], prefixes: &[&str], suffix: &str) -> String {
}
res.push(ch);
}
_ => write!(res, "\\x{:02x}", ch).unwrap(),
_ => write!(res, "\\x{ch:02x}").unwrap(),
}
}
res.push(quote);
+10 -10
View File
@@ -126,7 +126,7 @@ fn format_inf(case: Case) -> String {
pub fn format_fixed(precision: usize, magnitude: f64, case: Case) -> String {
match magnitude {
magnitude if magnitude.is_finite() => format!("{:.*}", precision, magnitude),
magnitude if magnitude.is_finite() => format!("{magnitude:.precision$}"),
magnitude if magnitude.is_nan() => format_nan(case),
magnitude if magnitude.is_infinite() => format_inf(case),
_ => "".to_string(),
@@ -138,7 +138,7 @@ pub fn format_fixed(precision: usize, magnitude: f64, case: Case) -> String {
pub fn format_exponent(precision: usize, magnitude: f64, case: Case) -> String {
match magnitude {
magnitude if magnitude.is_finite() => {
let r_exp = format!("{:.*e}", precision, magnitude);
let r_exp = format!("{magnitude:.precision$e}");
let mut parts = r_exp.splitn(2, 'e');
let base = parts.next().unwrap();
let exponent = parts.next().unwrap().parse::<i64>().unwrap();
@@ -146,7 +146,7 @@ pub fn format_exponent(precision: usize, magnitude: f64, case: Case) -> String {
Case::Lower => 'e',
Case::Upper => 'E',
};
format!("{}{}{:+#03}", base, e, exponent)
format!("{base}{e}{exponent:+#03}")
}
magnitude if magnitude.is_nan() => format_nan(case),
magnitude if magnitude.is_infinite() => format_inf(case),
@@ -206,12 +206,12 @@ pub fn format_general(
format!("{:.*}", precision + 1, base),
alternate_form,
);
format!("{}{}{:+#03}", base, e, exponent)
format!("{base}{e}{exponent:+#03}")
} else {
let precision = (precision as i64) - 1 - exponent;
let precision = precision as usize;
maybe_remove_trailing_redundant_chars(
format!("{:.*}", precision, magnitude),
format!("{magnitude:.precision$}"),
alternate_form,
)
}
@@ -223,19 +223,19 @@ pub fn format_general(
}
pub fn to_string(value: f64) -> String {
let lit = format!("{:e}", value);
let lit = format!("{value:e}");
if let Some(position) = lit.find('e') {
let significand = &lit[..position];
let exponent = &lit[position + 1..];
let exponent = exponent.parse::<i32>().unwrap();
if exponent < 16 && exponent > -5 {
if is_integer(value) {
format!("{:.1?}", value)
format!("{value:.1?}")
} else {
value.to_string()
}
} else {
format!("{}e{:+#03}", significand, exponent)
format!("{significand}e{exponent:+#03}")
}
} else {
let mut s = value.to_string();
@@ -296,8 +296,8 @@ pub fn to_hex(value: f64) -> String {
let (mantissa, exponent, sign) = value.integer_decode();
let sign_fmt = if sign < 0 { "-" } else { "" };
match value {
value if value.is_zero() => format!("{}0x0.0p+0", sign_fmt),
value if value.is_infinite() => format!("{}inf", sign_fmt),
value if value.is_zero() => format!("{sign_fmt}0x0.0p+0"),
value if value.is_infinite() => format!("{sign_fmt}inf"),
value if value.is_nan() => "nan".to_owned(),
_ => {
const BITS: i16 = 52;
+7 -9
View File
@@ -323,7 +323,7 @@ impl FormatSpec {
let int_digit_cnt = disp_digit_cnt - dec_digit_cnt;
let mut result = FormatSpec::separate_integer(magnitude_int_str, inter, sep, int_digit_cnt);
if let Some(part) = parts.next() {
result.push_str(&format!(".{}", part))
result.push_str(&format!(".{part}"))
}
result
}
@@ -342,7 +342,7 @@ impl FormatSpec {
// separate with 0 padding
let sep_cnt = disp_digit_cnt / (inter + 1);
let padding = "0".repeat((pad_cnt - sep_cnt) as usize);
let padded_num = format!("{}{}", padding, magnitude_str);
let padded_num = format!("{padding}{magnitude_str}");
FormatSpec::insert_separator(padded_num, inter, sep, sep_cnt)
} else {
// separate without padding
@@ -373,14 +373,14 @@ impl FormatSpec {
| FormatType::Number,
) => {
let ch = char::from(format_type);
Err(format!("Cannot specify ',' with '{}'.", ch))
Err(format!("Cannot specify ',' with '{ch}'."))
}
(
Some(FormatGrouping::Underscore),
FormatType::String | FormatType::Character | FormatType::Number,
) => {
let ch = char::from(format_type);
Err(format!("Cannot specify '_' with '{}'.", ch))
Err(format!("Cannot specify '_' with '{ch}'."))
}
_ => Ok(()),
}
@@ -446,8 +446,7 @@ impl FormatSpec {
| Some(FormatType::Character) => {
let ch = char::from(self.format_type.as_ref().unwrap());
Err(format!(
"Unknown format code '{}' for object of type 'float'",
ch
"Unknown format code '{ch}' for object of type 'float'",
))
}
Some(FormatType::Number) => {
@@ -597,7 +596,7 @@ impl FormatSpec {
FormatSign::MinusOrSpace => " ",
},
};
let sign_prefix = format!("{}{}", sign_str, prefix);
let sign_prefix = format!("{sign_str}{prefix}");
let magnitude_str = self.add_magnitude_separators(raw_magnitude_str?, &sign_prefix);
self.format_sign_and_align(
unsafe { &BorrowedStr::from_ascii_unchecked(magnitude_str.as_bytes()) },
@@ -620,8 +619,7 @@ impl FormatSpec {
_ => {
let ch = char::from(self.format_type.as_ref().unwrap());
Err(format!(
"Unknown format code '{}' for object of type 'str'",
ch
"Unknown format code '{ch}' for object of type 'str'",
))
}
}
+2 -2
View File
@@ -196,8 +196,8 @@ unsafe impl RawRwLockRecursive for RawCellRwLock {
#[cold]
#[inline(never)]
fn deadlock(lockkind: &str, ty: &str) -> ! {
panic!("deadlock: tried to {}lock a Cell{} twice", lockkind, ty)
fn deadlock(lock_kind: &str, ty: &str) -> ! {
panic!("deadlock: tried to {lock_kind}lock a Cell{ty} twice")
}
pub struct SingleThreadId(());
+3 -3
View File
@@ -192,11 +192,11 @@ pub fn to_ascii(value: &str) -> AsciiString {
} else {
let c = c as i64;
let hex = if c < 0x100 {
format!("\\x{:02x}", c)
format!("\\x{c:02x}")
} else if c < 0x10000 {
format!("\\u{:04x}", c)
format!("\\u{c:04x}")
} else {
format!("\\U{:08x}", c)
format!("\\U{c:08x}")
};
ascii.append(&mut hex.into_bytes());
}
+3 -3
View File
@@ -46,7 +46,7 @@ impl std::fmt::Display for Constant {
Constant::Int(i) => i.fmt(f),
Constant::Tuple(tup) => {
if let [elt] = &**tup {
write!(f, "({},)", elt)
write!(f, "({elt},)")
} else {
f.write_str("(")?;
for (i, elt) in tup.iter().enumerate() {
@@ -61,9 +61,9 @@ impl std::fmt::Display for Constant {
Constant::Float(fp) => f.pad(&rustpython_common::float_ops::to_string(*fp)),
Constant::Complex { real, imag } => {
if *real == 0.0 {
write!(f, "{}j", imag)
write!(f, "{imag}j")
} else {
write!(f, "({}{:+}j)", real, imag)
write!(f, "({real}{imag:+}j)")
}
}
Constant::Ellipsis => f.pad("..."),
+1 -1
View File
@@ -400,7 +400,7 @@ impl<'a> Unparser<'a> {
.checked_sub(defaults_start)
.and_then(|i| args.kw_defaults.get(i))
{
write!(self, "={}", default)?;
write!(self, "={default}")?;
}
}
if let Some(kwarg) = &args.kwarg {
+7 -7
View File
@@ -109,7 +109,7 @@ impl CompilationSource {
let source = fs::read_to_string(&path).map_err(|err| {
Diagnostic::spans_error(
self.span,
format!("Error reading file {:?}: {}", path, err),
format!("Error reading file {path:?}: {err}"),
)
})?;
self.compile_string(&source, mode, module_name, compiler, || rel_path.display())
@@ -143,15 +143,15 @@ impl CompilationSource {
Err(e)
})
.map_err(|err| {
Diagnostic::spans_error(self.span, format!("Error listing dir {:?}: {}", path, err))
Diagnostic::spans_error(self.span, format!("Error listing dir {path:?}: {err}"))
})?;
for path in paths {
let path = path.map_err(|err| {
Diagnostic::spans_error(self.span, format!("Failed to list file: {}", err))
Diagnostic::spans_error(self.span, format!("Failed to list file: {err}"))
})?;
let path = path.path();
let file_name = path.file_name().unwrap().to_str().ok_or_else(|| {
Diagnostic::spans_error(self.span, format!("Invalid UTF-8 in file name {:?}", path))
Diagnostic::spans_error(self.span, format!("Invalid UTF-8 in file name {path:?}"))
})?;
if path.is_dir() {
code_map.extend(self.compile_dir(
@@ -159,7 +159,7 @@ impl CompilationSource {
if parent.is_empty() {
file_name.to_string()
} else {
format!("{}.{}", parent, file_name)
format!("{parent}.{file_name}")
},
mode,
compiler,
@@ -172,14 +172,14 @@ impl CompilationSource {
} else if parent.is_empty() {
stem.to_owned()
} else {
format!("{}.{}", parent, stem)
format!("{parent}.{stem}")
};
let compile_path = |src_path: &Path| {
let source = fs::read_to_string(src_path).map_err(|err| {
Diagnostic::spans_error(
self.span,
format!("Error reading file {:?}: {}", path, err),
format!("Error reading file {path:?}: {err}"),
)
})?;
self.compile_string(&source, mode, module_name.clone(), compiler, || {
+9 -8
View File
@@ -1,7 +1,8 @@
use super::Diagnostic;
use crate::util::{
pyclass_ident_and_attrs, text_signature, ClassItemMeta, ContentItem, ContentItemInner,
ErrorVec, ItemMeta, ItemMetaInner, ItemNursery, SimpleItemMeta, ALL_ALLOWED_NAMES,
format_doc, pyclass_ident_and_attrs, text_signature, ClassItemMeta, ContentItem,
ContentItemInner, ErrorVec, ItemMeta, ItemMetaInner, ItemNursery, SimpleItemMeta,
ALL_ALLOWED_NAMES,
};
use proc_macro2::{Span, TokenStream};
use quote::{quote, quote_spanned, ToTokens};
@@ -212,7 +213,7 @@ fn generate_class_def(
quote!(None)
};
let module_class_name = if let Some(module_name) = module_name {
format!("{}.{}", module_name, name)
format!("{module_name}.{name}")
} else {
name.to_owned()
};
@@ -504,7 +505,7 @@ where
let tokens = {
let doc = args.attrs.doc().map_or_else(TokenStream::new, |mut doc| {
doc = format!("{}\n--\n\n{}", sig_doc, doc);
doc = format_doc(&sig_doc, &doc);
quote!(.with_doc(#doc.to_owned(), ctx))
});
let build_func = match self.inner.attr_name {
@@ -597,7 +598,7 @@ where
}
};
let pyname = format!("(slot {})", slot_name);
let pyname = format!("(slot {slot_name})");
args.context.extend_slots_items.add_item(
ident.clone(),
vec![pyname],
@@ -914,7 +915,7 @@ impl MethodItemMeta {
} else {
let name = inner.item_name();
if magic {
format!("__{}__", name)
format!("__{name}__")
} else {
name
}
@@ -985,7 +986,7 @@ impl GetSetItemMeta {
GetSetItemKind::Delete => extract_prefix_name("del_", "deleter")?,
};
if magic {
format!("__{}__", name)
format!("__{name}__")
} else {
name
}
@@ -1107,7 +1108,7 @@ impl MemberItemMeta {
MemberItemKind::Get => sig_name,
MemberItemKind::Set => extract_prefix_name("set_", "setter")?,
};
Ok((if magic { format!("__{}__", name) } else { name }, kind))
Ok((if magic { format!("__{name}__") } else { name }, kind))
}
fn member_kind(&self) -> Result<Option<String>> {
+4 -4
View File
@@ -1,8 +1,8 @@
use crate::error::Diagnostic;
use crate::util::{
iter_use_idents, pyclass_ident_and_attrs, text_signature, AttrItemMeta, AttributeExt,
ClassItemMeta, ContentItem, ContentItemInner, ErrorVec, ItemMeta, ItemNursery, SimpleItemMeta,
ALL_ALLOWED_NAMES,
format_doc, iter_use_idents, pyclass_ident_and_attrs, text_signature, AttrItemMeta,
AttributeExt, ClassItemMeta, ContentItem, ContentItemInner, ErrorVec, ItemMeta, ItemNursery,
SimpleItemMeta, ALL_ALLOWED_NAMES,
};
use proc_macro2::{Span, TokenStream};
use quote::{quote, quote_spanned, ToTokens};
@@ -328,7 +328,7 @@ impl ModuleItem for FunctionItem {
.map(str::to_owned)
});
let doc = if let Some(doc) = doc {
format!("{}\n--\n\n{}", sig_doc, doc)
format_doc(&sig_doc, &doc)
} else {
sig_doc
};
+6 -5
View File
@@ -399,10 +399,7 @@ impl AttributeExt for Attribute {
if found.is_some() {
return Err(syn::Error::new(
item.span(),
format!(
"#[py..({}...)] must be unique but found multiple times",
item_name,
),
format!("#[py..({item_name}...)] must be unique but found multiple times"),
));
}
found = Some(i);
@@ -545,7 +542,7 @@ where
pub(crate) fn text_signature(sig: &Signature, name: &str) -> String {
let signature = func_sig(sig);
if signature.starts_with("$self") {
format!("{}({})", name, signature)
format!("{name}({signature})")
} else {
format!("{}({}, {})", name, "$module", signature)
}
@@ -584,3 +581,7 @@ fn func_sig(sig: &Signature) -> String {
.collect::<Vec<_>>()
.join(", ")
}
pub(crate) fn format_doc(sig: &str, doc: &str) -> String {
format!("{sig}\n--\n\n{doc}")
}
+3 -4
View File
@@ -9,14 +9,13 @@ fn main() {
if cfg!(windows) {
if let Ok(real_path) = std::fs::read_to_string("Lib") {
println!("rustc-env:win_lib_path={:?}", real_path);
println!("rustc-env:win_lib_path={real_path:?}");
}
}
}
fn rerun_if_changed(pattern: &str) {
let glob =
glob::glob(pattern).unwrap_or_else(|e| panic!("failed to glob {:?}: {}", pattern, e));
let glob = glob::glob(pattern).unwrap_or_else(|e| panic!("failed to glob {pattern:?}: {e}"));
for entry in glob.flatten() {
if entry.is_dir() {
continue;
@@ -25,6 +24,6 @@ fn rerun_if_changed(pattern: &str) {
if display.to_string().ends_with(".pyc") {
continue;
}
println!("cargo:rerun-if-changed={}", display);
println!("cargo:rerun-if-changed={display}");
}
}
+1 -1
View File
@@ -123,7 +123,7 @@ impl<'de> DeserializeSeed<'de> for PyObjectDeserializer<'de> {
where
D: serde::Deserializer<'de>,
{
deserializer.deserialize_any(self.clone())
deserializer.deserialize_any(self)
}
}