Replace if let with match where appropriate
This commit is contained in:
@@ -60,10 +60,9 @@ impl GenericParamsOwnerEdit for ast::Impl {
|
||||
match self.generic_param_list() {
|
||||
Some(it) => it,
|
||||
None => {
|
||||
let position = if let Some(imp_token) = self.impl_token() {
|
||||
Position::after(imp_token)
|
||||
} else {
|
||||
Position::last_child_of(self.syntax())
|
||||
let position = match self.impl_token() {
|
||||
Some(imp_token) => Position::after(imp_token),
|
||||
None => Position::last_child_of(self.syntax()),
|
||||
};
|
||||
create_generic_param_list(position)
|
||||
}
|
||||
@@ -72,10 +71,9 @@ impl GenericParamsOwnerEdit for ast::Impl {
|
||||
|
||||
fn get_or_create_where_clause(&self) -> ast::WhereClause {
|
||||
if self.where_clause().is_none() {
|
||||
let position = if let Some(items) = self.assoc_item_list() {
|
||||
Position::before(items.syntax())
|
||||
} else {
|
||||
Position::last_child_of(self.syntax())
|
||||
let position = match self.assoc_item_list() {
|
||||
Some(items) => Position::before(items.syntax()),
|
||||
None => Position::last_child_of(self.syntax()),
|
||||
};
|
||||
create_where_clause(position);
|
||||
}
|
||||
@@ -102,10 +100,9 @@ impl GenericParamsOwnerEdit for ast::Trait {
|
||||
|
||||
fn get_or_create_where_clause(&self) -> ast::WhereClause {
|
||||
if self.where_clause().is_none() {
|
||||
let position = if let Some(items) = self.assoc_item_list() {
|
||||
Position::before(items.syntax())
|
||||
} else {
|
||||
Position::last_child_of(self.syntax())
|
||||
let position = match self.assoc_item_list() {
|
||||
Some(items) => Position::before(items.syntax()),
|
||||
None => Position::last_child_of(self.syntax()),
|
||||
};
|
||||
create_where_clause(position);
|
||||
}
|
||||
@@ -253,12 +250,9 @@ impl ast::WhereClause {
|
||||
|
||||
impl ast::TypeBoundList {
|
||||
pub fn remove(&self) {
|
||||
if let Some(colon) =
|
||||
self.syntax().siblings_with_tokens(Direction::Prev).find(|it| it.kind() == T![:])
|
||||
{
|
||||
ted::remove_all(colon..=self.syntax().clone().into())
|
||||
} else {
|
||||
ted::remove(self.syntax())
|
||||
match self.syntax().siblings_with_tokens(Direction::Prev).find(|it| it.kind() == T![:]) {
|
||||
Some(colon) => ted::remove_all(colon..=self.syntax().clone().into()),
|
||||
None => ted::remove(self.syntax()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -641,9 +641,14 @@ pub fn fn_(
|
||||
ret_type: Option<ast::RetType>,
|
||||
is_async: bool,
|
||||
) -> ast::Fn {
|
||||
let type_params =
|
||||
if let Some(type_params) = type_params { format!("<{}>", type_params) } else { "".into() };
|
||||
let ret_type = if let Some(ret_type) = ret_type { format!("{} ", ret_type) } else { "".into() };
|
||||
let type_params = match type_params {
|
||||
Some(type_params) => format!("<{}>", type_params),
|
||||
None => "".into(),
|
||||
};
|
||||
let ret_type = match ret_type {
|
||||
Some(ret_type) => format!("{} ", ret_type),
|
||||
None => "".into(),
|
||||
};
|
||||
let visibility = match visibility {
|
||||
None => String::new(),
|
||||
Some(it) => format!("{} ", it),
|
||||
|
||||
@@ -549,10 +549,9 @@ impl ast::FieldExpr {
|
||||
}
|
||||
|
||||
pub fn field_access(&self) -> Option<FieldKind> {
|
||||
if let Some(nr) = self.name_ref() {
|
||||
Some(FieldKind::Name(nr))
|
||||
} else {
|
||||
self.index_token().map(FieldKind::Index)
|
||||
match self.name_ref() {
|
||||
Some(nr) => Some(FieldKind::Name(nr)),
|
||||
None => self.index_token().map(FieldKind::Index),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,10 +283,9 @@ pub trait HasFormatSpecifier: AstToken {
|
||||
where
|
||||
F: FnMut(TextRange, FormatSpecifier),
|
||||
{
|
||||
let char_ranges = if let Some(char_ranges) = self.char_ranges() {
|
||||
char_ranges
|
||||
} else {
|
||||
return;
|
||||
let char_ranges = match self.char_ranges() {
|
||||
Some(char_ranges) => char_ranges,
|
||||
None => return,
|
||||
};
|
||||
let mut chars = char_ranges.iter().peekable();
|
||||
|
||||
@@ -528,10 +527,11 @@ pub trait HasFormatSpecifier: AstToken {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some((_, Ok('}'))) = chars.peek() {
|
||||
skip_char_and_emit(&mut chars, FormatSpecifier::Close, &mut callback);
|
||||
} else {
|
||||
continue;
|
||||
match chars.peek() {
|
||||
Some((_, Ok('}'))) => {
|
||||
skip_char_and_emit(&mut chars, FormatSpecifier::Close, &mut callback);
|
||||
}
|
||||
Some((_, _)) | None => continue,
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
|
||||
@@ -227,12 +227,9 @@ where
|
||||
T: crate::AstNode,
|
||||
F: Fn(&str) -> Result<T, ()>,
|
||||
{
|
||||
dir_tests(&test_data_dir(), ok_paths, "rast", |text, path| {
|
||||
if let Ok(node) = f(text) {
|
||||
format!("{:#?}", crate::ast::AstNode::syntax(&node))
|
||||
} else {
|
||||
panic!("Failed to parse '{:?}'", path);
|
||||
}
|
||||
dir_tests(&test_data_dir(), ok_paths, "rast", |text, path| match f(text) {
|
||||
Ok(node) => format!("{:#?}", crate::ast::AstNode::syntax(&node)),
|
||||
Err(_) => panic!("Failed to parse '{:?}'", path),
|
||||
});
|
||||
dir_tests(&test_data_dir(), err_paths, "rast", |text, path| {
|
||||
if f(text).is_ok() {
|
||||
|
||||
Reference in New Issue
Block a user