Skip to content

Commit

Permalink
Scope exceptions to the Linebender lint set (#730)
Browse files Browse the repository at this point in the history
This allows exceptions to be burned down on a per-crate basis, rather
than needing to be addressed across the whole codebase at once.

Additionally, this now follows completely the Linebender lint set,
except for the unexpected-cfgs. I don't think I've introduced any
behaviour changes in this PR.
  • Loading branch information
DJMcNab authored Nov 9, 2024
1 parent ee31261 commit 18a6805
Show file tree
Hide file tree
Showing 52 changed files with 421 additions and 228 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env:
# If the compilation fails, then the version specified here needs to be bumped up to reality.
# Be sure to also update the rust-version property in the workspace Cargo.toml file,
# plus all the README.md files of the affected packages.
RUST_MIN_VER: "1.79"
RUST_MIN_VER: "1.81"
# List of packages that will be checked with the minimum supported Rust version.
# This should be limited to packages that are intended for publishing.
RUST_MIN_VER_PKGS: "-p xilem -p xilem_core -p masonry"
Expand Down
87 changes: 43 additions & 44 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,86 +20,85 @@ members = [
[workspace.package]
edition = "2021"
# Keep in sync with RUST_MIN_VER in .github/workflows/ci.yml, with the relevant README.md files.
rust-version = "1.79"
rust-version = "1.81"
license = "Apache-2.0"
repository = "https://github.com/linebender/xilem"
homepage = "https://xilem.dev/"

[workspace.lints]
rust.unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(FALSE)',
'cfg(tarpaulin_include)',
] }
# unsafe code is not allowed in Xilem or Masonry
# We would like to set this to `forbid`, but we have to use `deny` because `android_activity`
# requires us to use the unsafe `#[no_mangle]` attribute
# (And cargo doesn't let us have platform specific lints here)
rust.unsafe_code = "deny"

# Intentional break from the lint set. Intended to be temporary
rust.unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(FALSE)',
'cfg(tarpaulin_include)',
] }

# LINEBENDER LINT SET - v1
# See https://linebender.org/wiki/canonical-lints/
rust.keyword_idents_2024 = "forbid"
rust.non_ascii_idents = "forbid"
rust.unsafe_op_in_unsafe_fn = "forbid"
rust.non_local_definitions = "forbid"
rust.unsafe_op_in_unsafe_fn = "forbid"

rust.unused_lifetimes = "warn"
rust.elided_lifetimes_in_paths = "warn"
rust.let_underscore_drop = "warn"
rust.missing_debug_implementations = "warn"
rust.missing_docs = "warn"
rust.single_use_lifetimes = "warn"
rust.trivial_numeric_casts = "warn"
# rust.unexpected_cfgs = "warn"
rust.unit_bindings = "warn"
rust.unnameable_types = "warn"
rust.unreachable_pub = "warn"
rust.unused_import_braces = "warn"
rust.trivial_numeric_casts = "warn"
rust.unused_lifetimes = "warn"
rust.unused_macro_rules = "warn"
rust.unused_qualifications = "warn"
rust.variant_size_differences = "warn"

clippy.allow_attributes = "warn"
clippy.allow_attributes_without_reason = "warn"
clippy.cast_possible_truncation = "warn"
clippy.collection_is_never_read = "warn"
clippy.dbg_macro = "warn"
clippy.debug_assert_with_mut_call = "warn"
clippy.doc_markdown = "warn"
clippy.exhaustive_enums = "warn"
clippy.fn_to_numeric_cast_any = "forbid"
clippy.infinite_loop = "warn"
clippy.large_include_file = "warn"
clippy.large_stack_arrays = "warn"
clippy.match_same_arms = "warn"
clippy.mismatching_type_param_order = "warn"
clippy.missing_assert_message = "warn"
clippy.missing_errors_doc = "warn"
clippy.missing_fields_in_debug = "warn"
clippy.missing_panics_doc = "warn"
clippy.partial_pub_fields = "warn"
clippy.return_self_not_must_use = "warn"
clippy.same_functions_in_if_condition = "warn"
clippy.semicolon_if_nothing_returned = "warn"
clippy.shadow_unrelated = "warn"
clippy.should_panic_without_expect = "warn"
clippy.todo = "warn"
clippy.unseparated_literal_suffix = "warn"
clippy.use_self = "warn"
clippy.wildcard_imports = "warn"

# Follow-ups for their own PRs, too noisy to go in lint group PR

# rust.let_underscore_drop = "warn"
# rust.missing_debug_implementations = "warn"
# rust.unused_qualifications = "warn"
# rust.single_use_lifetimes = "warn"
# clippy.exhaustive_enums = "warn"
# clippy.dbg_macro = "warn"
# clippy.match_same_arms = "warn"
# clippy.cast_possible_truncation = "warn"
# clippy.missing_assert_message = "warn"
# clippy.return_self_not_must_use = "warn"
# clippy.wildcard_imports = "warn"
# rust.elided_lifetimes_in_paths = "warn"
# clippy.use_self = "warn"

# Aspirational lints, not enabled for one reason or another

# rust.missing_docs = "warn" # We have many as-yet undocumented items
# rust.unreachable_pub = "warn" # Potentially controversial code style
# rust.unnameable_types = "warn" # Requires lint_reasons rustc feature for exceptions
# clippy.todo = "warn" # We have a lot of "real" todos
# clippy.missing_errors_doc = "warn" # Can be quite noisy?
# clippy.missing_panics_doc = "warn" # Can be quite noisy?
# clippy.partial_pub_fields = "warn" # Potentially controversial code style
# clippy.shadow_unrelated = "warn" # Potentially controversial code style

# This catches duplicated dependencies in the tree, which we don't have much control over
# We should use cargo deny for this, anyway
# clippy.cargo = "warn"
clippy.cargo_common_metadata = "warn"
clippy.negative_feature_names = "warn"
clippy.redundant_feature_names = "warn"
clippy.wildcard_dependencies = "warn"
# END LINEBENDER LINT SET

# Lints which we still set in individual crates lib.rs
# False positives with example targets - https://github.com/rust-lang/rust/issues/57274
# rust.unused_crate_dependencies = "warn"
# Examples often do want to print
# clippy.print_stdout = "warn"
# clippy.print_stderr = "warn"
# "https://github.com/rust-lang/rust-clippy/issues/13355"
# Please remove once 1.83 is stable
clippy.duplicated_attributes = "allow"

[workspace.dependencies]
masonry = { version = "0.2.0", path = "masonry" }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ sudo apt-get install clang libwayland-dev libxkbcommon-x11-dev libvulkan-dev

## Minimum supported Rust Version (MSRV)

This version of Xilem has been verified to compile with **Rust 1.79** and later.
This version of Xilem has been verified to compile with **Rust 1.81** and later.

Future versions of Xilem might increase the Rust version requirement.
It will not be treated as a breaking change and as such can even happen with small patch releases.
Expand Down
2 changes: 1 addition & 1 deletion masonry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ The following feature flags are available:

## Minimum supported Rust Version (MSRV)

This version of Masonry has been verified to compile with **Rust 1.79** and later.
This version of Masonry has been verified to compile with **Rust 1.81** and later.

Future versions of Masonry might increase the Rust version requirement.
It will not be treated as a breaking change and as such can even happen with small patch releases.
Expand Down
9 changes: 7 additions & 2 deletions masonry/examples/calc_masonry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
// On Windows platform, don't show a console when opening the app.
#![windows_subsystem = "windows"]
#![allow(variant_size_differences, clippy::single_match)]
#![allow(
variant_size_differences,
clippy::single_match,
reason = "Don't matter for example code"
)]
#![expect(elided_lifetimes_in_paths, reason = "Deferred: Noisy")]

use accesskit::{DefaultActionVerb, NodeBuilder, Role};
use masonry::dpi::LogicalSize;
Expand Down Expand Up @@ -373,7 +378,7 @@ fn build_calc() -> impl Widget {
)
}

