Skip to content

Commit 52deec0

Browse files
authored
Clippy (#211)
1 parent 4258e1f commit 52deec0

File tree

9 files changed

+61
-40
lines changed

9 files changed

+61
-40
lines changed

typed_floats/Cargo.toml

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ version.workspace = true
55
edition.workspace = true
66
license.workspace = true
77
repository.workspace = true
8-
include = [
9-
"Cargo.toml",
10-
"src/*.rs",
11-
"src/**/*.rs",
12-
"*.md",
13-
]
8+
include = ["Cargo.toml", "src/*.rs", "src/**/*.rs", "*.md"]
149
keywords.workspace = true
1510
categories.workspace = true
1611
readme = "./README.md"
@@ -64,13 +59,28 @@ num-traits = "0.2"
6459
[package.metadata.docs.rs]
6560
features = ["serde"]
6661

62+
[lints.rust]
63+
dead-code = { level = "deny", priority = 1 }
64+
# missing_docs = { level = "deny", priority = 1 }
65+
unsafe_op_in_unsafe_fn = { level = "deny", priority = 1 }
66+
# unused_crate_dependencies = { level = "warn", priority = 1 }
67+
warnings = { level = "deny", priority = 0 }
68+
6769
[lints.clippy]
68-
cargo = { priority = -1, level = "deny" }
69-
complexity = { priority = -1, level = "deny" }
70-
correctness = { priority = -1, level = "deny" }
71-
suspicious = { priority = -1, level = "deny" }
72-
style = { priority = -1, level = "deny" }
73-
perf = { priority = -1, level = "deny" }
74-
pedantic = { priority = -1, level = "deny" }
75-
nursery = { priority = -1, level = "deny" }
76-
# restriction = { priority = -1, level = "deny" }
70+
indexing_slicing = { priority = -1, level = "deny" }
71+
panic_in_result_fn = { priority = -1, level = "deny" }
72+
panic = { priority = -1, level = "deny" }
73+
unwrap_in_result = { priority = -1, level = "deny" }
74+
unwrap_used = { priority = -1, level = "deny" }
75+
cargo = { priority = -1, level = "deny" }
76+
complexity = { priority = -1, level = "deny" }
77+
correctness = { priority = -1, level = "deny" }
78+
suspicious = { priority = -1, level = "deny" }
79+
style = { priority = -1, level = "deny" }
80+
perf = { priority = -1, level = "deny" }
81+
pedantic = { priority = -1, level = "deny" }
82+
nursery = { priority = -1, level = "deny" }
83+
# restriction = { priority = -1, level = "deny" }
84+
unusual_byte_groupings = { priority = 1, level = "allow" }
85+
# msrv is tested in CI and this lint doesn't detects the `rustversion` guard
86+
incompatible_msrv = { priority = 1, level = "allow" }

typed_floats/build.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,24 @@ pub fn create_creadmes() {
1515

1616
// Copy the README.md from the root (used by GitHub)
1717
// to the crate root (used by crates.io)
18-
fs::copy(orig_readme, crate_readme).unwrap();
18+
fs::copy(orig_readme, crate_readme)
19+
.expect("Failed to copy README.md from project root to crate root");
1920

2021
// Truncate the README to include it in the documentation of the crate
2122
let trucated_readme = Path::new("../typed_floats/README.truncated.md");
2223

2324
// remove the parts that are not used by docs.io
2425
// That truncated version is the introduction of the documentation
25-
let text_readme = fs::read_to_string(crate_readme).unwrap();
26+
let text_readme = fs::read_to_string(crate_readme).expect("Failed to read crate README.md");
2627

27-
let text = text_readme.split("# Full documentation").next().unwrap();
28+
let text = text_readme
29+
.split("# Full documentation")
30+
.next()
31+
.expect("Failed to find '# Full documentation' section in README.md");
2832

2933
let text = text.replace("```rust", "```ignore");
3034

31-
fs::write(trucated_readme, text).unwrap();
35+
fs::write(trucated_readme, text).expect("Failed to write truncated README.md");
3236
}
3337

3438
fn main() {

typed_floats/src/lib.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,8 @@
9999
//!
100100
//!
101101
//!
102-
#![warn(clippy::indexing_slicing)]
103-
#![warn(clippy::nursery)]
104-
#![warn(clippy::panic_in_result_fn)]
105-
#![warn(clippy::panic)]
106-
#![warn(clippy::pedantic)]
107-
#![warn(clippy::unwrap_in_result)]
108-
#![warn(clippy::unwrap_used)]
109102
#![warn(missing_docs)]
110-
#![warn(unsafe_op_in_unsafe_fn)]
111-
#![warn(unused_crate_dependencies)]
112103
#![cfg_attr(not(feature = "std"), no_std)]
113-
#![allow(clippy::unusual_byte_groupings)]
114-
// msrv is tested in CI and this lint doesn't detects the `rustversion` guard
115-
#![allow(clippy::incompatible_msrv)]
116104

117105
// `format!` is used during the tests even in `no_std` environments
118106
#[cfg(all(test, not(feature = "std")))]

typed_floats/src/types/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ use crate::traits::{Atan2, Copysign, DivEuclid, Hypot, Powf};
187187
use crate::traits::Midpoint;
188188

189189
#[cfg(all(feature = "libm", not(feature = "std")))]
190+
#[allow(unused_imports)]
190191
use num_traits::Float;
191192

192193
mod accept;

typed_floats_macros/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,21 @@ quote = "1.0"
2424
syn = { version = "2.0" }
2525
proc-macro2 = "1.0"
2626
rustversion.workspace = true
27+
28+
[lints.rust]
29+
dead-code = { level = "deny", priority = 1 }
30+
missing_docs = { level = "deny", priority = 1 }
31+
unsafe_op_in_unsafe_fn = { level = "deny", priority = 1 }
32+
unused_crate_dependencies = { level = "deny", priority = 1 }
33+
warnings = { level = "deny", priority = 0 }
34+
35+
[lints.clippy]
36+
cargo = { priority = -1, level = "deny" }
37+
complexity = { priority = -1, level = "deny" }
38+
correctness = { priority = -1, level = "deny" }
39+
suspicious = { priority = -1, level = "deny" }
40+
style = { priority = -1, level = "deny" }
41+
perf = { priority = -1, level = "deny" }
42+
# pedantic = { priority = -1, level = "deny" }
43+
# nursery = { priority = -1, level = "deny" }
44+
# restriction = { priority = -1, level = "deny" }

typed_floats_macros/src/gen_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,28 @@ fn test_op_checks(
1919
let has_inf = #var.iter().any(|x| x.is_infinite());
2020
assert!(has_inf, "No inf generated with {} but the output type {} accept it. Generated: {:?}", #op_name, stringify!(#full_type), #var);
2121
});
22-
};
22+
}
2323

