Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import the Linebender lint set. MSRV -> 1.74 #47

Merged
merged 12 commits into from
Aug 6, 2024
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ This release has an [MSRV] of 1.70.

### Added

- Breaking change: An `alpha` multiplier to `Image` ([#40][] by [@DJMcNab][])
- Breaking: An `alpha` multiplier to `Image` ([#40][] by [@DJMcNab][])
- `mint` feature to enable `mint` support in kurbo ([#46][] by [@waywardmonkeys][])

### Changed

...
- Breaking: Mark `Format` as `#[non_exhaustive]` ([#47][] by [@DJMcNab][])

### Fixed

Expand All @@ -47,6 +47,7 @@ This release has an [MSRV] of 1.70.
[#26]: https://github.com/linebender/peniko/pull/26
[#40]: https://github.com/linebender/peniko/pull/40
[#46]: https://github.com/linebender/peniko/pull/46
[#47]: https://github.com/linebender/peniko/pull/47

[@DJMcNab]: https://github.com/DJMcNab
[@ratmice]: https://github.com/ratmice
Expand Down
74 changes: 72 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ keywords = ["graphics", "vector", "style"]
categories = ["graphics"]
repository = "https://github.com/linebender/peniko"
readme = "README.md"
# We support from Rust 1.70 to ensure that CI uses the sparse registry protocol.
# We support from Rust 1.70 so that CI uses the sparse protocol.
# Keep in sync with RUST_MIN_VER in .github/workflows/ci.yml and with the relevant README.md files.
# TODO: When this hits 1.74, move lint configuration into this file via a lints table.
# and with the MSRV in the `Unreleased` section of CHANGELOG.md.
rust-version = "1.70"

[features]
Expand Down Expand Up @@ -39,3 +39,73 @@ version = "0.11.14"
optional = true
default-features = false
features = ["alloc"]

[lints]
rust.unsafe_code = "forbid"

rust.keyword_idents_2024 = "forbid"
rust.non_ascii_idents = "forbid"
rust.unsafe_op_in_unsafe_fn = "forbid"
rust.non_local_definitions = "forbid"

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

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

# 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 = { level = "warn", priority = -1 }

# Lints which we set in `lib.rs`, instead of at a package level.

# 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" # Note that this is allowed in Masonry
# clippy.print_stderr = "warn" # Note that this is allowed in Masonry

## Explicit per-crate exceptions, should be manually checked occasionally.
# Most enums are correctly exhaustive, as this is a vocabulary crate.
# clippy.exhaustive_enums = "warn"
# There are lots of conversion to u8 color field, which in degenerate cases might not work
# properly, but generally are fine.
# E.g. `with_alpha_factor` sets the alpha to `0` for a negative provided `alpha`
# clippy.cast_possible_truncation = "warn"
5 changes: 3 additions & 2 deletions src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ where
{
let byte_buf: serde_bytes::ByteBuf = serde_bytes::Deserialize::deserialize(des)?;
let boxed_slice: Box<[u8]> = byte_buf.into_boxed_slice();
Ok(Blob::new(Arc::new(boxed_slice)))
Ok(Self::new(Arc::new(boxed_slice)))
}
}

impl<T> fmt::Debug for Blob<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Blob")
.field("id", &self.id)
.finish_non_exhaustive()
Expand Down Expand Up @@ -153,6 +153,7 @@ impl<T> Blob<T> {
}

/// Weak reference to a shared [blob](Blob).
#[derive(Debug)]
pub struct WeakBlob<T> {
data: Weak<dyn AsRef<[T]> + Send + Sync>,
id: u64,
Expand Down
10 changes: 5 additions & 5 deletions src/brush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ impl Brush {
/// Returns the brush with the alpha component multiplied by the specified
/// factor.
#[must_use]
pub fn with_alpha_factor(self, alpha: f32) -> Brush {
pub fn with_alpha_factor(self, alpha: f32) -> Self {
if alpha == 1.0 {
self
} else {
match self {
Brush::Solid(color) => color.with_alpha_factor(alpha).into(),
Brush::Gradient(mut gradient) => {
Self::Solid(color) => color.with_alpha_factor(alpha).into(),
Self::Gradient(mut gradient) => {
gradient
.stops
.iter_mut()
.for_each(|stop| *stop = stop.with_alpha_factor(alpha));
gradient.into()
}
Brush::Image(image) => image.with_alpha_factor(alpha).into(),
Self::Image(image) => image.with_alpha_factor(alpha).into(),
}
}
}
Expand All @@ -79,7 +79,7 @@ pub enum BrushRef<'a> {
Image(&'a Image),
}

impl<'a> BrushRef<'a> {
impl BrushRef<'_> {
/// Converts the reference to an owned brush.
#[must_use]
pub fn to_owned(&self) -> Brush {
Expand Down
6 changes: 3 additions & 3 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ impl Color {
#[allow(clippy::many_single_char_names)]
#[allow(clippy::unreadable_literal)]
#[must_use]
pub fn hlca(h: f64, l: f64, c: f64, a: f64) -> Color {
let alpha = a;
pub fn hlca(h: f64, l: f64, c: f64, alpha: f64) -> Self {
// The reverse transformation from Lab to XYZ, see
// https://en.wikipedia.org/wiki/CIELAB_color_space
fn f_inv(t: f64) -> f64 {
Expand Down Expand Up @@ -128,7 +127,7 @@ impl Color {
1.055 * u.powf(1. / 2.4) - 0.055
}
}
Color::rgba(gamma(r_lin), gamma(g_lin), gamma(b_lin), alpha)
Self::rgba(gamma(r_lin), gamma(g_lin), gamma(b_lin), alpha)
}

/// Parses a color from a string.
Expand Down Expand Up @@ -161,6 +160,7 @@ impl Color {
}

/// Named SVG colors.
#[allow(clippy::use_self)]
impl Color {
/// Alice blue (240, 248, 255, 255)
pub const ALICE_BLUE: Color = Color::rgba8(240, 248, 255, 255);
Expand Down
1 change: 1 addition & 0 deletions src/gradient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ impl Gradient {

/// Trait for types that represent a source of color stops.
pub trait ColorStopsSource {
/// Append the stops represented within `self` into `vec`.
fn collect_stops(&self, vec: &mut SmallVec<[ColorStop; 4]>);
}

Expand Down
3 changes: 2 additions & 1 deletion src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use super::{Blob, Extend};
/// Defines the pixel format of an [image](Image).
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum Format {
/// 32-bit RGBA with 8-bit channels.
Rgba8,
Expand All @@ -23,7 +24,7 @@ impl Format {
#[must_use]
pub fn size_in_bytes(self, width: u32, height: u32) -> Option<usize> {
match self {
Self::Rgba8 => 4usize
Self::Rgba8 => 4_usize
.checked_mul(width as usize)
.and_then(|x| x.checked_mul(height as usize)),
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//! [`kurbo`]: https://crates.io/crates/kurbo

#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
#![warn(clippy::doc_markdown, unused_qualifications)]
#![warn(unused_crate_dependencies)]

mod blend;
mod blob;
Expand Down
4 changes: 3 additions & 1 deletion src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ impl From<Stroke> for Style {
/// This is useful for methods that would like to accept draw styles by reference. Defining
/// the type as `impl<Into<DrawRef>>` allows accepting types like `&Stroke` or `Fill`
/// directly without cloning or allocating.
#[allow(variant_size_differences)] // We don't expect this enum to be operated on in bulk.
#[derive(Debug, Copy, Clone)]
pub enum StyleRef<'a> {
/// Filled draw operation.
Fill(Fill),
/// Stroked draw operation.
Stroke(&'a Stroke),
}

impl<'a> StyleRef<'a> {
impl StyleRef<'_> {
/// Converts the reference to an owned draw.
#[must_use]
pub fn to_owned(&self) -> Style {
Expand Down