mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
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:
parent
75f641799e
commit
bfe6ec9b77
3 changed files with 87 additions and 38 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue