Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/base-db/src/input.rs6
-rw-r--r--crates/hir-expand/src/ast_id_map.rs10
-rw-r--r--crates/hir-expand/src/attrs.rs4
-rw-r--r--crates/hir-expand/src/builtin_derive_macro.rs2
-rw-r--r--crates/hir-expand/src/builtin_fn_macro.rs8
-rw-r--r--crates/hir-expand/src/db.rs14
-rw-r--r--crates/hir-expand/src/fixup.rs2
-rw-r--r--crates/hir-expand/src/lib.rs16
-rw-r--r--crates/hir-expand/src/mod_path.rs2
-rw-r--r--crates/hir-expand/src/quote.rs4
-rw-r--r--crates/hir-ty/src/chalk_db.rs2
-rw-r--r--crates/hir-ty/src/chalk_ext.rs4
-rw-r--r--crates/hir-ty/src/consteval.rs6
-rw-r--r--crates/hir-ty/src/diagnostics/decl_check.rs2
-rw-r--r--crates/hir-ty/src/diagnostics/expr.rs4
-rw-r--r--crates/hir-ty/src/diagnostics/match_check/usefulness.rs2
-rw-r--r--crates/hir-ty/src/display.rs27
-rw-r--r--crates/hir-ty/src/infer.rs27
-rw-r--r--crates/hir-ty/src/infer/cast.rs1
-rw-r--r--crates/hir-ty/src/infer/closure.rs7
-rw-r--r--crates/hir-ty/src/infer/expr.rs9
-rw-r--r--crates/hir-ty/src/infer/pat.rs10
-rw-r--r--crates/hir-ty/src/infer/path.rs2
-rw-r--r--crates/hir-ty/src/infer/unify.rs9
-rw-r--r--crates/hir-ty/src/interner.rs2
-rw-r--r--crates/hir-ty/src/layout.rs4
-rw-r--r--crates/hir-ty/src/layout/adt.rs2
-rw-r--r--crates/hir-ty/src/layout/target.rs2
-rw-r--r--crates/hir-ty/src/layout/tests.rs8
-rw-r--r--crates/hir-ty/src/layout/tests/closure.rs12
-rw-r--r--crates/hir-ty/src/lib.rs2
-rw-r--r--crates/hir-ty/src/lower.rs8
-rw-r--r--crates/hir-ty/src/method_resolution.rs9
-rw-r--r--crates/hir-ty/src/mir.rs16
-rw-r--r--crates/hir-ty/src/mir/borrowck.rs21
-rw-r--r--crates/hir-ty/src/mir/eval.rs136
-rw-r--r--crates/hir-ty/src/mir/eval/shim.rs51
-rw-r--r--crates/hir-ty/src/mir/eval/shim/simd.rs4
-rw-r--r--crates/hir-ty/src/mir/eval/tests.rs6
-rw-r--r--crates/hir-ty/src/mir/lower.rs107
-rw-r--r--crates/hir-ty/src/mir/lower/as_place.rs8
-rw-r--r--crates/hir-ty/src/mir/lower/pattern_matching.rs56
-rw-r--r--crates/hir-ty/src/mir/monomorphization.rs2
-rw-r--r--crates/hir-ty/src/mir/pretty.rs2
-rw-r--r--crates/hir-ty/src/test_db.rs4
-rw-r--r--crates/hir-ty/src/utils.rs2
-rw-r--r--crates/ide-assists/src/handlers/add_missing_match_arms.rs4
-rw-r--r--crates/ide-assists/src/handlers/add_turbo_fish.rs4
-rw-r--r--crates/ide-assists/src/handlers/bool_to_enum.rs4
-rw-r--r--crates/ide-assists/src/handlers/change_visibility.rs2
-rw-r--r--crates/ide-assists/src/handlers/convert_match_to_let_else.rs2
-rw-r--r--crates/ide-assists/src/handlers/convert_to_guarded_return.rs4
-rw-r--r--crates/ide-assists/src/handlers/destructure_tuple_binding.rs8
-rw-r--r--crates/ide-assists/src/handlers/extract_module.rs2
-rw-r--r--crates/ide-assists/src/handlers/extract_type_alias.rs2
-rw-r--r--crates/ide-assists/src/handlers/extract_variable.rs2
-rw-r--r--crates/ide-assists/src/handlers/flip_trait_bound.rs4
-rw-r--r--crates/ide-assists/src/handlers/generate_constant.rs7
-rw-r--r--crates/ide-assists/src/handlers/generate_delegate_methods.rs2
-rw-r--r--crates/ide-assists/src/handlers/generate_delegate_trait.rs30
-rw-r--r--crates/ide-assists/src/handlers/generate_documentation_template.rs2
-rw-r--r--crates/ide-assists/src/handlers/generate_enum_variant.rs4
-rw-r--r--crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs2
-rw-r--r--crates/ide-assists/src/handlers/generate_getter_or_setter.rs12
-rw-r--r--crates/ide-assists/src/handlers/generate_is_empty_from_len.rs2
-rw-r--r--crates/ide-assists/src/handlers/generate_trait_from_impl.rs5
-rw-r--r--crates/ide-assists/src/handlers/inline_const_as_literal.rs18
-rw-r--r--crates/ide-assists/src/handlers/inline_macro.rs2
-rw-r--r--crates/ide-assists/src/handlers/introduce_named_generic.rs2
-rw-r--r--crates/ide-assists/src/handlers/remove_unused_imports.rs10
-rw-r--r--crates/ide-assists/src/handlers/replace_if_let_with_match.rs2
-rw-r--r--crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs2
-rw-r--r--crates/ide-assists/src/handlers/replace_method_eager_lazy.rs2
-rw-r--r--crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs2
-rw-r--r--crates/ide-assists/src/handlers/unwrap_block.rs2
-rw-r--r--crates/ide-assists/src/tests.rs2
-rw-r--r--crates/ide-assists/src/tests/sourcegen.rs2
-rw-r--r--crates/ide-assists/src/utils.rs4
-rw-r--r--crates/ide-assists/src/utils/gen_trait_fn_body.rs4
-rw-r--r--crates/ide-completion/src/completions/attribute.rs4
-rw-r--r--crates/ide-completion/src/completions/env_vars.rs2
-rw-r--r--crates/ide-completion/src/completions/flyimport.rs12
-rw-r--r--crates/ide-completion/src/completions/fn_param.rs2
-rw-r--r--crates/ide-completion/src/completions/postfix.rs4
-rw-r--r--crates/ide-completion/src/completions/snippet.rs4
-rw-r--r--crates/ide-completion/src/context/analysis.rs26
-rw-r--r--crates/ide-completion/src/item.rs2
-rw-r--r--crates/ide-completion/src/render/function.rs4
-rw-r--r--crates/ide-db/src/active_parameter.rs22
-rw-r--r--crates/ide-db/src/imports/import_assets.rs2
-rw-r--r--crates/ide-db/src/imports/merge_imports.rs4
-rw-r--r--crates/ide-db/src/lib.rs6
-rw-r--r--crates/ide-db/src/path_transform.rs2
-rw-r--r--crates/ide-db/src/rename.rs2
-rw-r--r--crates/ide-db/src/search.rs6
-rw-r--r--crates/ide-db/src/symbol_index.rs6
-rw-r--r--crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/expected_function.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/inactive_code.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/incoherent_impl.rs4
-rw-r--r--crates/ide-diagnostics/src/handlers/incorrect_case.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/invalid_derive_target.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/macro_error.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/malformed_derive.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs4
-rw-r--r--crates/ide-diagnostics/src/handlers/missing_fields.rs9
-rw-r--r--crates/ide-diagnostics/src/handlers/missing_match_arms.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/missing_unsafe.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/moved_out_of_ref.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/mutability_errors.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/no_such_field.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/private_assoc_item.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/private_field.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/trait_impl_orphan.rs5
-rw-r--r--crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs11
-rw-r--r--crates/ide-diagnostics/src/handlers/type_mismatch.rs8
-rw-r--r--crates/ide-diagnostics/src/handlers/typed_hole.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/undeclared_label.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/unimplemented_builtin_macro.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/unreachable_label.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/unresolved_assoc_item.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/unresolved_extern_crate.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/unresolved_import.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/unresolved_module.rs2
-rw-r--r--crates/ide-diagnostics/src/lib.rs8
-rw-r--r--crates/ide-ssr/src/fragments.rs4
-rw-r--r--crates/ide-ssr/src/matching.rs2
-rw-r--r--crates/ide-ssr/src/search.rs2
-rw-r--r--crates/ide/src/annotations/fn_references.rs2
-rw-r--r--crates/ide/src/doc_links.rs8
-rw-r--r--crates/ide/src/doc_links/tests.rs24
-rw-r--r--crates/ide/src/fetch_crates.rs2
-rw-r--r--crates/ide/src/highlight_related.rs3
-rw-r--r--crates/ide/src/hover/render.rs10
-rw-r--r--crates/ide/src/inlay_hints.rs2
-rw-r--r--crates/ide/src/inlay_hints/fn_lifetime_fn.rs4
-rw-r--r--crates/ide/src/inlay_hints/implicit_drop.rs5
-rw-r--r--crates/ide/src/interpret_function.rs2
-rw-r--r--crates/ide/src/lib.rs8
-rw-r--r--crates/ide/src/navigation_target.rs2
-rw-r--r--crates/ide/src/runnables.rs4
-rw-r--r--crates/ide/src/signature_help.rs12
-rw-r--r--crates/ide/src/typing.rs4
-rw-r--r--crates/ide/src/view_crate_graph.rs2
-rw-r--r--crates/ide/src/view_memory_layout.rs4
-rw-r--r--crates/mbe/src/expander/transcriber.rs2
-rw-r--r--crates/mbe/src/lib.rs2
-rw-r--r--crates/mbe/src/syntax_bridge.rs4
-rw-r--r--crates/project-model/src/cargo_workspace.rs2
-rw-r--r--crates/project-model/src/sysroot.rs9
-rw-r--r--crates/project-model/src/tests.rs2
-rw-r--r--crates/project-model/src/workspace.rs10
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs2
-rw-r--r--crates/rust-analyzer/src/cli/diagnostics.rs2
-rw-r--r--crates/rust-analyzer/src/cli/lsif.rs5
-rw-r--r--crates/rust-analyzer/src/cli/progress_report.rs2
-rw-r--r--crates/rust-analyzer/src/cli/scip.rs4
-rw-r--r--crates/rust-analyzer/src/config.rs14
-rw-r--r--crates/rust-analyzer/src/diagnostics.rs2
-rw-r--r--crates/rust-analyzer/src/global_state.rs4
-rw-r--r--crates/rust-analyzer/src/handlers/request.rs24
-rw-r--r--crates/rust-analyzer/src/lsp/from_proto.rs2
-rw-r--r--crates/rust-analyzer/src/lsp/semantic_tokens.rs2
-rw-r--r--crates/rust-analyzer/src/lsp/to_proto.rs8
-rw-r--r--crates/rust-analyzer/src/main_loop.rs4
-rw-r--r--crates/rust-analyzer/src/reload.rs2
-rw-r--r--crates/rust-analyzer/tests/slow-tests/testdir.rs4
-rw-r--r--crates/span/src/map.rs2
-rw-r--r--crates/syntax/src/algo.rs4
-rw-r--r--crates/syntax/src/ast/node_ext.rs8
-rw-r--r--crates/syntax/src/ast/token_ext.rs64
-rw-r--r--crates/syntax/src/ptr.rs4
-rw-r--r--crates/test-fixture/src/lib.rs2
-rw-r--r--lib/lsp-server/src/lib.rs18
175 files changed, 592 insertions, 735 deletions
diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs
index 8c43f97b91..3f84657d01 100644
--- a/crates/base-db/src/input.rs
+++ b/crates/base-db/src/input.rs
@@ -639,7 +639,7 @@ impl CrateGraph {
let res = self.arena.iter().find_map(|(id, data)| {
match (&data.origin, &crate_data.origin) {
(a, b) if a == b => {
- if data.eq_ignoring_origin_and_deps(&crate_data, false) {
+ if data.eq_ignoring_origin_and_deps(crate_data, false) {
return Some((id, false));
}
}
@@ -651,8 +651,8 @@ impl CrateGraph {
// version and discard the library one as the local version may have
// dev-dependencies that we want to keep resolving. See #15656 for more
// information.
- if data.eq_ignoring_origin_and_deps(&crate_data, true) {
- return Some((id, if a.is_local() { false } else { true }));
+ if data.eq_ignoring_origin_and_deps(crate_data, true) {
+ return Some((id, !a.is_local()));
}
}
(_, _) => return None,
diff --git a/crates/hir-expand/src/ast_id_map.rs b/crates/hir-expand/src/ast_id_map.rs
index d0d229e131..7bdd6db932 100644
--- a/crates/hir-expand/src/ast_id_map.rs
+++ b/crates/hir-expand/src/ast_id_map.rs
@@ -191,7 +191,7 @@ impl AstIdMap {
/// The [`AstId`] of the root node
pub fn root(&self) -> SyntaxNodePtr {
- self.arena[Idx::from_raw(RawIdx::from_u32(0))].clone()
+ self.arena[Idx::from_raw(RawIdx::from_u32(0))]
}
pub fn ast_id<N: AstIdNode>(&self, item: &N) -> FileAstId<N> {
@@ -213,11 +213,11 @@ impl AstIdMap {
}
pub fn get<N: AstIdNode>(&self, id: FileAstId<N>) -> AstPtr<N> {
- AstPtr::try_from_raw(self.arena[id.raw].clone()).unwrap()
+ AstPtr::try_from_raw(self.arena[id.raw]).unwrap()
}
pub fn get_erased(&self, id: ErasedFileAstId) -> SyntaxNodePtr {
- self.arena[id].clone()
+ self.arena[id]
}
fn erased_ast_id(&self, item: &SyntaxNode) -> ErasedFileAstId {
@@ -239,9 +239,7 @@ impl AstIdMap {
}
fn hash_ptr(ptr: &SyntaxNodePtr) -> u64 {
- let mut hasher = BuildHasherDefault::<FxHasher>::default().build_hasher();
- ptr.hash(&mut hasher);
- hasher.finish()
+ BuildHasherDefault::<FxHasher>::default().hash_one(ptr)
}
#[derive(Copy, Clone, PartialEq, Eq)]
diff --git a/crates/hir-expand/src/attrs.rs b/crates/hir-expand/src/attrs.rs
index bd0f81881e..67a318afd0 100644
--- a/crates/hir-expand/src/attrs.rs
+++ b/crates/hir-expand/src/attrs.rs
@@ -31,7 +31,7 @@ impl ops::Deref for RawAttrs {
fn deref(&self) -> &[Attr] {
match &self.entries {
- Some(it) => &*it,
+ Some(it) => it,
None => &[],
}
}
@@ -79,7 +79,7 @@ impl RawAttrs {
Self {
entries: Some(Arc::from_iter(a.iter().cloned().chain(b.iter().map(|it| {
let mut it = it.clone();
- it.id.id = it.id.ast_index() as u32 + last_ast_index
+ it.id.id = (it.id.ast_index() as u32 + last_ast_index)
| (it.id.cfg_attr_index().unwrap_or(0) as u32)
<< AttrId::AST_INDEX_BITS;
it
diff --git a/crates/hir-expand/src/builtin_derive_macro.rs b/crates/hir-expand/src/builtin_derive_macro.rs
index 46bbb7f92c..024fb8c1f6 100644
--- a/crates/hir-expand/src/builtin_derive_macro.rs
+++ b/crates/hir-expand/src/builtin_derive_macro.rs
@@ -425,7 +425,7 @@ fn clone_expand(span: Span, tt: &ast::Adt, tm: SpanMapRef<'_>) -> ExpandResult<t
let name = &adt.name;
let patterns = adt.shape.as_pattern(span, name);
let exprs = adt.shape.as_pattern_map(name, |it| quote! {span => #it .clone() }, span);
- let arms = patterns.into_iter().zip(exprs.into_iter()).map(|(pat, expr)| {
+ let arms = patterns.into_iter().zip(exprs).map(|(pat, expr)| {
let fat_arrow = fat_arrow(span);
quote! {span =>
#pat #fat_arrow #expr,
diff --git a/crates/hir-expand/src/builtin_fn_macro.rs b/crates/hir-expand/src/builtin_fn_macro.rs
index c892f462d2..8fc78b3eca 100644
--- a/crates/hir-expand/src/builtin_fn_macro.rs
+++ b/crates/hir-expand/src/builtin_fn_macro.rs
@@ -125,7 +125,7 @@ fn mk_pound(span: Span) -> tt::Subtree {
vec![crate::tt::Leaf::Punct(crate::tt::Punct {
char: '#',
spacing: crate::tt::Spacing::Alone,
- span: span,
+ span,
})
.into()],
span,
@@ -279,9 +279,9 @@ fn format_args_expand_general(
let pound = mk_pound(span);
let mut tt = tt.clone();
tt.delimiter.kind = tt::DelimiterKind::Parenthesis;
- return ExpandResult::ok(quote! {span =>
+ ExpandResult::ok(quote! {span =>
builtin #pound format_args #tt
- });
+ })
}
fn asm_expand(
@@ -624,7 +624,7 @@ fn relative_file(
fn parse_string(tt: &tt::Subtree) -> Result<String, ExpandError> {
tt.token_trees
- .get(0)
+ .first()
.and_then(|tt| match tt {
tt::TokenTree::Leaf(tt::Leaf::Literal(it)) => unquote_str(it),
_ => None,
diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs
index 035664c644..2f8c0951b1 100644
--- a/crates/hir-expand/src/db.rs
+++ b/crates/hir-expand/src/db.rs
@@ -633,8 +633,8 @@ fn decl_macro_expander(
map.as_ref(),
map.span_for_range(macro_rules.macro_rules_token().unwrap().text_range()),
);
- let mac = mbe::DeclarativeMacro::parse_macro_rules(&tt, is_2021, new_meta_vars);
- mac
+
+ mbe::DeclarativeMacro::parse_macro_rules(&tt, is_2021, new_meta_vars)
}
None => mbe::DeclarativeMacro::from_err(
mbe::ParseError::Expected("expected a token tree".into()),
@@ -651,8 +651,8 @@ fn decl_macro_expander(
map.as_ref(),
map.span_for_range(macro_def.macro_token().unwrap().text_range()),
);
- let mac = mbe::DeclarativeMacro::parse_macro2(&tt, is_2021, new_meta_vars);
- mac
+
+ mbe::DeclarativeMacro::parse_macro2(&tt, is_2021, new_meta_vars)
}
None => mbe::DeclarativeMacro::from_err(
mbe::ParseError::Expected("expected a token tree".into()),
@@ -722,7 +722,7 @@ fn macro_expand(
db.decl_macro_expander(loc.def.krate, id).expand(db, arg.clone(), macro_call_id)
}
MacroDefKind::BuiltIn(it, _) => {
- it.expand(db, macro_call_id, &arg).map_err(Into::into)
+ it.expand(db, macro_call_id, arg).map_err(Into::into)
}
// This might look a bit odd, but we do not expand the inputs to eager macros here.
// Eager macros inputs are expanded, well, eagerly when we collect the macro calls.
@@ -746,10 +746,10 @@ fn macro_expand(
};
}
MacroDefKind::BuiltInEager(it, _) => {
- it.expand(db, macro_call_id, &arg).map_err(Into::into)
+ it.expand(db, macro_call_id, arg).map_err(Into::into)
}
MacroDefKind::BuiltInAttr(it, _) => {
- let mut res = it.expand(db, macro_call_id, &arg);
+ let mut res = it.expand(db, macro_call_id, arg);
fixup::reverse_fixups(&mut res.value, &undo_info);
res
}
diff --git a/crates/hir-expand/src/fixup.rs b/crates/hir-expand/src/fixup.rs
index d241d94b8c..492501f5b6 100644
--- a/crates/hir-expand/src/fixup.rs
+++ b/crates/hir-expand/src/fixup.rs
@@ -68,7 +68,7 @@ pub(crate) fn fixup_syntax(
let node_range = node.text_range();
if can_handle_error(&node) && has_error_to_handle(&node) {
- remove.insert(node.clone().into());
+ remove.insert(node.clone());
// the node contains an error node, we have to completely replace it by something valid
let original_tree = mbe::syntax_node_to_token_tree(&node, span_map, call_site);
let idx = original.len() as u32;
diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs
index ae7d17e49a..bd216ccca8 100644
--- a/crates/hir-expand/src/lib.rs
+++ b/crates/hir-expand/src/lib.rs
@@ -77,7 +77,7 @@ macro_rules! impl_intern_lookup {
impl $crate::Intern for $loc {
type Database<'db> = dyn $db + 'db;
type ID = $id;
- fn intern<'db>(self, db: &Self::Database<'db>) -> $id {
+ fn intern(self, db: &Self::Database<'_>) -> $id {
db.$intern(self)
}
}
@@ -85,7 +85,7 @@ macro_rules! impl_intern_lookup {
impl $crate::Lookup for $id {
type Database<'db> = dyn $db + 'db;
type Data = $loc;
- fn lookup<'db>(&self, db: &Self::Database<'db>) -> $loc {
+ fn lookup(&self, db: &Self::Database<'_>) -> $loc {
db.$lookup(*self)
}
}
@@ -96,13 +96,13 @@ macro_rules! impl_intern_lookup {
pub trait Intern {
type Database<'db>: ?Sized;
type ID;
- fn intern<'db>(self, db: &Self::Database<'db>) -> Self::ID;
+ fn intern(self, db: &Self::Database<'_>) -> Self::ID;
}
pub trait Lookup {
type Database<'db>: ?Sized;
type Data;
- fn lookup<'db>(&self, db: &Self::Database<'db>) -> Self::Data;
+ fn lookup(&self, db: &Self::Database<'_>) -> Self::Data;
}
impl_intern_lookup!(
@@ -425,7 +425,7 @@ impl MacroDefId {
pub fn ast_id(&self) -> Either<AstId<ast::Macro>, AstId<ast::Fn>> {
match self.kind {
- MacroDefKind::ProcMacro(.., id) => return Either::Right(id),
+ MacroDefKind::ProcMacro(.., id) => Either::Right(id),
MacroDefKind::Declarative(id)
| MacroDefKind::BuiltIn(_, id)
| MacroDefKind::BuiltInAttr(_, id)
@@ -657,10 +657,10 @@ impl ExpansionInfo {
}
/// Maps the passed in file range down into a macro expansion if it is the input to a macro call.
- pub fn map_range_down<'a>(
- &'a self,
+ pub fn map_range_down(
+ &self,
span: Span,
- ) -> Option<InMacroFile<impl Iterator<Item = SyntaxToken> + 'a>> {
+ ) -> Option<InMacroFile<impl Iterator<Item = SyntaxToken> + '_>> {
let tokens = self
.exp_map
.ranges_with_span(span)
diff --git a/crates/hir-expand/src/mod_path.rs b/crates/hir-expand/src/mod_path.rs
index 30b8c189f5..47a587e407 100644
--- a/crates/hir-expand/src/mod_path.rs
+++ b/crates/hir-expand/src/mod_path.rs
@@ -301,7 +301,7 @@ pub fn resolve_crate_root(db: &dyn ExpandDatabase, mut ctxt: SyntaxContextId) ->
result_mark = Some(mark);
}
- result_mark.flatten().map(|call| db.lookup_intern_macro_call(call.into()).def.krate)
+ result_mark.flatten().map(|call| db.lookup_intern_macro_call(call).def.krate)
}
pub use crate::name as __name;
diff --git a/crates/hir-expand/src/quote.rs b/crates/hir-expand/src/quote.rs
index 91f8c5a5a5..04b427e8b4 100644
--- a/crates/hir-expand/src/quote.rs
+++ b/crates/hir-expand/src/quote.rs
@@ -18,13 +18,13 @@ pub(crate) const fn dollar_crate(span: Span) -> tt::Ident<Span> {
#[macro_export]
macro_rules! __quote {
($span:ident) => {
- Vec::<crate::tt::TokenTree>::new()
+ Vec::<$crate::tt::TokenTree>::new()
};
( @SUBTREE($span:ident) $delim:ident $($tt:tt)* ) => {
{
let children = $crate::__quote!($span $($tt)*);
- crate::tt::Subtree {
+ $crate::tt::Subtree {
delimiter: crate::tt::Delimiter {
kind: crate::tt::DelimiterKind::$delim,
open: $span,
diff --git a/crates/hir-ty/src/chalk_db.rs b/crates/hir-ty/src/chalk_db.rs
index 5b0b16eb9a..f475c1c178 100644
--- a/crates/hir-ty/src/chalk_db.rs
+++ b/crates/hir-ty/src/chalk_db.rs
@@ -230,7 +230,7 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
well_known_trait: rust_ir::WellKnownTrait,
) -> Option<chalk_ir::TraitId<Interner>> {
let lang_attr = lang_item_from_well_known_trait(well_known_trait);
- let trait_ = match self.db.lang_item(self.krate, lang_attr.into()) {
+ let trait_ = match self.db.lang_item(self.krate, lang_attr) {
Some(LangItemTarget::Trait(trait_)) => trait_,
_ => return None,
};
diff --git a/crates/hir-ty/src/chalk_ext.rs b/crates/hir-ty/src/chalk_ext.rs
index c9ab356854..d6d0b34934 100644
--- a/crates/hir-ty/src/chalk_ext.rs
+++ b/crates/hir-ty/src/chalk_ext.rs
@@ -218,7 +218,7 @@ impl TyExt for Ty {
// invariant ensured by `TyLoweringContext::lower_dyn_trait()`.
// FIXME: dyn types may not have principal trait and we don't want to return auto trait
// here.
- TyKind::Dyn(dyn_ty) => dyn_ty.bounds.skip_binders().interned().get(0).and_then(|b| {
+ TyKind::Dyn(dyn_ty) => dyn_ty.bounds.skip_binders().interned().first().and_then(|b| {
match b.skip_binders() {
WhereClause::Implemented(trait_ref) => Some(trait_ref),
_ => None,
@@ -427,7 +427,7 @@ pub trait DynTyExt {
impl DynTyExt for DynTy {
fn principal(&self) -> Option<&TraitRef> {
- self.bounds.skip_binders().interned().get(0).and_then(|b| match b.skip_binders() {
+ self.bounds.skip_binders().interned().first().and_then(|b| match b.skip_binders() {
crate::WhereClause::Implemented(trait_ref) => Some(trait_ref),
_ => None,
})
diff --git a/crates/hir-ty/src/consteval.rs b/crates/hir-ty/src/consteval.rs
index dae612e6d2..705609ba68 100644
--- a/crates/hir-ty/src/consteval.rs
+++ b/crates/hir-ty/src/consteval.rs
@@ -173,7 +173,7 @@ pub fn try_const_usize(db: &dyn HirDatabase, c: &Const) -> Option<u128> {
chalk_ir::ConstValue::InferenceVar(_) => None,
chalk_ir::ConstValue::Placeholder(_) => None,
chalk_ir::ConstValue::Concrete(c) => match &c.interned {
- ConstScalar::Bytes(it, _) => Some(u128::from_le_bytes(pad16(&it, false))),
+ ConstScalar::Bytes(it, _) => Some(u128::from_le_bytes(pad16(it, false))),
ConstScalar::UnevaluatedConst(c, subst) => {
let ec = db.const_eval(*c, subst.clone(), None).ok()?;
try_const_usize(db, &ec)
@@ -298,7 +298,7 @@ pub(crate) fn eval_to_const(
body[expr].walk_child_exprs(|idx| r |= has_closure(body, idx));
r
}
- if has_closure(&ctx.body, expr) {
+ if has_closure(ctx.body, expr) {
// Type checking clousres need an isolated body (See the above FIXME). Bail out early to prevent panic.
return unknown_const(infer[expr].clone());
}
@@ -308,7 +308,7 @@ pub(crate) fn eval_to_const(
return c;
}
}
- if let Ok(mir_body) = lower_to_mir(ctx.db, ctx.owner, &ctx.body, &infer, expr) {
+ if let Ok(mir_body) = lower_to_mir(ctx.db, ctx.owner, ctx.body, &infer, expr) {
if let Ok(result) = interpret_mir(db, Arc::new(mir_body), true, None).0 {
return result;
}
diff --git a/crates/hir-ty/src/diagnostics/decl_check.rs b/crates/hir-ty/src/diagnostics/decl_check.rs
index 7ea1b9e421..a37dba4805 100644
--- a/crates/hir-ty/src/diagnostics/decl_check.rs
+++ b/crates/hir-ty/src/diagnostics/decl_check.rs
@@ -387,7 +387,7 @@ impl<'a> DeclValidator<'a> {
for (id, replacement) in pats_replacements {
if let Ok(source_ptr) = source_map.pat_syntax(id) {
- if let Some(ptr) = source_ptr.value.clone().cast::<ast::IdentPat>() {
+ if let Some(ptr) = source_ptr.value.cast::<ast::IdentPat>() {
let root = source_ptr.file_syntax(self.db.upcast());
let ident_pat = ptr.to_node(&root);
let parent = match ident_pat.syntax().parent() {
diff --git a/crates/hir-ty/src/diagnostics/expr.rs b/crates/hir-ty/src/diagnostics/expr.rs
index ab34dc88d8..6c09a67233 100644
--- a/crates/hir-ty/src/diagnostics/expr.rs
+++ b/crates/hir-ty/src/diagnostics/expr.rs
@@ -141,8 +141,8 @@ impl ExprValidator {
);
}
}
- _ => return,
- };
+ _ => (),
+ }
}
fn validate_match(
diff --git a/crates/hir-ty/src/diagnostics/match_check/usefulness.rs b/crates/hir-ty/src/diagnostics/match_check/usefulness.rs
index d737b24ad3..1b1a5ff269 100644
--- a/crates/hir-ty/src/diagnostics/match_check/usefulness.rs
+++ b/crates/hir-ty/src/diagnostics/match_check/usefulness.rs
@@ -409,7 +409,7 @@ impl<'p> Matrix<'p> {
/// Number of columns of this matrix. `None` is the matrix is empty.
pub(super) fn _column_count(&self) -> Option<usize> {
- self.patterns.get(0).map(|r| r.len())
+ self.patterns.first().map(|r| r.len())
}
/// Pushes a new row to the matrix. If the row starts with an or-pattern, this recursively
diff --git a/crates/hir-ty/src/display.rs b/crates/hir-ty/src/display.rs
index 3a0ec6a582..750e159727 100644
--- a/crates/hir-ty/src/display.rs
+++ b/crates/hir-ty/src/display.rs
@@ -427,7 +427,7 @@ impl HirDisplay for Const {
Ok(())
}
ConstValue::Concrete(c) => match &c.interned {
- ConstScalar::Bytes(b, m) => render_const_scalar(f, &b, m, &data.ty),
+ ConstScalar::Bytes(b, m) => render_const_scalar(f, b, m, &data.ty),
ConstScalar::UnevaluatedConst(c, parameters) => {
write!(f, "{}", c.name(f.db.upcast()))?;
hir_fmt_generics(f, parameters, c.generic_def(f.db.upcast()))?;
@@ -451,7 +451,7 @@ fn render_const_scalar(
TraitEnvironment::empty(*f.db.crate_graph().crates_in_topological_order().last().unwrap());
match ty.kind(Interner) {
TyKind::Scalar(s) => match s {
- Scalar::Bool => write!(f, "{}", if b[0] == 0 { false } else { true }),
+ Scalar::Bool => write!(f, "{}", b[0] != 0),
Scalar::Char => {
let it = u128::from_le_bytes(pad16(b, false)) as u32;
let Ok(c) = char::try_from(it) else {
@@ -485,7 +485,7 @@ fn render_const_scalar(
let Some(bytes) = memory_map.get(addr, size) else {
return f.write_str("<ref-data-not-available>");
};
- let s = std::str::from_utf8(&bytes).unwrap_or("<utf8-error>");
+ let s = std::str::from_utf8(bytes).unwrap_or("<utf8-error>");
write!(f, "{s:?}")
}
TyKind::Slice(ty) => {
@@ -507,7 +507,7 @@ fn render_const_scalar(
f.write_str(", ")?;
}
let offset = size_one * i;
- render_const_scalar(f, &bytes[offset..offset + size_one], memory_map, &ty)?;
+ render_const_scalar(f, &bytes[offset..offset + size_one], memory_map, ty)?;
}
f.write_str("]")
}
@@ -533,9 +533,7 @@ fn render_const_scalar(
write!(f, "&{}", data.name.display(f.db.upcast()))?;
Ok(())
}
- _ => {
- return f.write_str("<unsized-enum-or-union>");
- }
+ _ => f.write_str("<unsized-enum-or-union>"),
},
_ => {
let addr = usize::from_le_bytes(match b.try_into() {
@@ -579,7 +577,7 @@ fn render_const_scalar(
continue;
};
let size = layout.size.bytes_usize();
- render_const_scalar(f, &b[offset..offset + size], memory_map, &ty)?;
+ render_const_scalar(f, &b[offset..offset + size], memory_map, ty)?;
}
f.write_str(")")
}
@@ -620,7 +618,7 @@ fn render_const_scalar(
f,
&field_types,
f.db.trait_environment(adt.0.into()),
- &var_layout,
+ var_layout,
subst,
b,
memory_map,
@@ -651,7 +649,7 @@ fn render_const_scalar(
f.write_str(", ")?;
}
let offset = size_one * i;
- render_const_scalar(f, &b[offset..offset + size_one], memory_map, &ty)?;
+ render_const_scalar(f, &b[offset..offset + size_one], memory_map, ty)?;
}
f.write_str("]")
}
@@ -718,7 +716,7 @@ fn render_variant_after_name(
}
write!(f, ")")?;
}
- return Ok(());
+ Ok(())
}
VariantData::Unit => Ok(()),
}
@@ -864,7 +862,7 @@ impl HirDisplay for Ty {
write!(f, ",)")?;
} else {
write!(f, "(")?;
- f.write_joined(&*substs.as_slice(Interner), ", ")?;
+ f.write_joined(substs.as_slice(Interner), ", ")?;
write!(f, ")")?;
}
}
@@ -1210,8 +1208,7 @@ impl HirDisplay for Ty {
let subst = subst.as_slice(Interner);
let a: Option<SmallVec<[&Ty; 3]>> = subst
.get(subst.len() - 3..)
- .map(|args| args.iter().map(|arg| arg.ty(Interner)).collect())
- .flatten();
+ .and_then(|args| args.iter().map(|arg| arg.ty(Interner)).collect());
if let Some([resume_ty, yield_ty, ret_ty]) = a.as_deref() {
write!(f, "|")?;
@@ -1422,7 +1419,7 @@ fn write_bounds_like_dyn_trait(
f.start_location_link(trait_.into());
write!(f, "{}", f.db.trait_data(trait_).name.display(f.db.upcast()))?;
f.end_location_link();
- if let [_, params @ ..] = &*trait_ref.substitution.as_slice(Interner) {
+ if let [_, params @ ..] = trait_ref.substitution.as_slice(Interner) {
if is_fn_trait {
if let Some(args) =
params.first().and_then(|it| it.assert_ty_ref(Interner).as_tuple())
diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs
index 2aff53a4ac..c3ef6c9b35 100644
--- a/crates/hir-ty/src/infer.rs
+++ b/crates/hir-ty/src/infer.rs
@@ -88,7 +88,7 @@ pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<Infer
DefWithBodyId::StaticId(s) => ctx.collect_static(&db.static_data(s)),
DefWithBodyId::VariantId(v) => {
ctx.return_ty = TyBuilder::builtin(
- match db.enum_data(v.lookup(db.upcast()).parent.into()).variant_body_type() {
+ match db.enum_data(v.lookup(db.upcast()).parent).variant_body_type() {
hir_def::layout::IntegerType::Pointer(signed) => match signed {
true => BuiltinType::Int(BuiltinInt::Isize),
false => BuiltinType::Uint(BuiltinUint::Usize),
@@ -156,8 +156,9 @@ pub(crate) fn normalize(db: &dyn HirDatabase, trait_env: Arc<TraitEnvironment>,
/// Binding modes inferred for patterns.
/// <https://doc.rust-lang.org/reference/patterns.html#binding-modes>
-#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)]
pub enum BindingMode {
+ #[default]
Move,
Ref(Mutability),
}
@@ -172,12 +173,6 @@ impl BindingMode {
}
}
-impl Default for BindingMode {
- fn default() -> Self {
- BindingMode::Move
- }
-}
-
#[derive(Debug)]
pub(crate) struct InferOk<T> {
value: T,
@@ -572,10 +567,10 @@ enum BreakableKind {
Border,
}
-fn find_breakable<'c>(
- ctxs: &'c mut [BreakableContext],
+fn find_breakable(
+ ctxs: &mut [BreakableContext],
label: Option<LabelId>,
-) -> Option<&'c mut BreakableContext> {
+) -> Option<&mut BreakableContext> {
let mut ctxs = ctxs
.iter_mut()
.rev()
@@ -586,10 +581,10 @@ fn find_breakable<'c>(
}
}
-fn find_continuable<'c>(
- ctxs: &'c mut [BreakableContext],
+fn find_continuable(
+ ctxs: &mut [BreakableContext],
label: Option<LabelId>,
-) -> Option<&'c mut BreakableContext> {
+) -> Option<&mut BreakableContext> {
match label {
Some(_) => find_breakable(ctxs, label).filter(|it| matches!(it.kind, BreakableKind::Loop)),
None => find_breakable(ctxs, label),
@@ -825,8 +820,8 @@ impl<'a> InferenceContext<'a> {
ImplTraitId::ReturnTypeImplTrait(_, idx) => idx,
_ => unreachable!(),
};
- let bounds = (*rpits)
- .map_ref(|rpits| rpits.impl_traits[idx].bounds.map_ref(|it| it.into_iter()));
+ let bounds =
+ (*rpits).map_ref(|rpits| rpits.impl_traits[idx].bounds.map_ref(|it| it.iter()));
let var = self.table.new_type_var();
let var_subst = Substitution::from1(Interner, var.clone());
for bound in bounds {
diff --git a/crates/hir-ty/src/infer/cast.rs b/crates/hir-ty/src/infer/cast.rs
index a116d44473..f8c03ee288 100644
--- a/crates/hir-ty/src/infer/cast.rs
+++ b/crates/hir-ty/src/infer/cast.rs
@@ -31,7 +31,6 @@ impl CastCheck {
// Note that this type of cast is actually split into a coercion to a
// pointer type and a cast:
// &[T; N] -> *[T; N] -> *T
- return;
}
// FIXME: Check other kinds of non-coercion casts and report error if any?
diff --git a/crates/hir-ty/src/infer/closure.rs b/crates/hir-ty/src/infer/closure.rs
index c194270b91..4ec82865ac 100644
--- a/crates/hir-ty/src/infer/closure.rs
+++ b/crates/hir-ty/src/infer/closure.rs
@@ -815,8 +815,7 @@ impl InferenceContext<'_> {
.iter()
.cloned()
.chain((0..cnt).map(|_| ProjectionElem::Deref))
- .collect::<Vec<_>>()
- .into();
+ .collect::<Vec<_>>();
match &self.body[pat] {
Pat::Missing | Pat::Wild => (),
Pat::Tuple { args, ellipsis } => {
@@ -858,7 +857,7 @@ impl InferenceContext<'_> {
};
let mut p = place.clone();
p.projections.push(ProjectionElem::Field(Either::Left(FieldId {
- parent: variant.into(),
+ parent: variant,
local_id,
})));
self.consume_with_pat(p, arg);
@@ -902,7 +901,7 @@ impl InferenceContext<'_> {
for (arg, (i, _)) in it {
let mut p = place.clone();
p.projections.push(ProjectionElem::Field(Either::Left(FieldId {
- parent: variant.into(),
+ parent: variant,
local_id: i,
})));
self.consume_with_pat(p, *arg);
diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs
index d4b6999614..a655d1614a 100644
--- a/crates/hir-ty/src/infer/expr.rs
+++ b/crates/hir-ty/src/infer/expr.rs
@@ -276,7 +276,7 @@ impl InferenceContext<'_> {
// Now go through the argument patterns
for (arg_pat, arg_ty) in args.iter().zip(&sig_tys) {
- self.infer_top_pat(*arg_pat, &arg_ty);
+ self.infer_top_pat(*arg_pat, arg_ty);
}
// FIXME: lift these out into a struct
@@ -1081,8 +1081,7 @@ impl InferenceContext<'_> {
let inner_exp = expected
.to_option(table)
.as_ref()
- .map(|e| e.as_adt())
- .flatten()
+ .and_then(|e| e.as_adt())
.filter(|(e_adt, _)| e_adt == &box_id)
.map(|(_, subts)| {
let g = subts.at(Interner, 0);
@@ -1320,7 +1319,7 @@ impl InferenceContext<'_> {
.unwrap_or_else(|| this.table.new_type_var());
let ty = if let Some(expr) = initializer {
- let ty = if contains_explicit_ref_binding(&this.body, *pat) {
+ let ty = if contains_explicit_ref_binding(this.body, *pat) {
this.infer_expr(*expr, &Expectation::has_type(decl_ty.clone()))
} else {
this.infer_expr_coerce(
@@ -1716,7 +1715,7 @@ impl InferenceContext<'_> {
// that we have more information about the types of arguments when we
// type-check the functions. This isn't really the right way to do this.
for check_closures in [false, true] {
- let mut skip_indices = skip_indices.into_iter().copied().fuse().peekable();
+ let mut skip_indices = skip_indices.iter().copied().fuse().peekable();
let param_iter = param_tys.iter().cloned().chain(repeat(self.err_ty()));
let expected_iter = expected_inputs
.iter()
diff --git a/crates/hir-ty/src/infer/pat.rs b/crates/hir-ty/src/infer/pat.rs
index 1bf8babe83..09a4d998ee 100644
--- a/crates/hir-ty/src/infer/pat.rs
+++ b/crates/hir-ty/src/infer/pat.rs
@@ -93,7 +93,7 @@ impl InferenceContext<'_> {
ty.as_adt().map(|(_, s)| s.clone()).unwrap_or_else(|| Substitution::empty(Interner));
match def {
- _ if subs.len() == 0 => {}
+ _ if subs.is_empty() => {}
Some(def) => {
let field_types = self.db.field_types(def);
let variant_data = def.variant_data(self.db.upcast());
@@ -223,13 +223,13 @@ impl InferenceContext<'_> {
) -> Ty {
let expected = self.resolve_ty_shallow(expected);
let expectations = match expected.as_tuple() {
- Some(parameters) => &*parameters.as_slice(Interner),
+ Some(parameters) => parameters.as_slice(Interner),
_ => &[],
};
let ((pre, post), n_uncovered_patterns) = match ellipsis {
Some(idx) => (subs.split_at(idx), expectations.len().saturating_sub(subs.len())),
- None => ((&subs[..], &[][..]), 0),
+ None => ((subs, &[][..]), 0),
};
let mut expectations_iter = expectations
.iter()
@@ -423,7 +423,7 @@ impl InferenceContext<'_> {
self.result.binding_modes.insert(pat, mode);
let inner_ty = match subpat {
- Some(subpat) => self.infer_pat(subpat, &expected, default_bm),
+ Some(subpat) => self.infer_pat(subpat, expected, default_bm),
None => expected.clone(),
};
let inner_ty = self.insert_type_vars_shallow(inner_ty);
@@ -436,7 +436,7 @@ impl InferenceContext<'_> {
};
self.write_pat_ty(pat, inner_ty.clone());
self.write_binding_ty(binding, bound_ty);
- return inner_ty;
+ inner_ty
}
fn infer_slice_pat(
diff --git a/crates/hir-ty/src/infer/path.rs b/crates/hir-ty/src/infer/path.rs
index 19ffac22d1..16ae028427 100644
--- a/crates/hir-ty/src/infer/path.rs
+++ b/crates/hir-ty/src/infer/path.rs
@@ -389,7 +389,7 @@ impl InferenceContext<'_> {
name: &Name,
id: ExprOrPatId,
) -> Option<(ValueNs, Substitution)> {
- let ty = self.resolve_ty_shallow(&ty);
+ let ty = self.resolve_ty_shallow(ty);
let (enum_id, subst) = match ty.as_adt() {
Some((AdtId::EnumId(e), subst)) => (e, subst),
_ => return None,
diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs
index ac39bdf5bf..9c41540077 100644
--- a/crates/hir-ty/src/infer/unify.rs
+++ b/crates/hir-ty/src/infer/unify.rs
@@ -250,9 +250,7 @@ impl<'a> InferenceTable<'a> {
// and registering an obligation. But it needs chalk support, so we handle the most basic
// case (a non associated const without generic parameters) manually.
if subst.len(Interner) == 0 {
- if let Ok(eval) =
- self.db.const_eval((*c_id).into(), subst.clone(), None)
- {
+ if let Ok(eval) = self.db.const_eval(*c_id, subst.clone(), None) {
eval
} else {
unknown_const(c.data(Interner).ty.clone())
@@ -490,9 +488,8 @@ impl<'a> InferenceTable<'a> {
pub(crate) fn try_obligation(&mut self, goal: Goal) -> Option<Solution> {
let in_env = InEnvironment::new(&self.trait_env.env, goal);
let canonicalized = self.canonicalize(in_env);
- let solution =
- self.db.trait_solve(self.trait_env.krate, self.trait_env.block, canonicalized.value);
- solution
+
+ self.db.trait_solve(self.trait_env.krate, self.trait_env.block, canonicalized.value)
}
pub(crate) fn register_obligation(&mut self, goal: Goal) {
diff --git a/crates/hir-ty/src/interner.rs b/crates/hir-ty/src/interner.rs
index eb6296f7a0..3d16fec790 100644
--- a/crates/hir-ty/src/interner.rs
+++ b/crates/hir-ty/src/interner.rs
@@ -387,7 +387,7 @@ impl chalk_ir::interner::HasInterner for Interner {
macro_rules! has_interner {
($t:ty) => {
impl HasInterner for $t {
- type Interner = crate::Interner;
+ type Interner = $crate::Interner;
}
};
}
diff --git a/crates/hir-ty/src/layout.rs b/crates/hir-ty/src/layout.rs
index 5c7decb689..2b84cb6b13 100644
--- a/crates/hir-ty/src/layout.rs
+++ b/crates/hir-ty/src/layout.rs
@@ -202,7 +202,7 @@ pub fn layout_of_ty_query(
return Err(LayoutError::TargetLayoutNotAvailable);
};
let cx = LayoutCx { target: &target };
- let dl = &*cx.current_data_layout();
+ let dl = cx.current_data_layout();
let ty = normalize(db, trait_env.clone(), ty);
let result = match ty.kind(Interner) {
TyKind::Adt(AdtId(def), subst) => {
@@ -278,7 +278,7 @@ pub fn layout_of_ty_query(
cx.univariant(dl, &fields, &ReprOptions::default(), kind).ok_or(LayoutError::Unknown)?
}
TyKind::Array(element, count) => {
- let count = try_const_usize(db, &count).ok_or(LayoutError::HasErrorConst)? as u64;
+ let count = try_const_usize(db, count).ok_or(LayoutError::HasErrorConst)? as u64;
let element = db.layout_of_ty(element.clone(), trait_env)?;
let size = element.size.checked_mul(count, dl).ok_or(LayoutError::SizeOverflow)?;
diff --git a/crates/hir-ty/src/layout/adt.rs b/crates/hir-ty/src/layout/adt.rs
index 9fcc251356..47930358a1 100644
--- a/crates/hir-ty/src/layout/adt.rs
+++ b/crates/hir-ty/src/layout/adt.rs
@@ -80,7 +80,7 @@ pub fn layout_of_adt_query(
matches!(def, AdtId::EnumId(..)),
is_unsafe_cell(db, def),
layout_scalar_valid_range(db, def),
- |min, max| repr_discr(&dl, &repr, min, max).unwrap_or((Integer::I8, false)),
+ |min, max| repr_discr(dl, &repr, min, max).unwrap_or((Integer::I8, false)),
variants.iter_enumerated().filter_map(|(id, _)| {
let AdtId::EnumId(e) = def else { return None };
let d = db.const_eval_discriminant(db.enum_data(e).variants[id.0].0).ok()?;
diff --git a/crates/hir-ty/src/layout/target.rs b/crates/hir-ty/src/layout/target.rs
index 04b940afbe..b2185a03ea 100644
--- a/crates/hir-ty/src/layout/target.rs
+++ b/crates/hir-ty/src/layout/target.rs
@@ -12,7 +12,7 @@ pub fn target_data_layout_query(
) -> Option<Arc<TargetDataLayout>> {
let crate_graph = db.crate_graph();
let target_layout = crate_graph[krate].target_layout.as_ref().ok()?;
- let res = TargetDataLayout::parse_from_llvm_datalayout_string(&target_layout);
+ let res = TargetDataLayout::parse_from_llvm_datalayout_string(target_layout);
if let Err(_e) = &res {
// FIXME: Print the error here once it implements debug/display
// also logging here is somewhat wrong, but unfortunately this is the earliest place we can
diff --git a/crates/hir-ty/src/layout/tests.rs b/crates/hir-ty/src/layout/tests.rs
index 57214193cf..1f2ea753c1 100644
--- a/crates/hir-ty/src/layout/tests.rs
+++ b/crates/hir-ty/src/layout/tests.rs
@@ -366,11 +366,11 @@ fn return_position_impl_trait() {
}
let waker = Arc::new(EmptyWaker).into();
let mut context = Context::from_waker(&waker);
- let x = pinned.poll(&mut context);
- x
+
+ pinned.poll(&mut context)
}
- let x = unwrap_fut(f());
- x
+
+ unwrap_fut(f())
}
size_and_align_expr! {
struct Foo<T>(T, T, (T, T));
diff --git a/crates/hir-ty/src/layout/tests/closure.rs b/crates/hir-ty/src/layout/tests/closure.rs
index 939025461f..dd0e5729b6 100644
--- a/crates/hir-ty/src/layout/tests/closure.rs
+++ b/crates/hir-ty/src/layout/tests/closure.rs
@@ -36,7 +36,7 @@ fn ref_simple() {
let mut y: i32 = 5;
]
|x: i32| {
- y = y + x;
+ y += x;
y
}
}
@@ -66,7 +66,7 @@ fn ref_simple() {
let x: &mut X = &mut X(2, 6);
]
|| {
- (*x).0 as i64 + x.1
+ x.0 as i64 + x.1
}
}
}
@@ -188,9 +188,7 @@ fn match_pattern() {
struct X(i64, i32, (u8, i128));
let _y: X = X(2, 5, (7, 3));
move |x: i64| {
- match _y {
- _ => x,
- }
+ x
}
}
size_and_align_expr! {
@@ -264,8 +262,8 @@ fn regression_15623() {
let c = 5;
move || {
let 0 = a else { return b; };
- let y = c;
- y
+
+ c
}
}
}
diff --git a/crates/hir-ty/src/lib.rs b/crates/hir-ty/src/lib.rs
index e72864a12e..a50e1b1c07 100644
--- a/crates/hir-ty/src/lib.rs
+++ b/crates/hir-ty/src/lib.rs
@@ -228,7 +228,7 @@ impl MemoryMap {
let mut transform = |(addr, val): (&usize, &Box<[u8]>)| {
let addr = *addr;
let align = if addr == 0 { 64 } else { (addr - (addr & (addr - 1))).min(64) };
- f(val, align).and_then(|it| Ok((addr, it)))
+ f(val, align).map(|it| (addr, it))
};
match self {
MemoryMap::Empty => Ok(Default::default()),
diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs
index a07063ba60..2d43fffa6a 100644
--- a/crates/hir-ty/src/lower.rs
+++ b/crates/hir-ty/src/lower.rs
@@ -1192,11 +1192,7 @@ impl<'a> TyLoweringContext<'a> {
return None;
}
- if bounds.first().and_then(|b| b.trait_id()).is_none() {
- // When there's no trait bound, that's an error. This happens when the trait refs
- // are unresolved.
- return None;
- }
+ bounds.first().and_then(|b| b.trait_id())?;
// As multiple occurrences of the same auto traits *are* permitted, we deduplicate the
// bounds. We shouldn't have repeated elements besides auto traits at this point.
@@ -1241,7 +1237,7 @@ impl<'a> TyLoweringContext<'a> {
});
crate::wrap_empty_binders(clause)
});
- predicates.extend(sized_clause.into_iter());
+ predicates.extend(sized_clause);
predicates.shrink_to_fit();
}
predicates
diff --git a/crates/hir-ty/src/method_resolution.rs b/crates/hir-ty/src/method_resolution.rs
index 1c74c24371..f8ce3008f1 100644
--- a/crates/hir-ty/src/method_resolution.rs
+++ b/crates/hir-ty/src/method_resolution.rs
@@ -86,7 +86,7 @@ impl TyFingerprint {
TyKind::Dyn(_) => ty.dyn_trait().map(TyFingerprint::Dyn)?,
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));
+ let first_ty = subst.interned().first().map(|arg| arg.assert_ty_ref(Interner));
match first_ty {
Some(ty) => return TyFingerprint::for_trait_impl(ty),
None => TyFingerprint::Unit,
@@ -541,7 +541,7 @@ impl ReceiverAdjustments {
if let TyKind::Ref(m, l, inner) = ty.kind(Interner) {
if let TyKind::Array(inner, _) = inner.kind(Interner) {
break 'it TyKind::Ref(
- m.clone(),
+ *m,
l.clone(),
TyKind::Slice(inner.clone()).intern(Interner),
)
@@ -953,7 +953,7 @@ pub fn iterate_method_candidates_dyn(
let ty = table.instantiate_canonical(ty.clone());
let deref_chain = autoderef_method_receiver(&mut table, ty);
- let result = deref_chain.into_iter().try_for_each(|(receiver_ty, adj)| {
+ deref_chain.into_iter().try_for_each(|(receiver_ty, adj)| {
iterate_method_candidates_with_autoref(
&receiver_ty,
adj,
@@ -964,8 +964,7 @@ pub fn iterate_method_candidates_dyn(
name,
callback,
)
- });
- result
+ })
}
LookupMode::Path => {
// No autoderef for path lookups
diff --git a/crates/hir-ty/src/mir.rs b/crates/hir-ty/src/mir.rs
index 44e182cb6f..952a97e3d0 100644
--- a/crates/hir-ty/src/mir.rs
+++ b/crates/hir-ty/src/mir.rs
@@ -159,7 +159,7 @@ impl<V, T> ProjectionElem<V, T> {
}
_ => {
never!("Overloaded deref on type {} is not a projection", base.display(db));
- return TyKind::Error.intern(Interner);
+ TyKind::Error.intern(Interner)
}
},
ProjectionElem::Field(Either::Left(f)) => match &base.kind(Interner) {
@@ -168,7 +168,7 @@ impl<V, T> ProjectionElem<V, T> {
}
ty => {
never!("Only adt has field, found {:?}", ty);
- return TyKind::Error.intern(Interner);
+ TyKind::Error.intern(Interner)
}
},
ProjectionElem::Field(Either::Right(f)) => match &base.kind(Interner) {
@@ -183,14 +183,14 @@ impl<V, T> ProjectionElem<V, T> {
}),
_ => {
never!("Only tuple has tuple field");
- return TyKind::Error.intern(Interner);
+ TyKind::Error.intern(Interner)
}
},
ProjectionElem::ClosureField(f) => match &base.kind(Interner) {
TyKind::Closure(id, subst) => closure_field(*id, subst, *f),
_ => {
never!("Only closure has closure field");
- return TyKind::Error.intern(Interner);
+ TyKind::Error.intern(Interner)
}
},
ProjectionElem::ConstantIndex { .. } | ProjectionElem::Index(_) => {
@@ -198,7 +198,7 @@ impl<V, T> ProjectionElem<V, T> {
TyKind::Array(inner, _) | TyKind::Slice(inner) => inner.clone(),
_ => {
never!("Overloaded index is not a projection");
- return TyKind::Error.intern(Interner);
+ TyKind::Error.intern(Interner)
}
}
}
@@ -217,12 +217,12 @@ impl<V, T> ProjectionElem<V, T> {
TyKind::Slice(_) => base.clone(),
_ => {
never!("Subslice projection should only happen on slice and array");
- return TyKind::Error.intern(Interner);
+ TyKind::Error.intern(Interner)
}
},
ProjectionElem::OpaqueCast(_) => {
never!("We don't emit these yet");
- return TyKind::Error.intern(Interner);
+ TyKind::Error.intern(Interner)
}
}
}
@@ -299,7 +299,7 @@ pub struct Place {
impl Place {
fn is_parent(&self, child: &Place, store: &ProjectionStore) -> bool {
self.local == child.local
- && child.projection.lookup(store).starts_with(&self.projection.lookup(store))
+ && child.projection.lookup(store).starts_with(self.projection.lookup(store))
}
/// The place itself is not included
diff --git a/crates/hir-ty/src/mir/borrowck.rs b/crates/hir-ty/src/mir/borrowck.rs
index 78d94bafc0..186921ae7a 100644
--- a/crates/hir-ty/src/mir/borrowck.rs
+++ b/crates/hir-ty/src/mir/borrowck.rs
@@ -53,7 +53,7 @@ fn all_mir_bodies(
match db.mir_body_for_closure(c) {
Ok(body) => {
cb(body.clone());
- body.closures.iter().map(|&it| for_closure(db, it, cb)).collect()
+ body.closures.iter().try_for_each(|&it| for_closure(db, it, cb))
}
Err(e) => Err(e),
}
@@ -61,7 +61,7 @@ fn all_mir_bodies(
match db.mir_body(def) {
Ok(body) => {
cb(body.clone());
- body.closures.iter().map(|&it| for_closure(db, it, &mut cb)).collect()
+ body.closures.iter().try_for_each(|&it| for_closure(db, it, &mut cb))
}
Err(e) => Err(e),
}
@@ -257,7 +257,7 @@ fn ever_initialized_map(
for statement in &block.statements {
match &statement.kind {
StatementKind::Assign(p, _) => {
- if p.projection.lookup(&body.projection_store).len() == 0 && p.local == l {
+ if p.projection.lookup(&body.projection_store).is_empty() && p.local == l {
is_ever_initialized = true;
}
}
@@ -295,21 +295,15 @@ fn ever_initialized_map(
| TerminatorKind::Return
| TerminatorKind::Unreachable => (),
TerminatorKind::Call { target, cleanup, destination, .. } => {
- if destination.projection.lookup(&body.projection_store).len() == 0
+ if destination.projection.lookup(&body.projection_store).is_empty()
&& destination.local == l
{
is_ever_initialized = true;
}
- target
- .into_iter()
- .chain(cleanup.into_iter())
- .for_each(|&it| process(it, is_ever_initialized));
+ target.iter().chain(cleanup).for_each(|&it| process(it, is_ever_initialized));
}
TerminatorKind::Drop { target, unwind, place: _ } => {
- iter::once(target)
- .into_iter()
- .chain(unwind.into_iter())
- .for_each(|&it| process(it, is_ever_initialized));
+ iter::once(target).chain(unwind).for_each(|&it| process(it, is_ever_initialized));
}
TerminatorKind::DropAndReplace { .. }
| TerminatorKind::Assert { .. }
@@ -318,7 +312,6 @@ fn ever_initialized_map(
| TerminatorKind::FalseEdge { .. }
| TerminatorKind::FalseUnwind { .. } => {
never!("We don't emit these MIR terminators yet");
- ()
}
}
}
@@ -452,7 +445,7 @@ fn mutability_of_locals(
for arg in args.iter() {
record_usage_for_operand(arg, &mut result);
}
- if destination.projection.lookup(&body.projection_store).len() == 0 {
+ if destination.projection.lookup(&body.projection_store).is_empty() {
if ever_init_map.get(destination.local).copied().unwrap_or_default() {
push_mut_span(destination.local, MirSpan::Unknown, &mut result);
} else {
diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs
index 551446962d..f8e4c6e43d 100644
--- a/crates/hir-ty/src/mir/eval.rs
+++ b/crates/hir-ty/src/mir/eval.rs
@@ -291,12 +291,11 @@ impl Address {
}
fn to_usize(&self) -> usize {
- let as_num = match self {
+ match self {
Stack(it) => *it + STACK_OFFSET,
Heap(it) => *it + HEAP_OFFSET,
Invalid(it) => *it,
- };
- as_num
+ }
}
fn map(&self, f: impl FnOnce(usize) -> usize) -> Address {
@@ -485,8 +484,7 @@ impl DropFlags {
fn remove_place(&mut self, p: &Place, store: &ProjectionStore) -> bool {
// FIXME: replace parents with parts
- if let Some(parent) = p.iterate_over_parents(store).find(|it| self.need_drop.contains(&it))
- {
+ if let Some(parent) = p.iterate_over_parents(store).find(|it| self.need_drop.contains(it)) {
self.need_drop.remove(&parent);
return true;
}
@@ -551,7 +549,7 @@ pub fn interpret_mir(
memory_map.vtable.shrink_to_fit();
MemoryMap::Complex(Box::new(memory_map))
};
- return Ok(intern_const_scalar(ConstScalar::Bytes(bytes, memory_map), ty));
+ Ok(intern_const_scalar(ConstScalar::Bytes(bytes, memory_map), ty))
})();
(it, MirOutput { stdout: evaluator.stdout, stderr: evaluator.stderr })
}
@@ -562,12 +560,12 @@ const EXECUTION_LIMIT: usize = 100_000;
const EXECUTION_LIMIT: usize = 10_000_000;
impl Evaluator<'_> {
- pub fn new<'a>(
- db: &'a dyn HirDatabase,
+ pub fn new(
+ db: &dyn HirDatabase,
owner: DefWithBodyId,
assert_placeholder_ty_is_unused: bool,
trait_env: Option<Arc<TraitEnvironment>>,
- ) -> Evaluator<'a> {
+ ) -> Evaluator<'_> {
let crate_id = owner.module(db.upcast()).krate();
Evaluator {
stack: vec![0],
@@ -585,7 +583,7 @@ impl Evaluator<'_> {
assert_placeholder_ty_is_unused,
stack_depth_limit: 100,
execution_limit: EXECUTION_LIMIT,
- memory_limit: 1000_000_000, // 2GB, 1GB for stack and 1GB for heap
+ memory_limit: 1_000_000_000, // 2GB, 1GB for stack and 1GB for heap
layout_cache: RefCell::new(Default::default()),
projected_ty_cache: RefCell::new(Default::default()),
not_special_fn_cache: RefCell::new(Default::default()),
@@ -816,8 +814,8 @@ impl Evaluator<'_> {
})
}
- fn interpret_mir<'slf>(
- &'slf mut self,
+ fn interpret_mir(
+ &mut self,
body: Arc<MirBody>,
args: impl Iterator<Item = IntervalOrOwned>,
) -> Result<Interval> {
@@ -837,7 +835,7 @@ impl Evaluator<'_> {
not_supported!("missing stack frame");
};
let e = (|| {
- let mut locals = &mut my_stack_frame.locals;
+ let locals = &mut my_stack_frame.locals;
let body = locals.body.clone();
loop {
let current_block = &body.basic_blocks[current_block_idx];
@@ -849,12 +847,10 @@ impl Evaluator<'_> {
for statement in &current_block.statements {
match &statement.kind {
StatementKind::Assign(l, r) => {
- let addr = self.place_addr(l, &locals)?;
- let result = self.eval_rvalue(r, &mut locals)?;
+ let addr = self.place_addr(l, locals)?;
+ let result = self.eval_rvalue(r, locals)?;
self.copy_from_interval_or_owned(addr, result)?;
- locals
- .drop_flags
- .add_place(l.clone(), &locals.body.projection_store);
+ locals.drop_flags.add_place(*l, &locals.body.projection_store);
}
StatementKind::Deinit(_) => not_supported!("de-init statement"),
StatementKind::StorageLive(_)
@@ -878,20 +874,20 @@ impl Evaluator<'_> {
cleanup: _,
from_hir_call: _,
} => {
- let destination_interval = self.place_interval(destination, &locals)?;
- let fn_ty = self.operand_ty(func, &locals)?;
+ let destination_interval = self.place_interval(destination, locals)?;
+ let fn_ty = self.operand_ty(func, locals)?;
let args = args
.iter()
- .map(|it| self.operand_ty_and_eval(it, &mut locals))
+ .map(|it| self.operand_ty_and_eval(it, locals))
.collect::<Result<Vec<_>>>()?;
let stack_frame = match &fn_ty.kind(Interner) {
TyKind::Function(_) => {
- let bytes = self.eval_operand(func, &mut locals)?;
+ let bytes = self.eval_operand(func, locals)?;
self.exec_fn_pointer(
bytes,
destination_interval,
&args,
- &locals,
+ locals,
*target,
terminator.span,
)?
@@ -901,7 +897,7 @@ impl Evaluator<'_> {
generic_args,
destination_interval,
&args,
- &locals,
+ locals,
*target,
terminator.span,
)?,
@@ -909,7 +905,7 @@ impl Evaluator<'_> {
};
locals
.drop_flags
- .add_place(destination.clone(), &locals.body.projection_store);
+ .add_place(*destination, &locals.body.projection_store);
if let Some(stack_frame) = stack_frame {
self.code_stack.push(my_stack_frame);
current_block_idx = stack_frame.locals.body.start_block;
@@ -924,7 +920,7 @@ impl Evaluator<'_> {
}
TerminatorKind::SwitchInt { discr, targets } => {
let val = u128::from_le_bytes(pad16(
- self.eval_operand(discr, &mut locals)?.get(&self)?,
+ self.eval_operand(discr, locals)?.get(self)?,
false,
));
current_block_idx = targets.target_for_value(val);
@@ -938,7 +934,7 @@ impl Evaluator<'_> {
));
}
TerminatorKind::Drop { place, target, unwind: _ } => {
- self.drop_place(place, &mut locals, terminator.span)?;
+ self.drop_place(place, locals, terminator.span)?;
current_block_idx = *target;
}
_ => not_supported!("unknown terminator"),
@@ -1081,7 +1077,7 @@ impl Evaluator<'_> {
}
}
Rvalue::UnaryOp(op, val) => {
- let mut c = self.eval_operand(val, locals)?.get(&self)?;
+ let mut c = self.eval_operand(val, locals)?.get(self)?;
let mut ty = self.operand_ty(val, locals)?;
while let TyKind::Ref(_, _, z) = ty.kind(Interner) {
ty = z.clone();
@@ -1124,8 +1120,8 @@ impl Evaluator<'_> {
Rvalue::CheckedBinaryOp(op, lhs, rhs) => 'binary_op: {
let lc = self.eval_operand(lhs, locals)?;
let rc = self.eval_operand(rhs, locals)?;
- let mut lc = lc.get(&self)?;
- let mut rc = rc.get(&self)?;
+ let mut lc = lc.get(self)?;
+ let mut rc = rc.get(self)?;
let mut ty = self.operand_ty(lhs, locals)?;
while let TyKind::Ref(_, _, z) = ty.kind(Interner) {
ty = z.clone();
@@ -1277,12 +1273,12 @@ impl Evaluator<'_> {
}
Rvalue::Discriminant(p) => {
let ty = self.place_ty(p, locals)?;
- let bytes = self.eval_place(p, locals)?.get(&self)?;
+ let bytes = self.eval_place(p, locals)?.get(self)?;
let result = self.compute_discriminant(ty, bytes)?;
Owned(result.to_le_bytes().to_vec())
}
Rvalue::Repeat(it, len) => {
- let len = match try_const_usize(self.db, &len) {
+ let len = match try_const_usize(self.db, len) {
Some(it) => it as usize,
None => not_supported!("non evaluatable array len in repeat Rvalue"),
};
@@ -1308,13 +1304,13 @@ impl Evaluator<'_> {
AggregateKind::Array(_) => {
let mut r = vec![];
for it in values {
- let value = it.get(&self)?;
+ let value = it.get(self)?;
r.extend(value);
}
Owned(r)
}
AggregateKind::Tuple(ty) => {
- let layout = self.layout(&ty)?;
+ let layout = self.layout(ty)?;
Owned(self.make_by_layout(
layout.size.bytes_usize(),
&layout,
@@ -1329,7 +1325,7 @@ impl Evaluator<'_> {
.fields
.offset(u32::from(f.local_id.into_raw()) as usize)
.bytes_usize();
- let op = values[0].get(&self)?;
+ let op = values[0].get(self)?;
let mut result = vec![0; layout.size.bytes_usize()];
result[offset..offset + op.len()].copy_from_slice(op);
Owned(result)
@@ -1345,7 +1341,7 @@ impl Evaluator<'_> {
)?)
}
AggregateKind::Closure(ty) => {
- let layout = self.layout(&ty)?;
+ let layout = self.layout(ty)?;
Owned(self.make_by_layout(
layout.size.bytes_usize(),
&layout,
@@ -1397,7 +1393,7 @@ impl Evaluator<'_> {
},
_ => false,
};
- let current = pad16(self.eval_operand(operand, locals)?.get(&self)?, is_signed);
+ let current = pad16(self.eval_operand(operand, locals)?.get(self)?, is_signed);
let dest_size =
self.size_of_sized(target_ty, locals, "destination of int to int cast")?;
Owned(current[0..dest_size].to_vec())
@@ -1513,7 +1509,7 @@ impl Evaluator<'_> {
let mut r = Vec::with_capacity(16);
let addr = addr.get(self)?;
r.extend(addr.iter().copied());
- r.extend(len.to_le_bytes().into_iter());
+ r.extend(len.to_le_bytes());
Owned(r)
}
t => {
@@ -1525,7 +1521,7 @@ impl Evaluator<'_> {
let mut r = Vec::with_capacity(16);
let addr = addr.get(self)?;
r.extend(addr.iter().copied());
- r.extend(vtable.to_le_bytes().into_iter());
+ r.extend(vtable.to_le_bytes());
Owned(r)
}
TyKind::Adt(id, target_subst) => match &current_ty.kind(Interner) {
@@ -1539,7 +1535,7 @@ impl Evaluator<'_> {
AdtId::EnumId(_) => not_supported!("unsizing enums"),
};
let Some((last_field, _)) =
- self.db.struct_data(id).variant_data.fields().iter().rev().next()
+ self.db.struct_data(id).variant_data.fields().iter().next_back()
else {
not_supported!("unsizing struct without field");
};
@@ -1645,7 +1641,7 @@ impl Evaluator<'_> {
}
for (i, op) in values.enumerate() {
let offset = variant_layout.fields.offset(i).bytes_usize();
- let op = op.get(&self)?;
+ let op = op.get(self)?;
match result.get_mut(offset..offset + op.len()) {
Some(it) => it.copy_from_slice(op),
None => return Err(MirEvalError::BrokenLayout(Box::new(variant_layout.clone()))),
@@ -1686,7 +1682,7 @@ impl Evaluator<'_> {
}
result_owner = self
.db
- .const_eval(const_id.into(), subst, Some(self.trait_env.clone()))
+ .const_eval(const_id, subst, Some(self.trait_env.clone()))
.map_err(|e| {
let name = const_id.name(self.db.upcast());
MirEvalError::ConstEvalError(name, Box::new(e))
@@ -1769,9 +1765,8 @@ impl Evaluator<'_> {
)));
}
};
- Ok(mem.get_mut(pos..pos + size).ok_or_else(|| {
- MirEvalError::UndefinedBehavior("out of bound memory write".to_string())
- })?)
+ mem.get_mut(pos..pos + size)
+ .ok_or_else(|| MirEvalError::UndefinedBehavior("out of bound memory write".to_string()))
}
fn write_memory(&mut self, addr: Address, r: &[u8]) -> Result<()> {
@@ -1960,14 +1955,14 @@ impl Evaluator<'_> {
if let Some(ty) = check_inner {
for i in 0..count {
let offset = element_size * i;
- rec(this, &b[offset..offset + element_size], &ty, locals, mm)?;
+ rec(this, &b[offset..offset + element_size], ty, locals, mm)?;
}
}
}
}
}
chalk_ir::TyKind::Array(inner, len) => {
- let len = match try_const_usize(this.db, &len) {
+ let len = match try_const_usize(this.db, len) {
Some(it) => it as usize,
None => not_supported!("non evaluatable array len in patching addresses"),
};
@@ -2028,7 +2023,7 @@ impl Evaluator<'_> {
Ok(())
}
let mut mm = ComplexMemoryMap::default();
- rec(&self, bytes, ty, locals, &mut mm)?;
+ rec(self, bytes, ty, locals, &mut mm)?;
Ok(mm)
}
@@ -2111,7 +2106,7 @@ impl Evaluator<'_> {
}
}
TyKind::Array(inner, len) => {
- let len = match try_const_usize(self.db, &len) {
+ let len = match try_const_usize(self.db, len) {
Some(it) => it as usize,
None => not_supported!("non evaluatable array len in patching addresses"),
};
@@ -2161,7 +2156,7 @@ impl Evaluator<'_> {
let next_ty = self.vtable_map.ty(id)?.clone();
match &next_ty.kind(Interner) {
TyKind::FnDef(def, generic_args) => {
- self.exec_fn_def(*def, generic_args, destination, args, &locals, target_bb, span)
+ self.exec_fn_def(*def, generic_args, destination, args, locals, target_bb, span)
}
TyKind::Closure(id, subst) => {
self.exec_closure(*id, bytes.slice(0..0), subst, destination, args, locals, span)
@@ -2195,7 +2190,7 @@ impl Evaluator<'_> {
closure_data.get(self)?.to_owned()
};
let arg_bytes = iter::once(Ok(closure_data))
- .chain(args.iter().map(|it| Ok(it.get(&self)?.to_owned())))
+ .chain(args.iter().map(|it| Ok(it.get(self)?.to_owned())))
.collect::<Result<Vec<_>>>()?;
let interval = self
.interpret_mir(mir_body, arg_bytes.into_iter().map(IntervalOrOwned::Owned))
@@ -2246,7 +2241,7 @@ impl Evaluator<'_> {
}
CallableDefId::StructId(id) => {
let (size, variant_layout, tag) =
- self.layout_of_variant(id.into(), generic_args, &locals)?;
+ self.layout_of_variant(id.into(), generic_args, locals)?;
let result = self.make_by_layout(
size,
&variant_layout,
@@ -2258,7 +2253,7 @@ impl Evaluator<'_> {
}
CallableDefId::EnumVariantId(id) => {
let (size, variant_layout, tag) =
- self.layout_of_variant(id.into(), generic_args, &locals)?;
+ self.layout_of_variant(id.into(), generic_args, locals)?;
let result = self.make_by_layout(
size,
&variant_layout,
@@ -2353,7 +2348,7 @@ impl Evaluator<'_> {
}
}),
);
- return self.exec_fn_with_args(
+ self.exec_fn_with_args(
def,
&args_for_target,
generics_for_target,
@@ -2361,7 +2356,7 @@ impl Evaluator<'_> {
destination,
target_bb,
span,
- );
+ )
}
MirOrDynIndex::Mir(body) => self.exec_looked_up_function(
body,
@@ -2413,7 +2408,7 @@ impl Evaluator<'_> {
target_bb: Option<BasicBlockId>,
span: MirSpan,
) -> Result<Option<StackFrame>> {
- let func = args.get(0).ok_or(MirEvalError::TypeError("fn trait with no arg"))?;
+ let func = args.first().ok_or(MirEvalError::TypeError("fn trait with no arg"))?;
let mut func_ty = func.ty.clone();
let mut func_data = func.interval;
while let TyKind::Ref(_, _, z) = func_ty.kind(Interner) {
@@ -2429,25 +2424,10 @@ impl Evaluator<'_> {
}
match &func_ty.kind(Interner) {
TyKind::FnDef(def, subst) => {
- return self.exec_fn_def(
- *def,
- subst,
- destination,
- &args[1..],
- locals,
- target_bb,
- span,
- );
+ self.exec_fn_def(*def, subst, destination, &args[1..], locals, target_bb, span)
}
TyKind::Function(_) => {
- return self.exec_fn_pointer(
- func_data,
- destination,
- &args[1..],
- locals,
- target_bb,
- span,
- );
+ self.exec_fn_pointer(func_data, destination, &args[1..], locals, target_bb, span)
}
TyKind::Closure(closure, subst) => {
return self.exec_closure(
@@ -2483,7 +2463,7 @@ impl Evaluator<'_> {
self.write_memory(addr, &result)?;
IntervalAndTy { interval: Interval { addr, size }, ty }
};
- return self.exec_fn_with_args(
+ self.exec_fn_with_args(
def,
&[arg0.clone(), arg1],
generic_args,
@@ -2491,7 +2471,7 @@ impl Evaluator<'_> {
destination,
target_bb,
span,
- );
+ )
}
}
}
@@ -2511,7 +2491,7 @@ impl Evaluator<'_> {
self.allocate_const_in_heap(locals, &konst)?
} else {
let ty = &self.db.infer(st.into())[self.db.body(st.into()).body_expr];
- let Some((size, align)) = self.size_align_of(&ty, locals)? else {
+ let Some((size, align)) = self.size_align_of(ty, locals)? else {
not_supported!("unsized extern static");
};
let addr = self.heap_allocate(size, align)?;
@@ -2669,7 +2649,7 @@ pub fn render_const_using_debug_impl(
db.upcast(),
&hir_def::path::Path::from_known_path_with_no_generic(ModPath::from_segments(
hir_expand::mod_path::PathKind::Abs,
- [name![core], name![fmt], name![Debug]].into_iter(),
+ [name![core], name![fmt], name![Debug]],
)),
) else {
not_supported!("core::fmt::Debug not found");
@@ -2701,7 +2681,7 @@ pub fn render_const_using_debug_impl(
db.upcast(),
&hir_def::path::Path::from_known_path_with_no_generic(ModPath::from_segments(
hir_expand::mod_path::PathKind::Abs,
- [name![std], name![fmt], name![format]].into_iter(),
+ [name![std], name![fmt], name![format]],
)),
) else {
not_supported!("std::fmt::format not found");
diff --git a/crates/hir-ty/src/mir/eval/shim.rs b/crates/hir-ty/src/mir/eval/shim.rs
index ff26a3d0be..4336e1e53b 100644
--- a/crates/hir-ty/src/mir/eval/shim.rs
+++ b/crates/hir-ty/src/mir/eval/shim.rs
@@ -60,7 +60,7 @@ impl Evaluator<'_> {
args,
generic_args,
destination,
- &locals,
+ locals,
span,
)?;
return Ok(true);
@@ -82,7 +82,7 @@ impl Evaluator<'_> {
args,
generic_args,
destination,
- &locals,
+ locals,
span,
)?;
return Ok(true);
@@ -100,7 +100,7 @@ impl Evaluator<'_> {
args,
generic_args,
destination,
- &locals,
+ locals,
span,
)?;
return Ok(true);
@@ -125,7 +125,7 @@ impl Evaluator<'_> {
}
if let Some(it) = self.detect_lang_function(def) {
let arg_bytes =
- args.iter().map(|it| Ok(it.get(&self)?.to_owned())).collect::<Result<Vec<_>>>()?;
+ args.iter().map(|it| Ok(it.get(self)?.to_owned())).collect::<Result<Vec<_>>>()?;
let result = self.exec_lang_item(it, generic_args, &arg_bytes, locals, span)?;
destination.write_from_bytes(self, &result)?;
return Ok(true);
@@ -313,7 +313,7 @@ impl Evaluator<'_> {
&hir_def::path::Path::from_known_path_with_no_generic(
ModPath::from_segments(
hir_expand::mod_path::PathKind::Abs,
- [name![std], name![fmt], name![format]].into_iter(),
+ [name![std], name![fmt], name![format]],
),
),
) else {
@@ -347,7 +347,7 @@ impl Evaluator<'_> {
}
DropInPlace => {
let ty =
- generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner)).ok_or(
+ generic_args.as_slice(Interner).first().and_then(|it| it.ty(Interner)).ok_or(
MirEvalError::TypeError(
"generic argument of drop_in_place is not provided",
),
@@ -445,7 +445,7 @@ impl Evaluator<'_> {
}
"pthread_key_create" => {
let key = self.thread_local_storage.create_key();
- let Some(arg0) = args.get(0) else {
+ let Some(arg0) = args.first() else {
return Err(MirEvalError::TypeError("pthread_key_create arg0 is not provided"));
};
let arg0_addr = Address::from_bytes(arg0.get(self)?)?;
@@ -466,7 +466,7 @@ impl Evaluator<'_> {
Ok(())
}
"pthread_getspecific" => {
- let Some(arg0) = args.get(0) else {
+ let Some(arg0) = args.first() else {
return Err(MirEvalError::TypeError(
"pthread_getspecific arg0 is not provided",
));
@@ -477,7 +477,7 @@ impl Evaluator<'_> {
Ok(())
}
"pthread_setspecific" => {
- let Some(arg0) = args.get(0) else {
+ let Some(arg0) = args.first() else {
return Err(MirEvalError::TypeError(
"pthread_setspecific arg0 is not provided",
));
@@ -728,7 +728,7 @@ impl Evaluator<'_> {
match name {
"size_of" => {
let Some(ty) =
- generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner))
+ generic_args.as_slice(Interner).first().and_then(|it| it.ty(Interner))
else {
return Err(MirEvalError::TypeError("size_of generic arg is not provided"));
};
@@ -737,7 +737,7 @@ impl Evaluator<'_> {
}
"min_align_of" | "pref_align_of" => {
let Some(ty) =
- generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner))
+ generic_args.as_slice(Interner).first().and_then(|it| it.ty(Interner))
else {
return Err(MirEvalError::TypeError("align_of generic arg is not provided"));
};
@@ -746,7 +746,7 @@ impl Evaluator<'_> {
}
"size_of_val" => {
let Some(ty) =
- generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner))
+ generic_args.as_slice(Interner).first().and_then(|it| it.ty(Interner))
else {
return Err(MirEvalError::TypeError("size_of_val generic arg is not provided"));
};
@@ -763,7 +763,7 @@ impl Evaluator<'_> {
}
"min_align_of_val" => {
let Some(ty) =
- generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner))
+ generic_args.as_slice(Interner).first().and_then(|it| it.ty(Interner))
else {
return Err(MirEvalError::TypeError(
"min_align_of_val generic arg is not provided",
@@ -782,7 +782,7 @@ impl Evaluator<'_> {
}
"type_name" => {
let Some(ty) =
- generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner))
+ generic_args.as_slice(Interner).first().and_then(|it| it.ty(Interner))
else {
return Err(MirEvalError::TypeError("type_name generic arg is not provided"));
};
@@ -806,7 +806,7 @@ impl Evaluator<'_> {
}
"needs_drop" => {
let Some(ty) =
- generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner))
+ generic_args.as_slice(Interner).first().and_then(|it| it.ty(Interner))
else {
return Err(MirEvalError::TypeError("size_of generic arg is not provided"));
};
@@ -859,7 +859,7 @@ impl Evaluator<'_> {
let rhs = i128::from_le_bytes(pad16(rhs.get(self)?, false));
let ans = lhs.wrapping_sub(rhs);
let Some(ty) =
- generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner))
+ generic_args.as_slice(Interner).first().and_then(|it| it.ty(Interner))
else {
return Err(MirEvalError::TypeError(
"ptr_offset_from generic arg is not provided",
@@ -971,7 +971,7 @@ impl Evaluator<'_> {
));
};
let Some(ty) =
- generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner))
+ generic_args.as_slice(Interner).first().and_then(|it| it.ty(Interner))
else {
return Err(MirEvalError::TypeError(
"copy_nonoverlapping generic arg is not provided",
@@ -992,7 +992,7 @@ impl Evaluator<'_> {
};
let ty = if name == "offset" {
let Some(ty0) =
- generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner))
+ generic_args.as_slice(Interner).first().and_then(|it| it.ty(Interner))
else {
return Err(MirEvalError::TypeError("offset generic arg is not provided"));
};
@@ -1022,7 +1022,7 @@ impl Evaluator<'_> {
}
} else {
let Some(ty) =
- generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner))
+ generic_args.as_slice(Interner).first().and_then(|it| it.ty(Interner))
else {
return Err(MirEvalError::TypeError(
"arith_offset generic arg is not provided",
@@ -1147,7 +1147,7 @@ impl Evaluator<'_> {
return Err(MirEvalError::TypeError("discriminant_value arg is not provided"));
};
let Some(ty) =
- generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner))
+ generic_args.as_slice(Interner).first().and_then(|it| it.ty(Interner))
else {
return Err(MirEvalError::TypeError(
"discriminant_value generic arg is not provided",
@@ -1207,7 +1207,7 @@ impl Evaluator<'_> {
};
let dst = Address::from_bytes(ptr.get(self)?)?;
let Some(ty) =
- generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner))
+ generic_args.as_slice(Interner).first().and_then(|it| it.ty(Interner))
else {
return Err(MirEvalError::TypeError(
"write_via_copy generic arg is not provided",
@@ -1224,7 +1224,7 @@ impl Evaluator<'_> {
let count = from_bytes!(usize, count.get(self)?);
let val = from_bytes!(u8, val.get(self)?);
let Some(ty) =
- generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner))
+ generic_args.as_slice(Interner).first().and_then(|it| it.ty(Interner))
else {
return Err(MirEvalError::TypeError("write_bytes generic arg is not provided"));
};
@@ -1265,7 +1265,7 @@ impl Evaluator<'_> {
};
let field_types = &self.db.field_types(id.into());
let last_field_ty =
- field_types.iter().rev().next().unwrap().1.clone().substitute(Interner, subst);
+ field_types.iter().next_back().unwrap().1.clone().substitute(Interner, subst);
let sized_part_size =
layout.fields.offset(field_types.iter().count() - 1).bytes_usize();
let sized_part_align = layout.align.abi.bytes() as usize;
@@ -1308,10 +1308,11 @@ impl Evaluator<'_> {
// The rest of atomic intrinsics have exactly one generic arg
- let Some(ty) = generic_args.as_slice(Interner).get(0).and_then(|it| it.ty(Interner)) else {
+ let Some(ty) = generic_args.as_slice(Interner).first().and_then(|it| it.ty(Interner))
+ else {
return Err(MirEvalError::TypeError("atomic intrinsic generic arg is not provided"));
};
- let Some(arg0) = args.get(0) else {
+ let Some(arg0) = args.first() else {
return Err(MirEvalError::TypeError("atomic intrinsic arg0 is not provided"));
};
let arg0_addr = Address::from_bytes(arg0.get(self)?)?;
diff --git a/crates/hir-ty/src/mir/eval/shim/simd.rs b/crates/hir-ty/src/mir/eval/shim/simd.rs
index 5190066242..f9156417f2 100644
--- a/crates/hir-ty/src/mir/eval/shim/simd.rs
+++ b/crates/hir-ty/src/mir/eval/shim/simd.rs
@@ -46,7 +46,7 @@ impl Evaluator<'_> {
match try_const_usize(self.db, len) {
Some(len) => {
let Some(ty) =
- subst.as_slice(Interner).get(0).and_then(|it| it.ty(Interner))
+ subst.as_slice(Interner).first().and_then(|it| it.ty(Interner))
else {
return Err(MirEvalError::TypeError("simd type with no ty param"));
};
@@ -106,7 +106,7 @@ impl Evaluator<'_> {
}
}
if is_signed {
- if let Some((&l, &r)) = l.iter().zip(r).rev().next() {
+ if let Some((&l, &r)) = l.iter().zip(r).next_back() {
if l != r {
result = (l as i8).cmp(&(r as i8));
}
diff --git a/crates/hir-ty/src/mir/eval/tests.rs b/crates/hir-ty/src/mir/eval/tests.rs
index 6552bf4933..381522c9ab 100644
--- a/crates/hir-ty/src/mir/eval/tests.rs
+++ b/crates/hir-ty/src/mir/eval/tests.rs
@@ -30,7 +30,7 @@ fn eval_main(db: &TestDB, file_id: FileId) -> Result<(String, String), MirEvalEr
Substitution::empty(Interner),
db.trait_environment(func_id.into()),
)
- .map_err(|e| MirEvalError::MirLowerError(func_id.into(), e))?;
+ .map_err(|e| MirEvalError::MirLowerError(func_id, e))?;
let (result, output) = interpret_mir(db, body, false, None);
result?;
Ok((output.stdout().into_owned(), output.stderr().into_owned()))
@@ -49,8 +49,8 @@ fn check_pass_and_stdio(ra_fixture: &str, expected_stdout: &str, expected_stderr
let mut err = String::new();
let line_index = |size: TextSize| {
let mut size = u32::from(size) as usize;
- let mut lines = ra_fixture.lines().enumerate();
- while let Some((i, l)) = lines.next() {
+ let lines = ra_fixture.lines().enumerate();
+ for (i, l) in lines {
if let Some(x) = size.checked_sub(l.len()) {
size = x;
} else {
diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs
index 749ca43fba..169e0e204c 100644
--- a/crates/hir-ty/src/mir/lower.rs
+++ b/crates/hir-ty/src/mir/lower.rs
@@ -259,7 +259,8 @@ impl<'ctx> MirLowerCtx<'ctx> {
owner,
closures: vec![],
};
- let ctx = MirLowerCtx {
+
+ MirLowerCtx {
result: mir,
db,
infer,
@@ -269,8 +270,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
labeled_loop_blocks: Default::default(),
discr_temp: None,
drop_scopes: vec![DropScope::default()],
- };
- ctx
+ }
}
fn temp(&mut self, ty: Ty, current: BasicBlockId, span: MirSpan) -> Result<LocalId> {
@@ -345,8 +345,8 @@ impl<'ctx> MirLowerCtx<'ctx> {
current,
place,
Rvalue::Cast(
- CastKind::Pointer(cast.clone()),
- Operand::Copy(p).into(),
+ CastKind::Pointer(*cast),
+ Operand::Copy(p),
last.target.clone(),
),
expr_id.into(),
@@ -511,8 +511,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
return Ok(None);
};
let start_of_then = self.new_basic_block();
- let end_of_then =
- self.lower_expr_to_place(*then_branch, place.clone(), start_of_then)?;
+ let end_of_then = self.lower_expr_to_place(*then_branch, place, start_of_then)?;
let start_of_else = self.new_basic_block();
let end_of_else = if let Some(else_branch) = else_branch {
self.lower_expr_to_place(*else_branch, place, start_of_else)?
@@ -539,7 +538,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
self.pattern_match(current, None, cond_place, *pat)?;
self.write_bytes_to_place(
then_target,
- place.clone(),
+ place,
Box::new([1]),
TyBuilder::bool(),
MirSpan::Unknown,
@@ -560,25 +559,19 @@ impl<'ctx> MirLowerCtx<'ctx> {
}
Expr::Block { id: _, statements, tail, label } => {
if let Some(label) = label {
- self.lower_loop(
- current,
- place.clone(),
- Some(*label),
- expr_id.into(),
- |this, begin| {
- if let Some(current) = this.lower_block_to_place(
- statements,
- begin,
- *tail,
- place,
- expr_id.into(),
- )? {
- let end = this.current_loop_end()?;
- this.set_goto(current, end, expr_id.into());
- }
- Ok(())
- },
- )
+ self.lower_loop(current, place, Some(*label), expr_id.into(), |this, begin| {
+ if let Some(current) = this.lower_block_to_place(
+ statements,
+ begin,
+ *tail,
+ place,
+ expr_id.into(),
+ )? {
+ let end = this.current_loop_end()?;
+ this.set_goto(current, end, expr_id.into());
+ }
+ Ok(())
+ })
} else {
self.lower_block_to_place(statements, current, *tail, place, expr_id.into())
}
@@ -646,9 +639,9 @@ impl<'ctx> MirLowerCtx<'ctx> {
);
}
TyKind::Error => {
- return Err(MirLowerError::MissingFunctionDefinition(self.owner, expr_id))
+ Err(MirLowerError::MissingFunctionDefinition(self.owner, expr_id))
}
- _ => return Err(MirLowerError::TypeError("function call on bad type")),
+ _ => Err(MirLowerError::TypeError("function call on bad type")),
}
}
Expr::MethodCall { receiver, args, method_name, .. } => {
@@ -678,7 +671,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
let mut end = None;
for MatchArm { pat, guard, expr } in arms.iter() {
let (then, mut otherwise) =
- self.pattern_match(current, None, cond_place.clone(), *pat)?;
+ self.pattern_match(current, None, cond_place, *pat)?;
let then = if let &Some(guard) = guard {
let next = self.new_basic_block();
let o = otherwise.get_or_insert_with(|| self.new_basic_block());
@@ -696,7 +689,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
} else {
then
};
- if let Some(block) = self.lower_expr_to_place(*expr, place.clone(), then)? {
+ if let Some(block) = self.lower_expr_to_place(*expr, place, then)? {
let r = end.get_or_insert_with(|| self.new_basic_block());
self.set_goto(block, *r, expr_id.into());
}
@@ -742,9 +735,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
.as_ref()
.ok_or(MirLowerError::BreakWithoutLoop)?,
};
- let Some(c) =
- self.lower_expr_to_place(expr, loop_data.place.clone(), current)?
- else {
+ let Some(c) = self.lower_expr_to_place(expr, loop_data.place, current)? else {
return Ok(None);
};
current = c;
@@ -906,7 +897,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
let ty = self.expr_ty_after_adjustments(*expr);
self.push_assignment(
current,
- place.clone(),
+ place,
Rvalue::ShallowInitBoxWithAlloc(ty),
expr_id.into(),
);
@@ -1006,11 +997,8 @@ impl<'ctx> MirLowerCtx<'ctx> {
else {
return Ok(None);
};
- let r_value = Rvalue::CheckedBinaryOp(
- op.into(),
- Operand::Copy(lhs_place.clone()),
- rhs_op,
- );
+ let r_value =
+ Rvalue::CheckedBinaryOp(op.into(), Operand::Copy(lhs_place), rhs_op);
self.push_assignment(current, lhs_place, r_value, expr_id.into());
return Ok(Some(current));
} else {
@@ -1029,7 +1017,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
let start_of_then = self.new_basic_block();
self.push_assignment(
start_of_then,
- place.clone(),
+ place,
lhs_op.clone().into(),
expr_id.into(),
);
@@ -1168,12 +1156,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
let tmp_ty =
capture.ty.clone().substitute(Interner, &placeholder_subst);
let tmp: Place = self.temp(tmp_ty, current, capture.span)?.into();
- self.push_assignment(
- current,
- tmp.clone(),
- Rvalue::Ref(bk.clone(), p),
- capture.span,
- );
+ self.push_assignment(current, tmp, Rvalue::Ref(*bk, p), capture.span);
operands.push(Operand::Move(tmp));
}
CaptureKind::ByValue => operands.push(Operand::Move(p)),
@@ -1322,7 +1305,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
) {
let temp = self.temp(self.expr_ty_after_adjustments(rhs), current, rhs.into())?;
let temp = Place::from(temp);
- self.push_assignment(current, temp.clone(), rhs_op.into(), span);
+ self.push_assignment(current, temp, rhs_op.into(), span);
return self.lower_destructing_assignment(current, lhs, temp, span);
}
let Some((lhs_place, current)) = self.lower_expr_as_place(current, lhs, false)? else {
@@ -1333,11 +1316,10 @@ impl<'ctx> MirLowerCtx<'ctx> {
}
fn placeholder_subst(&mut self) -> Substitution {
- let placeholder_subst = match self.owner.as_generic_def_id() {
+ match self.owner.as_generic_def_id() {
Some(it) => TyBuilder::placeholder_subst(self.db, it),
None => Substitution::empty(Interner),
- };
- placeholder_subst
+ }
}
fn push_field_projection(&mut self, place: &mut Place, expr_id: ExprId) -> Result<()> {
@@ -1470,7 +1452,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
} else {
let name = const_id.name(self.db.upcast());
self.db
- .const_eval(const_id.into(), subst, None)
+ .const_eval(const_id, subst, None)
.map_err(|e| MirLowerError::ConstEvalError(name.into(), Box::new(e)))?
};
Ok(Operand::Constant(c))
@@ -1612,13 +1594,13 @@ impl<'ctx> MirLowerCtx<'ctx> {
fn discr_temp_place(&mut self, current: BasicBlockId) -> Place {
match &self.discr_temp {
- Some(it) => it.clone(),
+ Some(it) => *it,
None => {
let tmp: Place = self
.temp(TyBuilder::discr_ty(), current, MirSpan::Unknown)
.expect("discr_ty is never unsized")
.into();
- self.discr_temp = Some(tmp.clone());
+ self.discr_temp = Some(tmp);
tmp
}
}
@@ -2041,19 +2023,16 @@ pub fn mir_body_for_closure_query(
ctx.result.walk_places(|p, store| {
if let Some(it) = upvar_map.get(&p.local) {
let r = it.iter().find(|it| {
- if p.projection.lookup(&store).len() < it.0.place.projections.len() {
+ if p.projection.lookup(store).len() < it.0.place.projections.len() {
return false;
}
- for (it, y) in p.projection.lookup(&store).iter().zip(it.0.place.projections.iter())
+ for (it, y) in p.projection.lookup(store).iter().zip(it.0.place.projections.iter())
{
match (it, y) {
(ProjectionElem::Deref, ProjectionElem::Deref) => (),
(ProjectionElem::Field(it), ProjectionElem::Field(y)) if it == y => (),
(ProjectionElem::ClosureField(it), ProjectionElem::ClosureField(y))
- if it == y =>
- {
- ()
- }
+ if it == y => {}
_ => return false,
}
}
@@ -2069,15 +2048,11 @@ pub fn mir_body_for_closure_query(
next_projs.push(ProjectionElem::Deref);
}
next_projs.extend(
- prev_projs
- .lookup(&store)
- .iter()
- .skip(it.0.place.projections.len())
- .cloned(),
+ prev_projs.lookup(store).iter().skip(it.0.place.projections.len()).cloned(),
);
p.projection = store.intern(next_projs.into());
}
- None => err = Some(p.clone()),
+ None => err = Some(*p),
}
}
});
diff --git a/crates/hir-ty/src/mir/lower/as_place.rs b/crates/hir-ty/src/mir/lower/as_place.rs
index cb5588a5c1..fc51168f99 100644
--- a/crates/hir-ty/src/mir/lower/as_place.rs
+++ b/crates/hir-ty/src/mir/lower/as_place.rs
@@ -148,7 +148,7 @@ impl MirLowerCtx<'_> {
let temp: Place = self.temp(ref_ty, current, expr_id.into())?.into();
self.push_assignment(
current,
- temp.clone(),
+ temp,
Operand::Static(s).into(),
expr_id.into(),
);
@@ -304,7 +304,7 @@ impl MirLowerCtx<'_> {
let Some(current) = self.lower_call(
index_fn_op,
Box::new([Operand::Copy(place), index_operand]),
- result.clone(),
+ result,
current,
false,
span,
@@ -338,7 +338,7 @@ impl MirLowerCtx<'_> {
let ty_ref = TyKind::Ref(chalk_mut, static_lifetime(), source_ty.clone()).intern(Interner);
let target_ty_ref = TyKind::Ref(chalk_mut, static_lifetime(), target_ty).intern(Interner);
let ref_place: Place = self.temp(ty_ref, current, span)?.into();
- self.push_assignment(current, ref_place.clone(), Rvalue::Ref(borrow_kind, place), span);
+ self.push_assignment(current, ref_place, Rvalue::Ref(borrow_kind, place), span);
let deref_trait = self
.resolve_lang_item(trait_lang_item)?
.as_trait()
@@ -359,7 +359,7 @@ impl MirLowerCtx<'_> {
let Some(current) = self.lower_call(
deref_fn_op,
Box::new([Operand::Copy(ref_place)]),
- result.clone(),
+ result,
current,
false,
span,
diff --git a/crates/hir-ty/src/mir/lower/pattern_matching.rs b/crates/hir-ty/src/mir/lower/pattern_matching.rs
index bbb513b24c..ea0beef3c0 100644
--- a/crates/hir-ty/src/mir/lower/pattern_matching.rs
+++ b/crates/hir-ty/src/mir/lower/pattern_matching.rs
@@ -58,7 +58,7 @@ impl MirLowerCtx<'_> {
let (current, current_else) = self.pattern_match_inner(
current,
current_else,
- cond_place.clone(),
+ cond_place,
pattern,
MatchingMode::Check,
)?;
@@ -114,7 +114,7 @@ impl MirLowerCtx<'_> {
index: i as u32,
}))
}),
- &(&mut cond_place),
+ &mut cond_place,
mode,
)?
}
@@ -125,7 +125,7 @@ impl MirLowerCtx<'_> {
let (mut next, next_else) = self.pattern_match_inner(
current,
None,
- (&mut cond_place).clone(),
+ cond_place,
*pat,
MatchingMode::Check,
)?;
@@ -133,7 +133,7 @@ impl MirLowerCtx<'_> {
(next, _) = self.pattern_match_inner(
next,
None,
- (&mut cond_place).clone(),
+ cond_place,
*pat,
MatchingMode::Bind,
)?;
@@ -169,7 +169,7 @@ impl MirLowerCtx<'_> {
current,
pattern.into(),
current_else,
- AdtPatternShape::Record { args: &*args },
+ AdtPatternShape::Record { args },
mode,
)?
}
@@ -183,12 +183,8 @@ impl MirLowerCtx<'_> {
self.temp(TyBuilder::bool(), current, pattern.into())?.into();
self.push_assignment(
current,
- discr.clone(),
- Rvalue::CheckedBinaryOp(
- binop,
- lv,
- Operand::Copy((&mut cond_place).clone()),
- ),
+ discr,
+ Rvalue::CheckedBinaryOp(binop, lv, Operand::Copy(cond_place)),
pattern.into(),
);
let discr = Operand::Copy(discr);
@@ -222,8 +218,8 @@ impl MirLowerCtx<'_> {
self.temp(TyBuilder::usize(), current, pattern.into())?.into();
self.push_assignment(
current,
- place_len.clone(),
- Rvalue::Len((&mut cond_place).clone()),
+ place_len,
+ Rvalue::Len(cond_place),
pattern.into(),
);
let else_target =
@@ -252,7 +248,7 @@ impl MirLowerCtx<'_> {
self.temp(TyBuilder::bool(), current, pattern.into())?.into();
self.push_assignment(
current,
- discr.clone(),
+ discr,
Rvalue::CheckedBinaryOp(BinOp::Le, c, Operand::Copy(place_len)),
pattern.into(),
);
@@ -270,7 +266,7 @@ impl MirLowerCtx<'_> {
}
}
for (i, &pat) in prefix.iter().enumerate() {
- let next_place = (&mut cond_place).project(
+ let next_place = cond_place.project(
ProjectionElem::ConstantIndex { offset: i as u64, from_end: false },
&mut self.result.projection_store,
);
@@ -280,7 +276,7 @@ impl MirLowerCtx<'_> {
if let Some(slice) = slice {
if mode == MatchingMode::Bind {
if let Pat::Bind { id, subpat: _ } = self.body[*slice] {
- let next_place = (&mut cond_place).project(
+ let next_place = cond_place.project(
ProjectionElem::Subslice {
from: prefix.len() as u64,
to: suffix.len() as u64,
@@ -299,7 +295,7 @@ impl MirLowerCtx<'_> {
}
}
for (i, &pat) in suffix.iter().enumerate() {
- let next_place = (&mut cond_place).project(
+ let next_place = cond_place.project(
ProjectionElem::ConstantIndex { offset: i as u64, from_end: true },
&mut self.result.projection_store,
);
@@ -348,7 +344,7 @@ impl MirLowerCtx<'_> {
self.lower_const(
c.into(),
current,
- tmp.clone(),
+ tmp,
subst,
span,
self.infer[pattern].clone(),
@@ -356,7 +352,7 @@ impl MirLowerCtx<'_> {
let tmp2: Place = self.temp(TyBuilder::bool(), current, pattern.into())?.into();
self.push_assignment(
current,
- tmp2.clone(),
+ tmp2,
Rvalue::CheckedBinaryOp(
BinOp::Eq,
Operand::Copy(tmp),
@@ -390,13 +386,8 @@ impl MirLowerCtx<'_> {
},
Pat::Bind { id, subpat } => {
if let Some(subpat) = subpat {
- (current, current_else) = self.pattern_match_inner(
- current,
- current_else,
- (&mut cond_place).clone(),
- *subpat,
- mode,
- )?
+ (current, current_else) =
+ self.pattern_match_inner(current, current_else, cond_place, *subpat, mode)?
}
if mode == MatchingMode::Bind {
self.pattern_match_binding(
@@ -475,7 +466,7 @@ impl MirLowerCtx<'_> {
let discr: Place = self.temp(TyBuilder::bool(), current, pattern.into())?.into();
self.push_assignment(
current,
- discr.clone(),
+ discr,
Rvalue::CheckedBinaryOp(BinOp::Eq, c, Operand::Copy(cond_place)),
pattern.into(),
);
@@ -506,12 +497,7 @@ impl MirLowerCtx<'_> {
if mode == MatchingMode::Check {
let e = self.const_eval_discriminant(v)? as u128;
let tmp = self.discr_temp_place(current);
- self.push_assignment(
- current,
- tmp.clone(),
- Rvalue::Discriminant(cond_place.clone()),
- span,
- );
+ self.push_assignment(current, tmp, Rvalue::Discriminant(cond_place), span);
let next = self.new_basic_block();
let else_target = current_else.get_or_insert_with(|| self.new_basic_block());
self.set_terminator(
@@ -568,7 +554,7 @@ impl MirLowerCtx<'_> {
variant_data.field(&x.name).ok_or(MirLowerError::UnresolvedField)?;
Ok((
PlaceElem::Field(Either::Left(FieldId {
- parent: v.into(),
+ parent: v,
local_id: field_id,
})),
x.pat,
@@ -579,7 +565,7 @@ impl MirLowerCtx<'_> {
}
AdtPatternShape::Tuple { args, ellipsis } => {
let fields = variant_data.fields().iter().map(|(x, _)| {
- PlaceElem::Field(Either::Left(FieldId { parent: v.into(), local_id: x }))
+ PlaceElem::Field(Either::Left(FieldId { parent: v, local_id: x }))
});
self.pattern_match_tuple_like(
current,
diff --git a/crates/hir-ty/src/mir/monomorphization.rs b/crates/hir-ty/src/mir/monomorphization.rs
index d2f8b592be..46dec257e8 100644
--- a/crates/hir-ty/src/mir/monomorphization.rs
+++ b/crates/hir-ty/src/mir/monomorphization.rs
@@ -306,7 +306,7 @@ pub fn monomorphized_mir_body_recover(
_: &Substitution,
_: &Arc<crate::TraitEnvironment>,
) -> Result<Arc<MirBody>, MirLowerError> {
- return Err(MirLowerError::Loop);
+ Err(MirLowerError::Loop)
}
pub fn monomorphized_mir_body_for_closure_query(
diff --git a/crates/hir-ty/src/mir/pretty.rs b/crates/hir-ty/src/mir/pretty.rs
index 65fb588482..23fc271355 100644
--- a/crates/hir-ty/src/mir/pretty.rs
+++ b/crates/hir-ty/src/mir/pretty.rs
@@ -344,7 +344,7 @@ impl<'a> MirPrettyCtx<'a> {
}
}
}
- f(self, p.local, &p.projection.lookup(&self.body.projection_store));
+ f(self, p.local, p.projection.lookup(&self.body.projection_store));
}
fn operand(&mut self, r: &Operand) {
diff --git a/crates/hir-ty/src/test_db.rs b/crates/hir-ty/src/test_db.rs
index d0a1fb1d57..460aabd733 100644
--- a/crates/hir-ty/src/test_db.rs
+++ b/crates/hir-ty/src/test_db.rs
@@ -43,13 +43,13 @@ impl fmt::Debug for TestDB {
impl Upcast<dyn ExpandDatabase> for TestDB {
fn upcast(&self) -> &(dyn ExpandDatabase + 'static) {
- &*self
+ self
}
}
impl Upcast<dyn DefDatabase> for TestDB {
fn upcast(&self) -> &(dyn DefDatabase + 'static) {
- &*self
+ self
}
}
diff --git a/crates/hir-ty/src/utils.rs b/crates/hir-ty/src/utils.rs
index e80eab8700..2cdee5a15a 100644
--- a/crates/hir-ty/src/utils.rs
+++ b/crates/hir-ty/src/utils.rs
@@ -438,7 +438,7 @@ pub(crate) fn detect_variant_from_bytes<'a>(
let krate = trait_env.krate;
let (var_id, var_layout) = match &layout.variants {
hir_def::layout::Variants::Single { index } => {
- (db.enum_data(e).variants[index.0].0, &*layout)
+ (db.enum_data(e).variants[index.0].0, layout)
}
hir_def::layout::Variants::Multiple { tag, tag_encoding, variants, .. } => {
let target_data_layout = db.target_data_layout(krate)?;
diff --git a/crates/ide-assists/src/handlers/add_missing_match_arms.rs b/crates/ide-assists/src/handlers/add_missing_match_arms.rs
index 2374da9a34..5ef374506e 100644
--- a/crates/ide-assists/src/handlers/add_missing_match_arms.rs
+++ b/crates/ide-assists/src/handlers/add_missing_match_arms.rs
@@ -188,7 +188,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
build_pat(
ctx.db(),
module,
- variant.clone(),
+ variant,
ctx.config.prefer_no_std,
ctx.config.prefer_prelude,
)
@@ -312,7 +312,7 @@ fn cursor_at_trivial_match_arm_list(
match_arm_list: &MatchArmList,
) -> Option<()> {
// match x { $0 }
- if match_arm_list.arms().next() == None {
+ if match_arm_list.arms().next().is_none() {
cov_mark::hit!(add_missing_match_arms_empty_body);
return Some(());
}
diff --git a/crates/ide-assists/src/handlers/add_turbo_fish.rs b/crates/ide-assists/src/handlers/add_turbo_fish.rs
index 88fd0b1b73..363aa142b2 100644
--- a/crates/ide-assists/src/handlers/add_turbo_fish.rs
+++ b/crates/ide-assists/src/handlers/add_turbo_fish.rs
@@ -85,9 +85,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
if let Some(let_stmt) = ctx.find_node_at_offset::<ast::LetStmt>() {
if let_stmt.colon_token().is_none() {
- if let_stmt.pat().is_none() {
- return None;
- }
+ let_stmt.pat()?;
acc.add(
AssistId("add_type_ascription", AssistKind::RefactorRewrite),
diff --git a/crates/ide-assists/src/handlers/bool_to_enum.rs b/crates/ide-assists/src/handlers/bool_to_enum.rs
index bec540790b..fd3a0506ab 100644
--- a/crates/ide-assists/src/handlers/bool_to_enum.rs
+++ b/crates/ide-assists/src/handlers/bool_to_enum.rs
@@ -422,9 +422,7 @@ fn find_record_pat_field_usage(name: &ast::NameLike) -> Option<ast::Pat> {
fn find_assoc_const_usage(name: &ast::NameLike) -> Option<(ast::Type, ast::Expr)> {
let const_ = name.syntax().parent().and_then(ast::Const::cast)?;
- if const_.syntax().parent().and_then(ast::AssocItemList::cast).is_none() {
- return None;
- }
+ const_.syntax().parent().and_then(ast::AssocItemList::cast)?;
Some((const_.ty()?, const_.body()?))
}
diff --git a/crates/ide-assists/src/handlers/change_visibility.rs b/crates/ide-assists/src/handlers/change_visibility.rs
index e6179ab8b1..07fd5e3418 100644
--- a/crates/ide-assists/src/handlers/change_visibility.rs
+++ b/crates/ide-assists/src/handlers/change_visibility.rs
@@ -96,7 +96,7 @@ fn can_add(node: &SyntaxNode) -> bool {
if p.kind() == ASSOC_ITEM_LIST {
p.parent()
- .and_then(|it| ast::Impl::cast(it))
+ .and_then(ast::Impl::cast)
// inherent impls i.e 'non-trait impls' have a non-local
// effect, thus can have visibility even when nested.
// so filter them out
diff --git a/crates/ide-assists/src/handlers/convert_match_to_let_else.rs b/crates/ide-assists/src/handlers/convert_match_to_let_else.rs
index fc6236a175..5657f2dbfb 100644
--- a/crates/ide-assists/src/handlers/convert_match_to_let_else.rs
+++ b/crates/ide-assists/src/handlers/convert_match_to_let_else.rs
@@ -113,7 +113,7 @@ fn find_extracted_variable(ctx: &AssistContext<'_>, arm: &ast::MatchArm) -> Opti
}
_ => {
cov_mark::hit!(extracting_arm_is_not_an_identity_expr);
- return None;
+ None
}
}
}
diff --git a/crates/ide-assists/src/handlers/convert_to_guarded_return.rs b/crates/ide-assists/src/handlers/convert_to_guarded_return.rs
index 73ba3f5c4c..53869d93b1 100644
--- a/crates/ide-assists/src/handlers/convert_to_guarded_return.rs
+++ b/crates/ide-assists/src/handlers/convert_to_guarded_return.rs
@@ -87,9 +87,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext<'
_ => return None,
};
- if then_block.syntax().first_child_or_token().map(|t| t.kind() == T!['{']).is_none() {
- return None;
- }
+ then_block.syntax().first_child_or_token().map(|t| t.kind() == T!['{'])?;
then_block.syntax().last_child_or_token().filter(|t| t.kind() == T!['}'])?;
diff --git a/crates/ide-assists/src/handlers/destructure_tuple_binding.rs b/crates/ide-assists/src/handlers/destructure_tuple_binding.rs
index 65b497e83a..06f7b6cc5a 100644
--- a/crates/ide-assists/src/handlers/destructure_tuple_binding.rs
+++ b/crates/ide-assists/src/handlers/destructure_tuple_binding.rs
@@ -84,8 +84,8 @@ fn destructure_tuple_edit_impl(
data: &TupleData,
in_sub_pattern: bool,
) {
- let assignment_edit = edit_tuple_assignment(ctx, edit, &data, in_sub_pattern);
- let current_file_usages_edit = edit_tuple_usages(&data, edit, ctx, in_sub_pattern);
+ let assignment_edit = edit_tuple_assignment(ctx, edit, data, in_sub_pattern);
+ let current_file_usages_edit = edit_tuple_usages(data, edit, ctx, in_sub_pattern);
assignment_edit.apply();
if let Some(usages_edit) = current_file_usages_edit {
@@ -258,7 +258,7 @@ fn edit_tuple_usage(
Some(index) => Some(edit_tuple_field_usage(ctx, builder, data, index)),
None if in_sub_pattern => {
cov_mark::hit!(destructure_tuple_call_with_subpattern);
- return None;
+ None
}
None => Some(EditTupleUsage::NoIndex(usage.range)),
}
@@ -375,7 +375,7 @@ impl RefData {
expr = make::expr_paren(expr);
}
- return expr;
+ expr
}
}
fn handle_ref_field_usage(ctx: &AssistContext<'_>, field_expr: &FieldExpr) -> (ast::Expr, RefData) {
diff --git a/crates/ide-assists/src/handlers/extract_module.rs b/crates/ide-assists/src/handlers/extract_module.rs
index 4b9fedc7e8..3bc13bde26 100644
--- a/crates/ide-assists/src/handlers/extract_module.rs
+++ b/crates/ide-assists/src/handlers/extract_module.rs
@@ -668,7 +668,7 @@ fn check_intersection_and_push(
// check for intersection between all current members
// and combine all such ranges into one.
let s: SmallVec<[_; 2]> = import_paths_to_be_removed
- .into_iter()
+ .iter_mut()
.positions(|it| it.intersect(import_path).is_some())
.collect();
for pos in s.into_iter().rev() {
diff --git a/crates/ide-assists/src/handlers/extract_type_alias.rs b/crates/ide-assists/src/handlers/extract_type_alias.rs
index b6e7d6209c..3612eda784 100644
--- a/crates/ide-assists/src/handlers/extract_type_alias.rs
+++ b/crates/ide-assists/src/handlers/extract_type_alias.rs
@@ -185,7 +185,7 @@ fn collect_used_generics<'gp>(
ast::GenericParam::TypeParam(_) => 1,
});
- Some(generics).filter(|it| it.len() > 0)
+ Some(generics).filter(|it| !it.is_empty())
}
#[cfg(test)]
diff --git a/crates/ide-assists/src/handlers/extract_variable.rs b/crates/ide-assists/src/handlers/extract_variable.rs
index 0b3bd0bed6..0f23b69908 100644
--- a/crates/ide-assists/src/handlers/extract_variable.rs
+++ b/crates/ide-assists/src/handlers/extract_variable.rs
@@ -115,7 +115,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
let trailing_ws = if prev_ws.is_some_and(|it| it.text().starts_with('\n')) {
format!("\n{indent_to}")
} else {
- format!(" ")
+ " ".to_string()
};
ted::insert_all_raw(
diff --git a/crates/ide-assists/src/handlers/flip_trait_bound.rs b/crates/ide-assists/src/handlers/flip_trait_bound.rs
index e3ae4970b6..430cd5b080 100644
--- a/crates/ide-assists/src/handlers/flip_trait_bound.rs
+++ b/crates/ide-assists/src/handlers/flip_trait_bound.rs
@@ -23,9 +23,7 @@ pub(crate) fn flip_trait_bound(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
let plus = ctx.find_token_syntax_at_offset(T![+])?;
// Make sure we're in a `TypeBoundList`
- if ast::TypeBoundList::cast(plus.parent()?).is_none() {
- return None;
- }
+ ast::TypeBoundList::cast(plus.parent()?)?;
let (before, after) = (
non_trivia_sibling(plus.clone().into(), Direction::Prev)?,
diff --git a/crates/ide-assists/src/handlers/generate_constant.rs b/crates/ide-assists/src/handlers/generate_constant.rs
index 8b8c6ceee9..4d8116a715 100644
--- a/crates/ide-assists/src/handlers/generate_constant.rs
+++ b/crates/ide-assists/src/handlers/generate_constant.rs
@@ -107,10 +107,10 @@ fn get_text_for_generate_constant(
type_name: String,
) -> Option<String> {
let constant_token = not_exist_name_ref.pop()?;
- let vis = if not_exist_name_ref.len() == 0 && !outer_exists { "" } else { "\npub " };
+ let vis = if not_exist_name_ref.is_empty() && !outer_exists { "" } else { "\npub " };
let mut text = format!("{vis}const {constant_token}: {type_name} = $0;");
while let Some(name_ref) = not_exist_name_ref.pop() {
- let vis = if not_exist_name_ref.len() == 0 && !outer_exists { "" } else { "\npub " };
+ let vis = if not_exist_name_ref.is_empty() && !outer_exists { "" } else { "\npub " };
text = text.replace('\n', "\n ");
text = format!("{vis}mod {name_ref} {{{text}\n}}");
}
@@ -136,8 +136,7 @@ fn target_data_for_generate_constant(
let siblings_has_newline = l_curly_token
.siblings_with_tokens(Direction::Next)
- .find(|it| it.kind() == SyntaxKind::WHITESPACE && it.to_string().contains('\n'))
- .is_some();
+ .any(|it| it.kind() == SyntaxKind::WHITESPACE && it.to_string().contains('\n'));
let post_string =
if siblings_has_newline { format!("{indent}") } else { format!("\n{indent}") };
Some((offset, indent + 1, Some(file_id), post_string))
diff --git a/crates/ide-assists/src/handlers/generate_delegate_methods.rs b/crates/ide-assists/src/handlers/generate_delegate_methods.rs
index 1f5c24f8ea..d59bd71d31 100644
--- a/crates/ide-assists/src/handlers/generate_delegate_methods.rs
+++ b/crates/ide-assists/src/handlers/generate_delegate_methods.rs
@@ -134,7 +134,7 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
// compute the `body`
let arg_list = method_source
.param_list()
- .map(|list| convert_param_list_to_arg_list(list))
+ .map(convert_param_list_to_arg_list)
.unwrap_or_else(|| make::arg_list([]));
let tail_expr = make::expr_method_call(field, make::name_ref(&name), arg_list);
diff --git a/crates/ide-assists/src/handlers/generate_delegate_trait.rs b/crates/ide-assists/src/handlers/generate_delegate_trait.rs
index 339c3ac71e..efb92936c4 100644
--- a/crates/ide-assists/src/handlers/generate_delegate_trait.rs
+++ b/crates/ide-assists/src/handlers/generate_delegate_trait.rs
@@ -88,11 +88,11 @@ pub(crate) fn generate_delegate_trait(acc: &mut Assists, ctx: &AssistContext<'_>
let strukt = Struct::new(ctx.find_node_at_offset::<ast::Struct>()?)?;
let field: Field = match ctx.find_node_at_offset::<ast::RecordField>() {
- Some(field) => Field::new(&ctx, Either::Left(field))?,
+ Some(field) => Field::new(ctx, Either::Left(field))?,
None => {
let field = ctx.find_node_at_offset::<ast::TupleField>()?;
let field_list = ctx.find_node_at_offset::<ast::TupleFieldList>()?;
- Field::new(&ctx, either::Right((field, field_list)))?
+ Field::new(ctx, either::Right((field, field_list)))?
}
};
@@ -276,7 +276,7 @@ fn generate_impl(
.filter(|item| matches!(item, AssocItem::MacroCall(_)).not())
.for_each(|item| {
let assoc =
- process_assoc_item(item, qualified_path_type.clone(), &field_name);
+ process_assoc_item(item, qualified_path_type.clone(), field_name);
if let Some(assoc) = assoc {
delegate_assoc_items.add_item(assoc);
}
@@ -288,7 +288,7 @@ fn generate_impl(
let target_scope = ctx.sema.scope(strukt.strukt.syntax())?;
let source_scope = ctx.sema.scope(bound_def.syntax())?;
let transform = PathTransform::generic_transformation(&target_scope, &source_scope);
- transform.apply(&delegate.syntax());
+ transform.apply(delegate.syntax());
}
Delegee::Impls(trait_, old_impl) => {
let old_impl = ctx.sema.source(old_impl.to_owned())?.value;
@@ -306,7 +306,7 @@ fn generate_impl(
let field_ty = rename_strukt_args(ctx, ast_strukt, field_ty, &args)?;
let where_clause = ast_strukt
.where_clause()
- .and_then(|wc| Some(rename_strukt_args(ctx, ast_strukt, &wc, &args)?));
+ .and_then(|wc| rename_strukt_args(ctx, ast_strukt, &wc, &args));
(field_ty, where_clause)
}
None => (field_ty.clone_for_update(), None),
@@ -323,7 +323,7 @@ fn generate_impl(
.trait_()?
.generic_arg_list()
.map(|l| l.generic_args().map(|arg| arg.to_string()))
- .map_or_else(|| FxHashSet::default(), |it| it.collect());
+ .map_or_else(FxHashSet::default, |it| it.collect());
let trait_gen_params = remove_instantiated_params(
&old_impl.self_ty()?,
@@ -345,13 +345,13 @@ fn generate_impl(
let mut trait_gen_args = old_impl.trait_()?.generic_arg_list();
if let Some(trait_args) = &mut trait_gen_args {
*trait_args = trait_args.clone_for_update();
- transform_impl(ctx, ast_strukt, &old_impl, &transform_args, &trait_args.syntax())?;
+ transform_impl(ctx, ast_strukt, &old_impl, &transform_args, trait_args.syntax())?;
}
let type_gen_args = strukt_params.clone().map(|params| params.to_generic_args());
let path_type = make::ty(&trait_.name(db).to_smol_str()).clone_for_update();
- transform_impl(ctx, ast_strukt, &old_impl, &transform_args, &path_type.syntax())?;
+ transform_impl(ctx, ast_strukt, &old_impl, &transform_args, path_type.syntax())?;
// 3) Generate delegate trait impl
delegate = make::impl_trait(
@@ -383,7 +383,7 @@ fn generate_impl(
let item = item.clone_for_update();
transform_impl(ctx, ast_strukt, &old_impl, &transform_args, item.syntax())?;
- let assoc = process_assoc_item(item, qualified_path_type.clone(), &field_name)?;
+ let assoc = process_assoc_item(item, qualified_path_type.clone(), field_name)?;
delegate_assoc_items.add_item(assoc);
}
@@ -404,8 +404,8 @@ fn transform_impl(
args: &Option<GenericArgList>,
syntax: &syntax::SyntaxNode,
) -> Option<()> {
- let source_scope = ctx.sema.scope(&old_impl.self_ty()?.syntax())?;
- let target_scope = ctx.sema.scope(&strukt.syntax())?;
+ let source_scope = ctx.sema.scope(old_impl.self_ty()?.syntax())?;
+ let target_scope = ctx.sema.scope(strukt.syntax())?;
let hir_old_impl = ctx.sema.to_impl_def(old_impl)?;
let transform = args.as_ref().map_or_else(
@@ -420,7 +420,7 @@ fn transform_impl(
},
);
- transform.apply(&syntax);
+ transform.apply(syntax);
Some(())
}
@@ -481,7 +481,7 @@ fn remove_useless_where_clauses(trait_ty: &ast::Type, self_ty: &ast::Type, wc: a
.skip(1)
.take_while(|node_or_tok| node_or_tok.kind() == SyntaxKind::WHITESPACE)
})
- .for_each(|ws| ted::remove(ws));
+ .for_each(ted::remove);
ted::insert(
ted::Position::after(wc.syntax()),
@@ -539,7 +539,7 @@ fn generate_args_for_impl(
)
})
.collect_vec();
- args.is_empty().not().then(|| make::generic_arg_list(args.into_iter()))
+ args.is_empty().not().then(|| make::generic_arg_list(args))
}
fn rename_strukt_args<N>(
@@ -558,7 +558,7 @@ where
let scope = ctx.sema.scope(item.syntax())?;
let transform = PathTransform::adt_transformation(&scope, &scope, hir_adt, args.clone());
- transform.apply(&item.syntax());
+ transform.apply(item.syntax());
Some(item)
}
diff --git a/crates/ide-assists/src/handlers/generate_documentation_template.rs b/crates/ide-assists/src/handlers/generate_documentation_template.rs
index e87132218e..f298ce8916 100644
--- a/crates/ide-assists/src/handlers/generate_documentation_template.rs
+++ b/crates/ide-assists/src/handlers/generate_documentation_template.rs
@@ -148,7 +148,7 @@ fn make_example_for_fn(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<St
format_to!(example, "use {use_path};\n\n");
if let Some(self_name) = &self_name {
if let Some(mut_) = is_ref_mut_self(ast_func) {
- let mut_ = if mut_ == true { "mut " } else { "" };
+ let mut_ = if mut_ { "mut " } else { "" };
format_to!(example, "let {mut_}{self_name} = ;\n");
}
}
diff --git a/crates/ide-assists/src/handlers/generate_enum_variant.rs b/crates/ide-assists/src/handlers/generate_enum_variant.rs
index 2aaf9d0679..681f8c1fcf 100644
--- a/crates/ide-assists/src/handlers/generate_enum_variant.rs
+++ b/crates/ide-assists/src/handlers/generate_enum_variant.rs
@@ -124,7 +124,9 @@ fn add_variant_to_accumulator(
builder.edit_file(file_id);
let node = builder.make_mut(enum_node);
let variant = make_variant(ctx, name_ref, parent);
- node.variant_list().map(|it| it.add_variant(variant.clone_for_update()));
+ if let Some(it) = node.variant_list() {
+ it.add_variant(variant.clone_for_update())
+ }
},
)
}
diff --git a/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs b/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs
index 742f1f78c2..6091f06b96 100644
--- a/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs
+++ b/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs
@@ -90,7 +90,7 @@ fn existing_from_impl(
let enum_type = enum_.ty(sema.db);
- let wrapped_type = variant.fields(sema.db).get(0)?.ty(sema.db);
+ let wrapped_type = variant.fields(sema.db).first()?.ty(sema.db);
if enum_type.impls_trait(sema.db, from_trait, &[wrapped_type]) {
Some(())
diff --git a/crates/ide-assists/src/handlers/generate_getter_or_setter.rs b/crates/ide-assists/src/handlers/generate_getter_or_setter.rs
index 9c9478b040..596e277e0f 100644
--- a/crates/ide-assists/src/handlers/generate_getter_or_setter.rs
+++ b/crates/ide-assists/src/handlers/generate_getter_or_setter.rs
@@ -42,7 +42,7 @@ pub(crate) fn generate_setter(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt
let (strukt, info_of_record_fields, mut fn_names) = extract_and_parse(ctx, AssistType::Set)?;
// No record fields to do work on :(
- if info_of_record_fields.len() == 0 {
+ if info_of_record_fields.is_empty() {
return None;
}
@@ -163,7 +163,7 @@ pub(crate) fn generate_getter_impl(
let (strukt, info_of_record_fields, fn_names) =
extract_and_parse(ctx, if mutable { AssistType::MutGet } else { AssistType::Get })?;
// No record fields to do work on :(
- if info_of_record_fields.len() == 0 {
+ if info_of_record_fields.is_empty() {
return None;
}
@@ -318,15 +318,13 @@ fn extract_and_parse_record_fields(
})
.collect::<Vec<RecordFieldInfo>>();
- if info_of_record_fields_in_selection.len() == 0 {
+ if info_of_record_fields_in_selection.is_empty() {
return None;
}
Some((info_of_record_fields_in_selection, field_names))
}
- ast::FieldList::TupleFieldList(_) => {
- return None;
- }
+ ast::FieldList::TupleFieldList(_) => None,
}
}
@@ -409,7 +407,7 @@ fn build_source_change(
// getter and end of impl ( i.e. `}` ) with an
// extra line for no reason
if i < record_fields_count - 1 {
- buf = buf + "\n";
+ buf += "\n";
}
}
diff --git a/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs b/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs
index 4429186196..6bfc69b0ad 100644
--- a/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs
+++ b/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs
@@ -95,7 +95,7 @@ fn get_impl_method(
let scope = ctx.sema.scope(impl_.syntax())?;
let ty = impl_def.self_ty(db);
- ty.iterate_method_candidates(db, &scope, None, Some(fn_name), |func| Some(func))
+ ty.iterate_method_candidates(db, &scope, None, Some(fn_name), Some)
}
#[cfg(test)]
diff --git a/crates/ide-assists/src/handlers/generate_trait_from_impl.rs b/crates/ide-assists/src/handlers/generate_trait_from_impl.rs
index 315b6487b5..8f61b43cd0 100644
--- a/crates/ide-assists/src/handlers/generate_trait_from_impl.rs
+++ b/crates/ide-assists/src/handlers/generate_trait_from_impl.rs
@@ -85,10 +85,7 @@ pub(crate) fn generate_trait_from_impl(acc: &mut Assists, ctx: &AssistContext<'_
let assoc_items = impl_ast.assoc_item_list()?;
let first_element = assoc_items.assoc_items().next();
- if first_element.is_none() {
- // No reason for an assist.
- return None;
- }
+ first_element.as_ref()?;
let impl_name = impl_ast.self_ty()?;
diff --git a/crates/ide-assists/src/handlers/inline_const_as_literal.rs b/crates/ide-assists/src/handlers/inline_const_as_literal.rs
index 5b1540b50c..d5ede9e3c0 100644
--- a/crates/ide-assists/src/handlers/inline_const_as_literal.rs
+++ b/crates/ide-assists/src/handlers/inline_const_as_literal.rs
@@ -60,7 +60,7 @@ pub(crate) fn inline_const_as_literal(acc: &mut Assists, ctx: &AssistContext<'_>
let id = AssistId("inline_const_as_literal", AssistKind::RefactorInline);
- let label = format!("Inline const as literal");
+ let label = "Inline const as literal".to_string();
let target = variable.syntax().text_range();
return acc.add(id, label, target, |edit| {
@@ -138,7 +138,7 @@ mod tests {
// -----------Not supported-----------
#[test]
fn inline_const_as_literal_const_fn_call_slice() {
- TEST_PAIRS.into_iter().for_each(|(ty, val, _)| {
+ TEST_PAIRS.iter().for_each(|(ty, val, _)| {
check_assist_not_applicable(
inline_const_as_literal,
&format!(
@@ -240,7 +240,7 @@ mod tests {
#[test]
fn inline_const_as_literal_const_expr() {
- TEST_PAIRS.into_iter().for_each(|(ty, val, _)| {
+ TEST_PAIRS.iter().for_each(|(ty, val, _)| {
check_assist(
inline_const_as_literal,
&format!(
@@ -261,7 +261,7 @@ mod tests {
#[test]
fn inline_const_as_literal_const_block_expr() {
- TEST_PAIRS.into_iter().for_each(|(ty, val, _)| {
+ TEST_PAIRS.iter().for_each(|(ty, val, _)| {
check_assist(
inline_const_as_literal,
&format!(
@@ -282,7 +282,7 @@ mod tests {
#[test]
fn inline_const_as_literal_const_block_eval_expr() {
- TEST_PAIRS.into_iter().for_each(|(ty, val, _)| {
+ TEST_PAIRS.iter().for_each(|(ty, val, _)| {
check_assist(
inline_const_as_literal,
&format!(
@@ -303,7 +303,7 @@ mod tests {
#[test]
fn inline_const_as_literal_const_block_eval_block_expr() {
- TEST_PAIRS.into_iter().for_each(|(ty, val, _)| {
+ TEST_PAIRS.iter().for_each(|(ty, val, _)| {
check_assist(
inline_const_as_literal,
&format!(
@@ -324,7 +324,7 @@ mod tests {
#[test]
fn inline_const_as_literal_const_fn_call_block_nested_builtin() {
- TEST_PAIRS.into_iter().for_each(|(ty, val, _)| {
+ TEST_PAIRS.iter().for_each(|(ty, val, _)| {
check_assist(
inline_const_as_literal,
&format!(
@@ -347,7 +347,7 @@ mod tests {
#[test]
fn inline_const_as_literal_const_fn_call_tuple() {
- TEST_PAIRS.into_iter().for_each(|(ty, val, _)| {
+ TEST_PAIRS.iter().for_each(|(ty, val, _)| {
check_assist(
inline_const_as_literal,
&format!(
@@ -370,7 +370,7 @@ mod tests {
#[test]
fn inline_const_as_literal_const_fn_call_builtin() {
- TEST_PAIRS.into_iter().for_each(|(ty, val, _)| {
+ TEST_PAIRS.iter().for_each(|(ty, val, _)| {
check_assist(
inline_const_as_literal,
&format!(
diff --git a/crates/ide-assists/src/handlers/inline_macro.rs b/crates/ide-assists/src/handlers/inline_macro.rs
index 5d956b1a5e..c1beb46c80 100644
--- a/crates/ide-assists/src/handlers/inline_macro.rs
+++ b/crates/ide-assists/src/handlers/inline_macro.rs
@@ -41,7 +41,7 @@ pub(crate) fn inline_macro(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
acc.add(
AssistId("inline_macro", AssistKind::RefactorInline),
- format!("Inline macro"),
+ "Inline macro".to_string(),
text_range,
|builder| builder.replace(text_range, expanded.to_string()),
)
diff --git a/crates/ide-assists/src/handlers/introduce_named_generic.rs b/crates/ide-assists/src/handlers/introduce_named_generic.rs
index b1daa7802e..543b7f7ab6 100644
--- a/crates/ide-assists/src/handlers/introduce_named_generic.rs
+++ b/crates/ide-assists/src/handlers/introduce_named_generic.rs
@@ -18,7 +18,7 @@ use crate::{utils::suggest_name, AssistContext, AssistId, AssistKind, Assists};
// ```
pub(crate) fn introduce_named_generic(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let impl_trait_type = ctx.find_node_at_offset::<ast::ImplTraitType>()?;
- let param = impl_trait_type.syntax().ancestors().find_map(|node| ast::Param::cast(node))?;
+ let param = impl_trait_type.syntax().ancestors().find_map(ast::Param::cast)?;
let fn_ = param.syntax().ancestors().find_map(ast::Fn::cast)?;
let type_bound_list = impl_trait_type.type_bound_list()?;
diff --git a/crates/ide-assists/src/handlers/remove_unused_imports.rs b/crates/ide-assists/src/handlers/remove_unused_imports.rs
index 859ed1476c..35bf84c434 100644
--- a/crates/ide-assists/src/handlers/remove_unused_imports.rs
+++ b/crates/ide-assists/src/handlers/remove_unused_imports.rs
@@ -54,7 +54,7 @@ pub(crate) fn remove_unused_imports(acc: &mut Assists, ctx: &AssistContext<'_>)
.filter_map(|u| {
// Find any uses trees that are unused
- let use_module = ctx.sema.scope(&u.syntax()).map(|s| s.module())?;
+ let use_module = ctx.sema.scope(u.syntax()).map(|s| s.module())?;
let scope = match search_scopes.entry(use_module) {
Entry::Occupied(o) => o.into_mut(),
Entry::Vacant(v) => v.insert(module_search_scope(ctx.db(), use_module)),
@@ -113,10 +113,8 @@ pub(crate) fn remove_unused_imports(acc: &mut Assists, ctx: &AssistContext<'_>)
{
return Some(u);
}
- } else {
- if !used_once_in_scope(ctx, def, &scope) {
- return Some(u);
- }
+ } else if !used_once_in_scope(ctx, def, scope) {
+ return Some(u);
}
None
@@ -208,7 +206,7 @@ fn module_search_scope(db: &RootDatabase, module: hir::Module) -> Vec<SearchScop
};
let mut new_ranges = Vec::new();
for old_range in ranges.iter_mut() {
- let split = split_at_subrange(old_range.clone(), rng);
+ let split = split_at_subrange(*old_range, rng);
*old_range = split.0;
new_ranges.extend(split.1);
}
diff --git a/crates/ide-assists/src/handlers/replace_if_let_with_match.rs b/crates/ide-assists/src/handlers/replace_if_let_with_match.rs
index 5e31d38fbd..f13b0b0713 100644
--- a/crates/ide-assists/src/handlers/replace_if_let_with_match.rs
+++ b/crates/ide-assists/src/handlers/replace_if_let_with_match.rs
@@ -279,7 +279,7 @@ pub(crate) fn replace_match_with_if_let(acc: &mut Assists, ctx: &AssistContext<'
let then_block = make_block_expr(then_expr.reset_indent());
let else_expr = if is_empty_expr(&else_expr) { None } else { Some(else_expr) };
let if_let_expr = make::expr_if(
- condition.into(),
+ condition,
then_block,
else_expr.map(make_block_expr).map(ast::ElseBranch::Block),
)
diff --git a/crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs b/crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs
index 09759019ba..59bb0c45e1 100644
--- a/crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs
+++ b/crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs
@@ -74,7 +74,7 @@ pub(crate) fn replace_is_method_with_if_let_method(
},
)
}
- _ => return None,
+ _ => None,
}
}
diff --git a/crates/ide-assists/src/handlers/replace_method_eager_lazy.rs b/crates/ide-assists/src/handlers/replace_method_eager_lazy.rs
index a7e3ed793f..7f3b0d7588 100644
--- a/crates/ide-assists/src/handlers/replace_method_eager_lazy.rs
+++ b/crates/ide-assists/src/handlers/replace_method_eager_lazy.rs
@@ -133,7 +133,7 @@ pub(crate) fn replace_with_eager_method(acc: &mut Assists, ctx: &AssistContext<'
None,
None,
|func| {
- let valid = func.name(ctx.sema.db).as_str() == Some(&*method_name_eager)
+ let valid = func.name(ctx.sema.db).as_str() == Some(method_name_eager)
&& func.num_params(ctx.sema.db) == n_params;
valid.then_some(func)
},
diff --git a/crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs b/crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs
index 43a97d7d3a..5cc95fd9c0 100644
--- a/crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs
+++ b/crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs
@@ -111,7 +111,7 @@ fn generic_arg_list(expr: &Expr) -> Option<GenericArgList> {
pe.path()?.segment()?.generic_arg_list()
} else {
cov_mark::hit!(not_applicable_if_non_path_function_call);
- return None;
+ None
}
}
Expr::AwaitExpr(expr) => generic_arg_list(&expr.expr()?),
diff --git a/crates/ide-assists/src/handlers/unwrap_block.rs b/crates/ide-assists/src/handlers/unwrap_block.rs
index 939055f148..de801279a0 100644
--- a/crates/ide-assists/src/handlers/unwrap_block.rs
+++ b/crates/ide-assists/src/handlers/unwrap_block.rs
@@ -53,7 +53,7 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
let stmts: Vec<ast::Stmt> = list.statements().collect();
let initializer = ast::Expr::cast(last)?;
let let_stmt = make::let_stmt(pattern, ty, Some(initializer));
- if stmts.len() > 0 {
+ if !stmts.is_empty() {
let block = make::block_expr(stmts, None);
format!("{}\n {}", update_expr_string(block.to_string()), let_stmt)
} else {
diff --git a/crates/ide-assists/src/tests.rs b/crates/ide-assists/src/tests.rs
index 277e5f8e33..573d69b5c6 100644
--- a/crates/ide-assists/src/tests.rs
+++ b/crates/ide-assists/src/tests.rs
@@ -243,7 +243,7 @@ fn check_with_config(
.filter(|it| !it.source_file_edits.is_empty() || !it.file_system_edits.is_empty())
.expect("Assist did not contain any source changes");
let skip_header = source_change.source_file_edits.len() == 1
- && source_change.file_system_edits.len() == 0;
+ && source_change.file_system_edits.is_empty();
let mut buf = String::new();
for (file_id, (edit, snippet_edit)) in source_change.source_file_edits {
diff --git a/crates/ide-assists/src/tests/sourcegen.rs b/crates/ide-assists/src/tests/sourcegen.rs
index 3da90e9052..ad5ec83287 100644
--- a/crates/ide-assists/src/tests/sourcegen.rs
+++ b/crates/ide-assists/src/tests/sourcegen.rs
@@ -103,7 +103,7 @@ impl Assist {
let doc = take_until(lines.by_ref(), "```").trim().to_string();
assert!(
(doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with('.'))
- || assist.sections.len() > 0,
+ || !assist.sections.is_empty(),
"\n\n{}: assist docs should be proper sentences, with capitalization and a full stop at the end.\n\n{}\n\n",
&assist.id,
doc,
diff --git a/crates/ide-assists/src/utils.rs b/crates/ide-assists/src/utils.rs
index 927a8e3c19..2420945f75 100644
--- a/crates/ide-assists/src/utils.rs
+++ b/crates/ide-assists/src/utils.rs
@@ -117,7 +117,7 @@ pub fn filter_assoc_items(
return false;
}
- return true;
+ true
})
// Note: This throws away items with no source.
.filter_map(|assoc_item| {
@@ -165,7 +165,7 @@ pub fn add_trait_assoc_items_to_impl(
target_scope: hir::SemanticsScope<'_>,
) -> ast::AssocItem {
let new_indent_level = IndentLevel::from_node(impl_.syntax()) + 1;
- let items = original_items.into_iter().map(|InFile { file_id, value: original_item }| {
+ let items = original_items.iter().map(|InFile { file_id, value: original_item }| {
let cloned_item = {
if file_id.is_macro() {
if let Some(formatted) =
diff --git a/crates/ide-assists/src/utils/gen_trait_fn_body.rs b/crates/ide-assists/src/utils/gen_trait_fn_body.rs
index 808b234059..ad9cb6a171 100644
--- a/crates/ide-assists/src/utils/gen_trait_fn_body.rs
+++ b/crates/ide-assists/src/utils/gen_trait_fn_body.rs
@@ -648,7 +648,7 @@ fn gen_partial_ord(adt: &ast::Adt, func: &ast::Fn, trait_ref: Option<TraitRef>)
.into_iter()
.map(gen_partial_eq_match)
.collect::<Option<Vec<ast::Stmt>>>()?;
- make::block_expr(stmts.into_iter(), tail).indent(ast::edit::IndentLevel(1))
+ make::block_expr(stmts, tail).indent(ast::edit::IndentLevel(1))
}
Some(ast::FieldList::TupleFieldList(field_list)) => {
@@ -667,7 +667,7 @@ fn gen_partial_ord(adt: &ast::Adt, func: &ast::Fn, trait_ref: Option<TraitRef>)
.into_iter()
.map(gen_partial_eq_match)
.collect::<Option<Vec<ast::Stmt>>>()?;
- make::block_expr(stmts.into_iter(), tail).indent(ast::edit::IndentLevel(1))
+ make::block_expr(stmts, tail).indent(ast::edit::IndentLevel(1))
}
// No fields in the body means there's nothing to compare.
diff --git a/crates/ide-completion/src/completions/attribute.rs b/crates/ide-completion/src/completions/attribute.rs
index 9155caa2e0..8f7c3b5070 100644
--- a/crates/ide-completion/src/completions/attribute.rs
+++ b/crates/ide-completion/src/completions/attribute.rs
@@ -44,9 +44,7 @@ pub(crate) fn complete_known_attribute_input(
None => None,
};
let (path, tt) = name_ref.zip(attribute.token_tree())?;
- if tt.l_paren_token().is_none() {
- return None;
- }
+ tt.l_paren_token()?;
match path.text().as_str() {
"repr" => repr::complete_repr(acc, ctx, tt),
diff --git a/crates/ide-completion/src/completions/env_vars.rs b/crates/ide-completion/src/completions/env_vars.rs
index 419b864565..35e6b97eb7 100644
--- a/crates/ide-completion/src/completions/env_vars.rs
+++ b/crates/ide-completion/src/completions/env_vars.rs
@@ -37,7 +37,7 @@ pub(crate) fn complete_cargo_env_vars(
guard_env_macro(expanded, &ctx.sema)?;
let range = expanded.text_range_between_quotes()?;
- CARGO_DEFINED_VARS.into_iter().for_each(|&(var, detail)| {
+ CARGO_DEFINED_VARS.iter().for_each(|&(var, detail)| {
let mut item = CompletionItem::new(CompletionItemKind::Keyword, range, var);
item.detail(detail);
item.add_to(acc, ctx.db);
diff --git a/crates/ide-completion/src/completions/flyimport.rs b/crates/ide-completion/src/completions/flyimport.rs
index 446f0be834..3cb090da1a 100644
--- a/crates/ide-completion/src/completions/flyimport.rs
+++ b/crates/ide-completion/src/completions/flyimport.rs
@@ -209,9 +209,7 @@ fn import_on_the_fly(
) -> Option<()> {
let _p = profile::span("import_on_the_fly").detail(|| potential_import_name.clone());
- if ImportScope::find_insert_use_container(&position, &ctx.sema).is_none() {
- return None;
- }
+ ImportScope::find_insert_use_container(&position, &ctx.sema)?;
let ns_filter = |import: &LocatedImport| {
match (kind, import.original_item) {
@@ -297,9 +295,7 @@ fn import_on_the_fly_pat_(
) -> Option<()> {
let _p = profile::span("import_on_the_fly_pat").detail(|| potential_import_name.clone());
- if ImportScope::find_insert_use_container(&position, &ctx.sema).is_none() {
- return None;
- }
+ ImportScope::find_insert_use_container(&position, &ctx.sema)?;
let ns_filter = |import: &LocatedImport| match import.original_item {
ItemInNs::Macros(mac) => mac.is_fn_like(ctx.db),
@@ -349,9 +345,7 @@ fn import_on_the_fly_method(
) -> Option<()> {
let _p = profile::span("import_on_the_fly_method").detail(|| potential_import_name.clone());
- if ImportScope::find_insert_use_container(&position, &ctx.sema).is_none() {
- return None;
- }
+ ImportScope::find_insert_use_container(&position, &ctx.sema)?;
let user_input_lowercased = potential_import_name.to_lowercase();
diff --git a/crates/ide-completion/src/completions/fn_param.rs b/crates/ide-completion/src/completions/fn_param.rs
index 8b38d4f01f..d67c00c6c6 100644
--- a/crates/ide-completion/src/completions/fn_param.rs
+++ b/crates/ide-completion/src/completions/fn_param.rs
@@ -108,7 +108,7 @@ fn fill_fn_params(
remove_duplicated(&mut file_params, param_list.params());
let self_completion_items = ["self", "&self", "mut self", "&mut self"];
if should_add_self_completions(ctx.token.text_range().start(), param_list, impl_) {
- self_completion_items.into_iter().for_each(|self_item| add_new_item_to_acc(self_item));
+ self_completion_items.into_iter().for_each(&mut add_new_item_to_acc);
}
file_params.keys().for_each(|whole_param| add_new_item_to_acc(whole_param));
diff --git a/crates/ide-completion/src/completions/postfix.rs b/crates/ide-completion/src/completions/postfix.rs
index fc21bba456..a846ffe10e 100644
--- a/crates/ide-completion/src/completions/postfix.rs
+++ b/crates/ide-completion/src/completions/postfix.rs
@@ -306,9 +306,7 @@ fn add_custom_postfix_completions(
postfix_snippet: impl Fn(&str, &str, &str) -> Builder,
receiver_text: &str,
) -> Option<()> {
- if ImportScope::find_insert_use_container(&ctx.token.parent()?, &ctx.sema).is_none() {
- return None;
- }
+ ImportScope::find_insert_use_container(&ctx.token.parent()?, &ctx.sema)?;
ctx.config.postfix_snippets().filter(|(_, snip)| snip.scope == SnippetScope::Expr).for_each(
|(trigger, snippet)| {
let imports = match snippet.imports(ctx) {
diff --git a/crates/ide-completion/src/completions/snippet.rs b/crates/ide-completion/src/completions/snippet.rs
index 3ff68b9788..a019192205 100644
--- a/crates/ide-completion/src/completions/snippet.rs
+++ b/crates/ide-completion/src/completions/snippet.rs
@@ -129,9 +129,7 @@ fn add_custom_completions(
cap: SnippetCap,
scope: SnippetScope,
) -> Option<()> {
- if ImportScope::find_insert_use_container(&ctx.token.parent()?, &ctx.sema).is_none() {
- return None;
- }
+ ImportScope::find_insert_use_container(&ctx.token.parent()?, &ctx.sema)?;
ctx.config.prefix_snippets().filter(|(_, snip)| snip.scope == scope).for_each(
|(trigger, snip)| {
let imports = match snip.imports(ctx) {
diff --git a/crates/ide-completion/src/context/analysis.rs b/crates/ide-completion/src/context/analysis.rs
index 7da6648365..0264931db1 100644
--- a/crates/ide-completion/src/context/analysis.rs
+++ b/crates/ide-completion/src/context/analysis.rs
@@ -866,9 +866,7 @@ fn classify_name_ref(
TypeLocation::TypeAscription(TypeAscriptionTarget::Const(original.body()))
},
ast::RetType(it) => {
- if it.thin_arrow_token().is_none() {
- return None;
- }
+ it.thin_arrow_token()?;
let parent = match ast::Fn::cast(parent.parent()?) {
Some(it) => it.param_list(),
None => ast::ClosureExpr::cast(parent.parent()?)?.param_list(),
@@ -888,15 +886,11 @@ fn classify_name_ref(
}))
},
ast::Param(it) => {
- if it.colon_token().is_none() {
- return None;
- }
+ it.colon_token()?;
TypeLocation::TypeAscription(TypeAscriptionTarget::FnParam(find_opt_node_in_file(original_file, it.pat())))
},
ast::LetStmt(it) => {
- if it.colon_token().is_none() {
- return None;
- }
+ it.colon_token()?;
TypeLocation::TypeAscription(TypeAscriptionTarget::Let(find_opt_node_in_file(original_file, it.pat())))
},
ast::Impl(it) => {
@@ -1312,7 +1306,7 @@ fn pattern_context_for(
.parent()
.and_then(ast::MatchExpr::cast)
.and_then(|match_expr| {
- let expr_opt = find_opt_node_in_file(&original_file, match_expr.expr());
+ let expr_opt = find_opt_node_in_file(original_file, match_expr.expr());
expr_opt.and_then(|expr| {
sema.type_of_expr(&expr)?
@@ -1321,24 +1315,20 @@ fn pattern_context_for(
.find_map(|ty| match ty.as_adt() {
Some(hir::Adt::Enum(e)) => Some(e),
_ => None,
- }).and_then(|enum_| {
- Some(enum_.variants(sema.db))
- })
+ }).map(|enum_| enum_.variants(sema.db))
})
- }).and_then(|variants| {
- Some(variants.iter().filter_map(|variant| {
+ }).map(|variants| variants.iter().filter_map(|variant| {
let variant_name = variant.name(sema.db).display(sema.db).to_string();
let variant_already_present = match_arm_list.arms().any(|arm| {
arm.pat().and_then(|pat| {
let pat_already_present = pat.syntax().to_string().contains(&variant_name);
- pat_already_present.then(|| pat_already_present)
+ pat_already_present.then_some(pat_already_present)
}).is_some()
});
- (!variant_already_present).then_some(variant.clone())
+ (!variant_already_present).then_some(*variant)
}).collect::<Vec<Variant>>())
- })
});
if let Some(missing_variants_) = missing_variants_opt {
diff --git a/crates/ide-completion/src/item.rs b/crates/ide-completion/src/item.rs
index 5935a6c563..864b993f71 100644
--- a/crates/ide-completion/src/item.rs
+++ b/crates/ide-completion/src/item.rs
@@ -553,7 +553,7 @@ impl Builder {
self.detail = detail.map(Into::into);
if let Some(detail) = &self.detail {
if never!(detail.contains('\n'), "multiline detail:\n{}", detail) {
- self.detail = Some(detail.splitn(2, '\n').next().unwrap().to_string());
+ self.detail = Some(detail.split('\n').next().unwrap().to_string());
}
}
self
diff --git a/crates/ide-completion/src/render/function.rs b/crates/ide-completion/src/render/function.rs
index dfe78de1d6..0f2608d132 100644
--- a/crates/ide-completion/src/render/function.rs
+++ b/crates/ide-completion/src/render/function.rs
@@ -304,9 +304,7 @@ fn params(
func_kind: &FuncKind<'_>,
has_dot_receiver: bool,
) -> Option<(Option<hir::SelfParam>, Vec<hir::Param>)> {
- if ctx.config.callable.is_none() {
- return None;
- }
+ ctx.config.callable.as_ref()?;
// Don't add parentheses if the expected type is a function reference with the same signature.
if let Some(expected) = ctx.expected_type.as_ref().filter(|e| e.is_fn()) {
diff --git a/crates/ide-db/src/active_parameter.rs b/crates/ide-db/src/active_parameter.rs
index 0da4e729a8..8d34f01b00 100644
--- a/crates/ide-db/src/active_parameter.rs
+++ b/crates/ide-db/src/active_parameter.rs
@@ -66,19 +66,15 @@ pub fn callable_for_node(
}
ast::CallableExpr::MethodCall(call) => sema.resolve_method_call_as_callable(call),
}?;
- let active_param = if let Some(arg_list) = calling_node.arg_list() {
- Some(
- arg_list
- .syntax()
- .children_with_tokens()
- .filter_map(NodeOrToken::into_token)
- .filter(|t| t.kind() == T![,])
- .take_while(|t| t.text_range().start() <= token.text_range().start())
- .count(),
- )
- } else {
- None
- };
+ let active_param = calling_node.arg_list().map(|arg_list| {
+ arg_list
+ .syntax()
+ .children_with_tokens()
+ .filter_map(NodeOrToken::into_token)
+ .filter(|t| t.kind() == T![,])
+ .take_while(|t| t.text_range().start() <= token.text_range().start())
+ .count()
+ });
Some((callable, active_param))
}
diff --git a/crates/ide-db/src/imports/import_assets.rs b/crates/ide-db/src/imports/import_assets.rs
index b834f517d4..089bd44c2a 100644
--- a/crates/ide-db/src/imports/import_assets.rs
+++ b/crates/ide-db/src/imports/import_assets.rs
@@ -357,7 +357,7 @@ fn path_applicable_imports(
path_candidate.name.clone(),
AssocSearchMode::Include,
)
- .filter_map(|item| import_for_item(sema.db, mod_path, &qualifier, item, scope_filter))
+ .filter_map(|item| import_for_item(sema.db, mod_path, qualifier, item, scope_filter))
.take(DEFAULT_QUERY_SEARCH_LIMIT.inner())
.collect(),
}
diff --git a/crates/ide-db/src/imports/merge_imports.rs b/crates/ide-db/src/imports/merge_imports.rs
index c0ff332a23..7ec38c317d 100644
--- a/crates/ide-db/src/imports/merge_imports.rs
+++ b/crates/ide-db/src/imports/merge_imports.rs
@@ -112,7 +112,7 @@ fn recursive_merge(lhs: &ast::UseTree, rhs: &ast::UseTree, merge: MergeBehavior)
.collect::<Option<_>>()?;
// Sorts the use trees similar to rustfmt's algorithm for ordering imports
// (see `use_tree_cmp` doc).
- use_trees.sort_unstable_by(|a, b| use_tree_cmp(a, b));
+ use_trees.sort_unstable_by(use_tree_cmp);
for rhs_t in rhs.use_tree_list().into_iter().flat_map(|list| list.use_trees()) {
if !merge.is_tree_allowed(&rhs_t) {
return None;
@@ -365,7 +365,7 @@ fn path_segment_cmp(a: &ast::PathSegment, b: &ast::PathSegment) -> Ordering {
if is_upper_snake_case(a_text) && !is_upper_snake_case(b_text) {
return Ordering::Greater;
}
- a_text.cmp(&b_text)
+ a_text.cmp(b_text)
}
}
}
diff --git a/crates/ide-db/src/lib.rs b/crates/ide-db/src/lib.rs
index dc61fc0e4c..1cc1e36329 100644
--- a/crates/ide-db/src/lib.rs
+++ b/crates/ide-db/src/lib.rs
@@ -99,21 +99,21 @@ impl fmt::Debug for RootDatabase {
impl Upcast<dyn ExpandDatabase> for RootDatabase {
#[inline]
fn upcast(&self) -> &(dyn ExpandDatabase + 'static) {
- &*self
+ self
}
}
impl Upcast<dyn DefDatabase> for RootDatabase {
#[inline]
fn upcast(&self) -> &(dyn DefDatabase + 'static) {
- &*self
+ self
}
}
impl Upcast<dyn HirDatabase> for RootDatabase {
#[inline]
fn upcast(&self) -> &(dyn HirDatabase + 'static) {
- &*self
+ self
}
}
diff --git a/crates/ide-db/src/path_transform.rs b/crates/ide-db/src/path_transform.rs
index 47bcaae259..3862acc2af 100644
--- a/crates/ide-db/src/path_transform.rs
+++ b/crates/ide-db/src/path_transform.rs
@@ -381,7 +381,7 @@ impl Ctx<'_> {
true,
)
.ok()?;
- let ast_ty = make::ty(&ty_str).clone_for_update();
+ let ast_ty = make::ty(ty_str).clone_for_update();
if let Some(adt) = ty.as_adt() {
if let ast::Type::PathType(path_ty) = &ast_ty {
diff --git a/crates/ide-db/src/rename.rs b/crates/ide-db/src/rename.rs
index a6058b57f1..9e17666c90 100644
--- a/crates/ide-db/src/rename.rs
+++ b/crates/ide-db/src/rename.rs
@@ -107,7 +107,7 @@ impl Definition {
/// renamed and extern crate names will report its range, though a rename will introduce
/// an alias instead.
pub fn range_for_rename(self, sema: &Semantics<'_, RootDatabase>) -> Option<FileRange> {
- let syn_ctx_is_root = |(range, ctx): (_, SyntaxContextId)| ctx.is_root().then(|| range);
+ let syn_ctx_is_root = |(range, ctx): (_, SyntaxContextId)| ctx.is_root().then_some(range);
let res = match self {
Definition::Macro(mac) => {
let src = mac.source(sema.db)?;
diff --git a/crates/ide-db/src/search.rs b/crates/ide-db/src/search.rs
index e2b20ef92f..7769d8fba1 100644
--- a/crates/ide-db/src/search.rs
+++ b/crates/ide-db/src/search.rs
@@ -536,14 +536,12 @@ impl<'a> FindUsages<'a> {
// Search for occurrences of the items name
for offset in match_indices(&text, finder, search_range) {
- tree.token_at_offset(offset).into_iter().for_each(|token| {
+ tree.token_at_offset(offset).for_each(|token| {
let Some(str_token) = ast::String::cast(token.clone()) else { return };
if let Some((range, nameres)) =
sema.check_for_format_args_template(token, offset)
{
- if self.found_format_args_ref(file_id, range, str_token, nameres, sink) {
- return;
- }
+ if self.found_format_args_ref(file_id, range, str_token, nameres, sink) {}
}
});
diff --git a/crates/ide-db/src/symbol_index.rs b/crates/ide-db/src/symbol_index.rs
index c2e95ca860..e8a3c11dce 100644
--- a/crates/ide-db/src/symbol_index.rs
+++ b/crates/ide-db/src/symbol_index.rs
@@ -329,7 +329,7 @@ impl Query {
for index in indices.iter() {
op = op.add(index.map.search(&automaton));
}
- self.search_maps(&indices, op.union(), cb)
+ self.search_maps(indices, op.union(), cb)
}
SearchMode::Fuzzy => {
let automaton = fst::automaton::Subsequence::new(&self.lowercased);
@@ -337,7 +337,7 @@ impl Query {
for index in indices.iter() {
op = op.add(index.map.search(&automaton));
}
- self.search_maps(&indices, op.union(), cb)
+ self.search_maps(indices, op.union(), cb)
}
SearchMode::Prefix => {
let automaton = fst::automaton::Str::new(&self.lowercased).starts_with();
@@ -345,7 +345,7 @@ impl Query {
for index in indices.iter() {
op = op.add(index.map.search(&automaton));
}
- self.search_maps(&indices, op.union(), cb)
+ self.search_maps(indices, op.union(), cb)
}
}
}
diff --git a/crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs b/crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs
index 4910054038..c25b0a7bf7 100644
--- a/crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs
+++ b/crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs
@@ -17,7 +17,7 @@ pub(crate) fn break_outside_of_loop(
ctx,
DiagnosticCode::RustcHardError("E0268"),
message,
- d.expr.clone().map(|it| it.into()),
+ d.expr.map(|it| it.into()),
)
}
diff --git a/crates/ide-diagnostics/src/handlers/expected_function.rs b/crates/ide-diagnostics/src/handlers/expected_function.rs
index e1e5db91c5..05fb1c29b3 100644
--- a/crates/ide-diagnostics/src/handlers/expected_function.rs
+++ b/crates/ide-diagnostics/src/handlers/expected_function.rs
@@ -13,7 +13,7 @@ pub(crate) fn expected_function(
ctx,
DiagnosticCode::RustcHardError("E0618"),
format!("expected function, found {}", d.found.display(ctx.sema.db)),
- d.call.clone().map(|it| it.into()),
+ d.call.map(|it| it.into()),
)
.experimental()
}
diff --git a/crates/ide-diagnostics/src/handlers/inactive_code.rs b/crates/ide-diagnostics/src/handlers/inactive_code.rs
index 3b2e15a178..9f754f9c6f 100644
--- a/crates/ide-diagnostics/src/handlers/inactive_code.rs
+++ b/crates/ide-diagnostics/src/handlers/inactive_code.rs
@@ -31,7 +31,7 @@ pub(crate) fn inactive_code(
let res = Diagnostic::new(
DiagnosticCode::Ra("inactive-code", Severity::WeakWarning),
message,
- ctx.sema.diagnostics_display_range(d.node.clone()),
+ ctx.sema.diagnostics_display_range(d.node),
)
.with_unused(true);
Some(res)
diff --git a/crates/ide-diagnostics/src/handlers/incoherent_impl.rs b/crates/ide-diagnostics/src/handlers/incoherent_impl.rs
index 4afb4db03b..3b4d400912 100644
--- a/crates/ide-diagnostics/src/handlers/incoherent_impl.rs
+++ b/crates/ide-diagnostics/src/handlers/incoherent_impl.rs
@@ -9,8 +9,8 @@ pub(crate) fn incoherent_impl(ctx: &DiagnosticsContext<'_>, d: &hir::IncoherentI
Diagnostic::new_with_syntax_node_ptr(
ctx,
DiagnosticCode::RustcHardError("E0210"),
- format!("cannot define inherent `impl` for foreign type"),
- InFile::new(d.file_id, d.impl_.clone().into()),
+ "cannot define inherent `impl` for foreign type".to_string(),
+ InFile::new(d.file_id, d.impl_.into()),
)
}
diff --git a/crates/ide-diagnostics/src/handlers/incorrect_case.rs b/crates/ide-diagnostics/src/handlers/incorrect_case.rs
index 25a5cdde26..f5a6aa1197 100644
--- a/crates/ide-diagnostics/src/handlers/incorrect_case.rs
+++ b/crates/ide-diagnostics/src/handlers/incorrect_case.rs
@@ -27,7 +27,7 @@ pub(crate) fn incorrect_case(ctx: &DiagnosticsContext<'_>, d: &hir::IncorrectCas
"{} `{}` should have {} name, e.g. `{}`",
d.ident_type, d.ident_text, d.expected_case, d.suggested_text
),
- InFile::new(d.file, d.ident.clone().into()),
+ InFile::new(d.file, d.ident.into()),
)
.with_fixes(fixes(ctx, d))
}
diff --git a/crates/ide-diagnostics/src/handlers/invalid_derive_target.rs b/crates/ide-diagnostics/src/handlers/invalid_derive_target.rs
index f68f5b44b1..ab0f5139f1 100644
--- a/crates/ide-diagnostics/src/handlers/invalid_derive_target.rs
+++ b/crates/ide-diagnostics/src/handlers/invalid_derive_target.rs
@@ -8,7 +8,7 @@ pub(crate) fn invalid_derive_target(
ctx: &DiagnosticsContext<'_>,
d: &hir::InvalidDeriveTarget,
) -> Diagnostic {
- let display_range = ctx.sema.diagnostics_display_range(d.node.clone());
+ let display_range = ctx.sema.diagnostics_display_range(d.node);
Diagnostic::new(
DiagnosticCode::RustcHardError("E0774"),
diff --git a/crates/ide-diagnostics/src/handlers/macro_error.rs b/crates/ide-diagnostics/src/handlers/macro_error.rs
index 099de4528d..fc5c715981 100644
--- a/crates/ide-diagnostics/src/handlers/macro_error.rs
+++ b/crates/ide-diagnostics/src/handlers/macro_error.rs
@@ -20,7 +20,7 @@ pub(crate) fn macro_error(ctx: &DiagnosticsContext<'_>, d: &hir::MacroError) ->
pub(crate) fn macro_def_error(ctx: &DiagnosticsContext<'_>, d: &hir::MacroDefError) -> Diagnostic {
// Use more accurate position if available.
let display_range =
- ctx.resolve_precise_location(&d.node.clone().map(|it| it.syntax_node_ptr()), d.name);
+ ctx.resolve_precise_location(&d.node.map(|it| it.syntax_node_ptr()), d.name);
Diagnostic::new(
DiagnosticCode::Ra("macro-def-error", Severity::Error),
d.message.clone(),
diff --git a/crates/ide-diagnostics/src/handlers/malformed_derive.rs b/crates/ide-diagnostics/src/handlers/malformed_derive.rs
index 6202d15853..0e47fff6f9 100644
--- a/crates/ide-diagnostics/src/handlers/malformed_derive.rs
+++ b/crates/ide-diagnostics/src/handlers/malformed_derive.rs
@@ -7,7 +7,7 @@ pub(crate) fn malformed_derive(
ctx: &DiagnosticsContext<'_>,
d: &hir::MalformedDerive,
) -> Diagnostic {
- let display_range = ctx.sema.diagnostics_display_range(d.node.clone());
+ let display_range = ctx.sema.diagnostics_display_range(d.node);
Diagnostic::new(
DiagnosticCode::RustcHardError("E0777"),
diff --git a/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs b/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs
index 8296018022..5e950ecb0d 100644
--- a/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs
+++ b/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs
@@ -24,7 +24,7 @@ pub(crate) fn mismatched_tuple_struct_pat_arg_count(
Diagnostic::new(
DiagnosticCode::RustcHardError("E0023"),
message,
- invalid_args_range(ctx, d.expr_or_pat.clone().map(Into::into), d.expected, d.found),
+ invalid_args_range(ctx, d.expr_or_pat.map(Into::into), d.expected, d.found),
)
}
@@ -40,7 +40,7 @@ pub(crate) fn mismatched_arg_count(
Diagnostic::new(
DiagnosticCode::RustcHardError("E0107"),
message,
- invalid_args_range(ctx, d.call_expr.clone().map(Into::into), d.expected, d.found),
+ invalid_args_range(ctx, d.call_expr.map(Into::into), d.expected, d.found),
)
}
diff --git a/crates/ide-diagnostics/src/handlers/missing_fields.rs b/crates/ide-diagnostics/src/handlers/missing_fields.rs
index cb38bc54d7..37ac912f06 100644
--- a/crates/ide-diagnostics/src/handlers/missing_fields.rs
+++ b/crates/ide-diagnostics/src/handlers/missing_fields.rs
@@ -37,9 +37,8 @@ pub(crate) fn missing_fields(ctx: &DiagnosticsContext<'_>, d: &hir::MissingField
let ptr = InFile::new(
d.file,
d.field_list_parent_path
- .clone()
.map(SyntaxNodePtr::from)
- .unwrap_or_else(|| d.field_list_parent.clone().into()),
+ .unwrap_or_else(|| d.field_list_parent.into()),
);
Diagnostic::new_with_syntax_node_ptr(ctx, DiagnosticCode::RustcHardError("E0063"), message, ptr)
@@ -87,7 +86,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass
match &d.field_list_parent.to_node(&root) {
Either::Left(field_list_parent) => {
- let missing_fields = ctx.sema.record_literal_missing_fields(&field_list_parent);
+ let missing_fields = ctx.sema.record_literal_missing_fields(field_list_parent);
let mut locals = FxHashMap::default();
ctx.sema.scope(field_list_parent.syntax())?.process_all_names(&mut |name, def| {
@@ -99,7 +98,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass
let generate_fill_expr = |ty: &Type| match ctx.config.expr_fill_default {
crate::ExprFillDefaultMode::Todo => make::ext::expr_todo(),
crate::ExprFillDefaultMode::Default => {
- get_default_constructor(ctx, d, ty).unwrap_or_else(|| make::ext::expr_todo())
+ get_default_constructor(ctx, d, ty).unwrap_or_else(make::ext::expr_todo)
}
};
@@ -151,7 +150,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass
)
}
Either::Right(field_list_parent) => {
- let missing_fields = ctx.sema.record_pattern_missing_fields(&field_list_parent);
+ let missing_fields = ctx.sema.record_pattern_missing_fields(field_list_parent);
let old_field_list = field_list_parent.record_pat_field_list()?;
let new_field_list = old_field_list.clone_for_update();
diff --git a/crates/ide-diagnostics/src/handlers/missing_match_arms.rs b/crates/ide-diagnostics/src/handlers/missing_match_arms.rs
index ef6a273ed8..cb6d568442 100644
--- a/crates/ide-diagnostics/src/handlers/missing_match_arms.rs
+++ b/crates/ide-diagnostics/src/handlers/missing_match_arms.rs
@@ -11,7 +11,7 @@ pub(crate) fn missing_match_arms(
ctx,
DiagnosticCode::RustcHardError("E0004"),
format!("missing match arm: {}", d.uncovered_patterns),
- d.scrutinee_expr.clone().map(Into::into),
+ d.scrutinee_expr.map(Into::into),
)
}
diff --git a/crates/ide-diagnostics/src/handlers/missing_unsafe.rs b/crates/ide-diagnostics/src/handlers/missing_unsafe.rs
index f93a35cf18..1b29e0a374 100644
--- a/crates/ide-diagnostics/src/handlers/missing_unsafe.rs
+++ b/crates/ide-diagnostics/src/handlers/missing_unsafe.rs
@@ -15,7 +15,7 @@ pub(crate) fn missing_unsafe(ctx: &DiagnosticsContext<'_>, d: &hir::MissingUnsaf
ctx,
DiagnosticCode::RustcHardError("E0133"),
"this operation is unsafe and requires an unsafe function or block",
- d.expr.clone().map(|it| it.into()),
+ d.expr.map(|it| it.into()),
)
.with_fixes(fixes(ctx, d))
}
diff --git a/crates/ide-diagnostics/src/handlers/moved_out_of_ref.rs b/crates/ide-diagnostics/src/handlers/moved_out_of_ref.rs
index 886aefeb57..fa9a6577fc 100644
--- a/crates/ide-diagnostics/src/handlers/moved_out_of_ref.rs
+++ b/crates/ide-diagnostics/src/handlers/moved_out_of_ref.rs
@@ -9,7 +9,7 @@ pub(crate) fn moved_out_of_ref(ctx: &DiagnosticsContext<'_>, d: &hir::MovedOutOf
ctx,
DiagnosticCode::RustcHardError("E0507"),
format!("cannot move `{}` out of reference", d.ty.display(ctx.sema.db)),
- d.span.clone(),
+ d.span,
)
.experimental() // spans are broken, and I'm not sure how precise we can detect copy types
}
diff --git a/crates/ide-diagnostics/src/handlers/mutability_errors.rs b/crates/ide-diagnostics/src/handlers/mutability_errors.rs
index 1875111492..773a075f8f 100644
--- a/crates/ide-diagnostics/src/handlers/mutability_errors.rs
+++ b/crates/ide-diagnostics/src/handlers/mutability_errors.rs
@@ -37,7 +37,7 @@ pub(crate) fn need_mut(ctx: &DiagnosticsContext<'_>, d: &hir::NeedMut) -> Diagno
"cannot mutate immutable variable `{}`",
d.local.name(ctx.sema.db).display(ctx.sema.db)
),
- d.span.clone(),
+ d.span,
)
.with_fixes(fixes)
}
diff --git a/crates/ide-diagnostics/src/handlers/no_such_field.rs b/crates/ide-diagnostics/src/handlers/no_such_field.rs
index 0abcbffe72..5a20246cdd 100644
--- a/crates/ide-diagnostics/src/handlers/no_such_field.rs
+++ b/crates/ide-diagnostics/src/handlers/no_such_field.rs
@@ -13,7 +13,7 @@ use crate::{fix, Assist, Diagnostic, DiagnosticCode, DiagnosticsContext};
//
// This diagnostic is triggered if created structure does not have field provided in record.
pub(crate) fn no_such_field(ctx: &DiagnosticsContext<'_>, d: &hir::NoSuchField) -> Diagnostic {
- let node = d.field.clone().map(Into::into);
+ let node = d.field.map(Into::into);
if d.private {
// FIXME: quickfix to add required visibility
Diagnostic::new_with_syntax_node_ptr(
diff --git a/crates/ide-diagnostics/src/handlers/private_assoc_item.rs b/crates/ide-diagnostics/src/handlers/private_assoc_item.rs
index a828b8b4fd..f6ed0d7226 100644
--- a/crates/ide-diagnostics/src/handlers/private_assoc_item.rs
+++ b/crates/ide-diagnostics/src/handlers/private_assoc_item.rs
@@ -26,7 +26,7 @@ pub(crate) fn private_assoc_item(
},
name,
),
- d.expr_or_pat.clone().map(Into::into),
+ d.expr_or_pat.map(Into::into),
)
}
diff --git a/crates/ide-diagnostics/src/handlers/private_field.rs b/crates/ide-diagnostics/src/handlers/private_field.rs
index 553defcf99..3179a632e2 100644
--- a/crates/ide-diagnostics/src/handlers/private_field.rs
+++ b/crates/ide-diagnostics/src/handlers/private_field.rs
@@ -13,7 +13,7 @@ pub(crate) fn private_field(ctx: &DiagnosticsContext<'_>, d: &hir::PrivateField)
d.field.name(ctx.sema.db).display(ctx.sema.db),
d.field.parent_def(ctx.sema.db).name(ctx.sema.db).display(ctx.sema.db)
),
- d.expr.clone().map(|it| it.into()),
+ d.expr.map(|it| it.into()),
)
}
diff --git a/crates/ide-diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs b/crates/ide-diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs
index 258ac6cd82..72896b891b 100644
--- a/crates/ide-diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs
+++ b/crates/ide-diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs
@@ -19,7 +19,7 @@ pub(crate) fn replace_filter_map_next_with_find_map(
ctx,
DiagnosticCode::Clippy("filter_map_next"),
"replace filter_map(..).next() with find_map(..)",
- InFile::new(d.file, d.next_expr.clone().into()),
+ InFile::new(d.file, d.next_expr.into()),
)
.with_fixes(fixes(ctx, d))
}
diff --git a/crates/ide-diagnostics/src/handlers/trait_impl_orphan.rs b/crates/ide-diagnostics/src/handlers/trait_impl_orphan.rs
index 159d87d269..d36813381e 100644
--- a/crates/ide-diagnostics/src/handlers/trait_impl_orphan.rs
+++ b/crates/ide-diagnostics/src/handlers/trait_impl_orphan.rs
@@ -12,8 +12,9 @@ pub(crate) fn trait_impl_orphan(
Diagnostic::new_with_syntax_node_ptr(
ctx,
DiagnosticCode::RustcHardError("E0117"),
- format!("only traits defined in the current crate can be implemented for arbitrary types"),
- InFile::new(d.file_id, d.impl_.clone().into()),
+ "only traits defined in the current crate can be implemented for arbitrary types"
+ .to_string(),
+ InFile::new(d.file_id, d.impl_.into()),
)
// Not yet checked for false positives
.experimental()
diff --git a/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs b/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs
index 6ecfd55ea0..f58fcd1f7e 100644
--- a/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs
+++ b/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs
@@ -1,4 +1,4 @@
-use hir::{db::ExpandDatabase, Const, Function, HasSource, HirDisplay, TypeAlias};
+use hir::{db::ExpandDatabase, HasSource, HirDisplay};
use ide_db::{
assists::{Assist, AssistId, AssistKind},
label::Label,
@@ -25,7 +25,7 @@ pub(crate) fn trait_impl_redundant_assoc_item(
let (redundant_item_name, diagnostic_range, redundant_item_def) = match assoc_item {
hir::AssocItem::Function(id) => {
- let function = Function::from(id);
+ let function = id;
(
format!("`fn {}`", redundant_assoc_item_name),
function
@@ -36,7 +36,7 @@ pub(crate) fn trait_impl_redundant_assoc_item(
)
}
hir::AssocItem::Const(id) => {
- let constant = Const::from(id);
+ let constant = id;
(
format!("`const {}`", redundant_assoc_item_name),
constant
@@ -47,7 +47,7 @@ pub(crate) fn trait_impl_redundant_assoc_item(
)
}
hir::AssocItem::TypeAlias(id) => {
- let type_alias = TypeAlias::from(id);
+ let type_alias = id;
(
format!("`type {}`", redundant_assoc_item_name),
type_alias
@@ -94,7 +94,8 @@ fn quickfix_for_redundant_assoc_item(
let where_to_insert =
hir::InFile::new(d.file_id, l_curly).original_node_file_range_rooted(db).range;
- Some(builder.insert(where_to_insert.end(), redundant_item_def))
+ builder.insert(where_to_insert.end(), redundant_item_def);
+ Some(())
};
let file_id = d.file_id.file_id()?;
let mut source_change_builder = SourceChangeBuilder::new(file_id);
diff --git a/crates/ide-diagnostics/src/handlers/type_mismatch.rs b/crates/ide-diagnostics/src/handlers/type_mismatch.rs
index 70beb94689..23042e222b 100644
--- a/crates/ide-diagnostics/src/handlers/type_mismatch.rs
+++ b/crates/ide-diagnostics/src/handlers/type_mismatch.rs
@@ -59,8 +59,8 @@ pub(crate) fn type_mismatch(ctx: &DiagnosticsContext<'_>, d: &hir::TypeMismatch)
fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::TypeMismatch) -> Option<Vec<Assist>> {
let mut fixes = Vec::new();
- if let Some(expr_ptr) = d.expr_or_pat.value.clone().cast::<ast::Expr>() {
- let expr_ptr = &InFile { file_id: d.expr_or_pat.file_id, value: expr_ptr.clone() };
+ if let Some(expr_ptr) = d.expr_or_pat.value.cast::<ast::Expr>() {
+ let expr_ptr = &InFile { file_id: d.expr_or_pat.file_id, value: expr_ptr };
add_reference(ctx, d, expr_ptr, &mut fixes);
add_missing_ok_or_some(ctx, d, expr_ptr, &mut fixes);
remove_semicolon(ctx, d, expr_ptr, &mut fixes);
@@ -80,7 +80,7 @@ fn add_reference(
expr_ptr: &InFile<AstPtr<ast::Expr>>,
acc: &mut Vec<Assist>,
) -> Option<()> {
- let range = ctx.sema.diagnostics_display_range(expr_ptr.clone().map(|it| it.into()));
+ let range = ctx.sema.diagnostics_display_range((*expr_ptr).map(|it| it.into()));
let (_, mutability) = d.expected.as_reference()?;
let actual_with_ref = Type::reference(&d.actual, mutability);
@@ -182,7 +182,7 @@ fn str_ref_to_owned(
let expr = expr_ptr.value.to_node(&root);
let expr_range = expr.syntax().text_range();
- let to_owned = format!(".to_owned()");
+ let to_owned = ".to_owned()".to_string();
let edit = TextEdit::insert(expr.syntax().text_range().end(), to_owned);
let source_change =
diff --git a/crates/ide-diagnostics/src/handlers/typed_hole.rs b/crates/ide-diagnostics/src/handlers/typed_hole.rs
index a740e332bb..6441343eba 100644
--- a/crates/ide-diagnostics/src/handlers/typed_hole.rs
+++ b/crates/ide-diagnostics/src/handlers/typed_hole.rs
@@ -13,7 +13,7 @@ use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
//
// This diagnostic is triggered when an underscore expression is used in an invalid position.
pub(crate) fn typed_hole(ctx: &DiagnosticsContext<'_>, d: &hir::TypedHole) -> Diagnostic {
- let display_range = ctx.sema.diagnostics_display_range(d.expr.clone().map(|it| it.into()));
+ let display_range = ctx.sema.diagnostics_display_range(d.expr.map(|it| it.into()));
let (message, fixes) = if d.expected.is_unknown() {
("`_` expressions may only appear on the left-hand side of an assignment".to_owned(), None)
} else {
diff --git a/crates/ide-diagnostics/src/handlers/undeclared_label.rs b/crates/ide-diagnostics/src/handlers/undeclared_label.rs
index 495ea74877..a6a0fdc655 100644
--- a/crates/ide-diagnostics/src/handlers/undeclared_label.rs
+++ b/crates/ide-diagnostics/src/handlers/undeclared_label.rs
@@ -10,7 +10,7 @@ pub(crate) fn undeclared_label(
ctx,
DiagnosticCode::RustcHardError("undeclared-label"),
format!("use of undeclared label `{}`", name.display(ctx.sema.db)),
- d.node.clone().map(|it| it.into()),
+ d.node.map(|it| it.into()),
)
}
diff --git a/crates/ide-diagnostics/src/handlers/unimplemented_builtin_macro.rs b/crates/ide-diagnostics/src/handlers/unimplemented_builtin_macro.rs
index bcce72a7d0..996b6eda59 100644
--- a/crates/ide-diagnostics/src/handlers/unimplemented_builtin_macro.rs
+++ b/crates/ide-diagnostics/src/handlers/unimplemented_builtin_macro.rs
@@ -11,6 +11,6 @@ pub(crate) fn unimplemented_builtin_macro(
ctx,
DiagnosticCode::Ra("unimplemented-builtin-macro", Severity::WeakWarning),
"unimplemented built-in macro".to_string(),
- d.node.clone(),
+ d.node,
)
}
diff --git a/crates/ide-diagnostics/src/handlers/unreachable_label.rs b/crates/ide-diagnostics/src/handlers/unreachable_label.rs
index 1c5d6cd090..3601041fc7 100644
--- a/crates/ide-diagnostics/src/handlers/unreachable_label.rs
+++ b/crates/ide-diagnostics/src/handlers/unreachable_label.rs
@@ -10,7 +10,7 @@ pub(crate) fn unreachable_label(
ctx,
DiagnosticCode::RustcHardError("E0767"),
format!("use of unreachable label `{}`", name.display(ctx.sema.db)),
- d.node.clone().map(|it| it.into()),
+ d.node.map(|it| it.into()),
)
}
diff --git a/crates/ide-diagnostics/src/handlers/unresolved_assoc_item.rs b/crates/ide-diagnostics/src/handlers/unresolved_assoc_item.rs
index 551021c55a..614057ab52 100644
--- a/crates/ide-diagnostics/src/handlers/unresolved_assoc_item.rs
+++ b/crates/ide-diagnostics/src/handlers/unresolved_assoc_item.rs
@@ -11,7 +11,7 @@ pub(crate) fn unresolved_assoc_item(
ctx,
DiagnosticCode::RustcHardError("E0599"),
"no such associated item",
- d.expr_or_pat.clone().map(Into::into),
+ d.expr_or_pat.map(Into::into),
)
.experimental()
}
diff --git a/crates/ide-diagnostics/src/handlers/unresolved_extern_crate.rs b/crates/ide-diagnostics/src/handlers/unresolved_extern_crate.rs
index f8265b6327..4cd73d46d5 100644
--- a/crates/ide-diagnostics/src/handlers/unresolved_extern_crate.rs
+++ b/crates/ide-diagnostics/src/handlers/unresolved_extern_crate.rs
@@ -11,7 +11,7 @@ pub(crate) fn unresolved_extern_crate(
ctx,
DiagnosticCode::RustcHardError("unresolved-extern-crate"),
"unresolved extern crate",
- d.decl.clone().map(|it| it.into()),
+ d.decl.map(|it| it.into()),
)
}
diff --git a/crates/ide-diagnostics/src/handlers/unresolved_import.rs b/crates/ide-diagnostics/src/handlers/unresolved_import.rs
index 6b8026c034..67c7e76a3b 100644
--- a/crates/ide-diagnostics/src/handlers/unresolved_import.rs
+++ b/crates/ide-diagnostics/src/handlers/unresolved_import.rs
@@ -12,7 +12,7 @@ pub(crate) fn unresolved_import(
ctx,
DiagnosticCode::RustcHardError("E0432"),
"unresolved import",
- d.decl.clone().map(|it| it.into()),
+ d.decl.map(|it| it.into()),
)
// This currently results in false positives in the following cases:
// - `cfg_if!`-generated code in libstd (we don't load the sysroot correctly)
diff --git a/crates/ide-diagnostics/src/handlers/unresolved_module.rs b/crates/ide-diagnostics/src/handlers/unresolved_module.rs
index 4d7d425bab..1604decf90 100644
--- a/crates/ide-diagnostics/src/handlers/unresolved_module.rs
+++ b/crates/ide-diagnostics/src/handlers/unresolved_module.rs
@@ -26,7 +26,7 @@ pub(crate) fn unresolved_module(
)
}
},
- d.decl.clone().map(|it| it.into()),
+ d.decl.map(|it| it.into()),
)
.with_fixes(fixes(ctx, d))
}
diff --git a/crates/ide-diagnostics/src/lib.rs b/crates/ide-diagnostics/src/lib.rs
index c7ad09e7eb..7743b060c8 100644
--- a/crates/ide-diagnostics/src/lib.rs
+++ b/crates/ide-diagnostics/src/lib.rs
@@ -174,7 +174,7 @@ impl Diagnostic {
node: InFile<SyntaxNodePtr>,
) -> Diagnostic {
let file_id = node.file_id;
- Diagnostic::new(code, message, ctx.sema.diagnostics_display_range(node.clone()))
+ Diagnostic::new(code, message, ctx.sema.diagnostics_display_range(node))
.with_main_node(node.map(|x| x.to_node(&ctx.sema.parse_or_expand(file_id))))
}
@@ -281,7 +281,7 @@ impl DiagnosticsContext<'_> {
}
}
})()
- .unwrap_or_else(|| sema.diagnostics_display_range(node.clone()))
+ .unwrap_or_else(|| sema.diagnostics_display_range(*node))
}
}
@@ -448,8 +448,8 @@ fn handle_lint_attributes(
diagnostics_of_range: &mut FxHashMap<InFile<SyntaxNode>, &mut Diagnostic>,
) {
let file_id = sema.hir_file_for(root);
- let mut preorder = root.preorder();
- while let Some(ev) = preorder.next() {
+ let preorder = root.preorder();
+ for ev in preorder {
match ev {
syntax::WalkEvent::Enter(node) => {
for attr in node.children().filter_map(ast::Attr::cast) {
diff --git a/crates/ide-ssr/src/fragments.rs b/crates/ide-ssr/src/fragments.rs
index 503754afe7..4d6809efbe 100644
--- a/crates/ide-ssr/src/fragments.rs
+++ b/crates/ide-ssr/src/fragments.rs
@@ -35,7 +35,9 @@ pub(crate) fn stmt(s: &str) -> Result<SyntaxNode, ()> {
parse.tree().syntax().descendants().skip(2).find_map(ast::Stmt::cast).ok_or(())?;
if !s.ends_with(';') && node.to_string().ends_with(';') {
node = node.clone_for_update();
- node.syntax().last_token().map(|it| it.detach());
+ if let Some(it) = node.syntax().last_token() {
+ it.detach()
+ }
}
if node.to_string() != s {
return Err(());
diff --git a/crates/ide-ssr/src/matching.rs b/crates/ide-ssr/src/matching.rs
index 0312a0f11e..66cb14451f 100644
--- a/crates/ide-ssr/src/matching.rs
+++ b/crates/ide-ssr/src/matching.rs
@@ -320,7 +320,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> {
kind.matches(code)?;
}
Constraint::Not(sub) => {
- if self.check_constraint(&*sub, code).is_ok() {
+ if self.check_constraint(sub, code).is_ok() {
fail_match!("Constraint {:?} failed for '{}'", constraint, code.text());
}
}
diff --git a/crates/ide-ssr/src/search.rs b/crates/ide-ssr/src/search.rs
index ca76d0a87b..8d2d796122 100644
--- a/crates/ide-ssr/src/search.rs
+++ b/crates/ide-ssr/src/search.rs
@@ -56,7 +56,7 @@ impl MatchFinder<'_> {
matches_out: &mut Vec<Match>,
) {
if let Some(resolved_path) = pick_path_for_usages(pattern) {
- let definition: Definition = resolved_path.resolution.clone().into();
+ let definition: Definition = resolved_path.resolution.into();
for file_range in self.find_usages(usage_cache, definition).file_ranges() {
for node_to_match in self.find_nodes_to_match(resolved_path, file_range) {
if !is_search_permitted_ancestors(&node_to_match) {
diff --git a/crates/ide/src/annotations/fn_references.rs b/crates/ide/src/annotations/fn_references.rs
index 0cadf125fe..a090b60413 100644
--- a/crates/ide/src/annotations/fn_references.rs
+++ b/crates/ide/src/annotations/fn_references.rs
@@ -14,7 +14,7 @@ pub(super) fn find_all_methods(
) -> Vec<(TextRange, Option<TextRange>)> {
let sema = Semantics::new(db);
let source_file = sema.parse(file_id);
- source_file.syntax().descendants().filter_map(|it| method_range(it)).collect()
+ source_file.syntax().descendants().filter_map(method_range).collect()
}
fn method_range(item: SyntaxNode) -> Option<(TextRange, Option<TextRange>)> {
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs
index 1357f42636..f221985719 100644
--- a/crates/ide/src/doc_links.rs
+++ b/crates/ide/src/doc_links.rs
@@ -351,8 +351,12 @@ fn get_doc_links(
web_url = join_url(web_url, &file);
local_url = join_url(local_url, &file);
- web_url.as_mut().map(|url| url.set_fragment(frag.as_deref()));
- local_url.as_mut().map(|url| url.set_fragment(frag.as_deref()));
+ if let Some(url) = web_url.as_mut() {
+ url.set_fragment(frag.as_deref())
+ }
+ if let Some(url) = local_url.as_mut() {
+ url.set_fragment(frag.as_deref())
+ }
DocumentationLinks {
web_url: web_url.map(|it| it.into()),
diff --git a/crates/ide/src/doc_links/tests.rs b/crates/ide/src/doc_links/tests.rs
index 37da3d6514..3bb0fc6064 100644
--- a/crates/ide/src/doc_links/tests.rs
+++ b/crates/ide/src/doc_links/tests.rs
@@ -130,10 +130,10 @@ fn external_docs_doc_builtin_type() {
//- /main.rs crate:foo
let x: u3$02 = 0;
"#,
- Some(&OsStr::new("/home/user/project")),
+ Some(OsStr::new("/home/user/project")),
Some(expect![[r#"https://doc.rust-lang.org/nightly/core/primitive.u32.html"#]]),
Some(expect![[r#"file:///sysroot/share/doc/rust/html/core/primitive.u32.html"#]]),
- Some(&OsStr::new("/sysroot")),
+ Some(OsStr::new("/sysroot")),
);
}
@@ -146,10 +146,10 @@ use foo$0::Foo;
//- /lib.rs crate:foo
pub struct Foo;
"#,
- Some(&OsStr::new("/home/user/project")),
+ Some(OsStr::new("/home/user/project")),
Some(expect![[r#"https://docs.rs/foo/*/foo/index.html"#]]),
Some(expect![[r#"file:///home/user/project/doc/foo/index.html"#]]),
- Some(&OsStr::new("/sysroot")),
+ Some(OsStr::new("/sysroot")),
);
}
@@ -160,10 +160,10 @@ fn external_docs_doc_url_std_crate() {
//- /main.rs crate:std
use self$0;
"#,
- Some(&OsStr::new("/home/user/project")),
+ Some(OsStr::new("/home/user/project")),
Some(expect!["https://doc.rust-lang.org/stable/std/index.html"]),
Some(expect!["file:///sysroot/share/doc/rust/html/std/index.html"]),
- Some(&OsStr::new("/sysroot")),
+ Some(OsStr::new("/sysroot")),
);
}
@@ -174,10 +174,10 @@ fn external_docs_doc_url_struct() {
//- /main.rs crate:foo
pub struct Fo$0o;
"#,
- Some(&OsStr::new("/home/user/project")),
+ Some(OsStr::new("/home/user/project")),
Some(expect![[r#"https://docs.rs/foo/*/foo/struct.Foo.html"#]]),
Some(expect![[r#"file:///home/user/project/doc/foo/struct.Foo.html"#]]),
- Some(&OsStr::new("/sysroot")),
+ Some(OsStr::new("/sysroot")),
);
}
@@ -188,10 +188,10 @@ fn external_docs_doc_url_windows_backslash_path() {
//- /main.rs crate:foo
pub struct Fo$0o;
"#,
- Some(&OsStr::new(r"C:\Users\user\project")),
+ Some(OsStr::new(r"C:\Users\user\project")),
Some(expect![[r#"https://docs.rs/foo/*/foo/struct.Foo.html"#]]),
Some(expect![[r#"file:///C:/Users/user/project/doc/foo/struct.Foo.html"#]]),
- Some(&OsStr::new("/sysroot")),
+ Some(OsStr::new("/sysroot")),
);
}
@@ -202,10 +202,10 @@ fn external_docs_doc_url_windows_slash_path() {
//- /main.rs crate:foo
pub struct Fo$0o;
"#,
- Some(&OsStr::new(r"C:/Users/user/project")),
+ Some(OsStr::new(r"C:/Users/user/project")),
Some(expect![[r#"https://docs.rs/foo/*/foo/struct.Foo.html"#]]),
Some(expect![[r#"file:///C:/Users/user/project/doc/foo/struct.Foo.html"#]]),
- Some(&OsStr::new("/sysroot")),
+ Some(OsStr::new("/sysroot")),
);
}
diff --git a/crates/ide/src/fetch_crates.rs b/crates/ide/src/fetch_crates.rs
index 46ee671def..14c2655f84 100644
--- a/crates/ide/src/fetch_crates.rs
+++ b/crates/ide/src/fetch_crates.rs
@@ -27,7 +27,7 @@ pub(crate) fn fetch_crates(db: &RootDatabase) -> FxIndexSet<CrateInfo> {
.iter()
.map(|crate_id| &crate_graph[crate_id])
.filter(|&data| !matches!(data.origin, CrateOrigin::Local { .. }))
- .map(|data| crate_info(data))
+ .map(crate_info)
.collect()
}
diff --git a/crates/ide/src/highlight_related.rs b/crates/ide/src/highlight_related.rs
index 3c34778efb..c3a403b107 100644
--- a/crates/ide/src/highlight_related.rs
+++ b/crates/ide/src/highlight_related.rs
@@ -475,8 +475,7 @@ fn find_defs(sema: &Semantics<'_, RootDatabase>, token: SyntaxToken) -> FxHashSe
sema.descend_into_macros(DescendPreference::None, token)
.into_iter()
.filter_map(|token| IdentClass::classify_token(sema, &token))
- .map(IdentClass::definitions_no_ops)
- .flatten()
+ .flat_map(IdentClass::definitions_no_ops)
.collect()
}
diff --git a/crates/ide/src/hover/render.rs b/crates/ide/src/hover/render.rs
index 5a51752266..45386df2b2 100644
--- a/crates/ide/src/hover/render.rs
+++ b/crates/ide/src/hover/render.rs
@@ -128,7 +128,7 @@ pub(super) fn try_expr(
let l = "Propagated as: ".len() - " Type: ".len();
let static_text_len_diff = l as isize - s.len() as isize;
let tpad = static_text_len_diff.max(0) as usize;
- let ppad = static_text_len_diff.min(0).abs() as usize;
+ let ppad = static_text_len_diff.min(0).unsigned_abs();
res.markup = format!(
"```text\n{} Type: {:>pad0$}\nPropagated as: {:>pad1$}\n```\n",
@@ -342,7 +342,7 @@ pub(super) fn try_for_lint(attr: &ast::Attr, token: &SyntaxToken) -> Option<Hove
tmp = format!("clippy::{}", token.text());
&tmp
} else {
- &*token.text()
+ token.text()
};
let lint =
@@ -507,7 +507,7 @@ fn render_notable_trait_comment(
format_to!(
desc,
"{}",
- assoc_types.into_iter().format_with(", ", |(ty, name), f| {
+ assoc_types.iter().format_with(", ", |(ty, name), f| {
f(&name.display(db))?;
f(&" = ")?;
match ty {
@@ -519,7 +519,7 @@ fn render_notable_trait_comment(
desc.push('>');
}
}
- desc.is_empty().not().then(|| desc)
+ desc.is_empty().not().then_some(desc)
}
fn type_info(
@@ -635,7 +635,7 @@ fn closure_ty(
});
let adjusted = if let Some(adjusted_ty) = adjusted {
- walk_and_push_ty(sema.db, &adjusted_ty, &mut push_new_def);
+ walk_and_push_ty(sema.db, adjusted_ty, &mut push_new_def);
format!(
"\nCoerced to: {}",
adjusted_ty.display(sema.db).with_closure_style(hir::ClosureStyle::ImplFn)
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index f466b8e938..79fff15f05 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -357,7 +357,7 @@ fn label_of_ty(
label_builder: &mut InlayHintLabelBuilder<'_>,
config: &InlayHintsConfig,
) -> Result<(), HirDisplayError> {
- let iter_item_type = hint_iterator(sema, famous_defs, &ty);
+ let iter_item_type = hint_iterator(sema, famous_defs, ty);
match iter_item_type {
Some((iter_trait, item, ty)) => {
const LABEL_START: &str = "impl ";
diff --git a/crates/ide/src/inlay_hints/fn_lifetime_fn.rs b/crates/ide/src/inlay_hints/fn_lifetime_fn.rs
index 725ec27155..eb97f2fb81 100644
--- a/crates/ide/src/inlay_hints/fn_lifetime_fn.rs
+++ b/crates/ide/src/inlay_hints/fn_lifetime_fn.rs
@@ -130,11 +130,11 @@ pub(super) fn hints(
[(_, _, lifetime, _), ..] if self_param.is_some() || potential_lt_refs.len() == 1 => {
match lifetime {
Some(lt) => match lt.text().as_str() {
- "'_" => allocated_lifetimes.get(0).cloned(),
+ "'_" => allocated_lifetimes.first().cloned(),
"'static" => None,
name => Some(name.into()),
},
- None => allocated_lifetimes.get(0).cloned(),
+ None => allocated_lifetimes.first().cloned(),
}
}
[..] => None,
diff --git a/crates/ide/src/inlay_hints/implicit_drop.rs b/crates/ide/src/inlay_hints/implicit_drop.rs
index 9cbaed090d..5a206643ac 100644
--- a/crates/ide/src/inlay_hints/implicit_drop.rs
+++ b/crates/ide/src/inlay_hints/implicit_drop.rs
@@ -118,9 +118,8 @@ fn nearest_token_after_node(
token_type: syntax::SyntaxKind,
) -> Option<syntax::SyntaxToken> {
node.siblings_with_tokens(syntax::Direction::Next)
- .filter_map(|it| it.as_token().map(|it| it.clone()))
- .filter(|it| it.kind() == token_type)
- .next()
+ .filter_map(|it| it.as_token().cloned())
+ .find(|it| it.kind() == token_type)
}
#[cfg(test)]
diff --git a/crates/ide/src/interpret_function.rs b/crates/ide/src/interpret_function.rs
index 2169749048..adbd191888 100644
--- a/crates/ide/src/interpret_function.rs
+++ b/crates/ide/src/interpret_function.rs
@@ -18,7 +18,7 @@ pub(crate) fn interpret_function(db: &RootDatabase, position: FilePosition) -> S
let mut result = find_and_interpret(db, position)
.unwrap_or_else(|| "Not inside a function body".to_string());
let duration = Instant::now() - start_time;
- writeln!(result, "").unwrap();
+ writeln!(result).unwrap();
writeln!(result, "----------------------").unwrap();
writeln!(result, " Finished in {}s", duration.as_secs_f32()).unwrap();
result
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index 9ad1630225..81682e07e0 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -269,7 +269,7 @@ impl Analysis {
/// Debug info about the current state of the analysis.
pub fn status(&self, file_id: Option<FileId>) -> Cancellable<String> {
- self.with_db(|db| status::status(&*db, file_id))
+ self.with_db(|db| status::status(db, file_id))
}
pub fn parallel_prime_caches<F>(&self, num_worker_threads: u8, cb: F) -> Cancellable<()>
@@ -348,7 +348,7 @@ impl Analysis {
}
pub fn fetch_crates(&self) -> Cancellable<FxIndexSet<CrateInfo>> {
- self.with_db(|db| fetch_crates::fetch_crates(db))
+ self.with_db(fetch_crates::fetch_crates)
}
pub fn expand_macro(&self, position: FilePosition) -> Cancellable<Option<ExpandedMacro>> {
@@ -667,8 +667,8 @@ impl Analysis {
let assists = ide_assists::assists(db, assist_config, resolve, frange);
let mut res = diagnostic_assists;
- res.extend(ssr_assists.into_iter());
- res.extend(assists.into_iter());
+ res.extend(ssr_assists);
+ res.extend(assists);
res
})
diff --git a/crates/ide/src/navigation_target.rs b/crates/ide/src/navigation_target.rs
index 9e60989c60..c8d7b7e25b 100644
--- a/crates/ide/src/navigation_target.rs
+++ b/crates/ide/src/navigation_target.rs
@@ -689,7 +689,7 @@ impl<T> UpmappingResult<T> {
}
pub fn collect<FI: FromIterator<T>>(self) -> FI {
- FI::from_iter(self.into_iter())
+ FI::from_iter(self)
}
}
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs
index 352ce89820..3008722cdb 100644
--- a/crates/ide/src/runnables.rs
+++ b/crates/ide/src/runnables.rs
@@ -500,7 +500,7 @@ fn has_runnable_doc_test(attrs: &hir::Attrs) -> bool {
docs_from_attrs(attrs).map_or(false, |doc| {
let mut in_code_block = false;
- for line in String::from(doc).lines() {
+ for line in doc.lines() {
if let Some(header) =
RUSTDOC_FENCES.into_iter().find_map(|fence| line.strip_prefix(fence))
{
@@ -570,7 +570,7 @@ mod tests {
if let Some(cfg) = runnable.cfg {
a.push_str(&format!(", {cfg:?}"));
}
- a.push_str(")");
+ a.push(')');
a
})
.collect::<Vec<_>>();
diff --git a/crates/ide/src/signature_help.rs b/crates/ide/src/signature_help.rs
index 483fb76d91..b2eb5a5fff 100644
--- a/crates/ide/src/signature_help.rs
+++ b/crates/ide/src/signature_help.rs
@@ -428,7 +428,7 @@ fn signature_help_for_tuple_struct_pat(
let fields: Vec<_> = if let PathResolution::Def(ModuleDef::Variant(variant)) = path_res {
let en = variant.parent_enum(db);
- res.doc = en.docs(db).map(|it| it.into());
+ res.doc = en.docs(db);
format_to!(
res.signature,
"enum {}::{} (",
@@ -445,7 +445,7 @@ fn signature_help_for_tuple_struct_pat(
match adt {
hir::Adt::Struct(it) => {
- res.doc = it.docs(db).map(|it| it.into());
+ res.doc = it.docs(db);
format_to!(res.signature, "struct {} (", it.name(db).display(db));
it.fields(db)
}
@@ -549,7 +549,7 @@ fn signature_help_for_record_(
fields = variant.fields(db);
let en = variant.parent_enum(db);
- res.doc = en.docs(db).map(|it| it.into());
+ res.doc = en.docs(db);
format_to!(
res.signature,
"enum {}::{} {{ ",
@@ -566,12 +566,12 @@ fn signature_help_for_record_(
match adt {
hir::Adt::Struct(it) => {
fields = it.fields(db);
- res.doc = it.docs(db).map(|it| it.into());
+ res.doc = it.docs(db);
format_to!(res.signature, "struct {} {{ ", it.name(db).display(db));
}
hir::Adt::Union(it) => {
fields = it.fields(db);
- res.doc = it.docs(db).map(|it| it.into());
+ res.doc = it.docs(db);
format_to!(res.signature, "union {} {{ ", it.name(db).display(db));
}
_ => return None,
@@ -638,7 +638,7 @@ fn signature_help_for_tuple_pat_ish(
res.push_call_param(&buf);
buf.clear();
}
- res.signature.push_str(")");
+ res.signature.push(')');
res
}
#[cfg(test)]
diff --git a/crates/ide/src/typing.rs b/crates/ide/src/typing.rs
index d21850bcff..b4a2dc28bb 100644
--- a/crates/ide/src/typing.rs
+++ b/crates/ide/src/typing.rs
@@ -384,9 +384,7 @@ fn on_right_angle_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit>
if file_text.char_at(after_arrow) != Some('{') {
return None;
}
- if find_node_at_offset::<ast::RetType>(file.syntax(), offset).is_none() {
- return None;
- }
+ find_node_at_offset::<ast::RetType>(file.syntax(), offset)?;
Some(TextEdit::insert(after_arrow, " ".to_string()))
}
diff --git a/crates/ide/src/view_crate_graph.rs b/crates/ide/src/view_crate_graph.rs
index 8c84461f65..727012112e 100644
--- a/crates/ide/src/view_crate_graph.rs
+++ b/crates/ide/src/view_crate_graph.rs
@@ -86,7 +86,7 @@ impl<'a> dot::Labeller<'a, CrateId, Edge<'a>> for DotCrateGraph {
}
fn node_label(&'a self, n: &CrateId) -> LabelText<'a> {
- let name = self.graph[*n].display_name.as_ref().map_or("(unnamed crate)", |name| &*name);
+ let name = self.graph[*n].display_name.as_ref().map_or("(unnamed crate)", |name| name);
LabelText::LabelStr(name.into())
}
}
diff --git a/crates/ide/src/view_memory_layout.rs b/crates/ide/src/view_memory_layout.rs
index 53f998e545..a229bc87c8 100644
--- a/crates/ide/src/view_memory_layout.rs
+++ b/crates/ide/src/view_memory_layout.rs
@@ -128,7 +128,7 @@ pub(crate) fn view_memory_layout(
)
.collect::<Vec<_>>();
- if fields.len() == 0 {
+ if fields.is_empty() {
return;
}
@@ -174,7 +174,7 @@ pub(crate) fn view_memory_layout(
for (i, (_, child_ty)) in fields.iter().enumerate() {
if let Ok(child_layout) = child_ty.layout(db) {
- read_layout(nodes, db, &child_ty, &child_layout, children_start + i);
+ read_layout(nodes, db, child_ty, &child_layout, children_start + i);
}
}
}
diff --git a/crates/mbe/src/expander/transcriber.rs b/crates/mbe/src/expander/transcriber.rs
index 822b712f1c..b3fb0e8de1 100644
--- a/crates/mbe/src/expander/transcriber.rs
+++ b/crates/mbe/src/expander/transcriber.rs
@@ -187,7 +187,7 @@ fn expand_subtree<S: Span>(
for punct in puncts {
arena.push(
tt::Leaf::from({
- let mut it = punct.clone();
+ let mut it = *punct;
marker(&mut it.span);
it
})
diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs
index 2622d7eac1..f968a89a44 100644
--- a/crates/mbe/src/lib.rs
+++ b/crates/mbe/src/lib.rs
@@ -254,7 +254,7 @@ impl<S: Span> DeclarativeMacro<S> {
new_meta_vars: bool,
call_site: S,
) -> ExpandResult<tt::Subtree<S>> {
- expander::expand_rules(&self.rules, &tt, marker, self.is_2021, new_meta_vars, call_site)
+ expander::expand_rules(&self.rules, tt, marker, self.is_2021, new_meta_vars, call_site)
}
}
diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs
index 8fa04ab983..8b57d7eeaf 100644
--- a/crates/mbe/src/syntax_bridge.rs
+++ b/crates/mbe/src/syntax_bridge.rs
@@ -775,7 +775,7 @@ where
self.punct_offset = Some((curr.clone(), 0.into()));
let range = curr.text_range();
let range = TextRange::at(range.start(), TextSize::of('.'));
- (SynToken::Punct { token: curr, offset: 0 as usize }, range)
+ (SynToken::Punct { token: curr, offset: 0_usize }, range)
} else {
self.punct_offset = None;
let range = curr.text_range();
@@ -799,7 +799,7 @@ where
}
let token = if curr.kind().is_punct() {
- SynToken::Punct { token: curr, offset: 0 as usize }
+ SynToken::Punct { token: curr, offset: 0_usize }
} else {
SynToken::Ordinary(curr)
};
diff --git a/crates/project-model/src/cargo_workspace.rs b/crates/project-model/src/cargo_workspace.rs
index dba9edab3c..66da084b49 100644
--- a/crates/project-model/src/cargo_workspace.rs
+++ b/crates/project-model/src/cargo_workspace.rs
@@ -441,7 +441,7 @@ impl CargoWorkspace {
.collect::<Vec<ManifestPath>>();
// some packages has this pkg as dep. return their manifests
- if parent_manifests.len() > 0 {
+ if !parent_manifests.is_empty() {
return Some(parent_manifests);
}
diff --git a/crates/project-model/src/sysroot.rs b/crates/project-model/src/sysroot.rs
index fb5e8c365a..c24c0196dd 100644
--- a/crates/project-model/src/sysroot.rs
+++ b/crates/project-model/src/sysroot.rs
@@ -201,7 +201,7 @@ impl Sysroot {
e
});
if let Err(e) =
- std::fs::remove_file(&format!("{sysroot_src_dir}/sysroot/Cargo.lock"))
+ std::fs::remove_file(format!("{sysroot_src_dir}/sysroot/Cargo.lock"))
{
tracing::error!(
"failed to remove sysroot `{sysroot_src_dir}/sysroot/Cargo.lock`: {}",
@@ -268,11 +268,8 @@ impl Sysroot {
res.workspace_members = res
.packages
.iter()
- .filter_map(|package| {
- RELEVANT_SYSROOT_CRATES
- .contains(&&*package.name)
- .then(|| package.id.clone())
- })
+ .filter(|&package| RELEVANT_SYSROOT_CRATES.contains(&&*package.name))
+ .map(|package| package.id.clone())
.collect();
let cargo_workspace = CargoWorkspace::new(res);
Some(Sysroot {
diff --git a/crates/project-model/src/tests.rs b/crates/project-model/src/tests.rs
index 9e6b00d938..7c078f72f5 100644
--- a/crates/project-model/src/tests.rs
+++ b/crates/project-model/src/tests.rs
@@ -106,7 +106,7 @@ fn replace_fake_sys_root(s: &mut String) {
let fake_sysroot_path = get_test_path("fake-sysroot");
let fake_sysroot_path = if cfg!(windows) {
let normalized_path =
- fake_sysroot_path.to_str().expect("expected str").replace(r#"\"#, r#"\\"#);
+ fake_sysroot_path.to_str().expect("expected str").replace('\\', r#"\\"#);
format!(r#"{}\\"#, normalized_path)
} else {
format!("{}/", fake_sysroot_path.to_str().expect("expected str"))
diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs
index cd7f37fe49..88974e889e 100644
--- a/crates/project-model/src/workspace.rs
+++ b/crates/project-model/src/workspace.rs
@@ -38,7 +38,7 @@ pub struct CfgOverrides {
impl CfgOverrides {
pub fn len(&self) -> usize {
- self.global.len() + self.selective.iter().map(|(_, it)| it.len()).sum::<usize>()
+ self.global.len() + self.selective.values().map(|it| it.len()).sum::<usize>()
}
}
@@ -177,7 +177,7 @@ impl ProjectWorkspace {
};
let res = match manifest {
ProjectManifest::ProjectJson(project_json) => {
- let file = fs::read_to_string(&project_json)
+ let file = fs::read_to_string(project_json)
.with_context(|| format!("Failed to read json file {project_json}"))?;
let data = serde_json::from_str(&file)
.with_context(|| format!("Failed to deserialize json file {project_json}"))?;
@@ -194,7 +194,7 @@ impl ProjectWorkspace {
ProjectManifest::CargoToml(cargo_toml) => {
let toolchain = version(cargo_toml.parent(), toolchain::cargo(), "cargo ")?;
let meta = CargoWorkspace::fetch_metadata(
- &cargo_toml,
+ cargo_toml,
cargo_toml.parent(),
config,
progress,
@@ -241,7 +241,7 @@ impl ProjectWorkspace {
.map_err(|p| Some(format!("rustc source path is not absolute: {p}"))),
Some(RustLibSource::Discover) => {
sysroot.as_ref().ok().and_then(Sysroot::discover_rustc_src).ok_or_else(
- || Some(format!("Failed to discover rustc source for sysroot.")),
+ || Some("Failed to discover rustc source for sysroot.".to_string()),
)
}
None => Err(None),
@@ -287,7 +287,7 @@ impl ProjectWorkspace {
let cfg_overrides = config.cfg_overrides.clone();
let data_layout = target_data_layout::get(
- Some(&cargo_toml),
+ Some(cargo_toml),
config.target.as_deref(),
&config.extra_env,
);
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index f601f00442..f42e14f2e5 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -277,7 +277,7 @@ impl flags::AnalysisStats {
}
all += 1;
let Err(e) = db.layout_of_adt(
- hir_def::AdtId::from(a).into(),
+ hir_def::AdtId::from(a),
Substitution::empty(Interner),
db.trait_environment(a.into()),
) else {
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs
index abec267946..0182cf5402 100644
--- a/crates/rust-analyzer/src/cli/diagnostics.rs
+++ b/crates/rust-analyzer/src/cli/diagnostics.rs
@@ -16,7 +16,7 @@ impl flags::Diagnostics {
let mut cargo_config = CargoConfig::default();
cargo_config.sysroot = Some(RustLibSource::Discover);
let with_proc_macro_server = if let Some(p) = &self.proc_macro_srv {
- let path = vfs::AbsPathBuf::assert(std::env::current_dir()?.join(&p));
+ let path = vfs::AbsPathBuf::assert(std::env::current_dir()?.join(p));
ProcMacroServerChoice::Explicit(path)
} else {
ProcMacroServerChoice::Sysroot
diff --git a/crates/rust-analyzer/src/cli/lsif.rs b/crates/rust-analyzer/src/cli/lsif.rs
index d6a45ce06f..2138ecead5 100644
--- a/crates/rust-analyzer/src/cli/lsif.rs
+++ b/crates/rust-analyzer/src/cli/lsif.rs
@@ -217,8 +217,7 @@ impl LsifManager<'_> {
let mut edges = token.references.iter().fold(
HashMap::<_, Vec<lsp_types::NumberOrString>>::new(),
|mut edges, it| {
- let entry =
- edges.entry((it.range.file_id, it.is_definition)).or_insert_with(Vec::new);
+ let entry = edges.entry((it.range.file_id, it.is_definition)).or_default();
entry.push((*self.range_map.get(&it.range).unwrap()).into());
edges
},
@@ -296,7 +295,7 @@ impl flags::Lsif {
with_proc_macro_server: ProcMacroServerChoice::Sysroot,
prefill_caches: false,
};
- let path = AbsPathBuf::assert(env::current_dir()?.join(&self.path));
+ let path = AbsPathBuf::assert(env::current_dir()?.join(self.path));
let manifest = ProjectManifest::discover_single(&path)?;
let workspace = ProjectWorkspace::load(manifest, &cargo_config, no_progress)?;
diff --git a/crates/rust-analyzer/src/cli/progress_report.rs b/crates/rust-analyzer/src/cli/progress_report.rs
index c236f9c7fe..8166aa23b4 100644
--- a/crates/rust-analyzer/src/cli/progress_report.rs
+++ b/crates/rust-analyzer/src/cli/progress_report.rs
@@ -59,7 +59,7 @@ impl<'a> ProgressReport<'a> {
"{}/{} {percent:3>}% {}",
self.pos,
self.len,
- self.msg.as_ref().map_or_else(|| String::new(), |it| it())
+ self.msg.as_ref().map_or_else(String::new, |it| it())
);
self.update_text(&text);
}
diff --git a/crates/rust-analyzer/src/cli/scip.rs b/crates/rust-analyzer/src/cli/scip.rs
index c86b2c0ba4..c9cf40db3a 100644
--- a/crates/rust-analyzer/src/cli/scip.rs
+++ b/crates/rust-analyzer/src/cli/scip.rs
@@ -246,7 +246,7 @@ fn new_descriptor(name: &str, suffix: scip_types::descriptor::Suffix) -> scip_ty
if name.contains('\'') {
new_descriptor_str(&format!("`{name}`"), suffix)
} else {
- new_descriptor_str(&name, suffix)
+ new_descriptor_str(name, suffix)
}
}
@@ -359,7 +359,7 @@ mod test {
}
}
- if expected == "" {
+ if expected.is_empty() {
assert!(found_symbol.is_none(), "must have no symbols {found_symbol:?}");
return;
}
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index b5360e1535..3c1b464c3c 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -1183,12 +1183,12 @@ impl Config {
}
pub fn lru_query_capacities(&self) -> Option<&FxHashMap<Box<str>, usize>> {
- self.data.lru_query_capacities.is_empty().not().then(|| &self.data.lru_query_capacities)
+ self.data.lru_query_capacities.is_empty().not().then_some(&self.data.lru_query_capacities)
}
pub fn proc_macro_srv(&self) -> Option<AbsPathBuf> {
let path = self.data.procMacro_server.clone()?;
- Some(AbsPathBuf::try_from(path).unwrap_or_else(|path| self.root_path.join(&path)))
+ Some(AbsPathBuf::try_from(path).unwrap_or_else(|path| self.root_path.join(path)))
}
pub fn dummy_replacements(&self) -> &FxHashMap<Box<str>, Box<[Box<str>]>> {
@@ -1863,18 +1863,14 @@ mod de_unit_v {
#[derive(Deserialize, Debug, Clone, Copy)]
#[serde(rename_all = "snake_case")]
+#[derive(Default)]
enum SnippetScopeDef {
+ #[default]
Expr,
Item,
Type,
}
-impl Default for SnippetScopeDef {
- fn default() -> Self {
- SnippetScopeDef::Expr
- }
-}
-
#[derive(Deserialize, Debug, Clone, Default)]
#[serde(default)]
struct SnippetDef {
@@ -2728,7 +2724,7 @@ mod tests {
.unwrap();
assert_eq!(config.data.rust_analyzerTargetDir, None);
assert!(
- matches!(config.flycheck(), FlycheckConfig::CargoCommand { target_dir, .. } if target_dir == None)
+ matches!(config.flycheck(), FlycheckConfig::CargoCommand { target_dir, .. } if target_dir.is_none())
);
}
diff --git a/crates/rust-analyzer/src/diagnostics.rs b/crates/rust-analyzer/src/diagnostics.rs
index f80beb9caa..ab3881f438 100644
--- a/crates/rust-analyzer/src/diagnostics.rs
+++ b/crates/rust-analyzer/src/diagnostics.rs
@@ -133,7 +133,7 @@ pub(crate) fn fetch_native_diagnostics(
let convert_diagnostic =
|line_index: &crate::line_index::LineIndex, d: ide::Diagnostic| lsp_types::Diagnostic {
- range: lsp::to_proto::range(&line_index, d.range.range),
+ range: lsp::to_proto::range(line_index, d.range.range),
severity: Some(lsp::to_proto::diagnostic_severity(d.severity)),
code: Some(lsp_types::NumberOrString::String(d.code.as_str().to_string())),
code_description: Some(lsp_types::CodeDescription {
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index c4a29e0cbb..232c03ae6c 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -299,11 +299,11 @@ impl GlobalState {
}
let text = if let vfs::Change::Create(v) | vfs::Change::Modify(v) = file.change {
- String::from_utf8(v).ok().and_then(|text| {
+ String::from_utf8(v).ok().map(|text| {
// FIXME: Consider doing normalization in the `vfs` instead? That allows
// getting rid of some locking
let (text, line_endings) = LineEndings::normalize(text);
- Some((Arc::from(text), line_endings))
+ (Arc::from(text), line_endings)
})
} else {
None
diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs
index 349e6e5023..4b2a1f7e8e 100644
--- a/crates/rust-analyzer/src/handlers/request.rs
+++ b/crates/rust-analyzer/src/handlers/request.rs
@@ -919,7 +919,7 @@ pub(crate) fn handle_completion_resolve(
}
if let Some(original_additional_edits) = original_completion.additional_text_edits.as_mut() {
- original_additional_edits.extend(additional_edits.into_iter())
+ original_additional_edits.extend(additional_edits)
} else {
original_completion.additional_text_edits = Some(additional_edits);
}
@@ -1039,11 +1039,7 @@ pub(crate) fn handle_rename(
{
for op in ops {
if let lsp_types::DocumentChangeOperation::Op(doc_change_op) = op {
- if let Err(err) =
- resource_ops_supported(&snap.config, resolve_resource_op(doc_change_op))
- {
- return Err(err);
- }
+ resource_ops_supported(&snap.config, resolve_resource_op(doc_change_op))?
}
}
}
@@ -1160,11 +1156,7 @@ pub(crate) fn handle_code_action(
if let Some(changes) = changes {
for change in changes {
if let lsp_ext::SnippetDocumentChangeOperation::Op(res_op) = change {
- if let Err(err) =
- resource_ops_supported(&snap.config, resolve_resource_op(res_op))
- {
- return Err(err);
- }
+ resource_ops_supported(&snap.config, resolve_resource_op(res_op))?
}
}
}
@@ -1256,11 +1248,7 @@ pub(crate) fn handle_code_action_resolve(
if let Some(changes) = edit.document_changes.as_ref() {
for change in changes {
if let lsp_ext::SnippetDocumentChangeOperation::Op(res_op) = change {
- if let Err(err) =
- resource_ops_supported(&snap.config, resolve_resource_op(res_op))
- {
- return Err(err);
- }
+ resource_ops_supported(&snap.config, resolve_resource_op(res_op))?
}
}
}
@@ -1984,14 +1972,14 @@ fn run_rustfmt(
}
RustfmtConfig::CustomCommand { command, args } => {
let cmd = PathBuf::from(&command);
- let workspace = CargoTargetSpec::for_file(&snap, file_id)?;
+ let workspace = CargoTargetSpec::for_file(snap, file_id)?;
let mut cmd = match workspace {
Some(spec) => {
// approach: if the command name contains a path separator, join it with the workspace root.
// however, if the path is absolute, joining will result in the absolute path being preserved.
// as a fallback, rely on $PATH-based discovery.
let cmd_path =
- if cfg!(windows) && command.contains(&[std::path::MAIN_SEPARATOR, '/']) {
+ if cfg!(windows) && command.contains([std::path::MAIN_SEPARATOR, '/']) {
spec.workspace_root.join(cmd).into()
} else if command.contains(std::path::MAIN_SEPARATOR) {
spec.workspace_root.join(cmd).into()
diff --git a/crates/rust-analyzer/src/lsp/from_proto.rs b/crates/rust-analyzer/src/lsp/from_proto.rs
index 69d6aba94c..9923be382b 100644
--- a/crates/rust-analyzer/src/lsp/from_proto.rs
+++ b/crates/rust-analyzer/src/lsp/from_proto.rs
@@ -51,7 +51,7 @@ pub(crate) fn text_range(
let start = offset(line_index, range.start)?;
let end = offset(line_index, range.end)?;
match end < start {
- true => Err(format_err!("Invalid Range").into()),
+ true => Err(format_err!("Invalid Range")),
false => Ok(TextRange::new(start, end)),
}
}
diff --git a/crates/rust-analyzer/src/lsp/semantic_tokens.rs b/crates/rust-analyzer/src/lsp/semantic_tokens.rs
index 1fe02fc7ea..dd7dcf5277 100644
--- a/crates/rust-analyzer/src/lsp/semantic_tokens.rs
+++ b/crates/rust-analyzer/src/lsp/semantic_tokens.rs
@@ -157,7 +157,7 @@ pub(crate) struct ModifierSet(pub(crate) u32);
impl ModifierSet {
pub(crate) fn standard_fallback(&mut self) {
// Remove all non standard modifiers
- self.0 = self.0 & !(!0u32 << LAST_STANDARD_MOD)
+ self.0 &= !(!0u32 << LAST_STANDARD_MOD)
}
}
diff --git a/crates/rust-analyzer/src/lsp/to_proto.rs b/crates/rust-analyzer/src/lsp/to_proto.rs
index 7f3c3aa7a1..d26fe16cbd 100644
--- a/crates/rust-analyzer/src/lsp/to_proto.rs
+++ b/crates/rust-analyzer/src/lsp/to_proto.rs
@@ -931,9 +931,9 @@ fn merge_text_and_snippet_edits(
) -> Vec<SnippetTextEdit> {
let mut edits: Vec<SnippetTextEdit> = vec![];
let mut snippets = snippet_edit.into_edit_ranges().into_iter().peekable();
- let mut text_edits = edit.into_iter();
+ let text_edits = edit.into_iter();
- while let Some(current_indel) = text_edits.next() {
+ for current_indel in text_edits {
let new_range = {
let insert_len =
TextSize::try_from(current_indel.insert.len()).unwrap_or(TextSize::from(u32::MAX));
@@ -956,7 +956,7 @@ fn merge_text_and_snippet_edits(
snippet_range
};
- let range = range(&line_index, snippet_range);
+ let range = range(line_index, snippet_range);
let new_text = format!("${snippet_index}");
edits.push(SnippetTextEdit {
@@ -1026,7 +1026,7 @@ fn merge_text_and_snippet_edits(
snippet_range
};
- let range = range(&line_index, snippet_range);
+ let range = range(line_index, snippet_range);
let new_text = format!("${snippet_index}");
SnippetTextEdit {
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 6a073307c0..f767585697 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -521,7 +521,7 @@ impl GlobalState {
if self.config.run_build_scripts() && workspaces_updated {
self.fetch_build_data_queue
- .request_op(format!("workspace updated"), ());
+ .request_op("workspace updated".to_string(), ());
}
(Progress::End, None)
@@ -604,7 +604,7 @@ impl GlobalState {
if let Some(dir) = dir {
message += &format!(
": {}",
- match dir.strip_prefix(&self.config.root_path()) {
+ match dir.strip_prefix(self.config.root_path()) {
Some(relative_path) => relative_path.as_ref(),
None => dir.as_ref(),
}
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index 9083f90908..83736c65ed 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -522,7 +522,7 @@ impl GlobalState {
let mut proc_macros = Vec::default();
for ws in &**self.workspaces {
let (other, mut crate_proc_macros) =
- ws.to_crate_graph(&mut load, &self.config.extra_env());
+ ws.to_crate_graph(&mut load, self.config.extra_env());
crate_graph.extend(other, &mut crate_proc_macros, |_| {});
proc_macros.push(crate_proc_macros);
}
diff --git a/crates/rust-analyzer/tests/slow-tests/testdir.rs b/crates/rust-analyzer/tests/slow-tests/testdir.rs
index 45241ad63e..b3ee7fa3d0 100644
--- a/crates/rust-analyzer/tests/slow-tests/testdir.rs
+++ b/crates/rust-analyzer/tests/slow-tests/testdir.rs
@@ -11,11 +11,11 @@ pub(crate) struct TestDir {
impl TestDir {
pub(crate) fn new() -> TestDir {
- return TestDir::new_dir(false);
+ TestDir::new_dir(false)
}
pub(crate) fn new_symlink() -> TestDir {
- return TestDir::new_dir(true);
+ TestDir::new_dir(true)
}
fn new_dir(symlink: bool) -> TestDir {
diff --git a/crates/span/src/map.rs b/crates/span/src/map.rs
index d69df91b63..9f8101c816 100644
--- a/crates/span/src/map.rs
+++ b/crates/span/src/map.rs
@@ -75,7 +75,7 @@ impl<S: Copy> SpanMap<S> {
let (start, end) = (range.start(), range.end());
let start_entry = self.spans.partition_point(|&(it, _)| it <= start);
let end_entry = self.spans[start_entry..].partition_point(|&(it, _)| it <= end); // FIXME: this might be wrong?
- (&self.spans[start_entry..][..end_entry]).iter().map(|&(_, s)| s)
+ self.spans[start_entry..][..end_entry].iter().map(|&(_, s)| s)
}
pub fn iter(&self) -> impl Iterator<Item = (TextSize, S)> + '_ {
diff --git a/crates/syntax/src/algo.rs b/crates/syntax/src/algo.rs
index c402a7bcea..c4548b1647 100644
--- a/crates/syntax/src/algo.rs
+++ b/crates/syntax/src/algo.rs
@@ -207,7 +207,7 @@ pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff {
TreeDiffInsertPos::AsFirstChild(lhs.clone().into())
}
};
- diff.insertions.entry(insert_pos).or_insert_with(Vec::new).push(element);
+ diff.insertions.entry(insert_pos).or_default().push(element);
}
(Some(element), None) => {
cov_mark::hit!(diff_delete);
@@ -239,7 +239,7 @@ pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff {
TreeDiffInsertPos::AsFirstChild(lhs.clone().into())
};
- diff.insertions.entry(insert_pos).or_insert_with(Vec::new).extend(drain);
+ diff.insertions.entry(insert_pos).or_default().extend(drain);
rhs_children = rhs_children_clone;
} else {
go(diff, lhs_ele, rhs_ele);
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index 0f06690b8c..f7c7327776 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -364,8 +364,12 @@ impl ast::UseTreeList {
let remove_brace_in_use_tree_list = |u: &ast::UseTreeList| {
let use_tree_count = u.use_trees().count();
if use_tree_count == 1 {
- u.l_curly_token().map(ted::remove);
- u.r_curly_token().map(ted::remove);
+ if let Some(a) = u.l_curly_token() {
+ ted::remove(a)
+ }
+ if let Some(a) = u.r_curly_token() {
+ ted::remove(a)
+ }
u.comma().for_each(ted::remove);
}
};
diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs
index 44e49d6d44..b39006e2ff 100644
--- a/crates/syntax/src/ast/token_ext.rs
+++ b/crates/syntax/src/ast/token_ext.rs
@@ -478,6 +478,38 @@ impl Radix {
}
}
+impl ast::Char {
+ pub fn value(&self) -> Option<char> {
+ let mut text = self.text();
+ if text.starts_with('\'') {
+ text = &text[1..];
+ } else {
+ return None;
+ }
+ if text.ends_with('\'') {
+ text = &text[0..text.len() - 1];
+ }
+
+ unescape_char(text).ok()
+ }
+}
+
+impl ast::Byte {
+ pub fn value(&self) -> Option<u8> {
+ let mut text = self.text();
+ if text.starts_with("b\'") {
+ text = &text[2..];
+ } else {
+ return None;
+ }
+ if text.ends_with('\'') {
+ text = &text[0..text.len() - 1];
+ }
+
+ unescape_byte(text).ok()
+ }
+}
+
#[cfg(test)]
mod tests {
use crate::ast::{self, make, FloatNumber, IntNumber};
@@ -579,35 +611,3 @@ bcde", b"abcde",
check_int_value("1_1_1_1_1_1", 111111);
}
}
-
-impl ast::Char {
- pub fn value(&self) -> Option<char> {
- let mut text = self.text();
- if text.starts_with('\'') {
- text = &text[1..];
- } else {
- return None;
- }
- if text.ends_with('\'') {
- text = &text[0..text.len() - 1];
- }
-
- unescape_char(text).ok()
- }
-}
-
-impl ast::Byte {
- pub fn value(&self) -> Option<u8> {
- let mut text = self.text();
- if text.starts_with("b\'") {
- text = &text[2..];
- } else {
- return None;
- }
- if text.ends_with('\'') {
- text = &text[0..text.len() - 1];
- }
-
- unescape_byte(text).ok()
- }
-}
diff --git a/crates/syntax/src/ptr.rs b/crates/syntax/src/ptr.rs
index 8750147ee1..b716d36706 100644
--- a/crates/syntax/src/ptr.rs
+++ b/crates/syntax/src/ptr.rs
@@ -36,7 +36,7 @@ impl<N: AstNode + std::fmt::Debug> std::fmt::Debug for AstPtr<N> {
impl<N: AstNode> Copy for AstPtr<N> {}
impl<N: AstNode> Clone for AstPtr<N> {
fn clone(&self) -> AstPtr<N> {
- AstPtr { raw: self.raw.clone(), _ty: PhantomData }
+ AstPtr { raw: self.raw, _ty: PhantomData }
}
}
@@ -65,7 +65,7 @@ impl<N: AstNode> AstPtr<N> {
}
pub fn syntax_node_ptr(&self) -> SyntaxNodePtr {
- self.raw.clone()
+ self.raw
}
pub fn text_range(&self) -> TextRange {
diff --git a/crates/test-fixture/src/lib.rs b/crates/test-fixture/src/lib.rs
index 1a042b2dea..b5ff7a1bf5 100644
--- a/crates/test-fixture/src/lib.rs
+++ b/crates/test-fixture/src/lib.rs
@@ -354,7 +354,7 @@ impl ChangeFixture {
files,
change: Change {
source_change,
- proc_macros: proc_macros.is_empty().not().then(|| proc_macros),
+ proc_macros: proc_macros.is_empty().not().then_some(proc_macros),
},
}
}
diff --git a/lib/lsp-server/src/lib.rs b/lib/lsp-server/src/lib.rs
index 6b732d4702..f717f8e0d4 100644
--- a/lib/lsp-server/src/lib.rs
+++ b/lib/lsp-server/src/lib.rs
@@ -184,9 +184,9 @@ impl Connection {
};
}
- return Err(ProtocolError::new(String::from(
+ Err(ProtocolError::new(String::from(
"Initialization has been aborted during initialization",
- )));
+ )))
}
/// Finishes the initialization process by sending an `InitializeResult` to the client
@@ -244,9 +244,9 @@ impl Connection {
}
}
- return Err(ProtocolError::new(String::from(
+ Err(ProtocolError::new(String::from(
"Initialization has been aborted during initialization",
- )));
+ )))
}
/// Initialize the connection. Sends the server capabilities
@@ -358,12 +358,14 @@ impl Connection {
)))
}
Err(RecvTimeoutError::Timeout) => {
- return Err(ProtocolError::new(format!("timed out waiting for exit notification")))
+ return Err(ProtocolError::new(
+ "timed out waiting for exit notification".to_string(),
+ ))
}
Err(RecvTimeoutError::Disconnected) => {
- return Err(ProtocolError::new(format!(
- "channel disconnected waiting for exit notification"
- )))
+ return Err(ProtocolError::new(
+ "channel disconnected waiting for exit notification".to_string(),
+ ))
}
}
Ok(true)