Add {TypeParam, ConstParam}::remove_default

Also includes a drive-by refactor of `utils::generate_impl_text_inner`,
since that's what drove this change
This commit is contained in:
DropDemBits 2022-10-09 18:12:08 -04:00
parent 75f641799e
commit bfe6ec9b77
3 changed files with 87 additions and 38 deletions

View file

@ -265,6 +265,42 @@ impl ast::WhereClause {
}
}
impl ast::TypeParam {
pub fn remove_default(&self) {
if let Some((eq, last)) = self
.syntax()
.children_with_tokens()
.find(|it| it.kind() == T![=])
.zip(self.syntax().last_child_or_token())
{
ted::remove_all(eq..=last);
// remove any trailing ws
if let Some(last) = self.syntax().last_token().filter(|it| it.kind() == WHITESPACE) {
last.detach();
}
}
}
}
impl ast::ConstParam {
pub fn remove_default(&self) {
if let Some((eq, last)) = self
.syntax()
.children_with_tokens()
.find(|it| it.kind() == T![=])
.zip(self.syntax().last_child_or_token())
{
ted::remove_all(eq..=last);
// remove any trailing ws
if let Some(last) = self.syntax().last_token().filter(|it| it.kind() == WHITESPACE) {
last.detach();
}
}
}
}
pub trait Removable: AstNode {
fn remove(&self);
}