Skip to main content

Source src/diagnostic/normalize.rs

1//! Preserve diagnostic trees and multipart suggestions as units.2use super::model::*; warning: clippy::wildcard_imports3use serde_json::Value;4use std::path::Path;5fn string(v: &Value, key: &str) -> String {6    v[key].as_str().unwrap_or_default().to_owned()7}8fn spans(v: &Value, root: &Path) -> Vec<Span> {9    v["spans"]10        .as_array()11        .into_iter()12        .flatten()13        .map(|s| Span {14            path: root.join(string(s, "file_name")),15            byte_start: s["byte_start"].as_u64().unwrap_or(0) as usize, warning: clippy::cast_possible_truncation16            byte_end: s["byte_end"].as_u64().unwrap_or(0) as usize, warning: clippy::cast_possible_truncation17            line_start: s["line_start"].as_u64().unwrap_or(0) as usize, warning: clippy::cast_possible_truncation18            line_end: s["line_end"].as_u64().unwrap_or(0) as usize, warning: clippy::cast_possible_truncation19            column_start: s["column_start"].as_u64().unwrap_or(0) as usize, warning: clippy::cast_possible_truncation20            column_end: s["column_end"].as_u64().unwrap_or(0) as usize, warning: clippy::cast_possible_truncation21            primary: s["is_primary"].as_bool().unwrap_or(false),22            label: s["label"].as_str().map(str::to_owned),23            text: s["text"]24                .as_array()25                .into_iter()26                .flatten()27                .map(|t| SnippetLine {28                    text: string(t, "text"),29                    highlight_start: t["highlight_start"].as_u64().unwrap_or(0) as usize, warning: clippy::cast_possible_truncation30                    highlight_end: t["highlight_end"].as_u64().unwrap_or(0) as usize, warning: clippy::cast_possible_truncation31                })32                .collect(),33            expansion: if s["expansion"].is_null() {34                None35            } else {36                Some(s["expansion"].clone())37            },38        })39        .collect()40}41fn note(v: &Value, root: &Path, path: Vec<usize>, suggestions: &mut Vec<Suggestion>) -> Note { warning: clippy::needless_pass_by_value42    let normalized = spans(v, root);43    let replacements: Vec<_> = v["spans"]44        .as_array()45        .into_iter()46        .flatten()47        .zip(&normalized)48        .filter_map(|(raw, span)| {49            raw["suggested_replacement"]50                .as_str()51                .map(|text| Replacement {52                    span: span.clone(),53                    text: text.into(),54                    applicability: raw["suggestion_applicability"]55                        .as_str()56                        .unwrap_or("Unspecified")57                        .into(),58                })59        })60        .collect();61    if !replacements.is_empty() {62        suggestions.push(Suggestion {63            message: string(v, "message"),64            child_path: path.clone(), warning: clippy::needless_pass_by_value65            replacements,66        });67    }68    let children = v["children"]69        .as_array()70        .into_iter()71        .flatten()72        .enumerate()73        .map(|(i, c)| {74            let mut p = path.clone();75            p.push(i);76            note(c, root, p, suggestions)77        })78        .collect();79    Note {80        level: string(v, "level"),81        message: string(v, "message"),82        spans: normalized,83        children,84    }85}86pub fn normalize(message: &cargo_metadata::CompilerMessage, root: &Path) -> Finding {87    let v = serde_json::to_value(&message.message).expect("Cargo diagnostic is JSON serializable");88    let mut suggestions = vec![];89    let n = note(&v, root, vec![], &mut suggestions);90    let code = v["code"]["code"].as_str().map(str::to_owned);91    let origin = if code.as_deref().is_some_and(|s| s.starts_with("clippy::")) {92        "Clippy"93    } else if code.is_some() {94        "Rust compiler"95    } else {96        "General"97    };98    Finding {99        id: String::new(),100        package_id: message.package_id.to_string(),101        targets: vec![TargetInfo {102            name: message.target.name.clone(),103            kinds: message.target.kind.iter().map(|k| k.to_string()).collect(), warning: clippy::redundant_closure_for_method_calls104            source: message.target.src_path.clone().into_std_path_buf(),105        }],106        origin: origin.into(),107        code,108        level: n.level,109        category: None,110        message: n.message,111        spans: n.spans,112        children: n.children,113        suggestions,114        rendered: v["rendered"].as_str().map(str::to_owned),115    }116}117#[cfg(test)]118mod tests {119    use super::*;120    pub fn finding() -> Finding {121        let msg: cargo_metadata::Message = serde_json::from_value(super::super::sample()).unwrap();122        let cargo_metadata::Message::CompilerMessage(m) = msg else {123            panic!()124        };125        normalize(&m, Path::new("/demo"))126    }127    #[test]128    fn preserves_diagnostic_kind_and_level() {129        let f = finding();130        assert_eq!(f.origin, "Clippy");131        assert_eq!(f.level, "warning");132        assert_eq!(f.spans.len(), 1);133    }134    #[test]135    fn multipart_replacements_stay_grouped() {136        let mut v = super::super::sample();137        let mut span = v["message"]["spans"][0].clone();138        span["suggested_replacement"] = "fixed".into();139        span["suggestion_applicability"] = "MachineApplicable".into();140        v["message"]["children"] = serde_json::json!([{"message":"replace both","level":"help","spans":[span.clone(),span],"children":[],"code":null,"rendered":null}]);141        let cargo_metadata::Message::CompilerMessage(m) = serde_json::from_value(v).unwrap() else {142            panic!()143        };144        let f = normalize(&m, Path::new("/demo"));145        assert_eq!(f.suggestions.len(), 1);146        assert_eq!(f.suggestions[0].replacements.len(), 2);147        assert_eq!(f.children.len(), 1);148    }149}150

