Skip to content

Commit

Permalink
Update Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Oct 7, 2023
1 parent 940b9c5 commit a71eebd
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 26 deletions.
48 changes: 42 additions & 6 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,70 @@ rustflags = [
"-Wclippy::nursery",
"-Wclippy::pedantic",
# Clippy restriction lints.
"-Wclippy::absolute_paths",
"-Wclippy::allow_attributes",
"-Wclippy::allow_attributes_without_reason",
"-Wclippy::as_conversions",
"-Wclippy::assertions_on_result_states",
"-Wclippy::clone_on_ref_ptr",
"-Wclippy::create_dir",
"-Wclippy::dbg_macro",
"-Wclippy::decimal_literal_representation",
"-Wclippy::default_union_representation",
"-Wclippy::empty_drop",
"-Wclippy::empty_structs_with_brackets",
"-Wclippy::error_impl_error",
"-Wclippy::exit",
"-Wclippy::filetype_is_file",
"-Wclippy::float_cmp_const",
"-Wclippy::fn_to_numeric_cast_any",
"-Wclippy::format_push_string",
"-Wclippy::get_unwrap",
"-Wclippy::if_then_some_else_none",
"-Wclippy::impl_trait_in_params",
"-Wclippy::indexing_slicing",
"-Wclippy::large_include_file",
"-Wclippy::lossy_float_literal",
"-Wclippy::min_ident_chars",
"-Wclippy::missing_assert_message",
"-Wclippy::missing_docs_in_private_items",
"-Wclippy::mixed_read_write_in_expression",
"-Wclippy::mutex_atomic",
"-Wclippy::non_ascii_literal",
"-Wclippy::partial_pub_fields",
"-Wclippy::print_stderr",
"-Wclippy::print_stdout",
"-Wclippy::pub_without_shorthand",
"-Wclippy::rc_buffer",
"-Wclippy::rc_mutex",
"-Wclippy::redundant_type_annotations",
"-Wclippy::ref_patterns",
"-Wclippy::rest_pat_in_fully_bound_structs",
"-Wclippy::same_name_method",
"-Wclippy::self_named_module_files",
"-Wclippy::semicolon_outside_block",
"-Wclippy::single_char_lifetime_names",
"-Wclippy::str_to_string",
"-Wclippy::string_add",
"-Wclippy::string_lit_chars_any",
"-Wclippy::string_slice",
"-Wclippy::string_to_string",
"-Wclippy::suspicious_xor_used_as_pow",
"-Wclippy::todo",
"-Wclippy::try_err",
"-Wclippy::undocumented_unsafe_blocks",
"-Wclippy::unimplemented",
"-Wclippy::unnecessary_safety_doc",
"-Wclippy::unnecessary_self_imports",
"-Wclippy::unneeded_field_pattern",
"-Wclippy::unseparated_literal_suffix",
"-Wclippy::unwrap_used",
"-Wclippy::use_debug",
"-Wclippy::verbose_file_reads",
# Allowed Clippy lints.
"-Aclippy::cast_possible_truncation",
"-Aclippy::cast_sign_loss",
"-Aclippy::equatable_if_let",
"-Aclippy::explicit_deref_methods",
"-Aclippy::future_not_send",
"-Aclippy::let_underscore_untyped",
"-Aclippy::module_inception",
"-Aclippy::module_name_repetitions",
"-Aclippy::option_if_let_else",
Expand All @@ -43,7 +82,6 @@ rustflags = [
"-Wrustdoc::all",
# Rust groups.
"-Wfuture_incompatible",
"-Wnonstandard_style",
"-Wrust_2018_compatibility",
"-Wrust_2018_idioms",
"-Wrust_2021_compatibility",
Expand All @@ -57,13 +95,11 @@ rustflags = [
"-Wmissing_debug_implementations",
"-Wmissing_docs",
"-Wnon_ascii_idents",
"-Wnoop_method_call",
"-Wsingle_use_lifetimes",
"-Wtrivial_casts",
"-Wtrivial_numeric_casts",
"-Wunreachable_pub",
"-Wunsafe_op_in_unsafe_fn",
"-Wunstable_features",
"-Wunused_import_braces",
"-Wunused_lifetimes",
"-Wunused_qualifications",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install additional Rust targets
run: rustup +nightly target add wasm32-unknown-unknown
- name: Install Rust nightly
run: rustup toolchain install nightly --profile minimal --target wasm32-unknown-unknown
- name: Run Rustdoc
env:
RUSTDOCFLAGS: --crate-version main
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
run: rustup target add ${{ matrix.target }}
run:
rustup toolchain install stable --profile minimal --component clippy
--target ${{ matrix.target }}
- name: Run Clippy
run:
cargo clippy --all-targets --target ${{ matrix.target }} -- -D
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ jobs:
- uses: taiki-e/install-action@v2
with:
tool: wasm-bindgen-cli
- name: Install additional Rust targets
- name: Install Rust
run: |
rustup toolchain install ${{ matrix.rust.version }} --profile minimal --target ${{ matrix.target.target }}
rustup default ${{ matrix.rust.version }}
rustup target add ${{ matrix.target.target }}
- name: Build
run: cargo build --target ${{ matrix.target.target }}
- name: Documentation
Expand Down Expand Up @@ -94,11 +94,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install additional Rust targets and components
run: |
rustup default nightly
rustup target add wasm32-unknown-unknown
rustup component add rust-src
- name: Install Rust
run: rustup toolchain install nightly --profile minimal
- uses: taiki-e/install-action@v2
with:
tool: wasm-bindgen-cli
Expand Down Expand Up @@ -139,10 +136,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install additional Rust targets
- name: Install Rust
run: |
rustup toolchain install ${{ matrix.rust }} --profile minimal --target ${{ matrix.target.target }}
rustup default ${{ matrix.rust }}
rustup target add ${{ matrix.target }}
- name: Install Rust nightly
run: rustup toolchain install nightly --profile minimal
- name: Build
Expand Down
3 changes: 3 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
allow-unwrap-in-tests = true
avoid-breaking-exported-api = false
semicolon-outside-block-ignore-multiline = true
6 changes: 5 additions & 1 deletion src/web/instant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ impl Instant {
performance.now()
});

#[allow(clippy::as_conversions)]
#[allow(
clippy::as_conversions,
clippy::cast_possible_truncation,
clippy::cast_sign_loss
)]
let duration = Duration::from_millis(now.trunc() as u64)
+ Duration::from_nanos((now.fract() * 1.0e6) as u64);

