1
Fork 0

Rollup merge of #87273 - fee1-dead:impl-const-impl-bounds, r=oli-obk

Recognize bounds on impls as const bounds

r? ```@oli-obk```
This commit is contained in:
Guillaume Gomez 2021-07-21 15:52:47 +02:00 committed by GitHub
commit 1008ace95c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 22 deletions

View file

@ -3060,6 +3060,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.