Skip to content

Commit

Permalink
Enable more clippy lints (rerun-io#259)
Browse files Browse the repository at this point in the history
* Enable unsafe_op_in_unsafe_fn lint
* Enable some new clippy lints
  • Loading branch information
emilk authored Nov 4, 2022
1 parent 4860e7c commit 5e59c74
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
8 changes: 7 additions & 1 deletion Cranky.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ deny = [
warn = [
"clippy::all",
"clippy::await_holding_lock",
"clippy::bool_to_int_with_if",
"clippy::char_lit_as_u8",
"clippy::checked_conversions",
"clippy::dbg_macro",
Expand Down Expand Up @@ -40,6 +41,8 @@ warn = [
"clippy::inefficient_to_string",
"clippy::invalid_upcast_comparisons",
"clippy::iter_not_returning_iterator",
"clippy::iter_on_empty_collections",
"clippy::iter_on_single_items",
"clippy::large_digit_groups",
"clippy::large_stack_arrays",
"clippy::large_types_passed_by_value",
Expand All @@ -48,7 +51,9 @@ warn = [
"clippy::lossy_float_literal",
"clippy::macro_use_imports",
"clippy::manual_assert",
"clippy::manual_instant_elapsed",
"clippy::manual_ok_or",
"clippy::manual_string_new",
"clippy::map_err_ignore",
"clippy::map_flatten",
"clippy::map_unwrap_or",
Expand Down Expand Up @@ -90,6 +95,7 @@ warn = [
"clippy::unimplemented",
"clippy::unnecessary_wraps",
"clippy::unnested_or_patterns",
"clippy::unused_peekable",
"clippy::unused_rounding",
"clippy::unused_self",
"clippy::useless_transmute",
Expand All @@ -102,14 +108,14 @@ warn = [
"rust_2021_prelude_collisions",
"semicolon_in_expressions_from_macros",
"trivial_numeric_casts",
"unsafe_op_in_unsafe_fn", # `unsafe_op_in_unsafe_fn` may become the default in future Rust versions: https://github.com/rust-lang/rust/issues/71668
"unused_extern_crates",
"unused_import_braces",
"unused_lifetimes",
# "clippy::cloned_instead_of_copied",
# "clippy::missing_errors_doc",
# "clippy::mod_module_files",
# "trivial_casts",
# "unsafe_op_in_unsafe_fn", # `unsafe_op_in_unsafe_fn` may become the default in future Rust versions: https://github.com/rust-lang/rust/issues/71668 TODO(emilk): enable this lint when Rust 1.65 is released (November 2022) and the `unused_unsafe` lint is off by default.
# "unused_qualifications",
]

Expand Down
8 changes: 6 additions & 2 deletions crates/re_data_store/examples/memory_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ unsafe impl std::alloc::GlobalAlloc for TrackingAllocator {
self.high_water_mark_bytes
.store(self.high_water_mark_bytes.load(SeqCst).max(used), SeqCst);

self.allocator.alloc(layout)
// SAFETY:
// Just deferring
unsafe { self.allocator.alloc(layout) }
}

unsafe fn dealloc(&self, ptr: *mut u8, layout: std::alloc::Layout) {
self.cumul_free_count.fetch_add(1, SeqCst);
self.cumul_free_size.fetch_add(layout.size(), SeqCst);

self.allocator.dealloc(ptr, layout);
// SAFETY:
// Just deferring
unsafe { self.allocator.dealloc(ptr, layout) };
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/re_renderer/examples/renderer_standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl Application {
// (wgpu has a swap chain with a limited amount of buffers, the exact count is dependent on `present_mode` and backend!).
// It's important to keep in mind that depending on the `present_mode`, the GPU might be waiting on the screen in turn.
let current_time = Instant::now();
let time_passed = Instant::now() - self.state.time.last_draw_time;
let time_passed = current_time - self.state.time.last_draw_time;
self.state.time.last_draw_time = current_time;

// TODO(andreas): Display a median over n frames and while we're on it also stddev thereof.
Expand Down Expand Up @@ -417,7 +417,7 @@ struct Time {

impl Time {
fn seconds_since_startup(&self) -> f32 {
(Instant::now() - self.start_time).as_secs_f32()
self.start_time.elapsed().as_secs_f32()
}
}

Expand Down
4 changes: 1 addition & 3 deletions crates/re_viewer/src/misc/time_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ impl TimeControl {
return;
}

let full_range = if let Some(full_range) = self.full_range(time_points) {
full_range
} else {
let Some(full_range) = self.full_range(time_points) else {
return;
};

Expand Down
5 changes: 0 additions & 5 deletions scripts/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ set -x

export RUSTFLAGS="--deny warnings"

# We need this Allow because of our code conforms to the lint `unsafe_op_in_unsafe_fn`,
# but we can remove this Allow when we update to Rust 1.65 in November 2022.
# See https://github.com/rust-lang/rust/issues/71668 and https://github.com/rust-lang/rust/pull/100081
export RUSTFLAGS="$RUSTFLAGS --allow unused_unsafe"

# https://github.com/ericseppanen/cargo-cranky/issues/8
export RUSTDOCFLAGS="--deny warnings --deny rustdoc::missing_crate_level_docs"

Expand Down

0 comments on commit 5e59c74

Please sign in to comment.