diff --git a/Cranky.toml b/Cranky.toml index 44f7b41f03dd..2a124e20e024 100644 --- a/Cranky.toml +++ b/Cranky.toml @@ -51,6 +51,7 @@ warn = [ "clippy::iter_on_empty_collections", "clippy::iter_on_single_items", "clippy::large_digit_groups", + "clippy::large_include_file", "clippy::large_stack_arrays", "clippy::large_types_passed_by_value", "clippy::let_unit_value", @@ -99,6 +100,7 @@ warn = [ "clippy::string_to_string", "clippy::suspicious_xor_used_as_pow", "clippy::todo", + "clippy::too_many_lines", "clippy::trailing_empty_array", "clippy::trait_duplication_in_bounds", "clippy::unchecked_duration_subtraction", diff --git a/clippy.toml b/clippy.toml index b329c6e476ad..33a48eb301bb 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,9 +1,25 @@ # There is also a scripts/clippy_wasm/clippy.toml which forbids some methods that are not available in wasm. +# ----------------------------------------------------------------------------- +# Section identical to the main scripts/clippy_wasm/clippy.toml: + msrv = "1.69" allow-unwrap-in-tests = true +# https://doc.rust-lang.org/nightly/clippy/lint_configuration.html#avoid-breaking-exported-api +# We want suggestions, even if it changes public API. +avoid-breaking-exported-api = false + +max-fn-params-bools = 2 # TODO(emilk): decrease this to 1 + +# https://rust-lang.github.io/rust-clippy/master/index.html#/large_include_file +max-include-file-size = 1000000 + +too-many-lines-threshold = 600 # TODO(emilk): decrease this + +# ----------------------------------------------------------------------------- + # https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_macros disallowed-macros = [ 'dbg', diff --git a/crates/re_arrow_store/src/store_arrow.rs b/crates/re_arrow_store/src/store_arrow.rs index 4085026eaab5..99cd3f5996e3 100644 --- a/crates/re_arrow_store/src/store_arrow.rs +++ b/crates/re_arrow_store/src/store_arrow.rs @@ -143,7 +143,7 @@ fn serialize_control_columns( // NOTE: Optional column, so make sure it's actually there: if !col_insert_id.is_empty() { let (insert_id_field, insert_id_column) = - DataTable::serialize_primitive_column(COLUMN_INSERT_ID, col_insert_id, None)?; + DataTable::serialize_primitive_column(COLUMN_INSERT_ID, col_insert_id, None); schema.fields.push(insert_id_field); columns.push(insert_id_column); } @@ -158,13 +158,13 @@ fn serialize_control_columns( timeline.name(), col_time, timeline.datatype().into(), - )?; + ); schema.fields.push(time_field); columns.push(time_column); } let (num_instances_field, num_instances_column) = - DataTable::serialize_primitive_column(COLUMN_NUM_INSTANCES, col_num_instances, None)?; + DataTable::serialize_primitive_column(COLUMN_NUM_INSTANCES, col_num_instances, None); schema.fields.push(num_instances_field); columns.push(num_instances_column); diff --git a/crates/re_arrow_store/src/store_polars.rs b/crates/re_arrow_store/src/store_polars.rs index c6d7c43ddc58..9dc52ab9c6b7 100644 --- a/crates/re_arrow_store/src/store_polars.rs +++ b/crates/re_arrow_store/src/store_polars.rs @@ -223,8 +223,7 @@ impl IndexedBucket { self.timeline.name(), col_time, self.timeline.datatype().into(), - ) - .unwrap(); + ); let num_rows = times.len(); let insert_ids = config diff --git a/crates/re_components/src/color.rs b/crates/re_components/src/color.rs index ceb4371a2367..630850dbe150 100644 --- a/crates/re_components/src/color.rs +++ b/crates/re_components/src/color.rs @@ -37,7 +37,7 @@ impl ColorRGBA { } #[inline] - pub fn to_array(&self) -> [u8; 4] { + pub fn to_array(self) -> [u8; 4] { [ (self.0 >> 24) as u8, (self.0 >> 16) as u8, diff --git a/crates/re_components/src/coordinates.rs b/crates/re_components/src/coordinates.rs index 6961189c94c7..86cddac30f61 100644 --- a/crates/re_components/src/coordinates.rs +++ b/crates/re_components/src/coordinates.rs @@ -1,3 +1,5 @@ +#![allow(clippy::wrong_self_convention)] // TODO(emilk): re-enable + use arrow2::datatypes::DataType; use arrow2_convert::{ deserialize::ArrowDeserialize, diff --git a/crates/re_components/src/rect.rs b/crates/re_components/src/rect.rs index 1fc34e43ab7c..4ca6ccb21888 100644 --- a/crates/re_components/src/rect.rs +++ b/crates/re_components/src/rect.rs @@ -1,3 +1,5 @@ +#![allow(clippy::upper_case_acronyms)] + use arrow2_convert::{ArrowDeserialize, ArrowField, ArrowSerialize}; use super::Vec4D; diff --git a/crates/re_components/src/tensor.rs b/crates/re_components/src/tensor.rs index d22a55fd4499..5e2b4be6d6a6 100644 --- a/crates/re_components/src/tensor.rs +++ b/crates/re_components/src/tensor.rs @@ -146,6 +146,7 @@ impl ArrowDeserialize for TensorId { /// ``` #[derive(Clone, PartialEq, ArrowField, ArrowSerialize, ArrowDeserialize)] #[arrow_field(type = "dense")] +#[allow(clippy::upper_case_acronyms)] // TODO(emilk): Rename to `Jpeg`. pub enum TensorData { U8(Buffer), U16(Buffer), diff --git a/crates/re_components/src/transform3d.rs b/crates/re_components/src/transform3d.rs index 25eea33752d2..b0518448f40e 100644 --- a/crates/re_components/src/transform3d.rs +++ b/crates/re_components/src/transform3d.rs @@ -519,7 +519,7 @@ impl Transform3D { #[cfg(feature = "glam")] impl Transform3D { #[inline] - pub fn to_parent_from_child_transform(&self) -> glam::Affine3A { + pub fn to_parent_from_child_transform(self) -> glam::Affine3A { let transform: glam::Affine3A = self.transform.into(); if self.from_parent { transform.inverse() diff --git a/crates/re_log_encoding/src/lib.rs b/crates/re_log_encoding/src/lib.rs index 97cb26287da0..196aed00589f 100644 --- a/crates/re_log_encoding/src/lib.rs +++ b/crates/re_log_encoding/src/lib.rs @@ -81,7 +81,7 @@ impl EncodingOptions { } } - pub fn to_bytes(&self) -> [u8; 4] { + pub fn to_bytes(self) -> [u8; 4] { [ self.compression as u8, self.serializer as u8, @@ -93,6 +93,7 @@ impl EncodingOptions { /// On failure to decode [`EncodingOptions`] #[derive(thiserror::Error, Debug)] +#[allow(clippy::enum_variant_names)] pub enum OptionsError { #[error("Reserved bytes not zero")] UnknownReservedBytes, diff --git a/crates/re_log_types/src/data_cell.rs b/crates/re_log_types/src/data_cell.rs index f7f62555e459..6afb448c70ff 100644 --- a/crates/re_log_types/src/data_cell.rs +++ b/crates/re_log_types/src/data_cell.rs @@ -230,6 +230,7 @@ impl DataCell { /// /// Fails if the array is not a valid list of components. #[inline] + #[allow(clippy::unnecessary_wraps)] // TODO(cmc): check that it is indeed a component datatype pub fn try_from_arrow( name: ComponentName, values: Box, @@ -267,12 +268,11 @@ impl DataCell { /// /// Fails if the datatype is not a valid component type. #[inline] + #[allow(clippy::unnecessary_wraps)] // TODO(cmc): check that it is indeed a component datatype pub fn try_from_arrow_empty( name: ComponentName, datatype: arrow2::datatypes::DataType, ) -> DataCellResult { - // TODO(cmc): check that it is indeed a component datatype - let mut inner = DataCellInner { name, size_bytes: 0, diff --git a/crates/re_log_types/src/data_table.rs b/crates/re_log_types/src/data_table.rs index c175d4e183cd..4267dadc34c9 100644 --- a/crates/re_log_types/src/data_table.rs +++ b/crates/re_log_types/src/data_table.rs @@ -678,7 +678,7 @@ impl DataTable { COLUMN_NUM_INSTANCES, col_num_instances.as_slice(), None, - )?; + ); schema.fields.push(num_instances_field); columns.push(num_instances_column); @@ -730,7 +730,7 @@ impl DataTable { name: &str, values: &[T], datatype: Option, - ) -> DataTableResult<(Field, Box)> { + ) -> (Field, Box) { re_tracing::profile_function!(); let data = PrimitiveArray::from_slice(values); @@ -747,7 +747,7 @@ impl DataTable { .extend([("ARROW:extension:name".to_owned(), name)]); } - Ok((field, data)) + (field, data) } /// Serializes all data columns into an arrow payload and schema. diff --git a/crates/re_log_types/src/time.rs b/crates/re_log_types/src/time.rs index 12f8dbb88dab..d98f4c59e16a 100644 --- a/crates/re_log_types/src/time.rs +++ b/crates/re_log_types/src/time.rs @@ -45,7 +45,7 @@ impl Time { } /// Returns the absolute datetime if applicable. - pub fn to_datetime(&self) -> Option { + pub fn to_datetime(self) -> Option { let ns_since_epoch = self.nanos_since_epoch(); if self.is_absolute_date() { OffsetDateTime::from_unix_timestamp_nanos(ns_since_epoch as i128).ok() diff --git a/crates/re_renderer/examples/2d.rs b/crates/re_renderer/examples/2d.rs index 2523601da173..6a4058cf403b 100644 --- a/crates/re_renderer/examples/2d.rs +++ b/crates/re_renderer/examples/2d.rs @@ -210,8 +210,8 @@ impl framework::Example for Render2D { ); } - let line_strip_draw_data = line_strip_builder.to_draw_data(re_ctx).unwrap(); - let point_draw_data = point_cloud_builder.to_draw_data(re_ctx).unwrap(); + let line_strip_draw_data = line_strip_builder.into_draw_data(re_ctx).unwrap(); + let point_draw_data = point_cloud_builder.into_draw_data(re_ctx); let image_scale = 4.0; let rectangle_draw_data = RectangleDrawData::new( diff --git a/crates/re_renderer/examples/depth_cloud.rs b/crates/re_renderer/examples/depth_cloud.rs index f982793168b0..da24b242e126 100644 --- a/crates/re_renderer/examples/depth_cloud.rs +++ b/crates/re_renderer/examples/depth_cloud.rs @@ -106,7 +106,7 @@ impl RenderDepthClouds { std::iter::empty::(), ); - builder.to_draw_data(re_ctx).unwrap() + builder.into_draw_data(re_ctx) }; let mut view_builder = ViewBuilder::new( @@ -305,7 +305,7 @@ impl framework::Example for RenderDepthClouds { glam::Vec3::ONE * 0.5, )); } - builder.to_draw_data(re_ctx).unwrap() + builder.into_draw_data(re_ctx).unwrap() }; let image_draw_data = RectangleDrawData::new( diff --git a/crates/re_renderer/examples/multiview.rs b/crates/re_renderer/examples/multiview.rs index 08bec6b8269c..93ef4c3ee3e3 100644 --- a/crates/re_renderer/examples/multiview.rs +++ b/crates/re_renderer/examples/multiview.rs @@ -132,7 +132,7 @@ fn build_lines(re_ctx: &mut RenderContext, seconds_since_startup: f32) -> LineDr .radius(Size::new_scene(0.1)) .flags(LineStripFlags::FLAG_CAP_END_TRIANGLE); - builder.to_draw_data(re_ctx).unwrap() + builder.into_draw_data(re_ctx).unwrap() } enum CameraControl { @@ -334,7 +334,7 @@ impl Example for Multiview { std::iter::empty::(), ); - let point_cloud = builder.to_draw_data(re_ctx).unwrap(); + let point_cloud = builder.into_draw_data(re_ctx); let meshes = build_mesh_instances( re_ctx, &self.model_mesh_instances, diff --git a/crates/re_renderer/examples/picking.rs b/crates/re_renderer/examples/picking.rs index 9535224ec851..7784fae824b4 100644 --- a/crates/re_renderer/examples/picking.rs +++ b/crates/re_renderer/examples/picking.rs @@ -167,7 +167,7 @@ impl framework::Example for Picking { point_set.picking_ids.iter().cloned(), ); } - view_builder.queue_draw(point_builder.to_draw_data(re_ctx).unwrap()); + view_builder.queue_draw(point_builder.into_draw_data(re_ctx)); let instances = self .model_mesh_instances diff --git a/crates/re_renderer/src/config.rs b/crates/re_renderer/src/config.rs index 5d1c3da6866b..a8d264252669 100644 --- a/crates/re_renderer/src/config.rs +++ b/crates/re_renderer/src/config.rs @@ -85,6 +85,7 @@ impl DeviceCaps { } /// Required features for the given device tier. + #[allow(clippy::unused_self)] pub fn features(&self) -> wgpu::Features { wgpu::Features::empty() } diff --git a/crates/re_renderer/src/file_server.rs b/crates/re_renderer/src/file_server.rs index 3b42ac0176d2..4918af82c5e2 100644 --- a/crates/re_renderer/src/file_server.rs +++ b/crates/re_renderer/src/file_server.rs @@ -311,6 +311,7 @@ mod file_server_impl { f(&mut Self) } + #[allow(clippy::unused_self)] pub fn collect( &mut self, _resolver: &mut FileResolver, diff --git a/crates/re_renderer/src/line_strip_builder.rs b/crates/re_renderer/src/line_strip_builder.rs index 4d5fab9bc209..6b529d79acb0 100644 --- a/crates/re_renderer/src/line_strip_builder.rs +++ b/crates/re_renderer/src/line_strip_builder.rs @@ -95,7 +95,7 @@ impl LineStripSeriesBuilder { } /// Finalizes the builder and returns a line draw data with all the lines added so far. - pub fn to_draw_data( + pub fn into_draw_data( self, ctx: &mut crate::context::RenderContext, ) -> Result { diff --git a/crates/re_renderer/src/point_cloud_builder.rs b/crates/re_renderer/src/point_cloud_builder.rs index 39a7f4b2f7e3..0cc1aacf8596 100644 --- a/crates/re_renderer/src/point_cloud_builder.rs +++ b/crates/re_renderer/src/point_cloud_builder.rs @@ -1,10 +1,7 @@ use crate::{ allocator::CpuWriteGpuReadBuffer, draw_phases::PickingLayerObjectId, - renderer::{ - PointCloudBatchFlags, PointCloudBatchInfo, PointCloudDrawData, PointCloudDrawDataError, - PointCloudVertex, - }, + renderer::{PointCloudBatchFlags, PointCloudBatchInfo, PointCloudDrawData, PointCloudVertex}, Color32, DebugLabel, DepthOffset, OutlineMaskPreference, PickingLayerInstanceId, RenderContext, Size, }; @@ -100,10 +97,7 @@ impl PointCloudBuilder { } /// Finalizes the builder and returns a point cloud draw data with all the points added so far. - pub fn to_draw_data( - self, - ctx: &mut crate::context::RenderContext, - ) -> Result { + pub fn into_draw_data(self, ctx: &mut crate::context::RenderContext) -> PointCloudDrawData { PointCloudDrawData::new(ctx, self) } } diff --git a/crates/re_renderer/src/renderer/point_cloud.rs b/crates/re_renderer/src/renderer/point_cloud.rs index 5a0ce6d015d2..0b324612cdb9 100644 --- a/crates/re_renderer/src/renderer/point_cloud.rs +++ b/crates/re_renderer/src/renderer/point_cloud.rs @@ -183,10 +183,7 @@ impl PointCloudDrawData { /// Number of vertices and colors has to be equal. /// /// If no batches are passed, all points are assumed to be in a single batch with identity transform. - pub fn new( - ctx: &mut RenderContext, - mut builder: PointCloudBuilder, - ) -> Result { + pub fn new(ctx: &mut RenderContext, mut builder: PointCloudBuilder) -> Self { re_tracing::profile_function!(); let mut renderers = ctx.renderers.write(); @@ -201,11 +198,11 @@ impl PointCloudDrawData { let batches = builder.batches.as_slice(); if vertices.is_empty() { - return Ok(PointCloudDrawData { + return PointCloudDrawData { bind_group_all_points: None, bind_group_all_points_outline_mask: None, batches: Vec::new(), - }); + }; } let fallback_batches = [PointCloudBatchInfo { @@ -491,11 +488,11 @@ impl PointCloudDrawData { } } - Ok(PointCloudDrawData { + PointCloudDrawData { bind_group_all_points: Some(bind_group_all_points), bind_group_all_points_outline_mask: Some(bind_group_all_points_outline_mask), batches: batches_internal, - }) + } } } diff --git a/crates/re_sdk/src/msg_sender.rs b/crates/re_sdk/src/msg_sender.rs index 04ee97ef7118..4ede7f46c8ff 100644 --- a/crates/re_sdk/src/msg_sender.rs +++ b/crates/re_sdk/src/msg_sender.rs @@ -320,6 +320,7 @@ impl MsgSender { /// Consumes, packs, sanity checks and finally sends the message to the currently configured /// target of the SDK. + #[allow(clippy::unnecessary_wraps)] // We might want to return errors in the future. pub fn send(self, rec_stream: &RecordingStream) -> Result<(), DataTableError> { if !rec_stream.is_enabled() { return Ok(()); // silently drop the message diff --git a/crates/re_sdk/src/recording_stream.rs b/crates/re_sdk/src/recording_stream.rs index 0c840878f2f0..dd3398d1bd57 100644 --- a/crates/re_sdk/src/recording_stream.rs +++ b/crates/re_sdk/src/recording_stream.rs @@ -136,6 +136,7 @@ impl RecordingStreamBuilder { self } + #[allow(clippy::wrong_self_convention)] #[doc(hidden)] pub fn is_official_example(mut self, is_official_example: bool) -> Self { self.is_official_example = is_official_example; diff --git a/crates/re_space_view_spatial/src/scene/contexts/shared_render_builders.rs b/crates/re_space_view_spatial/src/scene/contexts/shared_render_builders.rs index 095acf0a1dde..d8612f4a5c12 100644 --- a/crates/re_space_view_spatial/src/scene/contexts/shared_render_builders.rs +++ b/crates/re_space_view_spatial/src/scene/contexts/shared_render_builders.rs @@ -29,7 +29,7 @@ impl SharedRenderBuilders { ) -> Vec { let mut result = Vec::new(); result.extend(self.lines.take().and_then( - |l| match l.into_inner().to_draw_data(render_ctx) { + |l| match l.into_inner().into_draw_data(render_ctx) { Ok(d) => Some(d.into()), Err(err) => { re_log::error_once!("Failed to build line strip draw data: {err}"); @@ -37,15 +37,11 @@ impl SharedRenderBuilders { } }, )); - result.extend(self.points.take().and_then( - |l| match l.into_inner().to_draw_data(render_ctx) { - Ok(d) => Some(d.into()), - Err(err) => { - re_log::error_once!("Failed to build point draw data: {err}"); - None - } - }, - )); + result.extend( + self.points + .take() + .map(|l| l.into_inner().into_draw_data(render_ctx).into()), + ); result } } diff --git a/crates/re_space_view_spatial/src/ui_3d.rs b/crates/re_space_view_spatial/src/ui_3d.rs index d8e7685f7ddf..2a0191c27c4a 100644 --- a/crates/re_space_view_spatial/src/ui_3d.rs +++ b/crates/re_space_view_spatial/src/ui_3d.rs @@ -528,7 +528,7 @@ pub fn view_3d( } // Commit ui induced lines. - match line_builder.to_draw_data(ctx.render_ctx) { + match line_builder.into_draw_data(ctx.render_ctx) { Ok(line_draw_data) => { view_builder.queue_draw(line_draw_data); } diff --git a/crates/re_types/src/components/color_ext.rs b/crates/re_types/src/components/color_ext.rs index ea0703868e7e..887783d08772 100644 --- a/crates/re_types/src/components/color_ext.rs +++ b/crates/re_types/src/components/color_ext.rs @@ -12,7 +12,7 @@ impl Color { } #[inline] - pub fn to_array(&self) -> [u8; 4] { + pub fn to_array(self) -> [u8; 4] { [ (self.0 >> 24) as u8, (self.0 >> 16) as u8, diff --git a/crates/re_ui/src/command.rs b/crates/re_ui/src/command.rs index 1bc14f177bb5..20ffbc70d5ef 100644 --- a/crates/re_ui/src/command.rs +++ b/crates/re_ui/src/command.rs @@ -153,6 +153,7 @@ impl UICommand { } } + #[allow(clippy::unnecessary_wraps)] // Only on some platforms pub fn kb_shortcut(self) -> Option { fn key(key: Key) -> KeyboardShortcut { KeyboardShortcut::new(Modifiers::NONE, key) diff --git a/crates/re_ui/src/lib.rs b/crates/re_ui/src/lib.rs index 0ab0cbd5002d..7827496a4c13 100644 --- a/crates/re_ui/src/lib.rs +++ b/crates/re_ui/src/lib.rs @@ -143,6 +143,7 @@ impl ReUi { frame } + #[allow(clippy::unused_self)] pub fn bottom_panel_margin(&self) -> egui::Vec2 { egui::Vec2::splat(8.0) } diff --git a/crates/re_web_viewer_server/src/lib.rs b/crates/re_web_viewer_server/src/lib.rs index 4488beb1f52e..1277b9b0fa95 100644 --- a/crates/re_web_viewer_server/src/lib.rs +++ b/crates/re_web_viewer_server/src/lib.rs @@ -21,6 +21,8 @@ pub const DEFAULT_WEB_VIEWER_SERVER_PORT: u16 = 9090; #[cfg(not(feature = "__ci"))] mod data { + #![allow(clippy::large_include_file)] + // If you add/remove/change the paths here, also update the include-list in `Cargo.toml`! pub const INDEX_HTML: &[u8] = include_bytes!("../web_viewer/index_bundled.html"); pub const FAVICON: &[u8] = include_bytes!("../web_viewer/favicon.svg"); diff --git a/rerun_py/src/python_bridge.rs b/rerun_py/src/python_bridge.rs index dcddb931ecd0..cbf65787781c 100644 --- a/rerun_py/src/python_bridge.rs +++ b/rerun_py/src/python_bridge.rs @@ -177,8 +177,9 @@ fn rerun_bindings(_py: Python<'_>, m: &PyModule) -> PyResult<()> { // --- Init --- -#[allow(clippy::too_many_arguments)] +#[allow(clippy::fn_params_excessive_bools)] #[allow(clippy::struct_excessive_bools)] +#[allow(clippy::too_many_arguments)] #[pyfunction] #[pyo3(signature = ( application_id, @@ -243,7 +244,7 @@ fn new_recording( Ok(PyRecordingStream(recording)) } -#[allow(clippy::struct_excessive_bools)] +#[allow(clippy::fn_params_excessive_bools)] #[pyfunction] #[pyo3(signature = ( application_id, diff --git a/scripts/clippy_wasm/clippy.toml b/scripts/clippy_wasm/clippy.toml index 6e5b28b51a09..db38266beeb7 100644 --- a/scripts/clippy_wasm/clippy.toml +++ b/scripts/clippy_wasm/clippy.toml @@ -3,8 +3,26 @@ # We cannot forbid all these methods in the main `clippy.toml` because of # https://github.com/rust-lang/rust-clippy/issues/10406 +# ----------------------------------------------------------------------------- +# Section identical to the main clippy.toml: + msrv = "1.69" +allow-unwrap-in-tests = true + +# https://doc.rust-lang.org/nightly/clippy/lint_configuration.html#avoid-breaking-exported-api +# We want suggestions, even if it changes public API. +avoid-breaking-exported-api = false + +max-fn-params-bools = 2 # TODO(emilk): decrease this to 1 + +# https://rust-lang.github.io/rust-clippy/master/index.html#/large_include_file +max-include-file-size = 1000000 + +too-many-lines-threshold = 600 # TODO(emilk): decrease this + +# ----------------------------------------------------------------------------- + # https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods disallowed-methods = [ "std::time::Instant::now", # use `instant` crate instead for wasm/web compatibility