Skip to content

Commit 7a90686

Browse files
committed
refactor: add clippy pedantic lints
1 parent 22a588d commit 7a90686

39 files changed

+609
-529
lines changed

Cargo.lock

+1-63
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+12
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,15 @@ owo-colors = "4.0.0"
2424
parking_lot = "0.12.3"
2525
rayon = "1.10.0"
2626
logos = "0.14.1"
27+
28+
[workspace.lints.rust]
29+
# https://github.com/rust-lang/rust/issues/95513
30+
#unused_crate_dependencies = "warn"
31+
unsafe_code = "deny" # Not in this project's scope currently
32+
33+
[workspace.lints.clippy]
34+
pedantic = "warn"
35+
allow_attributes = "warn"
36+
allow_attributes_without_reason = "warn"
37+
should_panic_without_expect = "warn"
38+
match_wildcard_for_single_variants = { level = "allow", priority = 1 }

crates/dt-analyzer/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ dt-diagnostic.workspace = true
1616
tracing.workspace = true # TODO: remove, this is only for debugging
1717
either = "1.10.0"
1818
serde_json = "1.0.114"
19-
serde_yaml = "0.9.33"
2019
thiserror = "1.0.57"
2120
vec1 = "1.10.1"
2221
rustc-hash.workspace = true
@@ -25,6 +24,10 @@ enum-as-inner = "0.6.0"
2524
derive_more = { version = "1.0.0", features = ["debug"] }
2625

2726
[dev-dependencies]
27+
serde_yaml = "0.9.33"
2828
codespan-reporting = "0.11.1"
2929
owo-colors.workspace = true
3030
pretty_assertions.workspace = true
31+
32+
[lints]
33+
workspace = true

crates/dt-analyzer/examples/analyzer_json.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Parses the file at argv 1 and prints the analyzed data as JSON
22
//!
3-
//! Use `--assert` in argv[2] to pretty_assertions::assert_eq
3+
//! Use `--assert` in argv[2] to `pretty_assertions::assert_eq`
44
55
use dt_parser::ast::SourceFile;
66
use owo_colors::{colors::xterm::Gray, OwoColorize as _};
@@ -14,9 +14,9 @@ fn remove_first<T>(vec: &mut Vec<T>) -> Option<T> {
1414
Some(vec.swap_remove(0))
1515
}
1616

17-
/// This should be more efficient than "re-serializing" serde_yaml::Value into serde_json::Value
17+
/// This should be more efficient than "re-serializing" `serde_yaml::Value` into `serde_json::Value`
1818
/// but more importantly, this never errors and skips tags (not the values though), because thay
19-
/// can't be represented as serde_json::Value
19+
/// can't be represented as `serde_json::Value`
2020
///
2121
/// NOTE: this cuts out node children with the name phandle and returns `-1` for anything with the
2222
/// YAML tag `phandle` e.g. `!phandle 0x1`
@@ -157,10 +157,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
157157
std::process::exit(1);
158158
};
159159

160-
if !assert {
161-
eprintln!("DTC output: {}", serde_json::to_string(&dtc_json).unwrap());
162-
} else {
160+
if assert {
163161
pretty_assertions::assert_eq!(own_json, dtc_json);
162+
} else {
163+
eprintln!("DTC output: {}", serde_json::to_string(&dtc_json).unwrap());
164164
}
165165
eprintln!(
166166
"{}{:?}",

crates/dt-analyzer/examples/test_analyzer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
3434
vec.sort_by(|a, b| a.0.cmp(&b.0));
3535
for (name, value) in vec {
3636
let name = name.join("/");
37-
eprintln!("{} -> {:#?}", name, value);
37+
eprintln!("{name} -> {value:#?}");
3838
}
3939

4040
if !parse.lex_errors.is_empty() || !parse.errors.is_empty() {

crates/dt-analyzer/src/lib.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub struct Label {
7575
///
7676
/// See [crate root](crate).
7777
pub fn analyze_cst(file: &ast::SourceFile, src: &str) -> Option<FileDefinition> {
78-
let root_node = file.nodes().find(|node| node.is_root())?;
78+
let root_node = file.nodes().find(dt_parser::ast::DtNode::is_root)?;
7979
let extensions = file.nodes().filter(ast::DtNode::is_extension);
8080
// TODO: check includes for extension labels?
8181
let labels = {
@@ -94,25 +94,24 @@ pub fn analyze_cst(file: &ast::SourceFile, src: &str) -> Option<FileDefinition>
9494
// duplicate labels aren't allowed
9595
// labels can be used before and after their definition, without scope
9696

97-
let mut tree = analyze_node(root_node, src)?;
97+
let mut tree = analyze_node(&root_node, src)?;
9898
for extension in extensions {
9999
// TODO: path-based phandles
100100
let label = extension.extension_name()?.name()?;
101101
let label = label.syntax().text().as_str();
102102

103-
let label = match labels.get(label) {
104-
Some(labels) => labels,
105-
None => {
106-
tracing::warn!(
107-
"Couldn't find label {label} for extension at {:?}!",
108-
extension.syntax().text_range()
109-
);
110-
continue;
111-
}
103+
let label = if let Some(labels) = labels.get(label) {
104+
labels
105+
} else {
106+
tracing::warn!(
107+
"Couldn't find label {label} for extension at {:?}!",
108+
extension.syntax().text_range()
109+
);
110+
continue;
112111
}
113112
.last()?;
114113

115-
let Some(ex_tree) = analyze_node(extension, src) else {
114+
let Some(ex_tree) = analyze_node(&extension, src) else {
116115
continue;
117116
};
118117
let ex_tree = ex_tree.prefix(label.node_ast.path(src).map(Cow::into_owned));
@@ -125,6 +124,7 @@ pub fn analyze_cst(file: &ast::SourceFile, src: &str) -> Option<FileDefinition>
125124
})
126125
}
127126

127+
#[must_use]
128128
pub fn find_labels<'i>(node: &ast::DtNode, src: &'i str) -> Vec<(&'i str, Label)> {
129129
node.label()
130130
.and_then(|label| {

0 commit comments

Comments
 (0)