Skip to content

Commit 298d157

Browse files
committed
with_attrs -> attrs
We don't need to take a closure, instead just return the list of attributes.
1 parent 6e055c3 commit 298d157

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/libsyntax/ast_map/mod.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -457,35 +457,32 @@ impl<'ast> Map<'ast> {
457457
}
458458
}
459459

460-
/// Given a node ID and a closure, apply the closure to the array
461-
/// of attributes associated with the AST corresponding to the Node ID
462-
pub fn with_attrs<T, F>(&self, id: NodeId, f: F) -> T where
463-
F: FnOnce(Option<&[Attribute]>) -> T,
464-
{
465-
let attrs = match self.get(id) {
466-
NodeItem(i) => Some(&i.attrs[..]),
467-
NodeForeignItem(fi) => Some(&fi.attrs[..]),
468-
NodeTraitItem(ref tm) => match **tm {
460+
/// Given a node ID, get a list of of attributes associated with the AST
461+
/// corresponding to the Node ID
462+
pub fn attrs(&self, id: NodeId) -> &[Attribute] {
463+
let attrs = match self.find(id) {
464+
Some(NodeItem(i)) => Some(&i.attrs[..]),
465+
Some(NodeForeignItem(fi)) => Some(&fi.attrs[..]),
466+
Some(NodeTraitItem(ref tm)) => match **tm {
469467
RequiredMethod(ref type_m) => Some(&type_m.attrs[..]),
470468
ProvidedMethod(ref m) => Some(&m.attrs[..]),
471469
TypeTraitItem(ref typ) => Some(&typ.attrs[..]),
472470
},
473-
NodeImplItem(ref ii) => {
471+
Some(NodeImplItem(ref ii)) => {
474472
match **ii {
475473
MethodImplItem(ref m) => Some(&m.attrs[..]),
476474
TypeImplItem(ref t) => Some(&t.attrs[..]),
477475
}
478476
}
479-
NodeVariant(ref v) => Some(&v.node.attrs[..]),
477+
Some(NodeVariant(ref v)) => Some(&v.node.attrs[..]),
480478
// unit/tuple structs take the attributes straight from
481479
// the struct definition.
482-
// FIXME(eddyb) make this work again (requires access to the map).
483-
NodeStructCtor(_) => {
484-
return self.with_attrs(self.get_parent(id), f);
480+
Some(NodeStructCtor(_)) => {
481+
return self.attrs(self.get_parent(id));
485482
}
486483
_ => None
487484
};
488-
f(attrs)
485+
attrs.unwrap_or(&[])
489486
}
490487

491488
/// Returns an iterator that yields the node id's with paths that

0 commit comments

Comments
 (0)