mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-20 19:52:48 +00:00
move remove bounds to ast/edit.rs
This commit is contained in:
parent
e010b144d5
commit
054c53aeb9
@ -39,8 +39,7 @@ pub(crate) fn move_bounds_to_where_clause(mut ctx: AssistCtx<impl HirDatabase>)
|
||||
.type_params()
|
||||
.filter(|it| it.type_bound_list().is_some())
|
||||
.map(|type_param| {
|
||||
let without_bounds =
|
||||
AstEditor::new(type_param.clone()).remove_bounds().ast().clone();
|
||||
let without_bounds = type_param.remove_bounds();
|
||||
(type_param, without_bounds)
|
||||
});
|
||||
|
||||
|
@ -51,18 +51,3 @@ impl<N: AstNode> AstEditor<N> {
|
||||
N::cast(new_syntax).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl AstEditor<ast::TypeParam> {
|
||||
pub fn remove_bounds(&mut self) -> &mut Self {
|
||||
let colon = match self.ast.colon_token() {
|
||||
Some(it) => it,
|
||||
None => return self,
|
||||
};
|
||||
let end = match self.ast.type_bound_list() {
|
||||
Some(it) => it.syntax().clone().into(),
|
||||
None => colon.clone().into(),
|
||||
};
|
||||
self.ast = self.replace_children(RangeInclusive::new(colon.into(), end), iter::empty());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ use crate::{
|
||||
ast::{
|
||||
self,
|
||||
make::{self, tokens},
|
||||
AstNode,
|
||||
AstNode, TypeBoundsOwner,
|
||||
},
|
||||
AstToken, Direction, InsertPosition, SmolStr, SyntaxElement,
|
||||
SyntaxKind::{ATTR, COMMENT, WHITESPACE},
|
||||
@ -185,6 +185,20 @@ impl ast::RecordFieldList {
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::TypeParam {
|
||||
pub fn remove_bounds(&self) -> ast::TypeParam {
|
||||
let colon = match self.colon_token() {
|
||||
Some(it) => it,
|
||||
None => return self.clone(),
|
||||
};
|
||||
let end = match self.type_bound_list() {
|
||||
Some(it) => it.syntax().clone().into(),
|
||||
None => colon.clone().into(),
|
||||
};
|
||||
replace_children(self, RangeInclusive::new(colon.into(), end), iter::empty())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn strip_attrs_and_docs<N: ast::AttrsOwner>(node: N) -> N {
|
||||
N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user