Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
mkatychev committed Jul 26, 2024
1 parent 6a76a79 commit d04afbc
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
2 changes: 2 additions & 0 deletions bigerror/src/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub struct Type(&'static str);

impl Type {
// const fn when type_name is const fn in stable
#[must_use]
pub fn of<T>() -> Self {
Self(any::type_name::<T>())
}
Expand Down Expand Up @@ -208,6 +209,7 @@ impl std::ops::Deref for DisplayDuration {
}

/// convert a [`Duration`] into a "0H00m00s" string
#[must_use]
pub fn hms_string(duration: Duration) -> String {
if duration.is_zero() {
return "ZERO".to_string();
Expand Down
6 changes: 3 additions & 3 deletions bigerror/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ pub struct BoxCoreError(Box<dyn CoreError>);
/// * used by codecs/serializers/deserializers
///
/// here's an example of types/traits that can emit encode/decode errors:
/// * https://docs.rs/tonic/latest/tonic/codec/trait.Encoder.html
/// * https://docs.rs/rkyv/latest/rkyv/ser/serializers/type.AllocSerializer.html
/// * https://docs.rs/serde/latest/serde/trait.Serializer.html
/// * <https://docs.rs/tonic/latest/tonic/codec/trait.Encoder.html>
/// * <https://docs.rs/rkyv/latest/rkyv/ser/serializers/type.AllocSerializer.html>
/// * <https://docs.rs/serde/latest/serde/trait.Serializer.html>
#[derive(ThinContext)]
#[bigerror(crate)]
pub struct DecodeError;
Expand Down
2 changes: 1 addition & 1 deletion bigerror/src/error_stack/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl<C> ReportError<C> {

pub(crate) const fn from_ref(report: &Report<C>) -> &Self {
// SAFETY: `ReportError` is a `repr(transparent)` wrapper around `Report`.
unsafe { &*(report as *const Report<C>).cast() }
unsafe { &*std::ptr::from_ref::<Report<C>>(report).cast() }
}
}

Expand Down
14 changes: 7 additions & 7 deletions bigerror/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ mod test {
#[derive(Default)]
struct MyStruct {
my_field: Option<()>,
_string: String,
string: String,
}

impl MyStruct {
Expand Down Expand Up @@ -653,7 +653,7 @@ mod test {
.expect_or()
.attach_printable(format!("{:?}", (true, "I wish it wasn't true"))));

let id: u32 = 0xdeadbeef;
let id: u32 = 0xdead_beef;
assert_err!(None::<bool>.expect_kv("id", id));
assert!(Some(true).expect_kv("id", id).unwrap());

Expand Down Expand Up @@ -720,7 +720,7 @@ mod test {
// this is meant to be a compile time test of the `__field!` macro
fn __field() {
let my_struct = MyStruct::default();
__field!(MyStruct::__field::<&str> | &my_struct._string);
__field!(MyStruct::__field::<&str> | &my_struct.string);
}

#[test]
Expand All @@ -735,8 +735,6 @@ mod test {

#[test]
fn attach_variant() {
let my_number = 2;
let other_number = 3;
fn compare(mine: usize, other: usize) -> Result<(), Report<MyError>> {
if other != mine {
bail!(InvalidInput::attach("expected my number!")
Expand All @@ -745,15 +743,15 @@ mod test {
}
Ok(())
}
let my_number = 2;
let other_number = 3;
assert_err!(compare(my_number, other_number));
}

// should behave the same as `test::attach_variant`
// but displays lazy allocation of attachment
#[test]
fn attach_kv_macro() {
let my_number = 2;
let other_number = 3;
fn compare(mine: usize, other: usize) -> Result<(), Report<MyError>> {
if other != mine {
return Err(InvalidInput::attach("expected my number!"))
Expand All @@ -762,6 +760,8 @@ mod test {
}
Ok(())
}
let my_number = 2;
let other_number = 3;
assert_err!(compare(my_number, other_number));
}

Expand Down
2 changes: 1 addition & 1 deletion bigerror_derive/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Attributes {
pub fn parse(input: &DeriveInput) -> Result<Attributes, Error> {
let mut builder = Builder::default();

for attr in input.attrs.iter() {
for attr in &input.attrs {
if attr.path().is_ident("display") {
builder.display = Some(attr.parse_args()?);
}
Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ fmt:
rustup run nightly cargo fmt -- \
--config-path ./fmt/rustfmt.toml

[group("lint"), no_cd]
[no-cd, group("lint")]
lint *args:
cargo clippy --all-targets --all-features --no-deps {{args}} -- -D warnings

# Run clippy fix and rustfmt afterwards
[no_cd]
[no-cd]
fix *args: && fmt
cargo clippy --fix --all-targets --all-features {{args}}

Expand Down

0 comments on commit d04afbc

Please sign in to comment.