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

Use built-in [lints] table in Cargo.toml #2377

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 1 addition & 52 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,53 +1,2 @@
[alias]
lint = """
clippy --workspace --no-deps -- \
-D warnings \
-A clippy::type_complexity \
-D clippy::semicolon_if_nothing_returned \
-D clippy::trivially-copy-pass-by-ref \
-D clippy::default_trait_access \
-D clippy::match-wildcard-for-single-variants \
-D clippy::redundant-closure-for-method-calls \
-D clippy::filter_map_next \
-D clippy::manual_let_else \
-D clippy::unused_async \
-D clippy::from_over_into \
-D clippy::needless_borrow \
-D clippy::new_without_default \
-D clippy::useless_conversion
"""

nitpick = """
clippy --workspace --no-deps -- \
-D warnings \
-D clippy::pedantic \
-A clippy::type_complexity \
-A clippy::must_use_candidate \
-A clippy::return_self_not_must_use \
-A clippy::needless_pass_by_value \
-A clippy::cast_precision_loss \
-A clippy::cast_sign_loss \
-A clippy::cast_possible_truncation \
-A clippy::match_same_arms \
-A clippy::missing-errors-doc \
-A clippy::missing-panics-doc \
-A clippy::cast_lossless \
-A clippy::doc_markdown \
-A clippy::items_after_statements \
-A clippy::too_many_lines \
-A clippy::module_name_repetitions \
-A clippy::if_not_else \
-A clippy::redundant_else \
-A clippy::used_underscore_binding \
-A clippy::cast_possible_wrap \
-A clippy::unnecessary_wraps \
-A clippy::struct-excessive-bools \
-A clippy::float-cmp \
-A clippy::single_match_else \
-A clippy::unreadable_literal \
-A clippy::explicit_deref_methods \
-A clippy::map_unwrap_or \
-A clippy::unnested_or_patterns \
-A clippy::similar_names \
-A clippy::unused_self
"""
lint = "clippy --workspace --no-deps -- -D warnings"
42 changes: 35 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ homepage.workspace = true
categories.workspace = true
keywords.workspace = true

[lints]
workspace = true

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
all-features = true
Expand Down Expand Up @@ -74,6 +77,15 @@ thiserror.workspace = true
image.workspace = true
image.optional = true

[dev-dependencies]
criterion = "0.5"
iced_wgpu.workspace = true

[[bench]]
name = "wgpu"
harness = false
required-features = ["canvas"]

[profile.release-opt]
inherits = "release"
codegen-units = 1
Expand Down Expand Up @@ -165,11 +177,27 @@ winapi = "0.3"
window_clipboard = "0.4.1"
winit = { git = "https://github.com/iced-rs/winit.git", rev = "592bd152f6d5786fae7d918532d7db752c0d164f" }

[dev-dependencies]
criterion = "0.5"
iced_wgpu.workspace = true
[workspace.lints.rust]
rust_2018_idioms = "forbid"
missing_debug_implementations = "deny"
missing_docs = "deny"
unsafe_code = "deny"
unused_results = "deny"

[[bench]]
name = "wgpu"
harness = false
required-features = ["canvas"]
[workspace.lints.clippy]
type-complexity = "allow"
semicolon_if_nothing_returned = "deny"
trivially-copy-pass-by-ref = "deny"
default_trait_access = "deny"
match-wildcard-for-single-variants = "deny"
redundant-closure-for-method-calls = "deny"
filter_map_next = "deny"
manual_let_else = "deny"
unused_async = "deny"
from_over_into = "deny"
needless_borrow = "deny"
new_without_default = "deny"
useless_conversion = "deny"

[workspace.lints.rustdoc]
broken_intra_doc_links = "forbid"
11 changes: 8 additions & 3 deletions benches/wgpu.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(missing_docs)]
use criterion::{criterion_group, criterion_main, Bencher, Criterion};

use iced::alignment;
Expand All @@ -12,8 +13,12 @@ criterion_main!(benches);
criterion_group!(benches, wgpu_benchmark);

pub fn wgpu_benchmark(c: &mut Criterion) {
c.bench_function("wgpu — canvas (light)", |b| benchmark(b, scene(10)));
c.bench_function("wgpu — canvas (heavy)", |b| benchmark(b, scene(1_000)));
let _ = c
.bench_function("wgpu — canvas (light)", |b| benchmark(b, scene(10)));

let _ = c.bench_function("wgpu — canvas (heavy)", |b| {
benchmark(b, scene(1_000))
});
}

fn benchmark<'a>(
Expand Down Expand Up @@ -98,7 +103,7 @@ fn benchmark<'a>(
);

bencher.iter(|| {
user_interface.draw(
let _ = user_interface.draw(
&mut renderer,
&Theme::Dark,
&core::renderer::Style {
Expand Down
3 changes: 3 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ homepage.workspace = true
categories.workspace = true
keywords.workspace = true

[lints]
workspace = true

[features]
auto-detect-theme = ["dep:dark-light"]
advanced = []
Expand Down
7 changes: 0 additions & 7 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
#![doc(
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
)]
#![forbid(unsafe_code, rust_2018_idioms)]
#![deny(
missing_debug_implementations,
missing_docs,
unused_results,
rustdoc::broken_intra_doc_links
)]
pub mod alignment;
pub mod border;
pub mod clipboard;
Expand Down
3 changes: 3 additions & 0 deletions futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ homepage.workspace = true
categories.workspace = true
keywords.workspace = true

[lints]
workspace = true

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
all-features = true
Expand Down
7 changes: 0 additions & 7 deletions futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
#![doc(
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
)]
#![forbid(unsafe_code, rust_2018_idioms)]
#![deny(
missing_debug_implementations,
missing_docs,
unused_results,
rustdoc::broken_intra_doc_links
)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
pub use futures;
pub use iced_core as core;
Expand Down
3 changes: 3 additions & 0 deletions graphics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ homepage.workspace = true
categories.workspace = true
keywords.workspace = true

[lints]
workspace = true

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
all-features = true
Expand Down
8 changes: 0 additions & 8 deletions graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
#![doc(
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
)]
#![forbid(rust_2018_idioms)]
#![deny(
missing_debug_implementations,
missing_docs,
unsafe_code,
unused_results,
rustdoc::broken_intra_doc_links
)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
mod antialiasing;
mod cached;
Expand Down
5 changes: 2 additions & 3 deletions graphics/src/text/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use std::collections::hash_map;
use std::hash::{Hash, Hasher};

/// A store of recently used sections of text.
#[allow(missing_debug_implementations)]
#[derive(Default)]
#[derive(Debug, Default)]
pub struct Cache {
entries: FxHashMap<KeyHash, Entry>,
aliases: FxHashMap<KeyHash, KeyHash>,
Expand Down Expand Up @@ -135,7 +134,7 @@ impl Key<'_> {
pub type KeyHash = u64;

/// A cache entry.
#[allow(missing_debug_implementations)]
#[derive(Debug)]
pub struct Entry {
/// The buffer of text, ready for drawing.
pub buffer: cosmic_text::Buffer,
Expand Down
3 changes: 3 additions & 0 deletions highlighter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ homepage.workspace = true
categories.workspace = true
keywords.workspace = true

[lints]
workspace = true

[dependencies]
iced_core.workspace = true

Expand Down
31 changes: 30 additions & 1 deletion highlighter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! A syntax highlighter for iced.
use iced_core as core;

use crate::core::text::highlighter::{self, Format};
Expand All @@ -16,6 +17,8 @@ static THEMES: Lazy<highlighting::ThemeSet> =

const LINES_PER_SNAPSHOT: usize = 50;

/// A syntax highlighter.
#[derive(Debug)]
pub struct Highlighter {
syntax: &'static parsing::SyntaxReference,
highlighter: highlighting::Highlighter<'static>,
Expand Down Expand Up @@ -131,25 +134,47 @@ impl highlighter::Highlighter for Highlighter {
}
}

/// The settings of a [`Highlighter`].
#[derive(Debug, Clone, PartialEq)]
pub struct Settings {
/// The [`Theme`] of the [`Highlighter`].
///
/// It dictates the color scheme that will be used for highlighting.
pub theme: Theme,
/// The extension of the file to highlight.
///
/// The [`Highlighter`] will use the extension to automatically determine
/// the grammar to use for highlighting.
pub extension: String,
}

/// A highlight produced by a [`Highlighter`].
#[derive(Debug)]
pub struct Highlight(highlighting::StyleModifier);

impl Highlight {
/// Returns the color of this [`Highlight`].
///
/// If `None`, the original text color should be unchanged.
pub fn color(&self) -> Option<Color> {
self.0.foreground.map(|color| {
Color::from_rgba8(color.r, color.g, color.b, color.a as f32 / 255.0)
})
}

/// Returns the font of this [`Highlight`].
///
/// If `None`, the original font should be unchanged.
pub fn font(&self) -> Option<Font> {
None
}

/// Returns the [`Format`] of the [`Highlight`].
///
/// It contains both the [`color`] and the [`font`].
///
/// [`color`]: Self::color
/// [`font`]: Self::font
pub fn to_format(&self) -> Format<Font> {
Format {
color: self.color(),
Expand All @@ -158,6 +183,8 @@ impl Highlight {
}
}

/// A highlighting theme.
#[allow(missing_docs)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Theme {
SolarizedDark,
Expand All @@ -168,6 +195,7 @@ pub enum Theme {
}

impl Theme {
/// A static slice containing all the available themes.
pub const ALL: &'static [Self] = &[
Self::SolarizedDark,
Self::Base16Mocha,
Expand All @@ -176,6 +204,7 @@ impl Theme {
Self::InspiredGitHub,
];

/// Returns `true` if the [`Theme`] is dark, and false otherwise.
pub fn is_dark(self) -> bool {
match self {
Self::SolarizedDark
Expand Down Expand Up @@ -209,7 +238,7 @@ impl std::fmt::Display for Theme {
}
}

pub struct ScopeRangeIterator {
struct ScopeRangeIterator {
ops: Vec<(usize, parsing::ScopeStackOp)>,
line_length: usize,
index: usize,
Expand Down
3 changes: 3 additions & 0 deletions renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ homepage.workspace = true
categories.workspace = true
keywords.workspace = true

[lints]
workspace = true

[features]
wgpu = ["iced_wgpu"]
tiny-skia = ["iced_tiny_skia"]
Expand Down
Loading
Loading