2019-02-23 16:40:07 +09:00
|
|
|
use crate::clean::*;
|
|
|
|
|
use crate::core::DocContext;
|
|
|
|
|
use crate::fold::DocFolder;
|
|
|
|
|
use crate::passes::{look_for_tests, Pass};
|
2018-10-26 00:55:12 +02:00
|
|
|
|
2019-02-23 15:10:56 -05:00
|
|
|
pub const CHECK_PRIVATE_ITEMS_DOC_TESTS: Pass = Pass {
|
|
|
|
|
name: "check-private-items-doc-tests",
|
2020-01-04 10:58:32 -08:00
|
|
|
run: check_private_items_doc_tests,
|
2019-02-23 15:10:56 -05:00
|
|
|
description: "check private items doc tests",
|
|
|
|
|
};
|
2018-10-26 00:55:12 +02:00
|
|
|
|
2018-12-08 20:30:23 +01:00
|
|
|
struct PrivateItemDocTestLinter<'a, 'tcx> {
|
|
|
|
|
cx: &'a DocContext<'tcx>,
|
2018-10-26 00:55:12 +02:00
|
|
|
}
|
|
|
|
|
|
2018-12-08 20:30:23 +01:00
|
|
|
impl<'a, 'tcx> PrivateItemDocTestLinter<'a, 'tcx> {
|
|
|
|
|
fn new(cx: &'a DocContext<'tcx>) -> Self {
|
2019-12-22 17:42:04 -05:00
|
|
|
PrivateItemDocTestLinter { cx }
|
2018-10-26 00:55:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-08 20:30:23 +01:00
|
|
|
pub fn check_private_items_doc_tests(krate: Crate, cx: &DocContext<'_>) -> Crate {
|
2018-10-26 00:55:12 +02:00
|
|
|
let mut coll = PrivateItemDocTestLinter::new(cx);
|
|
|
|
|
|
|
|
|
|
coll.fold_crate(krate)
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-08 20:30:23 +01:00
|
|
|
impl<'a, 'tcx> DocFolder for PrivateItemDocTestLinter<'a, 'tcx> {
|
2018-10-26 00:55:12 +02:00
|
|
|
fn fold_item(&mut self, item: Item) -> Option<Item> {
|
|
|
|
|
let cx = self.cx;
|
|
|
|
|
let dox = item.attrs.collapsed_doc_value().unwrap_or_else(String::new);
|
|
|
|
|
|
2020-07-27 22:16:41 -04:00
|
|
|
look_for_tests(&cx, &dox, &item);
|
2018-10-26 00:55:12 +02:00
|
|
|
|
|
|
|
|
self.fold_item_recur(item)
|
|
|
|
|
}
|
|
|
|
|
}
|