Skip to content

Commit 3e3991e

Browse files
committed
Don't show methods and constants in impl Trait for Type blocks.
1 parent 716d1c7 commit 3e3991e

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

tools/unstable-api/src/visit/visit_item_impl.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,28 @@ impl<'a> ModuleVisitor<'a> {
9494
}
9595
}
9696

97+
impl<'a, 'ast> Visit<'ast> for ImplTraitForTypeVisitor<'a, '_> {
98+
fn visit_impl_item_const(&mut self, _node: &'ast syn::ImplItemConst) {
99+
// not relevant
100+
}
101+
102+
fn visit_impl_item_macro(&mut self, node: &'ast syn::ImplItemMacro) {
103+
self.0.visit_impl_item_macro(node)
104+
}
105+
106+
fn visit_impl_item_method(&mut self, _node: &'ast syn::ImplItemMethod) {
107+
// not relevant
108+
}
109+
110+
fn visit_impl_item_type(&mut self, node: &'ast syn::ImplItemType) {
111+
self.0.visit_impl_item_type(node)
112+
}
113+
}
114+
97115
let is_unstable = self.feature.is_unstable(&node.attrs, None);
116+
117+
struct ImplTraitForTypeVisitor<'a, 'b>(&'b mut FilteredUnstableItemVisitor<'a, syn::ImplItem>);
118+
98119
let mut visitor = FilteredUnstableItemVisitor {
99120
feature: Feature {
100121
name: self.feature.name,
@@ -104,7 +125,14 @@ impl<'a> ModuleVisitor<'a> {
104125
// that stability
105126
items: vec![],
106127
};
107-
visitor.visit_item_impl(node);
128+
129+
if node.trait_.is_some() {
130+
// 'impl Trait for Type { .. }', where only types are relevant.
131+
ImplTraitForTypeVisitor(&mut visitor).visit_item_impl(node);
132+
} else {
133+
// 'impl Type { .. }', where all items are relevant.
134+
visitor.visit_item_impl(node);
135+
}
108136

109137
// A stable trait impl will always be stable on a stable item but can contain unstable items
110138
if visitor.is_unstable() {

0 commit comments

Comments
 (0)