1
Fork 0

Recognize bounds on impls as const bounds

This commit is contained in:
Deadbeef 2021-07-19 18:50:47 +08:00
parent d05a286449
commit 4b82bbeac0
No known key found for this signature in database
GPG key ID: 6525773485376D92
4 changed files with 38 additions and 14 deletions

View file

@ -3064,6 +3064,27 @@ impl<'hir> Node<'hir> {
Node::Crate(_) | Node::Visibility(_) => None,
}
}
/// Returns `Constness::Const` when this node is a const fn/impl.
pub fn constness(&self) -> Constness {
match self {
Node::Item(Item {
kind: ItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
..
})
| Node::TraitItem(TraitItem {
kind: TraitItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
..
})
| Node::ImplItem(ImplItem {
kind: ImplItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
..
})
| Node::Item(Item { kind: ItemKind::Impl(Impl { constness, .. }), .. }) => *constness,
_ => Constness::NotConst,
}
}
}
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.