Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/hir/src/lib.rs7
-rw-r--r--crates/hir_def/src/body/lower.rs28
-rw-r--r--crates/hir_def/src/find_path.rs37
-rw-r--r--crates/hir_def/src/item_tree.rs7
-rw-r--r--crates/hir_def/src/nameres/path_resolution.rs11
-rw-r--r--crates/hir_def/src/path/lower/lower_use.rs7
-rw-r--r--crates/hir_def/src/type_ref.rs7
-rw-r--r--crates/hir_expand/src/name.rs7
-rw-r--r--crates/hir_ty/src/autoderef.rs7
-rw-r--r--crates/hir_ty/src/chalk_ext.rs7
-rw-r--r--crates/hir_ty/src/diagnostics/match_check/deconstruct_pat.rs7
-rw-r--r--crates/hir_ty/src/display.rs7
-rw-r--r--crates/hir_ty/src/infer/expr.rs7
-rw-r--r--crates/hir_ty/src/infer/pat.rs7
-rw-r--r--crates/hir_ty/src/infer/unify.rs7
-rw-r--r--crates/hir_ty/src/lower.rs7
-rw-r--r--crates/hir_ty/src/method_resolution.rs7
-rw-r--r--crates/hir_ty/src/tests.rs14
-rw-r--r--crates/ide/src/display/navigation_target.rs7
-rw-r--r--crates/ide/src/join_lines.rs7
-rw-r--r--crates/ide/src/static_index.rs14
-rw-r--r--crates/ide_assists/src/handlers/extract_function.rs7
-rw-r--r--crates/ide_assists/src/handlers/extract_variable.rs9
-rw-r--r--crates/ide_assists/src/handlers/generate_function.rs36
-rw-r--r--crates/ide_assists/src/handlers/inline_call.rs7
-rw-r--r--crates/ide_assists/src/handlers/pull_assignment_up.rs9
-rw-r--r--crates/ide_assists/src/handlers/qualify_path.rs7
-rw-r--r--crates/ide_assists/src/utils.rs22
-rw-r--r--crates/ide_assists/src/utils/suggest_name.rs7
-rw-r--r--crates/ide_completion/src/context.rs7
-rw-r--r--crates/ide_completion/src/render/function.rs7
-rw-r--r--crates/ide_completion/src/render/pattern.rs7
-rw-r--r--crates/ide_completion/src/render/struct_literal.rs7
-rw-r--r--crates/ide_ssr/src/resolving.rs7
-rw-r--r--crates/proc_macro_srv/src/abis/abi_1_47/rustc_server.rs7
-rw-r--r--crates/proc_macro_srv/src/abis/abi_1_55/rustc_server.rs7
-rw-r--r--crates/proc_macro_srv/src/abis/abi_1_56/rustc_server.rs7
-rw-r--r--crates/rust-analyzer/src/handlers.rs14
-rw-r--r--crates/syntax/src/ast/edit_in_place.rs30
-rw-r--r--crates/syntax/src/ast/make.rs11
-rw-r--r--crates/syntax/src/ast/node_ext.rs7
-rw-r--r--crates/syntax/src/ast/token_ext.rs16
-rw-r--r--crates/syntax/src/tests.rs9
-rw-r--r--crates/tt/src/buffer.rs7
44 files changed, 201 insertions, 269 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 7b010fc271..038c69bc73 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -2119,10 +2119,9 @@ impl Impl {
};
let fp = TyFingerprint::for_inherent_impl(&ty);
- let fp = if let Some(fp) = fp {
- fp
- } else {
- return Vec::new();
+ let fp = match fp {
+ Some(fp) => fp,
+ None => return Vec::new(),
};
let mut all = Vec::new();
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs
index 804d98ce38..4c1a3344ec 100644
--- a/crates/hir_def/src/body/lower.rs
+++ b/crates/hir_def/src/body/lower.rs
@@ -474,10 +474,9 @@ impl ExprCollector<'_> {
}
ast::Expr::PrefixExpr(e) => {
let expr = self.collect_expr_opt(e.expr());
- if let Some(op) = e.op_kind() {
- self.alloc_expr(Expr::UnaryOp { expr, op }, syntax_ptr)
- } else {
- self.alloc_expr(Expr::Missing, syntax_ptr)
+ match e.op_kind() {
+ Some(op) => self.alloc_expr(Expr::UnaryOp { expr, op }, syntax_ptr),
+ None => self.alloc_expr(Expr::Missing, syntax_ptr),
}
}
ast::Expr::ClosureExpr(e) => {
@@ -624,10 +623,9 @@ impl ExprCollector<'_> {
}
fn collect_expr_opt(&mut self, expr: Option<ast::Expr>) -> ExprId {
- if let Some(expr) = expr {
- self.collect_expr(expr)
- } else {
- self.missing_expr()
+ match expr {
+ Some(expr) => self.collect_expr(expr),
+ None => self.missing_expr(),
}
}
@@ -724,10 +722,9 @@ impl ExprCollector<'_> {
}
fn collect_block_opt(&mut self, expr: Option<ast::BlockExpr>) -> ExprId {
- if let Some(block) = expr {
- self.collect_block(block)
- } else {
- self.missing_expr()
+ match expr {
+ Some(block) => self.collect_block(block),
+ None => self.missing_expr(),
}
}
@@ -890,10 +887,9 @@ impl ExprCollector<'_> {
}
fn collect_pat_opt(&mut self, pat: Option<ast::Pat>) -> PatId {
- if let Some(pat) = pat {
- self.collect_pat(pat)
- } else {
- self.missing_pat()
+ match pat {
+ Some(pat) => self.collect_pat(pat),
+ None => self.missing_pat(),
}
}
diff --git a/crates/hir_def/src/find_path.rs b/crates/hir_def/src/find_path.rs
index 08ffa8e53d..3251638c7a 100644
--- a/crates/hir_def/src/find_path.rs
+++ b/crates/hir_def/src/find_path.rs
@@ -209,10 +209,9 @@ fn find_path_inner(
) {
path.push_segment(name);
- let new_path = if let Some(best_path) = best_path {
- select_best_path(best_path, path, prefer_no_std)
- } else {
- path
+ let new_path = match best_path {
+ Some(best_path) => select_best_path(best_path, path, prefer_no_std),
+ None => path,
};
best_path_len = new_path.len();
best_path = Some(new_path);
@@ -243,10 +242,9 @@ fn find_path_inner(
});
for path in extern_paths {
- let new_path = if let Some(best_path) = best_path {
- select_best_path(best_path, path, prefer_no_std)
- } else {
- path
+ let new_path = match best_path {
+ Some(best_path) => select_best_path(best_path, path, prefer_no_std),
+ None => path,
};
best_path = Some(new_path);
}
@@ -261,12 +259,11 @@ fn find_path_inner(
}
}
- if let Some(prefix) = prefixed.map(PrefixKind::prefix) {
- best_path.or_else(|| {
+ match prefixed.map(PrefixKind::prefix) {
+ Some(prefix) => best_path.or_else(|| {
scope_name.map(|scope_name| ModPath::from_segments(prefix, vec![scope_name]))
- })
- } else {
- best_path
+ }),
+ None => best_path,
}
}
@@ -346,15 +343,13 @@ fn find_local_import_locations(
if let Some((name, vis)) = data.scope.name_of(item) {
if vis.is_visible_from(db, from) {
- let is_private = if let Visibility::Module(private_to) = vis {
- private_to.local_id == module.local_id
- } else {
- false
+ let is_private = match vis {
+ Visibility::Module(private_to) => private_to.local_id == module.local_id,
+ Visibility::Public => false,
};
- let is_original_def = if let Some(module_def_id) = item.as_module_def_id() {
- data.scope.declarations().any(|it| it == module_def_id)
- } else {
- false
+ let is_original_def = match item.as_module_def_id() {
+ Some(module_def_id) => data.scope.declarations().any(|it| it == module_def_id),
+ None => false,
};
// Ignore private imports. these could be used if we are
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs
index 3900e7e97c..b7a5758a0a 100644
--- a/crates/hir_def/src/item_tree.rs
+++ b/crates/hir_def/src/item_tree.rs
@@ -475,10 +475,9 @@ macro_rules! mod_items {
}
fn id_from_mod_item(mod_item: ModItem) -> Option<FileItemTreeId<Self>> {
- if let ModItem::$typ(id) = mod_item {
- Some(id)
- } else {
- None
+ match mod_item {
+ ModItem::$typ(id) => Some(id),
+ _ => None,
}
}
diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs
index 4fb81bde46..30f11cc694 100644
--- a/crates/hir_def/src/nameres/path_resolution.rs
+++ b/crates/hir_def/src/nameres/path_resolution.rs
@@ -400,13 +400,10 @@ impl DefMap {
};
let from_scope_or_builtin = match shadow {
BuiltinShadowMode::Module => from_scope.or(from_builtin),
- BuiltinShadowMode::Other => {
- if let Some(ModuleDefId::ModuleId(_)) = from_scope.take_types() {
- from_builtin.or(from_scope)
- } else {
- from_scope.or(from_builtin)
- }
- }
+ BuiltinShadowMode::Other => match from_scope.take_types() {
+ Some(ModuleDefId::ModuleId(_)) => from_builtin.or(from_scope),
+ Some(_) | None => from_scope.or(from_builtin),
+ },
};
let from_extern_prelude = self
.extern_prelude
diff --git a/crates/hir_def/src/path/lower/lower_use.rs b/crates/hir_def/src/path/lower/lower_use.rs
index 0ee406f63a..6b777cfeff 100644
--- a/crates/hir_def/src/path/lower/lower_use.rs
+++ b/crates/hir_def/src/path/lower/lower_use.rs
@@ -18,10 +18,9 @@ pub(crate) fn convert_path(
path: ast::Path,
hygiene: &Hygiene,
) -> Option<ModPath> {
- let prefix = if let Some(qual) = path.qualifier() {
- Some(convert_path(db, prefix, qual, hygiene)?)
- } else {
- prefix
+ let prefix = match path.qualifier() {
+ Some(qual) => Some(convert_path(db, prefix, qual, hygiene)?),
+ None => prefix,
};
let segment = path.segment()?;
diff --git a/crates/hir_def/src/type_ref.rs b/crates/hir_def/src/type_ref.rs
index 9f33fd26e8..cfc69feccc 100644
--- a/crates/hir_def/src/type_ref.rs
+++ b/crates/hir_def/src/type_ref.rs
@@ -214,10 +214,9 @@ impl TypeRef {
}
pub(crate) fn from_ast_opt(ctx: &LowerCtx, node: Option<ast::Type>) -> Self {
- if let Some(node) = node {
- TypeRef::from_ast(ctx, node)
- } else {
- TypeRef::Error
+ match node {
+ Some(node) => TypeRef::from_ast(ctx, node),
+ None => TypeRef::Error,
}
}
diff --git a/crates/hir_expand/src/name.rs b/crates/hir_expand/src/name.rs
index 9c844c6138..552603dce7 100644
--- a/crates/hir_expand/src/name.rs
+++ b/crates/hir_expand/src/name.rs
@@ -48,10 +48,9 @@ impl Name {
/// Resolve a name from the text of token.
fn resolve(raw_text: &str) -> Name {
- if let Some(text) = raw_text.strip_prefix("r#") {
- Name::new_text(SmolStr::new(text))
- } else {
- Name::new_text(raw_text.into())
+ match raw_text.strip_prefix("r#") {
+ Some(text) => Name::new_text(SmolStr::new(text)),
+ None => Name::new_text(raw_text.into()),
}
}
diff --git a/crates/hir_ty/src/autoderef.rs b/crates/hir_ty/src/autoderef.rs
index e3f008645c..4dc46a2cde 100644
--- a/crates/hir_ty/src/autoderef.rs
+++ b/crates/hir_ty/src/autoderef.rs
@@ -109,10 +109,9 @@ pub(crate) fn deref(
ty: InEnvironment<&Canonical<Ty>>,
) -> Option<Canonical<Ty>> {
let _p = profile::span("deref");
- if let Some(derefed) = builtin_deref(&ty.goal.value) {
- Some(Canonical { value: derefed, binders: ty.goal.binders.clone() })
- } else {
- deref_by_trait(db, krate, ty)
+ match builtin_deref(&ty.goal.value) {
+ Some(derefed) => Some(Canonical { value: derefed, binders: ty.goal.binders.clone() }),
+ None => deref_by_trait(db, krate, ty),
}
}
diff --git a/crates/hir_ty/src/chalk_ext.rs b/crates/hir_ty/src/chalk_ext.rs
index c29fbd688a..36c56820eb 100644
--- a/crates/hir_ty/src/chalk_ext.rs
+++ b/crates/hir_ty/src/chalk_ext.rs
@@ -104,10 +104,9 @@ impl TyExt for Ty {
}
fn as_fn_def(&self, db: &dyn HirDatabase) -> Option<FunctionId> {
- if let Some(CallableDefId::FunctionId(func)) = self.callable_def(db) {
- Some(func)
- } else {
- None
+ match self.callable_def(db) {
+ Some(CallableDefId::FunctionId(func)) => Some(func),
+ Some(CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_)) | None => None,
}
}
fn as_reference(&self) -> Option<(&Ty, Lifetime, Mutability)> {
diff --git a/crates/hir_ty/src/diagnostics/match_check/deconstruct_pat.rs b/crates/hir_ty/src/diagnostics/match_check/deconstruct_pat.rs
index 2fa456a035..f9439c706e 100644
--- a/crates/hir_ty/src/diagnostics/match_check/deconstruct_pat.rs
+++ b/crates/hir_ty/src/diagnostics/match_check/deconstruct_pat.rs
@@ -105,10 +105,9 @@ impl IntRange {
#[inline]
fn from_range(lo: u128, hi: u128, scalar_ty: Scalar) -> IntRange {
- if let Scalar::Bool = scalar_ty {
- IntRange { range: lo..=hi }
- } else {
- unimplemented!()
+ match scalar_ty {
+ Scalar::Bool => IntRange { range: lo..=hi },
+ _ => unimplemented!(),
}
}
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index 1ae718a36b..adce43aa07 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -167,10 +167,9 @@ impl<'a> HirFormatter<'a> {
}
pub fn should_truncate(&self) -> bool {
- if let Some(max_size) = self.max_size {
- self.curr_size >= max_size
- } else {
- false
+ match self.max_size {
+ Some(max_size) => self.curr_size >= max_size,
+ None => false,
}
}
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index b0306d9148..f5bc898a85 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -264,10 +264,9 @@ impl<'a> InferenceContext<'a> {
// collect explicitly written argument types
for arg_type in arg_types.iter() {
- let arg_ty = if let Some(type_ref) = arg_type {
- self.make_ty(type_ref)
- } else {
- self.table.new_type_var()
+ let arg_ty = match arg_type {
+ Some(type_ref) => self.make_ty(type_ref),
+ None => self.table.new_type_var(),
};
sig_tys.push(arg_ty);
}
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs
index 957cd829aa..9aaf7db87b 100644
--- a/crates/hir_ty/src/infer/pat.rs
+++ b/crates/hir_ty/src/infer/pat.rs
@@ -204,10 +204,9 @@ impl<'a> InferenceContext<'a> {
} else {
BindingMode::convert(*mode)
};
- let inner_ty = if let Some(subpat) = subpat {
- self.infer_pat(*subpat, &expected, default_bm)
- } else {
- expected
+ let inner_ty = match subpat {
+ Some(subpat) => self.infer_pat(*subpat, &expected, default_bm),
+ None => expected,
};
let inner_ty = self.insert_type_vars_shallow(inner_ty);
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs
index 4c1e758904..c40ef7f587 100644
--- a/crates/hir_ty/src/infer/unify.rs
+++ b/crates/hir_ty/src/infer/unify.rs
@@ -324,10 +324,9 @@ impl<'a> InferenceTable<'a> {
/// Unify two types and register new trait goals that arise from that.
pub(crate) fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool {
- let result = if let Ok(r) = self.try_unify(ty1, ty2) {
- r
- } else {
- return false;
+ let result = match self.try_unify(ty1, ty2) {
+ Ok(r) => r,
+ Err(_) => return false,
};
self.register_infer_ok(result);
true
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 3734eb1013..df1eb1c961 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -368,10 +368,9 @@ impl<'a> TyLoweringContext<'a> {
Some((it, None)) => it,
_ => return None,
};
- if let TypeNs::GenericParam(param_id) = resolution {
- Some(param_id)
- } else {
- None
+ match resolution {
+ TypeNs::GenericParam(param_id) => Some(param_id),
+ _ => None,
}
}
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs
index c88a8b6535..8e6ab8af0f 100644
--- a/crates/hir_ty/src/method_resolution.rs
+++ b/crates/hir_ty/src/method_resolution.rs
@@ -82,10 +82,9 @@ impl TyFingerprint {
TyKind::Ref(_, _, ty) => return TyFingerprint::for_trait_impl(ty),
TyKind::Tuple(_, subst) => {
let first_ty = subst.interned().get(0).map(|arg| arg.assert_ty_ref(&Interner));
- if let Some(ty) = first_ty {
- return TyFingerprint::for_trait_impl(ty);
- } else {
- TyFingerprint::Unit
+ match first_ty {
+ Some(ty) => return TyFingerprint::for_trait_impl(ty),
+ None => TyFingerprint::Unit,
}
}
TyKind::AssociatedType(_, _)
diff --git a/crates/hir_ty/src/tests.rs b/crates/hir_ty/src/tests.rs
index cf6833e56a..29250dca00 100644
--- a/crates/hir_ty/src/tests.rs
+++ b/crates/hir_ty/src/tests.rs
@@ -195,10 +195,9 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
mismatch.expected.display_test(&db),
mismatch.actual.display_test(&db)
);
- if let Some(annotation) = mismatches.remove(&range) {
- assert_eq!(actual, annotation);
- } else {
- format_to!(unexpected_type_mismatches, "{:?}: {}\n", range.range, actual);
+ match mismatches.remove(&range) {
+ Some(annotation) => assert_eq!(actual, annotation),
+ None => format_to!(unexpected_type_mismatches, "{:?}: {}\n", range.range, actual),
}
}
for (expr, mismatch) in inference_result.expr_type_mismatches() {
@@ -215,10 +214,9 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
mismatch.expected.display_test(&db),
mismatch.actual.display_test(&db)
);
- if let Some(annotation) = mismatches.remove(&range) {
- assert_eq!(actual, annotation);
- } else {
- format_to!(unexpected_type_mismatches, "{:?}: {}\n", range.range, actual);
+ match mismatches.remove(&range) {
+ Some(annotation) => assert_eq!(actual, annotation),
+ None => format_to!(unexpected_type_mismatches, "{:?}: {}\n", range.range, actual),
}
}
}
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs
index 65c29f6805..01c1259fc5 100644
--- a/crates/ide/src/display/navigation_target.rs
+++ b/crates/ide/src/display/navigation_target.rs
@@ -292,10 +292,9 @@ impl TryToNav for hir::Impl {
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
let src = self.source(db)?;
let derive_attr = self.is_builtin_derive(db);
- let frange = if let Some(item) = &derive_attr {
- item.syntax().original_file_range(db)
- } else {
- src.syntax().original_file_range(db)
+ let frange = match &derive_attr {
+ Some(item) => item.syntax().original_file_range(db),
+ None => src.syntax().original_file_range(db),
};
let focus_range = if derive_attr.is_some() {
None
diff --git a/crates/ide/src/join_lines.rs b/crates/ide/src/join_lines.rs
index 000d74abac..4851f9aee0 100644
--- a/crates/ide/src/join_lines.rs
+++ b/crates/ide/src/join_lines.rs
@@ -136,10 +136,9 @@ fn remove_newline(
}
T!['}'] => {
// Removes: comma, newline (incl. surrounding whitespace)
- let space = if let Some(left) = prev.prev_sibling_or_token() {
- compute_ws(left.kind(), next.kind())
- } else {
- " "
+ let space = match prev.prev_sibling_or_token() {
+ Some(left) => compute_ws(left.kind(), next.kind()),
+ None => " ",
};
edit.replace(
TextRange::new(prev.text_range().start(), token.text_range().end()),
diff --git a/crates/ide/src/static_index.rs b/crates/ide/src/static_index.rs
index aa62e2eae5..eb1a04c3f7 100644
--- a/crates/ide/src/static_index.rs
+++ b/crates/ide/src/static_index.rs
@@ -103,10 +103,9 @@ impl StaticIndex<'_> {
for token in tokens {
let range = token.text_range();
let node = token.parent().unwrap();
- let def = if let Some(x) = get_definition(&sema, token.clone()) {
- x
- } else {
- continue;
+ let def = match get_definition(&sema, token.clone()) {
+ Some(x) => x,
+ None => continue,
};
let id = if let Some(x) = self.def_map.get(&def) {
*x
@@ -124,10 +123,9 @@ impl StaticIndex<'_> {
let token = self.tokens.get_mut(id).unwrap();
token.references.push(ReferenceData {
range: FileRange { range, file_id },
- is_definition: if let Some(x) = def.try_to_nav(self.db) {
- x.file_id == file_id && x.focus_or_full_range() == range
- } else {
- false
+ is_definition: match def.try_to_nav(self.db) {
+ Some(x) => x.file_id == file_id && x.focus_or_full_range() == range,
+ None => false,
},
});
result.tokens.push((range, id));
diff --git a/crates/ide_assists/src/handlers/extract_function.rs b/crates/ide_assists/src/handlers/extract_function.rs
index 585ef31daf..b7eb2aefad 100644
--- a/crates/ide_assists/src/handlers/extract_function.rs
+++ b/crates/ide_assists/src/handlers/extract_function.rs
@@ -827,10 +827,9 @@ impl FunctionBody {
locals
.map(|local| (local, local.source(ctx.db())))
.filter(|(_, src)| is_defined_outside_of_body(ctx, self, src))
- .filter_map(|(local, src)| {
- if let Either::Left(src) = src.value {
- Some((local, src))
- } else {
+ .filter_map(|(local, src)| match src.value {
+ Either::Left(src) => Some((local, src)),
+ Either::Right(_) => {
stdx::never!(false, "Local::is_self returned false, but source is SelfParam");
None
}
diff --git a/crates/ide_assists/src/handlers/extract_variable.rs b/crates/ide_assists/src/handlers/extract_variable.rs
index 9b4e1380a4..419bf27877 100644
--- a/crates/ide_assists/src/handlers/extract_variable.rs
+++ b/crates/ide_assists/src/handlers/extract_variable.rs
@@ -69,10 +69,11 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option
None => to_extract.syntax().text_range(),
};
- if let Anchor::WrapInBlock(_) = anchor {
- format_to!(buf, "{{ let {} = ", var_name);
- } else {
- format_to!(buf, "let {} = ", var_name);
+ match anchor {
+ Anchor::Before(_) | Anchor::Replace(_) => {
+ format_to!(buf, "let {} = ", var_name)
+ }
+ Anchor::WrapInBlock(_) => format_to!(buf, "{{ let {} = ", var_name),
};
format_to!(buf, "{}", to_extract.syntax());
diff --git a/crates/ide_assists/src/handlers/generate_function.rs b/crates/ide_assists/src/handlers/generate_function.rs
index 5e57cb76eb..ea3656ed21 100644
--- a/crates/ide_assists/src/handlers/generate_function.rs
+++ b/crates/ide_assists/src/handlers/generate_function.rs
@@ -213,10 +213,9 @@ impl FunctionTemplate {
Some(cap) => {
let cursor = if self.should_focus_return_type {
// Focus the return type if there is one
- if let Some(ref ret_type) = self.ret_type {
- ret_type.syntax()
- } else {
- self.tail_expr.syntax()
+ match self.ret_type {
+ Some(ref ret_type) => ret_type.syntax(),
+ None => self.tail_expr.syntax(),
}
} else {
self.tail_expr.syntax()
@@ -447,10 +446,9 @@ fn fn_args(
arg_types.push(match fn_arg_type(ctx, target_module, &arg) {
Some(ty) => {
if !ty.is_empty() && ty.starts_with('&') {
- if let Some((new_ty, _)) = useless_type_special_case("", &ty[1..].to_owned()) {
- new_ty
- } else {
- ty
+ match useless_type_special_case("", &ty[1..].to_owned()) {
+ Some((new_ty, _)) => new_ty,
+ None => ty,
}
} else {
ty
@@ -575,20 +573,14 @@ fn next_space_for_fn_in_module(
) -> Option<(FileId, GeneratedFunctionTarget)> {
let file = module_source.file_id.original_file(db);
let assist_item = match &module_source.value {
- hir::ModuleSource::SourceFile(it) => {
- if let Some(last_item) = it.items().last() {
- GeneratedFunctionTarget::BehindItem(last_item.syntax().clone())
- } else {
- GeneratedFunctionTarget::BehindItem(it.syntax().clone())
- }
- }
- hir::ModuleSource::Module(it) => {
- if let Some(last_item) = it.item_list().and_then(|it| it.items().last()) {
- GeneratedFunctionTarget::BehindItem(last_item.syntax().clone())
- } else {
- GeneratedFunctionTarget::InEmptyItemList(it.item_list()?.syntax().clone())
- }
- }
+ hir::ModuleSource::SourceFile(it) => match it.items().last() {
+ Some(last_item) => GeneratedFunctionTarget::BehindItem(last_item.syntax().clone()),
+ None => GeneratedFunctionTarget::BehindItem(it.syntax().clone()),
+ },
+ hir::ModuleSource::Module(it) => match it.item_list().and_then(|it| it.items().last()) {
+ Some(last_item) => GeneratedFunctionTarget::BehindItem(last_item.syntax().clone()),
+ None => GeneratedFunctionTarget::InEmptyItemList(it.item_list()?.syntax().clone()),
+ },
hir::ModuleSource::BlockExpr(it) => {
if let Some(last_item) =
it.statements().take_while(|stmt| matches!(stmt, ast::Stmt::Item(_))).last()
diff --git a/crates/ide_assists/src/handlers/inline_call.rs b/crates/ide_assists/src/handlers/inline_call.rs
index d252d61a69..091f015ee0 100644
--- a/crates/ide_assists/src/handlers/inline_call.rs
+++ b/crates/ide_assists/src/handlers/inline_call.rs
@@ -141,10 +141,9 @@ pub(crate) fn inline_into_callers(acc: &mut Assists, ctx: &AssistContext) -> Opt
for (file_id, refs) in usages.into_iter() {
inline_refs_for_file(file_id, refs);
}
- if let Some(refs) = current_file_usage {
- inline_refs_for_file(def_file, refs);
- } else {
- builder.edit_file(def_file);
+ match current_file_usage {
+ Some(refs) => inline_refs_for_file(def_file, refs),
+ None => builder.edit_file(def_file),
}
if remove_def {
builder.delete(ast_func.syntax().text_range());
diff --git a/crates/ide_assists/src/handlers/pull_assignment_up.rs b/crates/ide_assists/src/handlers/pull_assignment_up.rs
index 8946ecfac7..d142397c24 100644
--- a/crates/ide_assists/src/handlers/pull_assignment_up.rs
+++ b/crates/ide_assists/src/handlers/pull_assignment_up.rs
@@ -127,12 +127,9 @@ impl<'a> AssignmentsCollector<'a> {
}
}
fn collect_block(&mut self, block: &ast::BlockExpr) -> Option<()> {
- let last_expr = block.tail_expr().or_else(|| {
- if let ast::Stmt::ExprStmt(stmt) = block.statements().last()? {
- stmt.expr()
- } else {
- None
- }
+ let last_expr = block.tail_expr().or_else(|| match block.statements().last()? {
+ ast::Stmt::ExprStmt(stmt) => stmt.expr(),
+ ast::Stmt::Item(_) | ast::Stmt::LetStmt(_) => None,
})?;
if let ast::Expr::BinExpr(expr) = last_expr {
diff --git a/crates/ide_assists/src/handlers/qualify_path.rs b/crates/ide_assists/src/handlers/qualify_path.rs
index 8a2ec8ba80..0b33acc39b 100644
--- a/crates/ide_assists/src/handlers/qualify_path.rs
+++ b/crates/ide_assists/src/handlers/qualify_path.rs
@@ -181,10 +181,9 @@ fn find_trait_method(
fn item_as_trait(db: &RootDatabase, item: hir::ItemInNs) -> Option<hir::Trait> {
let item_module_def = item.as_module_def()?;
- if let hir::ModuleDef::Trait(trait_) = item_module_def {
- Some(trait_)
- } else {
- item_module_def.as_assoc_item(db)?.containing_trait(db)
+ match item_module_def {
+ hir::ModuleDef::Trait(trait_) => Some(trait_),
+ _ => item_module_def.as_assoc_item(db)?.containing_trait(db),
}
}
diff --git a/crates/ide_assists/src/utils.rs b/crates/ide_assists/src/utils.rs
index dfb22afc7e..3d4ab968fb 100644
--- a/crates/ide_assists/src/utils.rs
+++ b/crates/ide_assists/src/utils.rs
@@ -250,13 +250,10 @@ fn invert_special_case(expr: &ast::Expr) -> Option<ast::Expr> {
};
Some(make::expr_method_call(receiver, make::name_ref(method), arg_list))
}
- ast::Expr::PrefixExpr(pe) if pe.op_kind()? == ast::UnaryOp::Not => {
- if let ast::Expr::ParenExpr(parexpr) = pe.expr()? {
- parexpr.expr()
- } else {
- pe.expr()
- }
- }
+ ast::Expr::PrefixExpr(pe) if pe.op_kind()? == ast::UnaryOp::Not => match pe.expr()? {
+ ast::Expr::ParenExpr(parexpr) => parexpr.expr(),
+ _ => pe.expr(),
+ },
ast::Expr::Literal(lit) => match lit.kind() {
ast::LiteralKind::Bool(b) => match b {
true => Some(ast::Expr::Literal(make::expr_literal("false"))),
@@ -276,13 +273,10 @@ pub(crate) fn does_pat_match_variant(pat: &ast::Pat, var: &ast::Pat) -> bool {
let first_node_text = |pat: &ast::Pat| pat.syntax().first_child().map(|node| node.text());
let pat_head = match pat {
- ast::Pat::IdentPat(bind_pat) => {
- if let Some(p) = bind_pat.pat() {
- first_node_text(&p)
- } else {
- return pat.syntax().text() == var.syntax().text();
- }
- }
+ ast::Pat::IdentPat(bind_pat) => match bind_pat.pat() {
+ Some(p) => first_node_text(&p),
+ None => return pat.syntax().text() == var.syntax().text(),
+ },
pat => first_node_text(pat),
};
diff --git a/crates/ide_assists/src/utils/suggest_name.rs b/crates/ide_assists/src/utils/suggest_name.rs
index 35e2300196..74523234b0 100644
--- a/crates/ide_assists/src/utils/suggest_name.rs
+++ b/crates/ide_assists/src/utils/suggest_name.rs
@@ -144,10 +144,9 @@ fn is_valid_name(name: &str) -> bool {
fn is_useless_method(method: &ast::MethodCallExpr) -> bool {
let ident = method.name_ref().and_then(|it| it.ident_token());
- if let Some(ident) = ident {
- USELESS_METHODS.contains(&ident.text())
- } else {
- false
+ match ident {
+ Some(ident) => USELESS_METHODS.contains(&ident.text()),
+ None => false,
}
}
diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs
index ddf8722bc8..d6e15e6af7 100644
--- a/crates/ide_completion/src/context.rs
+++ b/crates/ide_completion/src/context.rs
@@ -509,10 +509,9 @@ impl<'a> CompletionContext<'a> {
.and_then(|pat| self.sema.type_of_pat(&pat))
.or_else(|| it.initializer().and_then(|it| self.sema.type_of_expr(&it)))
.map(TypeInfo::original);
- let name = if let Some(ast::Pat::IdentPat(ident)) = it.pat() {
- ident.name().map(NameOrNameRef::Name)
- } else {
- None
+ let name = match it.pat() {
+ Some(ast::Pat::IdentPat(ident)) => ident.name().map(NameOrNameRef::Name),
+ Some(_) | None => None,
};
(ty, name)
diff --git a/crates/ide_completion/src/render/function.rs b/crates/ide_completion/src/render/function.rs
index 95244a758d..904624f9ab 100644
--- a/crates/ide_completion/src/render/function.rs
+++ b/crates/ide_completion/src/render/function.rs
@@ -74,10 +74,9 @@ impl<'a> FunctionRender<'a> {
fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem {
let params = self.params();
- let call = if let Some(receiver) = &self.receiver {
- format!("{}.{}", receiver, &self.name)
- } else {
- self.name.clone()
+ let call = match &self.receiver {
+ Some(receiver) => format!("{}.{}", receiver, &self.name),
+ None => self.name.clone(),
};
let mut item =
CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), call.clone());
diff --git a/crates/ide_completion/src/render/pattern.rs b/crates/ide_completion/src/render/pattern.rs
index 306e418e91..521296fd9b 100644
--- a/crates/ide_completion/src/render/pattern.rs
+++ b/crates/ide_completion/src/render/pattern.rs
@@ -63,10 +63,9 @@ fn build_completion(
.set_documentation(ctx.docs(def))
.set_deprecated(ctx.is_deprecated(def))
.detail(&pat);
- if let Some(snippet_cap) = ctx.snippet_cap() {
- item.insert_snippet(snippet_cap, pat);
- } else {
- item.insert_text(pat);
+ match ctx.snippet_cap() {
+ Some(snippet_cap) => item.insert_snippet(snippet_cap, pat),
+ None => item.insert_text(pat),
};
item.build()
}
diff --git a/crates/ide_completion/src/render/struct_literal.rs b/crates/ide_completion/src/render/struct_literal.rs
index 68871a4671..810b51effd 100644
--- a/crates/ide_completion/src/render/struct_literal.rs
+++ b/crates/ide_completion/src/render/struct_literal.rs
@@ -38,10 +38,9 @@ fn build_completion(
.set_documentation(ctx.docs(def))
.set_deprecated(ctx.is_deprecated(def))
.detail(&literal);
- if let Some(snippet_cap) = ctx.snippet_cap() {
- item.insert_snippet(snippet_cap, literal);
- } else {
- item.insert_text(literal);
+ match ctx.snippet_cap() {
+ Some(snippet_cap) => item.insert_snippet(snippet_cap, literal),
+ None => item.insert_text(literal),
};
item.build()
}
diff --git a/crates/ide_ssr/src/resolving.rs b/crates/ide_ssr/src/resolving.rs
index df20ab375d..9cdd270b80 100644
--- a/crates/ide_ssr/src/resolving.rs
+++ b/crates/ide_ssr/src/resolving.rs
@@ -47,10 +47,9 @@ impl ResolvedRule {
) -> Result<ResolvedRule, SsrError> {
let resolver =
Resolver { resolution_scope, placeholders_by_stand_in: rule.placeholders_by_stand_in };
- let resolved_template = if let Some(template) = rule.template {
- Some(resolver.resolve_pattern_tree(template)?)
- } else {
- None
+ let resolved_template = match rule.template {
+ Some(template) => Some(resolver.resolve_pattern_tree(template)?),
+ None => None,
};
Ok(ResolvedRule {
pattern: resolver.resolve_pattern_tree(rule.pattern)?,
diff --git a/crates/proc_macro_srv/src/abis/abi_1_47/rustc_server.rs b/crates/proc_macro_srv/src/abis/abi_1_47/rustc_server.rs
index ff4976d0cb..a77433a551 100644
--- a/crates/proc_macro_srv/src/abis/abi_1_47/rustc_server.rs
+++ b/crates/proc_macro_srv/src/abis/abi_1_47/rustc_server.rs
@@ -497,10 +497,9 @@ impl server::Literal for Rustc {
}
fn integer(&mut self, n: &str) -> Self::Literal {
- let n = if let Ok(n) = n.parse::<i128>() {
- n.to_string()
- } else {
- n.parse::<u128>().unwrap().to_string()
+ let n = match n.parse::<i128>() {
+ Ok(n) => n.to_string(),
+ Err(_) => n.parse::<u128>().unwrap().to_string(),
};
Literal { text: n.into(), id: tt::TokenId::unspecified() }
}
diff --git a/crates/proc_macro_srv/src/abis/abi_1_55/rustc_server.rs b/crates/proc_macro_srv/src/abis/abi_1_55/rustc_server.rs
index 56f9853399..498fa7ea2d 100644
--- a/crates/proc_macro_srv/src/abis/abi_1_55/rustc_server.rs
+++ b/crates/proc_macro_srv/src/abis/abi_1_55/rustc_server.rs
@@ -500,10 +500,9 @@ impl server::Literal for Rustc {
}
fn integer(&mut self, n: &str) -> Self::Literal {
- let n = if let Ok(n) = n.parse::<i128>() {
- n.to_string()
- } else {
- n.parse::<u128>().unwrap().to_string()
+ let n = match n.parse::<i128>() {
+ Ok(n) => n.to_string(),
+ Err(_) => n.parse::<u128>().unwrap().to_string(),
};
Literal { text: n.into(), id: tt::TokenId::unspecified() }
}
diff --git a/crates/proc_macro_srv/src/abis/abi_1_56/rustc_server.rs b/crates/proc_macro_srv/src/abis/abi_1_56/rustc_server.rs
index c1064ae968..fb8a4c8cbe 100644
--- a/crates/proc_macro_srv/src/abis/abi_1_56/rustc_server.rs
+++ b/crates/proc_macro_srv/src/abis/abi_1_56/rustc_server.rs
@@ -504,10 +504,9 @@ impl server::Literal for Rustc {
}
fn integer(&mut self, n: &str) -> Self::Literal {
- let n = if let Ok(n) = n.parse::<i128>() {
- n.to_string()
- } else {
- n.parse::<u128>().unwrap().to_string()
+ let n = match n.parse::<i128>() {
+ Ok(n) => n.to_string(),
+ Err(_) => n.parse::<u128>().unwrap().to_string(),
};
Literal { text: n.into(), id: tt::TokenId::unspecified() }
}
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index e62bb9499f..6cb6b0a8d0 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -427,10 +427,9 @@ pub(crate) fn handle_workspace_symbol(
// If no explicit marker was set, check request params. If that's also empty
// use global config.
if !all_symbols {
- let search_kind = if let Some(ref search_kind) = params.search_kind {
- search_kind
- } else {
- &config.search_kind
+ let search_kind = match params.search_kind {
+ Some(ref search_kind) => search_kind,
+ None => &config.search_kind,
};
all_symbols = match search_kind {
lsp_ext::WorkspaceSymbolSearchKind::OnlyTypes => false,
@@ -439,10 +438,9 @@ pub(crate) fn handle_workspace_symbol(
}
if !libs {
- let search_scope = if let Some(ref search_scope) = params.search_scope {
- search_scope
- } else {
- &config.search_scope
+ let search_scope = match params.search_scope {
+ Some(ref search_scope) => search_scope,
+ None => &config.search_scope,
};
libs = match search_scope {
lsp_ext::WorkspaceSymbolSearchScope::Workspace => false,
diff --git a/crates/syntax/src/ast/edit_in_place.rs b/crates/syntax/src/ast/edit_in_place.rs
index d304e215b4..552d6fc1e3 100644
--- a/crates/syntax/src/ast/edit_in_place.rs
+++ b/crates/syntax/src/ast/edit_in_place.rs
@@ -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()),
}
}
}
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index b4ad26c13a..d1888d165c 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -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),
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index 00babfd394..2e6544f090 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -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),
}
}
}
diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs
index 6946f35ea5..2f8312d5d1 100644
--- a/crates/syntax/src/ast/token_ext.rs
+++ b/crates/syntax/src/ast/token_ext.rs
@@ -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,
}
}
_ => {
diff --git a/crates/syntax/src/tests.rs b/crates/syntax/src/tests.rs
index f8f7a3ad32..022db39f33 100644
--- a/crates/syntax/src/tests.rs
+++ b/crates/syntax/src/tests.rs
@@ -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() {
diff --git a/crates/tt/src/buffer.rs b/crates/tt/src/buffer.rs
index 3ce72fea85..1fa61c41dd 100644
--- a/crates/tt/src/buffer.rs
+++ b/crates/tt/src/buffer.rs
@@ -205,10 +205,9 @@ impl<'a> Cursor<'a> {
/// Bump the cursor
pub fn bump(self) -> Cursor<'a> {
if let Some(Entry::End(exit)) = self.buffer.entry(&self.ptr) {
- if let Some(exit) = exit {
- Cursor::create(self.buffer, *exit)
- } else {
- self
+ match exit {
+ Some(exit) => Cursor::create(self.buffer, *exit),
+ None => self,
}
} else {
Cursor::create(self.buffer, EntryPtr(self.ptr.0, self.ptr.1 + 1))