Use identifiers in format!

This commit is contained in:
Stephen Chung
2022-08-11 19:01:23 +08:00
parent ceaf9fab1b
commit be448dfe4d
36 changed files with 164 additions and 206 deletions

View File

@@ -131,7 +131,7 @@ pub fn inner_item_attributes<T: ExportedParams>(
{
return Err(syn::Error::new(
duplicate.span(),
format!("duplicated attribute '{}'", attr_name),
format!("duplicated attribute '{attr_name}'"),
));
}

View File

@@ -57,10 +57,10 @@ impl FnSpecialAccess {
match self {
FnSpecialAccess::None => None,
FnSpecialAccess::Property(Property::Get(ref g)) => {
Some((format!("{}{}", FN_GET, g), g.to_string(), g.span()))
Some((format!("{FN_GET}{g}"), g.to_string(), g.span()))
}
FnSpecialAccess::Property(Property::Set(ref s)) => {
Some((format!("{}{}", FN_SET, s), s.to_string(), s.span()))
Some((format!("{FN_SET}{s}"), s.to_string(), s.span()))
}
FnSpecialAccess::Index(Index::Get) => Some((
FN_IDX_GET.to_string(),
@@ -255,7 +255,7 @@ impl ExportedParams for ExportedFnParams {
(attr, ..) => {
return Err(syn::Error::new(
key.span(),
format!("unknown attribute '{}'", attr),
format!("unknown attribute '{attr}'"),
))
}
}
@@ -748,7 +748,7 @@ impl ExportedFn {
let str_type_path = syn::parse2::<syn::Path>(quote! { str }).unwrap();
let string_type_path = syn::parse2::<syn::Path>(quote! { String }).unwrap();
for (i, arg) in self.arg_list().enumerate().skip(skip_first_arg as usize) {
let var = syn::Ident::new(&format!("arg{}", i), Span::call_site());
let var = syn::Ident::new(&format!("arg{i}"), Span::call_site());
let is_string;
let is_ref;
match arg {

View File

@@ -72,7 +72,7 @@ impl ExportedParams for ExportedModParams {
(attr, ..) => {
return Err(syn::Error::new(
key.span(),
format!("unknown attribute '{}'", attr),
format!("unknown attribute '{attr}'"),
))
}
}

View File

@@ -319,11 +319,11 @@ pub fn check_rename_collisions(fns: &[ExportedFn]) -> Result<(), syn::Error> {
if let Some(other_span) = renames.insert(key, current_span) {
let mut err = syn::Error::new(
current_span,
format!("duplicate Rhai signature for '{}'", fn_name),
format!("duplicate Rhai signature for '{fn_name}'"),
);
err.combine(syn::Error::new(
other_span,
format!("duplicated function renamed '{}'", fn_name),
format!("duplicated function renamed '{fn_name}'"),
));
return Err(err);
}
@@ -332,10 +332,10 @@ pub fn check_rename_collisions(fns: &[ExportedFn]) -> Result<(), syn::Error> {
let ident = item_fn.name();
if let Some(other_span) = fn_defs.insert(ident.to_string(), ident.span()) {
let mut err =
syn::Error::new(ident.span(), format!("duplicate function '{}'", ident));
syn::Error::new(ident.span(), format!("duplicate function '{ident}'"));
err.combine(syn::Error::new(
other_span,
format!("duplicated function '{}'", ident),
format!("duplicated function '{ident}'"),
));
return Err(err);
}
@@ -343,11 +343,11 @@ pub fn check_rename_collisions(fns: &[ExportedFn]) -> Result<(), syn::Error> {
if let Some(fn_span) = renames.get(&key) {
let mut err = syn::Error::new(
ident.span(),
format!("duplicate Rhai signature for '{}'", ident),
format!("duplicate Rhai signature for '{ident}'"),
);
err.combine(syn::Error::new(
*fn_span,
format!("duplicated function '{}'", ident),
format!("duplicated function '{ident}'"),
));
return Err(err);
}

View File

@@ -88,10 +88,7 @@ mod function_tests {
};
let err = syn::parse2::<ExportedFn>(input_tokens).unwrap_err();
assert_eq!(
format!("{}", err),
"Rhai functions cannot return references"
);
assert_eq!(format!("{err}"), "Rhai functions cannot return references");
}
#[test]
@@ -101,7 +98,7 @@ mod function_tests {
};
let err = syn::parse2::<ExportedFn>(input_tokens).unwrap_err();
assert_eq!(format!("{}", err), "Rhai functions cannot return pointers");
assert_eq!(format!("{err}"), "Rhai functions cannot return pointers");
}
#[test]
@@ -112,7 +109,7 @@ mod function_tests {
let err = syn::parse2::<ExportedFn>(input_tokens).unwrap_err();
assert_eq!(
format!("{}", err),
format!("{err}"),
"references from Rhai in this position must be mutable"
);
}
@@ -125,7 +122,7 @@ mod function_tests {
let err = syn::parse2::<ExportedFn>(input_tokens).unwrap_err();
assert_eq!(
format!("{}", err),
format!("{err}"),
"function parameters other than the first one cannot be passed by reference"
);
}
@@ -138,7 +135,7 @@ mod function_tests {
let err = syn::parse2::<ExportedFn>(input_tokens).unwrap_err();
assert_eq!(
format!("{}", err),
format!("{err}"),
"function parameters other than the first one cannot be passed by reference"
);
}