2424
if def.s.accept_zero {
2525
res.extend(quote! {
2626
let has_zero = #var.iter().any(|x| x == &0.0);
2727
assert!(has_zero, "No zero generated with {} but the output type {} accept it. Generated: {:?}", #op_name, stringify!(#full_type), #var);
2828
});
29-
};
29+
}
3030

3131
if def.s.accept_positive {
3232
res.extend(quote! {
3333
let has_positive = #var.iter().any(|x| x.is_sign_positive());
3434
assert!(has_positive, "No positive generated with {} but the output type {} accept it. Generated: {:?}", #op_name, stringify!(#full_type), #var);
3535
});
36-
};
36+
}
3737

3838
if def.s.accept_negative {
3939
res.extend(quote! {
4040
let has_negative = #var.iter().any(|x| x.is_sign_negative());
4141
assert!(has_negative, "No negative generated with {} but the output type {} accept it. Generated: {:?}", #op_name, stringify!(#full_type), #var);
4242
});
43-
};
43+
}
4444
} else {
4545
let full_type = float.float_type;
4646

typed_floats_macros/src/impl_self_rhs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::types::{
44
FloatDefinition, FloatSpecifications, OpRhs, OpRhsBuilder, ReturnTypeSpecification,
55
};
66

7-
fn add_result(float: &FloatDefinition, rhs: &FloatDefinition) -> ReturnTypeSpecification {
7+
const fn add_result(float: &FloatDefinition, rhs: &FloatDefinition) -> ReturnTypeSpecification {
88
let spec_a = &float.s;
99
let spec_b = &rhs.s;
1010

@@ -36,7 +36,7 @@ fn add_result(float: &FloatDefinition, rhs: &FloatDefinition) -> ReturnTypeSpeci
3636
}
3737
}
3838

39-
fn can_one_be_zero_neg_and_the_other_zero_pos(
39+
const fn can_one_be_zero_neg_and_the_other_zero_pos(
4040
spec_a: &FloatSpecifications,
4141
spec_b: &FloatSpecifications,
4242
) -> bool {

typed_floats_macros/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub fn generate_tests_self_rhs(input: proc_macro::TokenStream) -> proc_macro::To
185185
output.into()
186186
}
187187

188-
/// Return the FloatDefinition for the given type
188+
/// Return the `FloatDefinition` for the given type
189189
fn get_definitions(float_type: &'static str) -> [FloatDefinition; 12] {
190190
TYPES
191191
.iter()

typed_floats_macros/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl OpBuilder {
227227
}
228228

229229
#[allow(dead_code)] // depending on the enabled features, this function might not be used
230-
pub fn comment(mut self, comment: &'static str) -> Self {
230+
pub const fn comment(mut self, comment: &'static str) -> Self {
231231
self.op.comment = Some(comment);
232232
self
233233
}
@@ -242,7 +242,7 @@ impl OpBuilder {
242242
self
243243
}
244244

245-
pub fn const_since(mut self, version: &'static str) -> Self {
245+
pub const fn const_since(mut self, version: &'static str) -> Self {
246246
self.op.const_since = Some(version);
247247
self
248248
}

0 commit comments

Comments
 (0)