Skip to content

Commit 402aab6

Browse files
authored
Merge pull request #8859 from cakebaker/clippy_unexpected_cfgs
clippy: move `unexpected_cfgs` to workspace lints & fix warnings in `seq`
2 parents 334c223 + 19284de commit 402aab6

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coreutils (uutils)
22
# * see the repository LICENSE, README, and CONTRIBUTING files for more information
33

4-
# spell-checker:ignore (libs) bigdecimal datetime serde bincode gethostid kqueue libselinux mangen memmap uuhelp startswith constness expl unnested logind
4+
# spell-checker:ignore (libs) bigdecimal datetime serde bincode gethostid kqueue libselinux mangen memmap uuhelp startswith constness expl unnested logind cfgs
55

66
[package]
77
name = "coreutils"
@@ -638,6 +638,9 @@ pedantic = { level = "deny", priority = -1 }
638638
# Eventually the clippy settings from the `[lints]` section should be moved here.
639639
# In order to use these, all crates have `[lints] workspace = true` section.
640640
[workspace.lints.rust]
641+
# Allow "fuzzing" as a "cfg" condition name
642+
# https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html
643+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fuzzing)'] }
641644
#unused_qualifications = "warn" // TODO: fix warnings in uucore, then re-enable this lint
642645

643646
[workspace.lints.clippy]

src/uu/seq/Cargo.toml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# spell-checker:ignore bigdecimal cfgs extendedbigdecimal
1+
# spell-checker:ignore bigdecimal extendedbigdecimal
22
[package]
33
name = "uu_seq"
44
description = "seq ~ (uutils) display a sequence of numbers"
@@ -12,6 +12,9 @@ categories.workspace = true
1212
edition.workspace = true
1313
readme.workspace = true
1414

15+
[lints]
16+
workspace = true
17+
1518
[lib]
1619
path = "src/seq.rs"
1720

@@ -33,13 +36,3 @@ fluent = { workspace = true }
3336
[[bin]]
3437
name = "seq"
3538
path = "src/main.rs"
36-
37-
# FIXME: this is the only crate that has a separate lints configuration,
38-
# which for now means a full copy of all clippy and rust lints here.
39-
[lints.clippy]
40-
all = { level = "deny", priority = -1 }
41-
42-
# Allow "fuzzing" as a "cfg" condition name
43-
# https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html
44-
[lints.rust]
45-
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fuzzing)'] }

src/uu/seq/src/numberparse.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn compute_num_digits(input: &str, ebd: ExtendedBigDecimal) -> PreciseNumber {
4040
return PreciseNumber {
4141
number: ebd,
4242
num_integral_digits: 0,
43-
num_fractional_digits: if input.contains(".") || input.contains("p") {
43+
num_fractional_digits: if input.contains('.') || input.contains('p') {
4444
None
4545
} else {
4646
Some(0)
@@ -49,17 +49,17 @@ fn compute_num_digits(input: &str, ebd: ExtendedBigDecimal) -> PreciseNumber {
4949
}
5050

5151
// Split the exponent part, if any
52-
let parts: Vec<&str> = input.split("e").collect();
52+
let parts: Vec<&str> = input.split('e').collect();
5353
debug_assert!(parts.len() <= 2);
5454

5555
// Count all the digits up to `.`, `-` sign is included.
56-
let (mut int_digits, mut frac_digits) = match parts[0].find(".") {
56+
let (mut int_digits, mut frac_digits) = match parts[0].find('.') {
5757
Some(i) => {
5858
// Cover special case .X and -.X where we behave as if there was a leading 0:
5959
// 0.X, -0.X.
6060
let int_digits = match i {
6161
0 => 1,
62-
1 if parts[0].starts_with("-") => 2,
62+
1 if parts[0].starts_with('-') => 2,
6363
_ => i,
6464
};
6565

@@ -75,7 +75,7 @@ fn compute_num_digits(input: &str, ebd: ExtendedBigDecimal) -> PreciseNumber {
7575
// For positive exponents, effectively expand the number. Ignore negative exponents.
7676
// Also ignore overflowed exponents (unwrap_or(0)).
7777
if exp > 0 {
78-
int_digits += exp.try_into().unwrap_or(0)
78+
int_digits += exp.try_into().unwrap_or(0);
7979
};
8080
frac_digits = if exp < frac_digits as i64 {
8181
// Subtract from i128 to avoid any overflow
@@ -106,7 +106,7 @@ impl FromStr for PreciseNumber {
106106
ebd
107107
}
108108
ExtendedBigDecimal::Infinity | ExtendedBigDecimal::MinusInfinity => {
109-
return Ok(PreciseNumber {
109+
return Ok(Self {
110110
number: ebd,
111111
num_integral_digits: 0,
112112
num_fractional_digits: Some(0),

src/uu/seq/src/seq.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
106106
let options = SeqOptions {
107107
separator: matches
108108
.get_one::<OsString>(OPT_SEPARATOR)
109-
.map_or(OsString::from("\n"), |s| s.to_os_string()),
109+
.cloned()
110+
.unwrap_or_else(|| OsString::from("\n")),
110111
terminator: matches
111112
.get_one::<OsString>(OPT_TERMINATOR)
112-
.map_or(OsString::from("\n"), |s| s.to_os_string()),
113+
.cloned()
114+
.unwrap_or_else(|| OsString::from("\n")),
113115
equal_width: matches.get_flag(OPT_EQUAL_WIDTH),
114116
format: matches.get_one::<String>(OPT_FORMAT).map(|s| s.as_str()),
115117
};

0 commit comments

Comments
 (0)