Findings in this file§

warning clippy::wildcard_imports §

usage of wildcard import

src/diagnostic/normalize.rs:2:5

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • cargo-clippy-html (bin)

Primary: src/diagnostic/normalize.rs:2:5

use super::model::*;

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#wildcard_imports

help: try

Suggestion: try

MachineApplicable

--- "a/src/diagnostic/normalize.rs"
+++ "b/src/diagnostic/normalize.rs"
@@ -1,5 +1,5 @@
 //! Preserve diagnostic trees and multipart suggestions as units.
-use super::model::*;
+use super::model::{Span, SnippetLine, Suggestion, Note, Replacement, Finding, TargetInfo};
 use serde_json::Value;
 use std::path::Path;
 fn string(v: &Value, key: &str) -> String {
Rendered diagnostic (text)
warning: usage of wildcard import
 --> src/diagnostic/normalize.rs:2:5
  |
2 | use super::model::*;
  |     ^^^^^^^^^^^^^^^ help: try: `super::model::{Span, SnippetLine, Suggestion, Note, Replacement, Finding, TargetInfo}`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#wildcard_imports

warning clippy::cast_possible_truncation §

casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers

src/diagnostic/normalize.rs:15:25

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • cargo-clippy-html (bin)

Primary: src/diagnostic/normalize.rs:15:25

            byte_start: s["byte_start"].as_u64().unwrap_or(0) as usize,

help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#cast_possible_truncation

note: `-W clippy::cast-possible-truncation` implied by `-W clippy::pedantic`

help: to override `-W clippy::pedantic` add `#[allow(clippy::cast_possible_truncation)]`

help: ... or use `try_from` and handle the error accordingly

Suggestion: ... or use `try_from` and handle the error accordingly

Unspecified

--- "a/src/diagnostic/normalize.rs"
+++ "b/src/diagnostic/normalize.rs"
@@ -12,7 +12,7 @@
         .flatten()
         .map(|s| Span {
             path: root.join(string(s, "file_name")),
-            byte_start: s["byte_start"].as_u64().unwrap_or(0) as usize,
+            byte_start: usize::try_from(s["byte_start"].as_u64().unwrap_or(0)),
             byte_end: s["byte_end"].as_u64().unwrap_or(0) as usize,
             line_start: s["line_start"].as_u64().unwrap_or(0) as usize,
             line_end: s["line_end"].as_u64().unwrap_or(0) as usize,
Rendered diagnostic (text)
warning: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers
  --> src/diagnostic/normalize.rs:15:25
   |
15 |             byte_start: s["byte_start"].as_u64().unwrap_or(0) as usize,
   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#cast_possible_truncation
   = note: `-W clippy::cast-possible-truncation` implied by `-W clippy::pedantic`
   = help: to override `-W clippy::pedantic` add `#[allow(clippy::cast_possible_truncation)]`
help: ... or use `try_from` and handle the error accordingly
   |
15 -             byte_start: s["byte_start"].as_u64().unwrap_or(0) as usize,
15 +             byte_start: usize::try_from(s["byte_start"].as_u64().unwrap_or(0)),
   |

warning clippy::cast_possible_truncation §

casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers

src/diagnostic/normalize.rs:16:23

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • cargo-clippy-html (bin)

Primary: src/diagnostic/normalize.rs:16:23

            byte_end: s["byte_end"].as_u64().unwrap_or(0) as usize,

help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#cast_possible_truncation

help: ... or use `try_from` and handle the error accordingly

Suggestion: ... or use `try_from` and handle the error accordingly

Unspecified

--- "a/src/diagnostic/normalize.rs"
+++ "b/src/diagnostic/normalize.rs"
@@ -13,7 +13,7 @@
         .map(|s| Span {
             path: root.join(string(s, "file_name")),
             byte_start: s["byte_start"].as_u64().unwrap_or(0) as usize,
-            byte_end: s["byte_end"].as_u64().unwrap_or(0) as usize,
+            byte_end: usize::try_from(s["byte_end"].as_u64().unwrap_or(0)),
             line_start: s["line_start"].as_u64().unwrap_or(0) as usize,
             line_end: s["line_end"].as_u64().unwrap_or(0) as usize,
             column_start: s["column_start"].as_u64().unwrap_or(0) as usize,
Rendered diagnostic (text)
warning: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers
  --> src/diagnostic/normalize.rs:16:23
   |
16 |             byte_end: s["byte_end"].as_u64().unwrap_or(0) as usize,
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#cast_possible_truncation
help: ... or use `try_from` and handle the error accordingly
   |
16 -             byte_end: s["byte_end"].as_u64().unwrap_or(0) as usize,
16 +             byte_end: usize::try_from(s["byte_end"].as_u64().unwrap_or(0)),
   |

warning clippy::cast_possible_truncation §

casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers

src/diagnostic/normalize.rs:17:25

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • cargo-clippy-html (bin)

Primary: src/diagnostic/normalize.rs:17:25

            line_start: s["line_start"].as_u64().unwrap_or(0) as usize,

help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#cast_possible_truncation

help: ... or use `try_from` and handle the error accordingly

Suggestion: ... or use `try_from` and handle the error accordingly

Unspecified

--- "a/src/diagnostic/normalize.rs"
+++ "b/src/diagnostic/normalize.rs"
@@ -14,7 +14,7 @@
             path: root.join(string(s, "file_name")),
             byte_start: s["byte_start"].as_u64().unwrap_or(0) as usize,
             byte_end: s["byte_end"].as_u64().unwrap_or(0) as usize,
-            line_start: s["line_start"].as_u64().unwrap_or(0) as usize,
+            line_start: usize::try_from(s["line_start"].as_u64().unwrap_or(0)),
             line_end: s["line_end"].as_u64().unwrap_or(0) as usize,
             column_start: s["column_start"].as_u64().unwrap_or(0) as usize,
             column_end: s["column_end"].as_u64().unwrap_or(0) as usize,
Rendered diagnostic (text)
warning: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers
  --> src/diagnostic/normalize.rs:17:25
   |
17 |             line_start: s["line_start"].as_u64().unwrap_or(0) as usize,
   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#cast_possible_truncation
help: ... or use `try_from` and handle the error accordingly
   |
17 -             line_start: s["line_start"].as_u64().unwrap_or(0) as usize,
17 +             line_start: usize::try_from(s["line_start"].as_u64().unwrap_or(0)),
   |

warning clippy::cast_possible_truncation §

casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers

src/diagnostic/normalize.rs:18:23

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • cargo-clippy-html (bin)

Primary: src/diagnostic/normalize.rs:18:23

            line_end: s["line_end"].as_u64().unwrap_or(0) as usize,

help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#cast_possible_truncation

help: ... or use `try_from` and handle the error accordingly

Suggestion: ... or use `try_from` and handle the error accordingly

Unspecified

--- "a/src/diagnostic/normalize.rs"
+++ "b/src/diagnostic/normalize.rs"
@@ -15,7 +15,7 @@
             byte_start: s["byte_start"].as_u64().unwrap_or(0) as usize,
             byte_end: s["byte_end"].as_u64().unwrap_or(0) as usize,
             line_start: s["line_start"].as_u64().unwrap_or(0) as usize,
-            line_end: s["line_end"].as_u64().unwrap_or(0) as usize,
+            line_end: usize::try_from(s["line_end"].as_u64().unwrap_or(0)),
             column_start: s["column_start"].as_u64().unwrap_or(0) as usize,
             column_end: s["column_end"].as_u64().unwrap_or(0) as usize,
             primary: s["is_primary"].as_bool().unwrap_or(false),
Rendered diagnostic (text)
warning: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers
  --> src/diagnostic/normalize.rs:18:23
   |
18 |             line_end: s["line_end"].as_u64().unwrap_or(0) as usize,
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#cast_possible_truncation
help: ... or use `try_from` and handle the error accordingly
   |
18 -             line_end: s["line_end"].as_u64().unwrap_or(0) as usize,
18 +             line_end: usize::try_from(s["line_end"].as_u64().unwrap_or(0)),
   |

warning clippy::cast_possible_truncation §

casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers

src/diagnostic/normalize.rs:19:27

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • cargo-clippy-html (bin)

Primary: src/diagnostic/normalize.rs:19:27

            column_start: s["column_start"].as_u64().unwrap_or(0) as usize,

help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#cast_possible_truncation

help: ... or use `try_from` and handle the error accordingly

Suggestion: ... or use `try_from` and handle the error accordingly

Unspecified

--- "a/src/diagnostic/normalize.rs"
+++ "b/src/diagnostic/normalize.rs"
@@ -16,7 +16,7 @@
             byte_end: s["byte_end"].as_u64().unwrap_or(0) as usize,
             line_start: s["line_start"].as_u64().unwrap_or(0) as usize,
             line_end: s["line_end"].as_u64().unwrap_or(0) as usize,
-            column_start: s["column_start"].as_u64().unwrap_or(0) as usize,
+            column_start: usize::try_from(s["column_start"].as_u64().unwrap_or(0)),
             column_end: s["column_end"].as_u64().unwrap_or(0) as usize,
             primary: s["is_primary"].as_bool().unwrap_or(false),
             label: s["label"].as_str().map(str::to_owned),
Rendered diagnostic (text)
warning: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers
  --> src/diagnostic/normalize.rs:19:27
   |
19 |             column_start: s["column_start"].as_u64().unwrap_or(0) as usize,
   |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#cast_possible_truncation
help: ... or use `try_from` and handle the error accordingly
   |
19 -             column_start: s["column_start"].as_u64().unwrap_or(0) as usize,
19 +             column_start: usize::try_from(s["column_start"].as_u64().unwrap_or(0)),
   |

warning clippy::cast_possible_truncation §

casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers

src/diagnostic/normalize.rs:20:25

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • cargo-clippy-html (bin)

Primary: src/diagnostic/normalize.rs:20:25

            column_end: s["column_end"].as_u64().unwrap_or(0) as usize,

help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#cast_possible_truncation

help: ... or use `try_from` and handle the error accordingly

Suggestion: ... or use `try_from` and handle the error accordingly

Unspecified

--- "a/src/diagnostic/normalize.rs"
+++ "b/src/diagnostic/normalize.rs"
@@ -17,7 +17,7 @@
             line_start: s["line_start"].as_u64().unwrap_or(0) as usize,
             line_end: s["line_end"].as_u64().unwrap_or(0) as usize,
             column_start: s["column_start"].as_u64().unwrap_or(0) as usize,
-            column_end: s["column_end"].as_u64().unwrap_or(0) as usize,
+            column_end: usize::try_from(s["column_end"].as_u64().unwrap_or(0)),
             primary: s["is_primary"].as_bool().unwrap_or(false),
             label: s["label"].as_str().map(str::to_owned),
             text: s["text"]
Rendered diagnostic (text)
warning: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers
  --> src/diagnostic/normalize.rs:20:25
   |
20 |             column_end: s["column_end"].as_u64().unwrap_or(0) as usize,
   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#cast_possible_truncation
help: ... or use `try_from` and handle the error accordingly
   |
20 -             column_end: s["column_end"].as_u64().unwrap_or(0) as usize,
20 +             column_end: usize::try_from(s["column_end"].as_u64().unwrap_or(0)),
   |

warning clippy::cast_possible_truncation §

casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers

src/diagnostic/normalize.rs:29:38

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • cargo-clippy-html (bin)

Primary: src/diagnostic/normalize.rs:29:38

                    highlight_start: t["highlight_start"].as_u64().unwrap_or(0) as usize,

help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#cast_possible_truncation

help: ... or use `try_from` and handle the error accordingly

Suggestion: ... or use `try_from` and handle the error accordingly

Unspecified

--- "a/src/diagnostic/normalize.rs"
+++ "b/src/diagnostic/normalize.rs"
@@ -26,7 +26,7 @@
                 .flatten()
                 .map(|t| SnippetLine {
                     text: string(t, "text"),
-                    highlight_start: t["highlight_start"].as_u64().unwrap_or(0) as usize,
+                    highlight_start: usize::try_from(t["highlight_start"].as_u64().unwrap_or(0)),
                     highlight_end: t["highlight_end"].as_u64().unwrap_or(0) as usize,
                 })
                 .collect(),
Rendered diagnostic (text)
warning: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers
  --> src/diagnostic/normalize.rs:29:38
   |
29 |                     highlight_start: t["highlight_start"].as_u64().unwrap_or(0) as usize,
   |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#cast_possible_truncation
help: ... or use `try_from` and handle the error accordingly
   |
29 -                     highlight_start: t["highlight_start"].as_u64().unwrap_or(0) as usize,
29 +                     highlight_start: usize::try_from(t["highlight_start"].as_u64().unwrap_or(0)),
   |

warning clippy::cast_possible_truncation §

casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers

src/diagnostic/normalize.rs:30:36

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • cargo-clippy-html (bin)

Primary: src/diagnostic/normalize.rs:30:36

                    highlight_end: t["highlight_end"].as_u64().unwrap_or(0) as usize,

help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#cast_possible_truncation

help: ... or use `try_from` and handle the error accordingly

Suggestion: ... or use `try_from` and handle the error accordingly

Unspecified

--- "a/src/diagnostic/normalize.rs"
+++ "b/src/diagnostic/normalize.rs"
@@ -27,7 +27,7 @@
                 .map(|t| SnippetLine {
                     text: string(t, "text"),
                     highlight_start: t["highlight_start"].as_u64().unwrap_or(0) as usize,
-                    highlight_end: t["highlight_end"].as_u64().unwrap_or(0) as usize,
+                    highlight_end: usize::try_from(t["highlight_end"].as_u64().unwrap_or(0)),
                 })
                 .collect(),
             expansion: if s["expansion"].is_null() {
Rendered diagnostic (text)
warning: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers
  --> src/diagnostic/normalize.rs:30:36
   |
30 |                     highlight_end: t["highlight_end"].as_u64().unwrap_or(0) as usize,
   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#cast_possible_truncation
help: ... or use `try_from` and handle the error accordingly
   |
30 -                     highlight_end: t["highlight_end"].as_u64().unwrap_or(0) as usize,
30 +                     highlight_end: usize::try_from(t["highlight_end"].as_u64().unwrap_or(0)),
   |

warning clippy::needless_pass_by_value §

this argument is passed by value, but not consumed in the function body

src/diagnostic/normalize.rs:41:39

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • cargo-clippy-html (bin)

Primary: src/diagnostic/normalize.rs:41:39

fn note(v: &Value, root: &Path, path: Vec<usize>, suggestions: &mut Vec<Suggestion>) -> Note {

Primary: src/diagnostic/normalize.rs:64:25

            child_path: path.clone(),

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#needless_pass_by_value

note: `-W clippy::needless-pass-by-value` implied by `-W clippy::pedantic`

help: to override `-W clippy::pedantic` add `#[allow(clippy::needless_pass_by_value)]`

help: consider changing the type to

help: change `path.clone()` to

Suggestion: consider changing the type to

Unspecified

--- "a/src/diagnostic/normalize.rs"
+++ "b/src/diagnostic/normalize.rs"
@@ -38,7 +38,7 @@
         })
         .collect()
 }
-fn note(v: &Value, root: &Path, path: Vec<usize>, suggestions: &mut Vec<Suggestion>) -> Note {
+fn note(v: &Value, root: &Path, path: &[usize], suggestions: &mut Vec<Suggestion>) -> Note {
     let normalized = spans(v, root);
     let replacements: Vec<_> = v["spans"]
         .as_array()
Suggestion: change `path.clone()` to

Unspecified

--- "a/src/diagnostic/normalize.rs"
+++ "b/src/diagnostic/normalize.rs"
@@ -61,7 +61,7 @@
     if !replacements.is_empty() {
         suggestions.push(Suggestion {
             message: string(v, "message"),
-            child_path: path.clone(),
+            child_path: path.to_owned(),
             replacements,
         });
     }
Rendered diagnostic (text)
warning: this argument is passed by value, but not consumed in the function body
  --> src/diagnostic/normalize.rs:41:39
   |
41 | fn note(v: &Value, root: &Path, path: Vec<usize>, suggestions: &mut Vec<Suggestion>) -> Note {
   |                                       ^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#needless_pass_by_value
   = note: `-W clippy::needless-pass-by-value` implied by `-W clippy::pedantic`
   = help: to override `-W clippy::pedantic` add `#[allow(clippy::needless_pass_by_value)]`
help: consider changing the type to
   |
41 - fn note(v: &Value, root: &Path, path: Vec<usize>, suggestions: &mut Vec<Suggestion>) -> Note {
41 + fn note(v: &Value, root: &Path, path: &[usize], suggestions: &mut Vec<Suggestion>) -> Note {
   |
help: change `path.clone()` to
   |
64 -             child_path: path.clone(),
64 +             child_path: path.to_owned(),
   |

warning clippy::redundant_closure_for_method_calls §

redundant closure

src/diagnostic/normalize.rs:103:51

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • cargo-clippy-html (bin)

Primary: src/diagnostic/normalize.rs:103:51

            kinds: message.target.kind.iter().map(|k| k.to_string()).collect(),

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#redundant_closure_for_method_calls

help: replace the closure with the method itself

Suggestion: replace the closure with the method itself

MachineApplicable

--- "a/src/diagnostic/normalize.rs"
+++ "b/src/diagnostic/normalize.rs"
@@ -100,7 +100,7 @@
         package_id: message.package_id.to_string(),
         targets: vec![TargetInfo {
             name: message.target.name.clone(),
-            kinds: message.target.kind.iter().map(|k| k.to_string()).collect(),
+            kinds: message.target.kind.iter().map(std::string::ToString::to_string).collect(),
             source: message.target.src_path.clone().into_std_path_buf(),
         }],
         origin: origin.into(),
Rendered diagnostic (text)
warning: redundant closure
   --> src/diagnostic/normalize.rs:103:51
    |
103 |             kinds: message.target.kind.iter().map(|k| k.to_string()).collect(),
    |                                                   ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::string::ToString::to_string`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#redundant_closure_for_method_calls