Unnamed repository; edit this file 'description' to name the repository.
Extract to hir_expand::name::is_generated
| -rw-r--r-- | crates/hir-expand/src/name.rs | 7 | ||||
| -rw-r--r-- | crates/hir/src/lib.rs | 2 | ||||
| -rw-r--r-- | crates/ide/src/inlay_hints/implicit_drop.rs | 3 | ||||
| -rw-r--r-- | crates/ide/src/inlay_hints/param_name.rs | 7 |
4 files changed, 13 insertions, 6 deletions
diff --git a/crates/hir-expand/src/name.rs b/crates/hir-expand/src/name.rs index 3ddc305f95..b511bc3c15 100644 --- a/crates/hir-expand/src/name.rs +++ b/crates/hir-expand/src/name.rs @@ -201,10 +201,15 @@ impl Name { #[inline] pub fn is_generated(&self) -> bool { - self.as_str().starts_with("<ra@gennew>") + is_generated(self.as_str()) } } +#[inline] +pub fn is_generated(name: &str) -> bool { + name.starts_with("<ra@gennew>") +} + struct Display<'a> { name: &'a Name, edition: Edition, diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index d187763151..ce03d7f3cb 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -164,7 +164,7 @@ pub use { }, inert_attr_macro::AttributeTemplate, mod_path::{ModPath, PathKind, tool_path}, - name::Name, + name::{self, Name}, prettify_macro_expansion, proc_macro::{ProcMacros, ProcMacrosBuilder}, tt, diff --git a/crates/ide/src/inlay_hints/implicit_drop.rs b/crates/ide/src/inlay_hints/implicit_drop.rs index f6b13cbe0b..9387573cf7 100644 --- a/crates/ide/src/inlay_hints/implicit_drop.rs +++ b/crates/ide/src/inlay_hints/implicit_drop.rs @@ -9,6 +9,7 @@ use hir::{ DefWithBody, db::HirDatabase as _, mir::{MirSpan, TerminatorKind}, + name, }; use ide_db::{FileRange, famous_defs::FamousDefs}; @@ -95,7 +96,7 @@ pub(super) fn hints( }; let binding = &hir[binding_idx]; let name = binding.name.display_no_db(display_target.edition).to_smolstr(); - if name.starts_with("<ra@") { + if name::is_generated(&name) { continue; // Ignore desugared variables } let mut label = InlayHintLabel::simple( diff --git a/crates/ide/src/inlay_hints/param_name.rs b/crates/ide/src/inlay_hints/param_name.rs index 6ae826623c..f1689e5f9d 100644 --- a/crates/ide/src/inlay_hints/param_name.rs +++ b/crates/ide/src/inlay_hints/param_name.rs @@ -7,7 +7,7 @@ use std::iter::zip; use either::Either; -use hir::{EditionedFileId, Semantics}; +use hir::{EditionedFileId, Semantics, name}; use ide_db::{RootDatabase, famous_defs::FamousDefs}; use stdx::to_lower_snake_case; @@ -195,15 +195,16 @@ fn should_hide_param_name_hint( // - the argument is a qualified constructing or call expression where the qualifier is an ADT // - exact argument<->parameter match(ignoring leading and trailing underscore) or // parameter is a prefix/suffix of argument with _ splitting it off - // - param starts with `ra_fixture` or `<ra@` + // - param starts with `ra_fixture` // - param is a well known name in a unary function + // - param is generated name let param_name = param_name.trim_matches('_'); if param_name.is_empty() { return true; } - if param_name.starts_with("ra_fixture") || param_name.starts_with("<ra@") { + if param_name.starts_with("ra_fixture") || name::is_generated(param_name) { return true; } |