Skip to content

Commit b91b291

Browse files
committed
Fix clippy lints
1 parent 357e931 commit b91b291

File tree

9 files changed

+30
-37
lines changed

9 files changed

+30
-37
lines changed

rustler/build.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ enum OsFamily {
3434

3535
fn write_ret(out: &mut String, ret: &str) {
3636
if !ret.is_empty() {
37-
write!(out, " -> {}", ret).unwrap();
37+
write!(out, " -> {ret}").unwrap();
3838
}
3939
}
4040

4141
fn write_fn_type(out: &mut String, args: &str, ret: &str) {
42-
write!(out, "extern \"C\" fn ({})", args).unwrap();
42+
write!(out, "extern \"C\" fn ({args})").unwrap();
4343
write_ret(out, ret);
4444
}
4545

4646
fn write_variadic_fn_type(out: &mut String, args: &str, ret: &str) {
47-
write!(out, "extern \"C\" fn ({}, ...)", args).unwrap();
47+
write!(out, "extern \"C\" fn ({args}, ...)").unwrap();
4848
write_ret(out, ret);
4949
}
5050

@@ -61,17 +61,17 @@ impl ApiBuilder for CallbacksApiBuilder<'_> {
6161
}
6262

6363
fn func(&mut self, ret: &str, name: &str, args: &str) {
64-
write!(self.0, " {}: Option<", name).unwrap();
64+
write!(self.0, " {name}: Option<").unwrap();
6565
write_fn_type(self.0, args, ret);
6666
writeln!(self.0, ">,").unwrap();
6767
}
6868
fn variadic_func(&mut self, ret: &str, name: &str, args: &str) {
69-
write!(self.0, " {}: Option<", name).unwrap();
69+
write!(self.0, " {name}: Option<").unwrap();
7070
write_variadic_fn_type(self.0, args, ret);
7171
writeln!(self.0, ">,").unwrap();
7272
}
7373
fn dummy(&mut self, name: &str) {
74-
write!(self.0, " {}: Option<", name).unwrap();
74+
write!(self.0, " {name}: Option<").unwrap();
7575
write_fn_type(self.0, "", "");
7676
writeln!(self.0, ">,").unwrap();
7777
}
@@ -91,43 +91,39 @@ impl ApiBuilder for ForwardersApiBuilder<'_> {
9191

9292
writeln!(
9393
self.0,
94-
"/// See [{}](http://www.erlang.org/doc/man/erl_nif.html#{}) in the Erlang docs.",
95-
name, name
94+
"/// See [{name}](http://www.erlang.org/doc/man/erl_nif.html#{name}) in the Erlang docs."
9695
)
9796
.unwrap();
9897
writeln!(self.0, "#[inline]").unwrap();
99-
writeln!(self.0, "pub unsafe extern \"C\" fn {}({})", name, args).unwrap();
98+
writeln!(self.0, "pub unsafe extern \"C\" fn {name}({args})").unwrap();
10099
write_ret(self.0, ret);
101100
writeln!(self.0, "{{").unwrap();
102101
writeln!(
103102
self.0,
104-
" (DYN_NIF_CALLBACKS.{}.unwrap_unchecked())({})",
105-
name, args_names
103+
" (DYN_NIF_CALLBACKS.{name}.unwrap_unchecked())({args_names})"
106104
)
107105
.unwrap();
108106
writeln!(self.0, "}}\n").unwrap();
109107
}
110108
fn variadic_func(&mut self, ret: &str, name: &str, args: &str) {
111-
writeln!(self.0, "#[macro_export] macro_rules! {} {{", name).unwrap();
109+
writeln!(self.0, "#[macro_export] macro_rules! {name} {{").unwrap();
112110
writeln!(
113111
self.0,
114-
" ( $( $arg:expr ),* ) => {{ $crate::sys::get_{}()($($arg),*) }};",
115-
name
112+
" ( $( $arg:expr ),* ) => {{ $crate::sys::get_{name}()($($arg),*) }};"
116113
)
117114
.unwrap();
118115
writeln!(
119116
self.0,
120-
" ( $( $arg:expr ),+, ) => {{ {}!($($arg),*) }};",
121-
name
117+
" ( $( $arg:expr ),+, ) => {{ {name}!($($arg),*) }};"
122118
)
123119
.unwrap();
124120
writeln!(self.0, "}}\n").unwrap();
125121
writeln!(self.0, "pub use {name};\n").unwrap();
126122

127-
write!(self.0, "pub unsafe fn get_{}() -> ", name).unwrap();
123+
write!(self.0, "pub unsafe fn get_{name}() -> ").unwrap();
128124
write_variadic_fn_type(self.0, args, ret);
129125
writeln!(self.0, " {{").unwrap();
130-
writeln!(self.0, " DYN_NIF_CALLBACKS.{}.unwrap_unchecked()", name).unwrap();
126+
writeln!(self.0, " DYN_NIF_CALLBACKS.{name}.unwrap_unchecked()").unwrap();
131127
writeln!(self.0, "}}\n").unwrap();
132128
}
133129
fn dummy(&mut self, _name: &str) {}
@@ -149,8 +145,7 @@ impl ApiBuilder for WriterBuilder<'_> {
149145
fn func(&mut self, _ret: &str, name: &str, _args: &str) {
150146
writeln!(
151147
self.0,
152-
" filler.write(&mut self.{}, \"{}\0\");",
153-
name, name
148+
" filler.write(&mut self.{name}, \"{name}\0\");"
154149
)
155150
.unwrap();
156151
}
@@ -849,7 +844,7 @@ fn build_api(b: &mut dyn ApiBuilder, opts: &GenerateOptions) {
849844
fn get_nif_version_from_features() -> (u32, u32) {
850845
for major in ((MIN_SUPPORTED_VERSION.0)..=(MAX_SUPPORTED_VERSION.0)).rev() {
851846
for minor in ((MIN_SUPPORTED_VERSION.1)..=(MAX_SUPPORTED_VERSION.1)).rev() {
852-
if env::var(format!("CARGO_FEATURE_NIF_VERSION_{}_{}", major, minor)).is_ok() {
847+
if env::var(format!("CARGO_FEATURE_NIF_VERSION_{major}_{minor}")).is_ok() {
853848
return (major, minor);
854849
}
855850
}
@@ -876,8 +871,7 @@ fn main() {
876871
let target_pointer_width = match env::var("CARGO_CFG_TARGET_POINTER_WIDTH") {
877872
Ok(target_pointer_width) => target_pointer_width,
878873
Err(err) => panic!(
879-
"An error occurred while determining the pointer width to compile `rustler_sys` for:\n\n{:?}\n\nPlease report a bug.",
880-
err
874+
"An error occurred while determining the pointer width to compile `rustler_sys` for:\n\n{err:?}\n\nPlease report a bug."
881875
)
882876
};
883877

rustler/src/codegen_runtime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ impl fmt::Debug for NifReturned {
9999
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
100100
match self {
101101
NifReturned::BadArg => write!(fmt, "{{error, badarg}}"),
102-
NifReturned::Term(ref s) => write!(fmt, "{{ok, {}}}", s),
103-
NifReturned::Raise(ref s) => write!(fmt, "throw({})", s),
102+
NifReturned::Term(ref s) => write!(fmt, "{{ok, {s}}}"),
103+
NifReturned::Raise(ref s) => write!(fmt, "throw({s})"),
104104
NifReturned::Reschedule { .. } => write!(fmt, "reschedule()"),
105105
}
106106
}

rustler/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ impl fmt::Debug for Error {
5151
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
5252
match self {
5353
Error::BadArg => write!(fmt, "{{error, badarg}}"),
54-
Error::Atom(ref s) => write!(fmt, "{{error, {}}}", s),
55-
Error::RaiseAtom(ref s) => write!(fmt, "throw({})", s),
54+
Error::Atom(ref s) => write!(fmt, "{{error, {s}}}"),
55+
Error::RaiseAtom(ref s) => write!(fmt, "throw({s})"),
5656
Error::RaiseTerm(_) => write!(fmt, "throw(<term>)"),
5757
Error::Term(_) => write!(fmt, "{{error, {{:error, <term>}}}}"),
5858
}

rustler/src/serde/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub enum Error {
4646

4747
impl Display for Error {
4848
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
49-
write!(f, "{:?}", self)
49+
write!(f, "{self:?}")
5050
}
5151
}
5252

rustler_codegen/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'a> Context<'a> {
132132
let ident_str = ident.to_string().to_snake_case();
133133
let ident_str = Self::remove_raw(&ident_str);
134134

135-
Ident::new(&format!("atom_{}", ident_str), Span::call_site())
135+
Ident::new(&format!("atom_{ident_str}"), Span::call_site())
136136
}
137137

138138
pub fn escape_ident_with_index(ident_str: &str, index: usize, infix: &str) -> Ident {

rustler_codegen/src/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn parse_expr_assigns(input: ParseStream) -> Vec<syn::ExprAssign> {
5555
while <Token![,]>::parse(input).is_ok() {
5656
match syn::ExprAssign::parse(input) {
5757
Ok(expr) => vec.push(expr),
58-
Err(err) => panic!("{} (i.e. `load = load`)", err),
58+
Err(err) => panic!("{err} (i.e. `load = load`)"),
5959
}
6060
}
6161
vec

rustler_codegen/src/nif.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ impl NifAttributes {
2323
Ok(())
2424
} else {
2525
Err(meta.error(format!(
26-
"The schedule option is expecting one of the values: {:?}",
27-
VALID_SCHEDULE_OPTIONS
26+
"The schedule option is expecting one of the values: {VALID_SCHEDULE_OPTIONS:?}"
2827
)))
2928
}
3029
} else if meta.path.is_ident("name") {
@@ -166,7 +165,7 @@ fn extract_inputs(inputs: Punctuated<syn::FnArg, Comma>) -> TokenStream {
166165
tokens.extend(decoder);
167166
}
168167
other => {
169-
panic!("unsupported input given: {:?}", other);
168+
panic!("unsupported input given: {other:?}");
170169
}
171170
}
172171
} else {

rustler_codegen/src/tagged_enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ fn gen_unnamed_encoder(
290290
) -> TokenStream {
291291
let len = fields.unnamed.len();
292292
let inners = (0..len)
293-
.map(|i| Ident::new(&format!("inner{}", i), Span::call_site()))
293+
.map(|i| Ident::new(&format!("inner{i}"), Span::call_site()))
294294
.collect::<Vec<_>>();
295295
quote! {
296296
#enum_name :: #variant_ident ( #(ref #inners),* ) => ::rustler::Encoder::encode(&(#atom_fn(), #(#inners),*), env),

rustler_codegen/src/unit_enum.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn transcoder_decorator(ast: &syn::DeriveInput) -> TokenStream {
2727
.iter()
2828
.map(|variant| {
2929
let atom_str = variant.ident.to_string().to_snake_case();
30-
let atom_fn = Ident::new(&format!("atom_{}", atom_str), Span::call_site());
30+
let atom_fn = Ident::new(&format!("atom_{atom_str}"), Span::call_site());
3131
quote! {
3232
#atom_fn = #atom_str,
3333
}
@@ -75,7 +75,7 @@ fn gen_decoder(ctx: &Context, variants: &[&Variant], atoms_module_name: &Ident)
7575
.map(|variant| {
7676
let variant_ident = &variant.ident;
7777
let atom_str = variant_ident.to_string().to_snake_case();
78-
let atom_fn = Ident::new(&format!("atom_{}", atom_str), Span::call_site());
78+
let atom_fn = Ident::new(&format!("atom_{atom_str}"), Span::call_site());
7979

8080
quote! {
8181
if value == #atom_fn() {
@@ -107,7 +107,7 @@ fn gen_encoder(ctx: &Context, variants: &[&Variant], atoms_module_name: &Ident)
107107
.map(|variant| {
108108
let variant_ident = &variant.ident;
109109
let atom_str = variant_ident.to_string().to_snake_case();
110-
let atom_fn = Ident::new(&format!("atom_{}", atom_str), Span::call_site());
110+
let atom_fn = Ident::new(&format!("atom_{atom_str}"), Span::call_site());
111111

112112
quote! {
113113
#enum_name :: #variant_ident => ::rustler::Encoder::encode(&#atom_fn(), env),

0 commit comments

Comments
 (0)