From fa5ffe8692ccc0ee720de7ddac87c0ad0df977e0 Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Sat, 23 Nov 2024 12:24:55 +0200 Subject: [PATCH] Update to Linebender lint set v2. --- .clippy.toml | 11 +++++++++++ Cargo.toml | 3 ++- masonry/src/lib.rs | 7 ++++--- xilem/examples/calc.rs | 4 ++-- xilem/examples/stopwatch.rs | 14 +++++++------- xilem/src/lib.rs | 8 +++++--- xilem_core/src/lib.rs | 10 +++++----- xilem_web/src/lib.rs | 5 +++-- xilem_web/src/modifiers/style.rs | 4 ++++ 9 files changed, 43 insertions(+), 23 deletions(-) diff --git a/.clippy.toml b/.clippy.toml index 9187aad44..3d9f0bc32 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1,3 +1,14 @@ +# LINEBENDER LINT SET - .clippy.toml - v1 +# See https://linebender.org/wiki/canonical-lints/ + +# The default Clippy value is capped at 8 bytes, which was chosen to improve performance on 32-bit. +# Given that we are building for the future and even low-end mobile phones have 64-bit CPUs, +# it makes sense to optimize for 64-bit and accept the performance hits on 32-bit. +# 16 bytes is the number of bytes that fits into two 64-bit CPU registers. +trivial-copy-size-limit = 16 + +# END LINEBENDER LINT SET + # Don't warn about these identifiers when using clippy::doc_markdown. doc-valid-idents = ["MathML", ".."] diff --git a/Cargo.toml b/Cargo.toml index a9fb0b033..35c16c1e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ rust.unexpected_cfgs = { level = "warn", check-cfg = [ 'cfg(tarpaulin_include)', ] } -# LINEBENDER LINT SET - v1 +# LINEBENDER LINT SET - Cargo.toml - v2 # See https://linebender.org/wiki/canonical-lints/ rust.keyword_idents_2024 = "forbid" rust.non_ascii_idents = "forbid" @@ -87,6 +87,7 @@ clippy.semicolon_if_nothing_returned = "warn" clippy.shadow_unrelated = "warn" clippy.should_panic_without_expect = "warn" clippy.todo = "warn" +clippy.trivially_copy_pass_by_ref = "warn" clippy.unseparated_literal_suffix = "warn" clippy.use_self = "warn" clippy.wildcard_imports = "warn" diff --git a/masonry/src/lib.rs b/masonry/src/lib.rs index 2064480a5..c6830e904 100644 --- a/masonry/src/lib.rs +++ b/masonry/src/lib.rs @@ -88,14 +88,15 @@ //! [Druid]: https://crates.io/crates/druid //! [Xilem]: https://crates.io/crates/xilem -#![cfg_attr(docsrs, feature(doc_cfg))] -#![cfg_attr(docsrs, feature(doc_auto_cfg))] -// LINEBENDER LINT SET - v1 +// LINEBENDER LINT SET - lib.rs - v1 // See https://linebender.org/wiki/canonical-lints/ // These lints aren't included in Cargo.toml because they // shouldn't apply to examples and tests #![warn(unused_crate_dependencies)] #![warn(clippy::print_stdout, clippy::print_stderr)] +// END LINEBENDER LINT SET +#![cfg_attr(docsrs, feature(doc_auto_cfg))] +#![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr( test, expect( diff --git a/xilem/examples/calc.rs b/xilem/examples/calc.rs index a7e1a4746..1e1f082f6 100644 --- a/xilem/examples/calc.rs +++ b/xilem/examples/calc.rs @@ -25,7 +25,7 @@ enum MathOperator { } impl MathOperator { - fn as_str(&self) -> &'static str { + fn as_str(self) -> &'static str { match self { MathOperator::Add => "+", MathOperator::Subtract => "\u{2212}", @@ -34,7 +34,7 @@ impl MathOperator { } } - fn perform_op(&self, num1: f64, num2: f64) -> f64 { + fn perform_op(self, num1: f64, num2: f64) -> f64 { match self { MathOperator::Add => num1 + num2, MathOperator::Subtract => num1 - num2, diff --git a/xilem/examples/stopwatch.rs b/xilem/examples/stopwatch.rs index 6fbb8772d..05defcfc2 100644 --- a/xilem/examples/stopwatch.rs +++ b/xilem/examples/stopwatch.rs @@ -101,7 +101,7 @@ impl Stopwatch { } } -fn get_formatted_duration(dur: &Duration) -> String { +fn get_formatted_duration(dur: Duration) -> String { let seconds = dur.as_secs_f64() % 60.0; let minutes = (dur.as_secs() / 60) % 60; let hours = (dur.as_secs() / 60) / 60; @@ -112,7 +112,7 @@ fn app_logic(data: &mut Stopwatch) -> impl WidgetView { fork( flex(( FlexSpacer::Fixed(5.0), - label(get_formatted_duration(&data.displayed_duration)).text_size(70.0), + label(get_formatted_duration(data.displayed_duration)).text_size(70.0), flex((lap_reset_button(data), start_stop_button(data))).direction(Axis::Horizontal), FlexSpacer::Fixed(1.0), laps_section(data), @@ -145,14 +145,14 @@ fn laps_section(data: &mut Stopwatch) -> impl FlexSequence { let current_lap = data.completed_lap_splits.len(); for (i, split_dur) in data.completed_lap_splits.iter().enumerate() { total_dur = total_dur.add(*split_dur); - items.push(single_lap(i, split_dur, &total_dur)); + items.push(single_lap(i, *split_dur, total_dur)); } let current_split_duration = data.get_current_duration().sub(total_dur); // Add the current lap, which is not stored in completed_lap_splits items.push(single_lap( current_lap, - ¤t_split_duration, - &data.get_current_duration(), + current_split_duration, + data.get_current_duration(), )); items.reverse(); items @@ -160,8 +160,8 @@ fn laps_section(data: &mut Stopwatch) -> impl FlexSequence { fn single_lap( lap_id: usize, - split_dur: &Duration, - total_dur: &Duration, + split_dur: Duration, + total_dur: Duration, ) -> impl WidgetView { flex(( FlexSpacer::Flex(1.0), diff --git a/xilem/src/lib.rs b/xilem/src/lib.rs index e149c5c03..bf23d1e6d 100644 --- a/xilem/src/lib.rs +++ b/xilem/src/lib.rs @@ -1,14 +1,16 @@ // Copyright 2024 the Xilem Authors // SPDX-License-Identifier: Apache-2.0 -#![cfg_attr(docsrs, feature(doc_auto_cfg))] -#![deny(clippy::trivially_copy_pass_by_ref)] -// LINEBENDER LINT SET - v1 +//! An experimental Rust native UI framework. + +// LINEBENDER LINT SET - lib.rs - v1 // See https://linebender.org/wiki/canonical-lints/ // These lints aren't included in Cargo.toml because they // shouldn't apply to examples and tests #![warn(unused_crate_dependencies)] #![warn(clippy::print_stdout, clippy::print_stderr)] +// END LINEBENDER LINT SET +#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![cfg_attr( test, expect( diff --git a/xilem_core/src/lib.rs b/xilem_core/src/lib.rs index fdd6e970e..ec9d90a81 100644 --- a/xilem_core/src/lib.rs +++ b/xilem_core/src/lib.rs @@ -13,17 +13,17 @@ //! .rustdoc-hidden { display: none; } //! #![doc = include_str!("../README.md")] -#![cfg_attr(not(test), no_std)] -#![cfg_attr(docsrs, feature(doc_auto_cfg))] -#![forbid(unsafe_code)] -// LINEBENDER LINT SET - v1 +// LINEBENDER LINT SET - lib.rs - v1 // See https://linebender.org/wiki/canonical-lints/ // These lints aren't included in Cargo.toml because they // shouldn't apply to examples and tests #![warn(unused_crate_dependencies)] #![warn(clippy::print_stdout, clippy::print_stderr)] +// END LINEBENDER LINT SET +#![cfg_attr(docsrs, feature(doc_auto_cfg))] +#![cfg_attr(not(test), no_std)] +#![forbid(unsafe_code)] // TODO: Remove any items listed as "Deferred" -#![deny(clippy::trivially_copy_pass_by_ref)] #![expect(single_use_lifetimes, reason = "Deferred: Noisy")] #![expect(clippy::exhaustive_enums, reason = "Deferred: Noisy")] #![expect( diff --git a/xilem_web/src/lib.rs b/xilem_web/src/lib.rs index 41863c597..630b1cf87 100644 --- a/xilem_web/src/lib.rs +++ b/xilem_web/src/lib.rs @@ -11,13 +11,14 @@ //! .rustdoc-hidden { display: none; } //! #![doc = include_str!("../README.md")] -#![cfg_attr(docsrs, feature(doc_auto_cfg))] -// LINEBENDER LINT SET - v1 +// LINEBENDER LINT SET - lib.rs - v1 // See https://linebender.org/wiki/canonical-lints/ // These lints aren't included in Cargo.toml because they // shouldn't apply to examples and tests #![warn(unused_crate_dependencies)] #![warn(clippy::print_stdout, clippy::print_stderr)] +// END LINEBENDER LINT SET +#![cfg_attr(docsrs, feature(doc_auto_cfg))] // TODO: Remove any items listed as "Deferred" #![cfg_attr(test, expect(clippy::print_stdout, reason = "Deferred: Noisy"))] #![expect(let_underscore_drop, reason = "Deferred: Noisy")] diff --git a/xilem_web/src/modifiers/style.rs b/xilem_web/src/modifiers/style.rs index 4d17cd642..5290c50f4 100644 --- a/xilem_web/src/modifiers/style.rs +++ b/xilem_web/src/modifiers/style.rs @@ -529,6 +529,10 @@ impl Rotate { } } +#[expect( + clippy::trivially_copy_pass_by_ref, + reason = "Needs to fit the generic signature of Styles::update_with_modify_style" +)] fn rotate_transform_modifier(transform: Option<&CowStr>, radians: &f64) -> StyleModifier { let value = if let Some(transform) = transform { format!("{transform} rotate({radians}rad)")