Skip to content

Commit

Permalink
Update to Linebender lint set v2. (#758)
Browse files Browse the repository at this point in the history
Some examples needed minor adjustments and `xilem_web` needed an
exception.
  • Loading branch information
xStrom authored Nov 23, 2024
1 parent 91b2343 commit af96e78
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 23 deletions.
11 changes: 11 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -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", ".."]

Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions masonry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions xilem/examples/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand All @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions xilem/examples/stopwatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -112,7 +112,7 @@ fn app_logic(data: &mut Stopwatch) -> impl WidgetView<Stopwatch> {
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),
Expand Down Expand Up @@ -145,23 +145,23 @@ fn laps_section(data: &mut Stopwatch) -> impl FlexSequence<Stopwatch> {
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,
&current_split_duration,
&data.get_current_duration(),
current_split_duration,
data.get_current_duration(),
));
items.reverse();
items
}

fn single_lap(
lap_id: usize,
split_dur: &Duration,
total_dur: &Duration,
split_dur: Duration,
total_dur: Duration,
) -> impl WidgetView<Stopwatch> {
flex((
FlexSpacer::Flex(1.0),
Expand Down
8 changes: 5 additions & 3 deletions xilem/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
10 changes: 5 additions & 5 deletions xilem_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
//! .rustdoc-hidden { display: none; }
//! </style>
#![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(
Expand Down
5 changes: 3 additions & 2 deletions xilem_web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
//! .rustdoc-hidden { display: none; }
//! </style>
#![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")]
Expand Down
4 changes: 4 additions & 0 deletions xilem_web/src/modifiers/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,10 @@ impl<E, State, Action> Rotate<E, State, Action> {
}
}

#[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)")
Expand Down

0 comments on commit af96e78

Please sign in to comment.