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

Move to using Cargo's [lints] #5976

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,16 @@ lto = true
[profile.bench-memory]
inherits = "bench"
debug = true

[workspace.lints.rust]
# missing_docs = "warn"
missing_debug_implementations = "deny"
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(icu4x_run_size_tests)', 'cfg(needs_alloc_error_handler)'] }

[workspace.lints.clippy]
indexing_slicing = "deny"
unwrap_used = "deny"
expect_used = "deny"
panic = "deny"
exhaustive_structs = "deny"
exhaustive_enums = "deny"
7 changes: 7 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
# (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

msrv = "1.81"

allow-panic-in-tests = true
allow-expect-in-tests = true
allow-unwrap-in-tests = true

# Not yet available in Clippy
# allow-indexing-slicing-in-tests = true
4 changes: 4 additions & 0 deletions components/calendar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ name = "iso_date_manipulations"

[[example]]
name = "iso_datetime_manipulations"


[lints]
workspace = true
2 changes: 2 additions & 0 deletions components/calendar/benches/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

#![allow(clippy::unwrap_used, clippy::expect_used, clippy::indexing_slicing)] // https://github.com/rust-lang/rust-clippy/issues/13981

mod fixtures;

use criterion::{
Expand Down
2 changes: 2 additions & 0 deletions components/calendar/benches/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

#![allow(clippy::unwrap_used, clippy::expect_used, clippy::indexing_slicing)] // https://github.com/rust-lang/rust-clippy/issues/13981

mod fixtures;

use criterion::{
Expand Down
16 changes: 3 additions & 13 deletions components/calendar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,9 @@

// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(
not(test),
deny(
clippy::indexing_slicing,
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::exhaustive_structs,
clippy::exhaustive_enums,
missing_debug_implementations,
)
)]
#![warn(missing_docs)]

// TODO: until we can enable allow-indexing-slicing-in-tests
#![cfg_attr(test, allow(clippy::indexing_slicing))]

extern crate alloc;

Expand Down
4 changes: 4 additions & 0 deletions components/casemap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ required-features = ["compiled_data", "datagen"] # datagen bound can be removed
name = "casemap"
harness = false
required-features = ["compiled_data"]


[lints]
workspace = true
13 changes: 0 additions & 13 deletions components/casemap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@

// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(
not(test),
deny(
clippy::indexing_slicing,
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::exhaustive_structs,
clippy::exhaustive_enums,
missing_debug_implementations,
)
)]
#![warn(missing_docs)]
// We're using Greek identifiers here on purpose. These lints can only be disabled at the crate level
#![allow(confusable_idents, uncommon_codepoints)]

Expand Down
4 changes: 4 additions & 0 deletions components/collator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ compiled_data = ["dep:icu_collator_data", "icu_normalizer/compiled_data"]
[[bench]]
name = "bench"
harness = false


[lints]
workspace = true
4 changes: 4 additions & 0 deletions components/collator/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ name = "compare_utf16"
path = "fuzz_targets/compare_utf16.rs"
test = false
doc = false


[lints]
workspace = true
13 changes: 0 additions & 13 deletions components/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,6 @@

// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(
not(test),
deny(
clippy::indexing_slicing,
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::exhaustive_structs,
clippy::exhaustive_enums,
missing_debug_implementations,
)
)]
#![warn(missing_docs)]

//! Comparing strings according to language-dependent conventions.
//!
Expand Down
2 changes: 2 additions & 0 deletions components/collator/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

#![allow(clippy::unwrap_used, clippy::expect_used, clippy::indexing_slicing)] // https://github.com/rust-lang/rust-clippy/issues/13981

use core::cmp::Ordering;

use atoi::FromRadix16;
Expand Down
4 changes: 4 additions & 0 deletions components/collections/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ path = "benches/iai_cpt.rs"
name = "inv_list"
harness = false
path = "benches/inv_list.rs"


[lints]
workspace = true
1 change: 1 addition & 0 deletions components/collections/codepointtrie_builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ denylist = ["icu4c"]

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(icu4c_enable_renaming)'] }

14 changes: 0 additions & 14 deletions components/collections/codepointtrie_builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,6 @@
//! [`CodePointTrie`]: icu_collections::codepointtrie::CodePointTrie
//! [`UMutableCPTrie`]: (https://unicode-org.github.io/icu-docs/apidoc/dev/icu4c/umutablecptrie_8h.html#ad8945cf34ca9d40596a66a1395baa19b)