pub fn main() {
fn main() {
let window_size = LogicalSize::new(223., 300.);

let window_attributes = Window::default_attributes()
Expand Down
5 changes: 4 additions & 1 deletion masonry/examples/custom_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// On Windows platform, don't show a console when opening the app.
#![windows_subsystem = "windows"]
#![expect(elided_lifetimes_in_paths, reason = "Deferred: Noisy")]
#![expect(clippy::shadow_unrelated, reason = "Deferred: Noisy")]
#![expect(clippy::cast_possible_truncation, reason = "Deferred: Noisy")]

use accesskit::{NodeBuilder, Role};
use masonry::kurbo::{BezPath, Stroke};
Expand Down Expand Up @@ -141,7 +144,7 @@ impl Widget for CustomWidget {
}
}

pub fn main() {
fn main() {
let my_string = "Masonry + Vello".to_string();
let window_attributes = Window::default_attributes().with_title("Fancy colors");

Expand Down
2 changes: 1 addition & 1 deletion masonry/examples/grid_masonry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn grid_button(params: GridParams) -> Button {
))
}

pub fn main() {
fn main() {
let label = SizedBox::new(
Prose::new("Change spacing by right and left clicking on the buttons")
.with_text_size(14.0)
Expand Down
2 changes: 1 addition & 1 deletion masonry/examples/hello_masonry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl AppDriver for Driver {
}
}

pub fn main() {
fn main() {
let label = Label::new("Hello")
.with_text_size(32.0)
.with_weight(Weight::BOLD);
Expand Down
2 changes: 1 addition & 1 deletion masonry/examples/simple_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl AppDriver for Driver {
fn on_action(&mut self, _ctx: &mut DriverCtx<'_>, _widget_id: WidgetId, _action: Action) {}
}

pub fn main() {
fn main() {
let image_bytes = include_bytes!("./assets/PicWithAlpha.png");
let image_data = image::load_from_memory(image_bytes).unwrap().to_rgba8();
let (width, height) = image_data.dimensions();
Expand Down
3 changes: 2 additions & 1 deletion masonry/examples/to_do_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// On Windows platform, don't show a console when opening the app.
#![windows_subsystem = "windows"]
#![expect(elided_lifetimes_in_paths, reason = "Deferred: Noisy")]

use masonry::dpi::LogicalSize;
use masonry::widget::{Button, Flex, Label, Portal, RootWidget, Textbox, WidgetMut};
Expand Down Expand Up @@ -41,7 +42,7 @@ impl AppDriver for Driver {
}
}

pub fn main() {
fn main() {
let main_widget = Portal::new(
Flex::column()
.with_child(
Expand Down
2 changes: 1 addition & 1 deletion masonry/examples/two_textboxes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl AppDriver for Driver {
fn on_action(&mut self, _ctx: &mut DriverCtx<'_>, _widget_id: WidgetId, _action: Action) {}
}

pub fn main() {
fn main() {
let main_widget = Flex::column()
.with_child(Textbox::new(""))
.with_child(Textbox::new(""))
Expand Down
3 changes: 1 addition & 2 deletions masonry/src/debug_logger.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright 2022 the Xilem Authors
// SPDX-License-Identifier: Apache-2.0

#![allow(missing_docs)]

#![expect(unused, reason = "Vestigial functionality")]
use std::collections::HashMap;
use std::sync::Arc;

Expand Down
67 changes: 53 additions & 14 deletions masonry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,67 @@
//! [Druid]: https://crates.io/crates/druid
//! [Xilem]: https://crates.io/crates/xilem
// TODO: Remove this once the issues within masonry are fixed. Tracked in https://github.com/linebender/xilem/issues/449
#![allow(rustdoc::broken_intra_doc_links)]
#![deny(clippy::trivially_copy_pass_by_ref)]
// #![deny(rustdoc::broken_intra_doc_links)]
// #![warn(missing_docs)]
#![warn(unused_imports)]
#![warn(clippy::print_stdout, clippy::print_stderr, clippy::dbg_macro)]
#![allow(clippy::needless_doctest_main)]
#![allow(clippy::should_implement_trait)]
#![allow(clippy::single_match)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![cfg_attr(not(debug_assertions), allow(unused))]
// False-positive with dev-dependencies only used in examples
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
// LINEBENDER LINT SET - 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)]
#![cfg_attr(
test,
expect(
unused_crate_dependencies,
reason = "False-positive with dev-dependencies only used in examples"
)
)]
#![expect(clippy::allow_attributes, reason = "Deferred: Noisy")]
#![expect(clippy::allow_attributes_without_reason, reason = "Deferred: Noisy")]
// TODO: Remove any items listed as "Deferred"
#![expect(
rustdoc::broken_intra_doc_links,
reason = "Deferred: Noisy. Tracked in https://github.com/linebender/xilem/issues/449"
)]
#![expect(clippy::needless_doctest_main, reason = "Deferred: Noisy")]
#![expect(clippy::should_implement_trait, reason = "Deferred: Noisy")]
#![cfg_attr(not(debug_assertions), expect(unused, reason = "Deferred: Noisy"))]
#![expect(let_underscore_drop, reason = "Deferred: Noisy")]
#![expect(missing_debug_implementations, reason = "Deferred: Noisy")]
#![expect(unused_qualifications, reason = "Deferred: Noisy")]
#![expect(single_use_lifetimes, reason = "Deferred: Noisy")]
#![expect(clippy::exhaustive_enums, reason = "Deferred: Noisy")]
#![expect(clippy::match_same_arms, reason = "Deferred: Noisy")]
#![expect(clippy::cast_possible_truncation, reason = "Deferred: Noisy")]
#![expect(clippy::missing_assert_message, reason = "Deferred: Noisy")]
#![expect(clippy::return_self_not_must_use, reason = "Deferred: Noisy")]
#![expect(elided_lifetimes_in_paths, reason = "Deferred: Noisy")]
#![expect(clippy::use_self, reason = "Deferred: Noisy")]
// https://github.com/rust-lang/rust/pull/130025
#![allow(missing_docs, reason = "We have many as-yet undocumented items")]
#![expect(unreachable_pub, reason = "Potentially controversial code style")]
#![expect(
unnameable_types,
reason = "Requires lint_reasons rustc feature for exceptions"
)]
#![expect(clippy::todo, reason = "We have a lot of 'real' todos")]
#![expect(clippy::missing_errors_doc, reason = "Can be quite noisy?")]
#![expect(clippy::missing_panics_doc, reason = "Can be quite noisy?")]
#![expect(
clippy::partial_pub_fields,
reason = "Potentially controversial code style"
)]
#![expect(
clippy::shadow_unrelated,
reason = "Potentially controversial code style"
)]
#![expect(clippy::single_match, reason = "General policy not decided")]

// TODO - Add logo

#[macro_use]
mod util;

#[allow(unused)]
mod debug_logger;
#[allow(unused)]
mod debug_values;
Expand Down
3 changes: 3 additions & 0 deletions masonry/src/testing/helper_widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ use widget::WidgetRef;

use crate::event::{PointerEvent, TextEvent};
use crate::widget::SizedBox;

// TODO: Expect doesn't work here
#[allow(clippy::wildcard_imports, reason = "Deferred: Noisy")]
use crate::*;

pub type PointerEventFn<S> = dyn FnMut(&mut S, &mut EventCtx, &PointerEvent);
Expand Down
5 changes: 5 additions & 0 deletions masonry/src/text/backspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

//! Calc start of a backspace delete interval
// TODO: `expect` doesn't work here
#[allow(
clippy::wildcard_imports,
reason = "Mostly a wrapper around xi_unicode."
)]
use xi_unicode::*;

use crate::text::StringCursor;
Expand Down
2 changes: 1 addition & 1 deletion xilem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Lots of things need improvements.

## Minimum supported Rust Version (MSRV)

This version of Xilem has been verified to compile with **Rust 1.79** and later.
This version of Xilem has been verified to compile with **Rust 1.81** and later.

Future versions of Xilem might increase the Rust version requirement.
It will not be treated as a breaking change and as such can even happen with small patch releases.
Expand Down
Loading

0 comments on commit 18a6805

Please sign in to comment.