Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
magiclen committed Dec 15, 2023
1 parent b395a07 commit c264b6d
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "educe"
version = "0.5.6"
version = "0.5.7"
authors = ["Magic Len <[email protected]>"]
edition = "2021"
rust-version = "1.60"
Expand Down
21 changes: 10 additions & 11 deletions src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Display for DisplayTraits {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
for t in &Trait::VARIANTS[..Trait::VARIANTS.len() - 1] {
f.write_str("\n ")?;
f.write_fmt(format_args!("{:?}", t))?;
f.write_fmt(format_args!("{t:?}"))?;
}

Ok(())
Expand All @@ -46,7 +46,7 @@ pub(crate) fn derive_attribute_not_set_up_yet() -> syn::Error {

#[inline]
pub(crate) fn attribute_incorrect_place(name: &Ident) -> syn::Error {
syn::Error::new(name.span(), format!("the `{}` attribute cannot be placed here", name,))
syn::Error::new(name.span(), format!("the `{name}` attribute cannot be placed here"))
}

#[inline]
Expand All @@ -61,8 +61,7 @@ pub(crate) fn attribute_incorrect_format_with_span(
syn::Error::new(
span,
format!(
"you are using an incorrect format of the `{}` attribute{}",
name,
"you are using an incorrect format of the `{name}` attribute{}",
DisplayStringSlice(correct_usage)
),
)
Expand All @@ -79,7 +78,7 @@ pub(crate) fn attribute_incorrect_format(

#[inline]
pub(crate) fn parameter_reset(name: &Ident) -> syn::Error {
syn::Error::new(name.span(), format!("you are trying to reset the `{}` parameter", name))
syn::Error::new(name.span(), format!("you are trying to reset the `{name}` parameter"))
}

#[inline]
Expand All @@ -94,38 +93,38 @@ pub(crate) fn unsupported_trait(name: &Path) -> syn::Error {
match name.get_ident() {
Some(name) => syn::Error::new(
span,
format!("unsupported trait `{}`, available traits:{}", name, DisplayTraits),
format!("unsupported trait `{name}`, available traits:{DisplayTraits}"),
),
None => {
let name = path_to_string(name);

syn::Error::new(
span,
format!("unsupported trait `{}`, available traits:{}", name, DisplayTraits),
format!("unsupported trait `{name}`, available traits:{DisplayTraits}"),
)
},
}
}

#[inline]
pub(crate) fn reuse_a_trait(name: &Ident) -> syn::Error {
syn::Error::new(name.span(), format!("the trait `{}` is used repeatedly", name))
syn::Error::new(name.span(), format!("the trait `{name}` is used repeatedly"))
}

#[inline]
pub(crate) fn trait_not_used(name: &Ident) -> syn::Error {
syn::Error::new(name.span(), format!("the trait `{}` is not used", name))
syn::Error::new(name.span(), format!("the trait `{name}` is not used"))
}

#[inline]
pub(crate) fn trait_not_support_union(name: &Ident) -> syn::Error {
syn::Error::new(name.span(), format!("the trait `{}` does not support to a union", name))
syn::Error::new(name.span(), format!("the trait `{name}` does not support to a union"))
}

#[inline]
pub(crate) fn trait_not_support_unit_variant(name: &Ident, variant: &Variant) -> syn::Error {
syn::Error::new(
variant.span(),
format!("the trait `{}` cannot be implemented for an enum which has unit variants", name),
format!("the trait `{name}` cannot be implemented for an enum which has unit variants"),
)
}
6 changes: 3 additions & 3 deletions src/trait_handlers/debug/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ pub(crate) fn union_without_unsafe(meta: &Meta) -> syn::Error {
"a union's `Debug` implementation may expose uninitialized memory\n* It is \
recommended that, for a union where `Debug` is implemented, types that allow \
uninitialized memory should not be used in it.\n* If you can ensure that the union \
uses no such types, use `#[educe({})]` to implement the `Debug` trait for it.\n* The \
`unsafe` keyword should be placed as the first parameter of the `Debug` attribute.",
s
uses no such types, use `#[educe({s})]` to implement the `Debug` trait for it.\n* \
The `unsafe` keyword should be placed as the first parameter of the `Debug` \
attribute."
),
)
}
5 changes: 2 additions & 3 deletions src/trait_handlers/hash/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ pub(crate) fn union_without_unsafe(meta: &Meta) -> syn::Error {
meta.span(),
format!(
"a union's `Hash` implementation is not precise, because it ignores the type of \
fields\n* If your union doesn't care about that, use `#[educe({})]` to implement the \
`Hash` trait for it.",
s
fields\n* If your union doesn't care about that, use `#[educe({s})]` to implement \
the `Hash` trait for it."
),
)
}
9 changes: 4 additions & 5 deletions src/trait_handlers/into/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use crate::common::tools::HashType;

#[inline]
pub(crate) fn reset_a_type(ty: &HashType) -> syn::Error {
syn::Error::new(ty.span(), format!("the type `{}` is repeatedly set", ty))
syn::Error::new(ty.span(), format!("the type `{ty}` is repeatedly set"))
}

#[inline]
pub(crate) fn no_into_field(ty: &HashType) -> syn::Error {
syn::Error::new(ty.span(), format!("there is no field which is assigned for `Into<{}>`", ty))
syn::Error::new(ty.span(), format!("there is no field which is assigned for `Into<{ty}>`"))
}

#[inline]
Expand All @@ -16,13 +16,12 @@ pub(crate) fn no_into_impl(ty: &HashType) -> syn::Error {
ty.span(),
format!(
"if you want to impl `Into<{ty}>` for this type, you should write \
`#[educe(Into({ty}))]` outside",
ty = ty
`#[educe(Into({ty}))]` outside"
),
)
}

#[inline]
pub(crate) fn multiple_into_fields(ty: &HashType) -> syn::Error {
syn::Error::new(ty.span(), format!("multiple fields are set for `Into<{}>`", ty))
syn::Error::new(ty.span(), format!("multiple fields are set for `Into<{ty}>`"))
}
2 changes: 1 addition & 1 deletion src/trait_handlers/ord/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use proc_macro2::Span;

#[inline]
pub(crate) fn reuse_a_rank(span: Span, rank: isize) -> syn::Error {
syn::Error::new(span, format!("the rank `{}` is repeatedly used", rank))
syn::Error::new(span, format!("the rank `{rank}` is repeatedly used"))
}
5 changes: 2 additions & 3 deletions src/trait_handlers/partial_eq/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ pub(crate) fn union_without_unsafe(meta: &Meta) -> syn::Error {
meta.span(),
format!(
"a union's `PartialEq` implementation is not precise, because it ignores the type of \
fields\n* If your union doesn't care about that, use `#[educe({})]` to implement the \
`PartialEq` trait for it.",
s
fields\n* If your union doesn't care about that, use `#[educe({s})]` to implement \
the `PartialEq` trait for it."
),
)
}
2 changes: 1 addition & 1 deletion src/trait_handlers/partial_ord/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use proc_macro2::Span;

#[inline]
pub(crate) fn reuse_a_rank(span: Span, rank: isize) -> syn::Error {
syn::Error::new(span, format!("the rank `{}` is repeatedly used", rank))
syn::Error::new(span, format!("the rank `{rank}` is repeatedly used"))
}

0 comments on commit c264b6d

Please sign in to comment.