Skip to content

Commit 3ad36e2

Browse files
authored
Merge pull request #13 from rust-lang/unstable-api-simplify-output
Simplify output of the `unstable-api` tool a bit.
2 parents 2547b4e + 3e3991e commit 3ad36e2

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

tools/unstable-api/src/util.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@ pub(crate) fn lit_is_str(lit: &syn::Lit, s: &str) -> bool {
1717
pub(crate) fn empty_block() -> syn::Block {
1818
syn::Block {
1919
brace_token: Default::default(),
20-
stmts: Default::default(),
20+
stmts: vec![syn::Stmt::Expr(empty_expr())],
2121
}
2222
}
2323

2424
pub(crate) fn empty_expr() -> syn::Expr {
25-
syn::ExprBlock {
26-
attrs: vec![],
27-
label: None,
28-
block: empty_block(),
25+
// This is just a `..` token, which is technically a valid expression,
26+
// but looks like a placeholder.
27+
syn::ExprRange {
28+
attrs: Vec::new(),
29+
from: None,
30+
to: None,
31+
limits: syn::RangeLimits::HalfOpen(Default::default()),
2932
}
3033
.into()
3134
}

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)