#![cfg_attr(
not(test),
deny(
// The crate is documented to allow panics.
// clippy::indexing_slicing,
// clippy::unwrap_used,
// clippy::expect_used,
// clippy::panic,
clippy::exhaustive_structs,
clippy::exhaustive_enums,
missing_debug_implementations,
)
)]

use icu_collections::codepointtrie::TrieType;
use icu_collections::codepointtrie::TrieValue;

Expand Down
2 changes: 0 additions & 2 deletions components/collections/src/codepointinvlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
//!
//! [`ICU4X`]: ../icu/index.html

#![warn(missing_docs)]

extern crate alloc;

#[macro_use]
Expand Down
14 changes: 5 additions & 9 deletions components/collections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@

// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(
not(test),
deny(
clippy::indexing_slicing,
clippy::unwrap_used,
clippy::expect_used,
clippy::panic
)
// TODO
#![allow(
clippy::exhaustive_structs,
clippy::exhaustive_enums,
missing_debug_implementations
)]
#![warn(missing_docs)]

extern crate alloc;

Expand Down
7 changes: 4 additions & 3 deletions components/datetime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ skip_optional_dependencies = true
# Bench feature gets tested separately and is only relevant for CI
denylist = ["bench"]

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(icu4x_run_size_tests)'] }

[[bench]]
name = "datetime"
harness = false
Expand Down Expand Up @@ -140,3 +137,7 @@ required-features = ["experimental"]
[[example]]
name = "work_log"
required-features = ["compiled_data"]


[lints]
workspace = true
16 changes: 3 additions & 13 deletions components/datetime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,9 @@

// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(
not(test),
deny(
clippy::indexing_slicing,
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::exhaustive_structs,
clippy::exhaustive_enums,
missing_debug_implementations,
)
)]
#![warn(missing_docs)]

// TODO: until we can enable allow-indexing-slicing-in-tests
#![cfg_attr(test, allow(clippy::indexing_slicing))]

extern crate alloc;

Expand Down
7 changes: 4 additions & 3 deletions components/decimal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ compiled_data = ["dep:icu_decimal_data"]
# Bench feature gets tested separately and is only relevant for CI
denylist = ["bench"]

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(icu4x_run_size_tests)'] }

[[bench]]
name = "fixed_decimal_format"
harness = false

[[example]]
name = "code_line_diff"
required-features = ["serde"]


[lints]
workspace = true
13 changes: 0 additions & 13 deletions components/decimal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,6 @@

// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(
not(test),
deny(
clippy::indexing_slicing,
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::exhaustive_structs,
clippy::exhaustive_enums,
missing_debug_implementations,
)
)]
#![warn(missing_docs)]

extern crate alloc;

Expand Down
4 changes: 4 additions & 0 deletions components/experimental/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,7 @@ path = "tests/transliterate/lower_ascii.rs"
[[test]]
name = "units_test"
path = "tests/units/units_test.rs"

# No boilerplate, each module has their own
# [lints]
# workspace = true
13 changes: 0 additions & 13 deletions components/experimental/src/compactdecimal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@
//! Compact decimal

// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(
not(test),
deny(
clippy::indexing_slicing,
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::exhaustive_structs,
clippy::exhaustive_enums,
missing_debug_implementations,
)
)]
#![warn(missing_docs)]

mod error;
mod format;
Expand Down
13 changes: 0 additions & 13 deletions components/experimental/src/displaynames/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@
// TODO: expand documentation

// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(
not(test),
deny(
clippy::indexing_slicing,
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::exhaustive_structs,
clippy::exhaustive_enums,
// missing_debug_implementations // TBD before stabilization
)
)]
#![warn(missing_docs)]

mod displaynames;
mod options;
Expand Down
2 changes: 0 additions & 2 deletions components/experimental/src/duration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

//! Duration formatting

#![warn(missing_docs)]

mod duration;
mod format;
mod formatter;
Expand Down
2 changes: 0 additions & 2 deletions components/experimental/src/relativetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

//! Relative time formatting

#![warn(missing_docs)]

mod format;
pub mod options;
pub mod provider;
Expand Down
13 changes: 0 additions & 13 deletions components/experimental/src/transliterate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@
//! See [`Transliterator`].

// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(
not(test),
deny(
clippy::indexing_slicing,
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::exhaustive_structs,
clippy::exhaustive_enums,
missing_debug_implementations,
)
)]
#![warn(missing_docs)]

pub mod provider;

Expand Down
Loading
Loading