Unnamed repository; edit this file 'description' to name the repository.
misc improvements
Ada Alakbarova 3 weeks ago
parent 2c88285 · commit c6a6968
-rw-r--r--crates/hir-expand/src/db.rs2
-rw-r--r--crates/ide-diagnostics/src/handlers/no_such_field.rs15
-rw-r--r--crates/ide-diagnostics/src/handlers/unresolved_method.rs30
3 files changed, 19 insertions, 28 deletions
diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs
index b09f69a295..878fae88ad 100644
--- a/crates/hir-expand/src/db.rs
+++ b/crates/hir-expand/src/db.rs
@@ -396,7 +396,7 @@ pub(crate) fn parse_with_map(
/// This resolves the [MacroCallId] to check if it is a derive macro if so get the [macro_arg] for the derive.
/// Other wise return the [macro_arg] for the macro_call_id.
///
-/// This is not connected to the database so it does not cached the result. However, the inner [macro_arg] query is
+/// This is not connected to the database so it does not cache the result. However, the inner [macro_arg] query is
#[allow(deprecated)] // we are macro_arg_considering_derives
fn macro_arg_considering_derives<'db>(
db: &'db dyn ExpandDatabase,
diff --git a/crates/ide-diagnostics/src/handlers/no_such_field.rs b/crates/ide-diagnostics/src/handlers/no_such_field.rs
index 7959fddc75..3dd6744b05 100644
--- a/crates/ide-diagnostics/src/handlers/no_such_field.rs
+++ b/crates/ide-diagnostics/src/handlers/no_such_field.rs
@@ -116,14 +116,13 @@ fn missing_record_expr_field_fixes(
let mut new_field = new_field.to_string();
// FIXME: check submodule instead of FileId
- if usage_file_id != def_file_id && !matches!(def_id, hir::Variant::EnumVariant(_)) {
- new_field = format!("pub(crate) {new_field}");
- }
- new_field = format!("\n{indent}{new_field}{postfix}");
-
- if needs_comma {
- new_field = format!(",{new_field}");
- }
+ let vis = if usage_file_id != def_file_id && !matches!(def_id, hir::Variant::EnumVariant(_)) {
+ "pub(crate) "
+ } else {
+ ""
+ };
+ let comma = if needs_comma { "," } else { "" };
+ new_field = format!("{comma}\n{indent}{vis}{new_field}{postfix}");
let source_change = SourceChange::from_text_edit(
def_file_id.file_id(sema.db),
diff --git a/crates/ide-diagnostics/src/handlers/unresolved_method.rs b/crates/ide-diagnostics/src/handlers/unresolved_method.rs
index 93caf281f0..01929a5144 100644
--- a/crates/ide-diagnostics/src/handlers/unresolved_method.rs
+++ b/crates/ide-diagnostics/src/handlers/unresolved_method.rs
@@ -129,25 +129,17 @@ fn assoc_func_fix(
let receiver_type = &ctx.sema.type_of_expr(&receiver)?.original;
let assoc_fn_params = f.assoc_fn_params(db);
- let need_to_take_receiver_as_first_arg = if assoc_fn_params.is_empty() {
- false
- } else {
- assoc_fn_params
- .first()
- .map(|first_arg| {
- // For generic type, say `Box`, take `Box::into_raw(b: Self)` as example,
- // type of `b` is `Self`, which is `Box<T, A>`, containing unspecified generics.
- // However, type of `receiver` is specified, it could be `Box<i32, Global>` or something like that,
- // so `first_arg.ty() == receiver_type` evaluate to `false` here.
- // Here add `first_arg.ty().as_adt() == receiver_type.as_adt()` as guard,
- // apply `.as_adt()` over `Box<T, A>` or `Box<i32, Global>` gets `Box`, so we get `true` here.
-
- // FIXME: it fails when type of `b` is `Box` with other generic param different from `receiver`
- first_arg.ty() == receiver_type
- || first_arg.ty().as_adt() == receiver_type.as_adt()
- })
- .unwrap_or(false)
- };
+ let need_to_take_receiver_as_first_arg = assoc_fn_params.first().is_some_and(|first_arg| {
+ // For generic type, say `Box`, take `Box::into_raw(b: Self)` as example,
+ // type of `b` is `Self`, which is `Box<T, A>`, containing unspecified generics.
+ // However, type of `receiver` is specified, it could be `Box<i32, Global>` or something like that,
+ // so `first_arg.ty() == receiver_type` evaluate to `false` here.
+ // Here add `first_arg.ty().as_adt() == receiver_type.as_adt()` as guard,
+ // apply `.as_adt()` over `Box<T, A>` or `Box<i32, Global>` gets `Box`, so we get `true` here.
+
+ // FIXME: it fails when type of `b` is `Box` with other generic param different from `receiver`
+ first_arg.ty() == receiver_type || first_arg.ty().as_adt() == receiver_type.as_adt()
+ });
let mut receiver_type_adt_name =
receiver_type.as_adt()?.name(db).display_no_db(ctx.edition).to_smolstr();