Lintcheck: More info on Diags without spans

This commit is contained in:
xFrednet 2024-07-18 16:31:50 +02:00
parent 31fdc2ec09
commit 9d82fb460a
No known key found for this signature in database
GPG key ID: F5C59D0E669E5302

View file

@ -70,7 +70,14 @@ impl ClippyWarning {
let rendered = diag.rendered.as_mut().unwrap();
*rendered = strip_ansi_escapes::strip_str(&rendered);
let span = diag.spans.iter().find(|span| span.is_primary).unwrap();
// Turns out that there are lints without spans... For example Rust's
// `renamed_and_removed_lints` if the lint is given via the CLI.
let span = diag
.spans
.iter()
.find(|span| span.is_primary)
.or(diag.spans.first())
.unwrap_or_else(|| panic!("Diagnositc without span: {diag}"));
let file = &span.file_name;
let url = if let Some(src_split) = file.find("/src/") {
// This removes the inital `target/lintcheck/sources/<crate>-<version>/`