1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use rustdoc_types::{Item, Visibility};
use crate::attributes::Attribute as ParsedAttribute;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum PublicApiStabilityPolicy {
Ignore,
RustStandardLibrary,
}
impl PublicApiStabilityPolicy {
pub(crate) fn item_is_unstable(self, _item: &Item) -> bool {
// Stability info is not present in this rustdoc version.
// Treat it as absent, so no item is marked unstable by rustdoc data.
false
}
/// This is item-local eligibility, not path reachability.
///
/// Eligible items can still be absent from stable public API,
/// for example when they are public inside a private module.
/// The local rules are:
/// - public/default visibility (e.g. enum variants have default visibility), and
/// - deprecated or not `#[doc(hidden)]`.
///
/// This rustdoc JSON version does not expose item stability as structured data, so
/// [`PublicApiStabilityPolicy::RustStandardLibrary`] behaves the same as
/// [`PublicApiStabilityPolicy::Ignore`].
pub(crate) fn public_api_eligible(self, item: &Item) -> bool {
let is_public = matches!(item.visibility, Visibility::Public | Visibility::Default);
let allowed_by_doc_hidden =
item.deprecation.is_some() || !item.attrs.iter().any(ParsedAttribute::is_doc_hidden);
is_public && allowed_by_doc_hidden && !self.item_is_unstable(item)
}
pub(crate) fn effective_constness(self, function_item: &Item, raw_constness: bool) -> bool {
assert!(
matches!(function_item.inner, rustdoc_types::ItemEnum::Function(..)),
"`function_item` was not a function: {function_item:?}"
);
// Stability info is not present in this rustdoc version.
// Treat it as absent, so syntactic constness is the effective constness.
raw_constness
}
pub(crate) fn effective_function_has_body(self, function: &rustdoc_types::Function) -> bool {
// Default-body stability info starts in rustdoc JSON v60.
// Treat it as absent and use syntactic body presence.
function.has_body
}
pub(crate) fn effective_assoc_type_has_default(self, item: &Item) -> bool {
let rustdoc_types::ItemEnum::AssocType { type_, .. } = &item.inner else {
unreachable!("`item` was not an associated type: {item:?}");
};
// Default-value stability info starts in rustdoc JSON v60.
// Treat it as absent and use syntactic default presence.
type_.is_some()
}
pub(crate) fn effective_assoc_const_default(self, item: &Item) -> Option<&str> {
let rustdoc_types::ItemEnum::AssocConst { value, .. } = &item.inner else {
unreachable!("`item` was not an associated constant: {item:?}");
};
// Default-value stability info starts in rustdoc JSON v60.
// Treat it as absent and use the syntactic default.
value.as_deref()
}
}