Expand Down
24 changes: 17 additions & 7 deletions src/web/system_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,46 @@ impl SystemTime {
/// See [`std::time::SystemTime::now()`].
#[must_use]
pub fn now() -> Self {
#[allow(clippy::as_conversions)]
#[allow(clippy::as_conversions, clippy::cast_possible_truncation)]
Self(js_sys::Date::now() as i64)
}

/// See [`std::time::SystemTime::duration_since()`].
#[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
#[allow(
clippy::missing_errors_doc,
clippy::missing_panics_doc,
clippy::trivially_copy_pass_by_ref
)]
pub fn duration_since(&self, earlier: Self) -> Result<Duration, SystemTimeError> {
if self.0 < earlier.0 {
let duration = (earlier.0 - self.0).try_into().unwrap();
let duration = (earlier.0 - self.0)
.try_into()
.expect("`self` bigger then `earlier` despite earlier check");

Err(SystemTimeError(Duration::from_millis(duration)))
} else {
let duration = (self.0 - earlier.0).try_into().unwrap();
let duration = (self.0 - earlier.0)
.try_into()
.expect("`earlier` bigger then `self` despite earlier check");
Ok(Duration::from_millis(duration))
}
}

/// See [`std::time::SystemTime::elapsed()`].
#[allow(clippy::missing_errors_doc)]
#[allow(clippy::missing_errors_doc, clippy::trivially_copy_pass_by_ref)]
pub fn elapsed(&self) -> Result<Duration, SystemTimeError> {
Self::now().duration_since(*self)
}

/// See [`std::time::SystemTime::checked_add()`].
#[allow(clippy::trivially_copy_pass_by_ref)]
pub fn checked_add(&self, duration: Duration) -> Option<Self> {
let duration = duration.as_millis().try_into().ok()?;
self.0.checked_add(duration).map(SystemTime)
}

/// See [`std::time::SystemTime::checked_sub()`].
#[allow(clippy::trivially_copy_pass_by_ref)]
pub fn checked_sub(&self, duration: Duration) -> Option<Self> {
let duration = duration.as_millis().try_into().ok()?;
self.0.checked_sub(duration).map(SystemTime)
Expand Down Expand Up @@ -102,8 +112,8 @@ impl SystemTimeError {
}

impl Display for SystemTimeError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "second time provided was later than self")
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
write!(formatter, "second time provided was later than self")
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/instant_failure.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(test)]

mod util;

use web_time::{Duration, Instant};
Expand Down
3 changes: 3 additions & 0 deletions tests/instant_success.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![cfg(test)]
#![allow(clippy::missing_assert_message)]

mod util;

use web_time::{Duration, Instant};
Expand Down
2 changes: 2 additions & 0 deletions tests/system_time_failure.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(test)]

mod util;

use web_time::{Duration, SystemTime};
Expand Down
3 changes: 3 additions & 0 deletions tests/system_time_success.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![cfg(test)]
#![allow(clippy::missing_assert_message)]

mod util;

use web_time::{Duration, SystemTime};
Expand Down

0 comments on commit a71eebd

Please sign in to comment.