Skip to content

Commit 9cbd177

Browse files
Detect unstable lint docs that dont enable their feature
1 parent e7ad3ae commit 9cbd177

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

Diff for: src/tools/lint-docs/src/lib.rs

+28-10
Original file line numberDiff line numberDiff line change
@@ -480,26 +480,44 @@ impl<'a> LintExtractor<'a> {
480480
.map(|msg| msg["rendered"].as_str().expect("rendered field should exist").to_string())
481481
.collect();
482482
if matches.is_empty() {
483-
// Some lints override their code to something else (E0566).
484-
// Try to find something that looks like it could be our lint.
485-
let matches: Vec<_> = msgs.iter().filter(|msg|
486-
matches!(&msg["rendered"], serde_json::Value::String(s) if s.contains(name)))
487-
.map(|msg| msg["rendered"].as_str().expect("rendered field should exist").to_string())
488-
.collect();
489-
if matches.is_empty() {
483+
// Try to detect if an unstable lint forgot to enable a `#![feature(..)]`.
484+
if name != "test_unstable_lint" && msgs.iter().any(|msg| {
485+
matches!(&msg["code"]["code"], serde_json::Value::String(s) if s=="unknown_lints")
486+
&& matches!(&msg["message"], serde_json::Value::String(s) if s.contains(name))
487+
}) {
490488
let rendered: Vec<&str> =
491489
msgs.iter().filter_map(|msg| msg["rendered"].as_str()).collect();
492490
let non_json: Vec<&str> =
493491
stderr.lines().filter(|line| !line.starts_with('{')).collect();
494492
Err(format!(
495-
"did not find lint `{}` in output of example, got:\n{}\n{}",
493+
"lint `{}` is unstable and must be enabled in example. see:\n{}\n{}",
496494
name,
495+
rendered.join("\n"),
497496
non_json.join("\n"),
498-
rendered.join("\n")
499497
)
500498
.into())
501499
} else {
502-
Ok(matches.join("\n"))
500+
// Some lints override their code to something else (E0566).
501+
// Try to find something that looks like it could be our lint.
502+
let matches: Vec<_> = msgs.iter().filter(|msg|
503+
matches!(&msg["rendered"], serde_json::Value::String(s) if s.contains(name)))
504+
.map(|msg| msg["rendered"].as_str().expect("rendered field should exist").to_string())
505+
.collect();
506+
if matches.is_empty() {
507+
let rendered: Vec<&str> =
508+
msgs.iter().filter_map(|msg| msg["rendered"].as_str()).collect();
509+
let non_json: Vec<&str> =
510+
stderr.lines().filter(|line| !line.starts_with('{')).collect();
511+
Err(format!(
512+
"did not find lint `{}` in output of example, got:\n{}\n{}",
513+
name,
514+
non_json.join("\n"),
515+
rendered.join("\n")
516+
)
517+
.into())
518+
} else {
519+
Ok(matches.join("\n"))
520+
}
503521
}
504522
} else {
505523
Ok(matches.join("\n"))

0 commit comments

Comments
 (0)