Skip to content

Commit 8d36fe6

Browse files
committed
Fix nightly clippy warnings
1 parent ba427c8 commit 8d36fe6

File tree

14 files changed

+59
-60
lines changed

14 files changed

+59
-60
lines changed

common/src/boxvec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,12 +706,12 @@ impl<T> std::error::Error for CapacityError<T> {}
706706

707707
impl<T> fmt::Display for CapacityError<T> {
708708
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
709-
write!(f, "{}", CAPERROR)
709+
write!(f, "{CAPERROR}")
710710
}
711711
}
712712

713713
impl<T> fmt::Debug for CapacityError<T> {
714714
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
715-
write!(f, "capacity error: {}", CAPERROR)
715+
write!(f, "capacity error: {CAPERROR}")
716716
}
717717
}

common/src/bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn repr_with(b: &[u8], prefixes: &[&str], suffix: &str) -> String {
5151
}
5252
res.push(ch);
5353
}
54-
_ => write!(res, "\\x{:02x}", ch).unwrap(),
54+
_ => write!(res, "\\x{ch:02x}").unwrap(),
5555
}
5656
}
5757
res.push(quote);

common/src/float_ops.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fn format_inf(case: Case) -> String {
126126

127127
pub fn format_fixed(precision: usize, magnitude: f64, case: Case) -> String {
128128
match magnitude {
129-
magnitude if magnitude.is_finite() => format!("{:.*}", precision, magnitude),
129+
magnitude if magnitude.is_finite() => format!("{magnitude:.precision$}"),
130130
magnitude if magnitude.is_nan() => format_nan(case),
131131
magnitude if magnitude.is_infinite() => format_inf(case),
132132
_ => "".to_string(),
@@ -138,15 +138,15 @@ pub fn format_fixed(precision: usize, magnitude: f64, case: Case) -> String {
138138
pub fn format_exponent(precision: usize, magnitude: f64, case: Case) -> String {
139139
match magnitude {
140140
magnitude if magnitude.is_finite() => {
141-
let r_exp = format!("{:.*e}", precision, magnitude);
141+
let r_exp = format!("{magnitude:.precision$e}");
142142
let mut parts = r_exp.splitn(2, 'e');
143143
let base = parts.next().unwrap();
144144
let exponent = parts.next().unwrap().parse::<i64>().unwrap();
145145
let e = match case {
146146
Case::Lower => 'e',
147147
Case::Upper => 'E',
148148
};
149-
format!("{}{}{:+#03}", base, e, exponent)
149+
format!("{base}{e}{exponent:+#03}")
150150
}
151151
magnitude if magnitude.is_nan() => format_nan(case),
152152
magnitude if magnitude.is_infinite() => format_inf(case),
@@ -206,12 +206,12 @@ pub fn format_general(
206206
format!("{:.*}", precision + 1, base),
207207
alternate_form,
208208
);
209-
format!("{}{}{:+#03}", base, e, exponent)
209+
format!("{base}{e}{exponent:+#03}")
210210
} else {
211211
let precision = (precision as i64) - 1 - exponent;
212212
let precision = precision as usize;
213213
maybe_remove_trailing_redundant_chars(
214-
format!("{:.*}", precision, magnitude),
214+
format!("{magnitude:.precision$}"),
215215
alternate_form,
216216
)
217217
}
@@ -223,19 +223,19 @@ pub fn format_general(
223223
}
224224

225225
pub fn to_string(value: f64) -> String {
226-
let lit = format!("{:e}", value);
226+
let lit = format!("{value:e}");
227227
if let Some(position) = lit.find('e') {
228228
let significand = &lit[..position];
229229
let exponent = &lit[position + 1..];
230230
let exponent = exponent.parse::<i32>().unwrap();
231231
if exponent < 16 && exponent > -5 {
232232
if is_integer(value) {
233-
format!("{:.1?}", value)
233+
format!("{value:.1?}")
234234
} else {
235235
value.to_string()
236236
}
237237
} else {
238-
format!("{}e{:+#03}", significand, exponent)
238+
format!("{significand}e{exponent:+#03}")
239239
}
240240
} else {
241241
let mut s = value.to_string();
@@ -296,8 +296,8 @@ pub fn to_hex(value: f64) -> String {
296296
let (mantissa, exponent, sign) = value.integer_decode();
297297
let sign_fmt = if sign < 0 { "-" } else { "" };
298298
match value {
299-
value if value.is_zero() => format!("{}0x0.0p+0", sign_fmt),
300-
value if value.is_infinite() => format!("{}inf", sign_fmt),
299+
value if value.is_zero() => format!("{sign_fmt}0x0.0p+0"),
300+
value if value.is_infinite() => format!("{sign_fmt}inf"),
301301
value if value.is_nan() => "nan".to_owned(),
302302
_ => {
303303
const BITS: i16 = 52;

common/src/format.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl FormatSpec {
323323
let int_digit_cnt = disp_digit_cnt - dec_digit_cnt;
324324
let mut result = FormatSpec::separate_integer(magnitude_int_str, inter, sep, int_digit_cnt);
325325
if let Some(part) = parts.next() {
326-
result.push_str(&format!(".{}", part))
326+
result.push_str(&format!(".{part}"))
327327
}
328328
result
329329
}
@@ -342,7 +342,7 @@ impl FormatSpec {
342342
// separate with 0 padding
343343
let sep_cnt = disp_digit_cnt / (inter + 1);
344344
let padding = "0".repeat((pad_cnt - sep_cnt) as usize);
345-
let padded_num = format!("{}{}", padding, magnitude_str);
345+
let padded_num = format!("{padding}{magnitude_str}");
346346
FormatSpec::insert_separator(padded_num, inter, sep, sep_cnt)
347347
} else {
348348
// separate without padding
@@ -373,14 +373,14 @@ impl FormatSpec {
373373
| FormatType::Number,
374374
) => {
375375
let ch = char::from(format_type);
376-
Err(format!("Cannot specify ',' with '{}'.", ch))
376+
Err(format!("Cannot specify ',' with '{ch}'."))
377377
}
378378
(
379379
Some(FormatGrouping::Underscore),
380380
FormatType::String | FormatType::Character | FormatType::Number,
381381
) => {
382382
let ch = char::from(format_type);
383-
Err(format!("Cannot specify '_' with '{}'.", ch))
383+
Err(format!("Cannot specify '_' with '{ch}'."))
384384
}
385385
_ => Ok(()),
386386
}
@@ -446,8 +446,7 @@ impl FormatSpec {
446446
| Some(FormatType::Character) => {
447447
let ch = char::from(self.format_type.as_ref().unwrap());
448448
Err(format!(
449-
"Unknown format code '{}' for object of type 'float'",
450-
ch
449+
"Unknown format code '{ch}' for object of type 'float'",
451450
))
452451
}
453452
Some(FormatType::Number) => {
@@ -597,7 +596,7 @@ impl FormatSpec {
597596
FormatSign::MinusOrSpace => " ",
598597
},
599598
};
600-
let sign_prefix = format!("{}{}", sign_str, prefix);
599+
let sign_prefix = format!("{sign_str}{prefix}");
601600
let magnitude_str = self.add_magnitude_separators(raw_magnitude_str?, &sign_prefix);
602601
self.format_sign_and_align(
603602
unsafe { &BorrowedStr::from_ascii_unchecked(magnitude_str.as_bytes()) },
@@ -620,8 +619,7 @@ impl FormatSpec {
620619
_ => {
621620
let ch = char::from(self.format_type.as_ref().unwrap());
622621
Err(format!(
623-
"Unknown format code '{}' for object of type 'str'",
624-
ch
622+
"Unknown format code '{ch}' for object of type 'str'",
625623
))
626624
}
627625
}

common/src/lock/cell_lock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ unsafe impl RawRwLockRecursive for RawCellRwLock {
196196

197197
#[cold]
198198
#[inline(never)]
199-
fn deadlock(lockkind: &str, ty: &str) -> ! {
200-
panic!("deadlock: tried to {}lock a Cell{} twice", lockkind, ty)
199+
fn deadlock(lock_kind: &str, ty: &str) -> ! {
200+
panic!("deadlock: tried to {lock_kind}lock a Cell{ty} twice")
201201
}
202202

203203
pub struct SingleThreadId(());

common/src/str.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ pub fn to_ascii(value: &str) -> AsciiString {
192192
} else {
193193
let c = c as i64;
194194
let hex = if c < 0x100 {
195-
format!("\\x{:02x}", c)
195+
format!("\\x{c:02x}")
196196
} else if c < 0x10000 {
197-
format!("\\u{:04x}", c)
197+
format!("\\u{c:04x}")
198198
} else {
199-
format!("\\U{:08x}", c)
199+
format!("\\U{c:08x}")
200200
};
201201
ascii.append(&mut hex.into_bytes());
202202
}

compiler/ast/src/constant.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl std::fmt::Display for Constant {
4646
Constant::Int(i) => i.fmt(f),
4747
Constant::Tuple(tup) => {
4848
if let [elt] = &**tup {
49-
write!(f, "({},)", elt)
49+
write!(f, "({elt},)")
5050
} else {
5151
f.write_str("(")?;
5252
for (i, elt) in tup.iter().enumerate() {
@@ -61,9 +61,9 @@ impl std::fmt::Display for Constant {
6161
Constant::Float(fp) => f.pad(&rustpython_common::float_ops::to_string(*fp)),
6262
Constant::Complex { real, imag } => {
6363
if *real == 0.0 {
64-
write!(f, "{}j", imag)
64+
write!(f, "{imag}j")
6565
} else {
66-
write!(f, "({}{:+}j)", real, imag)
66+
write!(f, "({real}{imag:+}j)")
6767
}
6868
}
6969
Constant::Ellipsis => f.pad("..."),

compiler/ast/src/unparse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ impl<'a> Unparser<'a> {
400400
.checked_sub(defaults_start)
401401
.and_then(|i| args.kw_defaults.get(i))
402402
{
403-
write!(self, "={}", default)?;
403+
write!(self, "={default}")?;
404404
}
405405
}
406406
if let Some(kwarg) = &args.kwarg {

derive-impl/src/compile_bytecode.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl CompilationSource {
109109
let source = fs::read_to_string(&path).map_err(|err| {
110110
Diagnostic::spans_error(
111111
self.span,
112-
format!("Error reading file {:?}: {}", path, err),
112+
format!("Error reading file {path:?}: {err}"),
113113
)
114114
})?;
115115
self.compile_string(&source, mode, module_name, compiler, || rel_path.display())
@@ -143,23 +143,23 @@ impl CompilationSource {
143143
Err(e)
144144
})
145145
.map_err(|err| {
146-
Diagnostic::spans_error(self.span, format!("Error listing dir {:?}: {}", path, err))
146+
Diagnostic::spans_error(self.span, format!("Error listing dir {path:?}: {err}"))
147147
})?;
148148
for path in paths {
149149
let path = path.map_err(|err| {
150-
Diagnostic::spans_error(self.span, format!("Failed to list file: {}", err))
150+
Diagnostic::spans_error(self.span, format!("Failed to list file: {err}"))
151151
})?;
152152
let path = path.path();
153153
let file_name = path.file_name().unwrap().to_str().ok_or_else(|| {
154-
Diagnostic::spans_error(self.span, format!("Invalid UTF-8 in file name {:?}", path))
154+
Diagnostic::spans_error(self.span, format!("Invalid UTF-8 in file name {path:?}"))
155155
})?;
156156
if path.is_dir() {
157157
code_map.extend(self.compile_dir(
158158
&path,
159159
if parent.is_empty() {
160160
file_name.to_string()
161161
} else {
162-
format!("{}.{}", parent, file_name)
162+
format!("{parent}.{file_name}")
163163
},
164164
mode,
165165
compiler,
@@ -172,14 +172,14 @@ impl CompilationSource {
172172
} else if parent.is_empty() {
173173
stem.to_owned()
174174
} else {
175-
format!("{}.{}", parent, stem)
175+
format!("{parent}.{stem}")
176176
};
177177

178178
let compile_path = |src_path: &Path| {
179179
let source = fs::read_to_string(src_path).map_err(|err| {
180180
Diagnostic::spans_error(
181181
self.span,
182-
format!("Error reading file {:?}: {}", path, err),
182+
format!("Error reading file {path:?}: {err}"),
183183
)
184184
})?;
185185
self.compile_string(&source, mode, module_name.clone(), compiler, || {

derive-impl/src/pyclass.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use super::Diagnostic;
22
use crate::util::{
3-
pyclass_ident_and_attrs, text_signature, ClassItemMeta, ContentItem, ContentItemInner,
4-
ErrorVec, ItemMeta, ItemMetaInner, ItemNursery, SimpleItemMeta, ALL_ALLOWED_NAMES,
3+
format_doc, pyclass_ident_and_attrs, text_signature, ClassItemMeta, ContentItem,
4+
ContentItemInner, ErrorVec, ItemMeta, ItemMetaInner, ItemNursery, SimpleItemMeta,
5+
ALL_ALLOWED_NAMES,
56
};
67
use proc_macro2::{Span, TokenStream};
78
use quote::{quote, quote_spanned, ToTokens};
@@ -212,7 +213,7 @@ fn generate_class_def(
212213
quote!(None)
213214
};
214215
let module_class_name = if let Some(module_name) = module_name {
215-
format!("{}.{}", module_name, name)
216+
format!("{module_name}.{name}")
216217
} else {
217218
name.to_owned()
218219
};
@@ -504,7 +505,7 @@ where
504505

505506
let tokens = {
506507
let doc = args.attrs.doc().map_or_else(TokenStream::new, |mut doc| {
507-
doc = format!("{}\n--\n\n{}", sig_doc, doc);
508+
doc = format_doc(&sig_doc, &doc);
508509
quote!(.with_doc(#doc.to_owned(), ctx))
509510
});
510511
let build_func = match self.inner.attr_name {
@@ -597,7 +598,7 @@ where
597598
}
598599
};
599600

600-
let pyname = format!("(slot {})", slot_name);
601+
let pyname = format!("(slot {slot_name})");
601602
args.context.extend_slots_items.add_item(
602603
ident.clone(),
603604
vec![pyname],
@@ -914,7 +915,7 @@ impl MethodItemMeta {
914915
} else {
915916
let name = inner.item_name();
916917
if magic {
917-
format!("__{}__", name)
918+
format!("__{name}__")
918919
} else {
919920
name
920921
}
@@ -985,7 +986,7 @@ impl GetSetItemMeta {
985986
GetSetItemKind::Delete => extract_prefix_name("del_", "deleter")?,
986987
};
987988
if magic {
988-
format!("__{}__", name)
989+
format!("__{name}__")
989990
} else {
990991
name
991992
}
@@ -1107,7 +1108,7 @@ impl MemberItemMeta {
11071108
MemberItemKind::Get => sig_name,
11081109
MemberItemKind::Set => extract_prefix_name("set_", "setter")?,
11091110
};
1110-
Ok((if magic { format!("__{}__", name) } else { name }, kind))
1111+
Ok((if magic { format!("__{name}__") } else { name }, kind))
11111112
}
11121113

11131114
fn member_kind(&self) -> Result<Option<String>> {

derive-impl/src/pymodule.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::error::Diagnostic;
22
use crate::util::{
3-
iter_use_idents, pyclass_ident_and_attrs, text_signature, AttrItemMeta, AttributeExt,
4-
ClassItemMeta, ContentItem, ContentItemInner, ErrorVec, ItemMeta, ItemNursery, SimpleItemMeta,
5-
ALL_ALLOWED_NAMES,
3+
format_doc, iter_use_idents, pyclass_ident_and_attrs, text_signature, AttrItemMeta,
4+
AttributeExt, ClassItemMeta, ContentItem, ContentItemInner, ErrorVec, ItemMeta, ItemNursery,
5+
SimpleItemMeta, ALL_ALLOWED_NAMES,
66
};
77
use proc_macro2::{Span, TokenStream};
88
use quote::{quote, quote_spanned, ToTokens};
@@ -328,7 +328,7 @@ impl ModuleItem for FunctionItem {
328328
.map(str::to_owned)
329329
});
330330
let doc = if let Some(doc) = doc {
331-
format!("{}\n--\n\n{}", sig_doc, doc)
331+
format_doc(&sig_doc, &doc)
332332
} else {
333333
sig_doc
334334
};

derive-impl/src/util.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,7 @@ impl AttributeExt for Attribute {
399399
if found.is_some() {
400400
return Err(syn::Error::new(
401401
item.span(),
402-
format!(
403-
"#[py..({}...)] must be unique but found multiple times",
404-
item_name,
405-
),
402+
format!("#[py..({item_name}...)] must be unique but found multiple times"),
406403
));
407404
}
408405
found = Some(i);
@@ -545,7 +542,7 @@ where
545542
pub(crate) fn text_signature(sig: &Signature, name: &str) -> String {
546543
let signature = func_sig(sig);
547544
if signature.starts_with("$self") {
548-
format!("{}({})", name, signature)
545+
format!("{name}({signature})")
549546
} else {
550547
format!("{}({}, {})", name, "$module", signature)
551548
}
@@ -584,3 +581,7 @@ fn func_sig(sig: &Signature) -> String {
584581
.collect::<Vec<_>>()
585582
.join(", ")
586583
}
584+
585+
pub(crate) fn format_doc(sig: &str, doc: &str) -> String {
586+
format!("{sig}\n--\n\n{doc}")
587+
}

0 commit comments

Comments
 (0)