E0229: Suggest Moving Type Constraints to Type Parameter Declaration
This commit is contained in:
parent
6d19ac36b9
commit
5da1b4189e
6 changed files with 105 additions and 13 deletions
|
@ -2456,6 +2456,15 @@ pub enum AssocItemConstraintKind<'hir> {
|
|||
Bound { bounds: &'hir [GenericBound<'hir>] },
|
||||
}
|
||||
|
||||
impl<'hir> AssocItemConstraintKind<'hir> {
|
||||
pub fn descr(&self) -> &'static str {
|
||||
match self {
|
||||
AssocItemConstraintKind::Equality { .. } => "binding",
|
||||
AssocItemConstraintKind::Bound { .. } => "constraint",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, HashStable_Generic)]
|
||||
pub struct Ty<'hir> {
|
||||
pub hir_id: HirId,
|
||||
|
@ -3735,6 +3744,21 @@ impl<'hir> Node<'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get a `hir::Impl` if the node is an impl block for the given `trait_def_id`.
|
||||
pub fn impl_block_of_trait(self, trait_def_id: DefId) -> Option<&'hir Impl<'hir>> {
|
||||
match self {
|
||||
Node::Item(Item { kind: ItemKind::Impl(impl_block), .. })
|
||||
if impl_block
|
||||
.of_trait
|
||||
.and_then(|trait_ref| trait_ref.trait_def_id())
|
||||
.is_some_and(|trait_id| trait_id == trait_def_id) =>
|
||||
{
|
||||
Some(impl_block)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fn_sig(self) -> Option<&'hir FnSig<'hir>> {
|
||||
match self {
|
||||
Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue