Avoid cloning IMPL node if we don't have to

This commit is contained in:
Tiddo Langerak 2022-08-10 17:03:15 +03:00
parent 7c568961fd
commit 7402366877
No known key found for this signature in database
GPG Key ID: 7E7AEEE487C75300

View File

@ -1288,6 +1288,9 @@ fn last_impl_member(impl_node: &SyntaxNode) -> Option<SyntaxNode> {
}
fn is_trait_impl(node: &SyntaxNode) -> bool {
if !ast::Impl::can_cast(node.kind()) {
return false;
}
match ast::Impl::cast(node.clone()) {
Some(c) => c.trait_().is_some(),
None => false,
@ -1295,6 +1298,9 @@ fn is_trait_impl(node: &SyntaxNode) -> bool {
}
fn impl_type_name(impl_node: &SyntaxNode) -> Option<String> {
if !ast::Impl::can_cast(impl_node.kind()) {
return None;
}
Some(ast::Impl::cast(impl_node.clone())?.self_ty()?.to_string())
}