Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/inlay_hints/fn_lifetime_fn.rs')
-rw-r--r--crates/ide/src/inlay_hints/fn_lifetime_fn.rs24
1 files changed, 11 insertions, 13 deletions
diff --git a/crates/ide/src/inlay_hints/fn_lifetime_fn.rs b/crates/ide/src/inlay_hints/fn_lifetime_fn.rs
index 7b05e32ad8..6e5f23bed0 100644
--- a/crates/ide/src/inlay_hints/fn_lifetime_fn.rs
+++ b/crates/ide/src/inlay_hints/fn_lifetime_fn.rs
@@ -4,11 +4,11 @@
//! ```
use ide_db::{syntax_helpers::node_ext::walk_ty, FxHashMap};
use itertools::Itertools;
-use syntax::SmolStr;
use syntax::{
ast::{self, AstNode, HasGenericParams, HasName},
SyntaxToken,
};
+use syntax::{format_smolstr, SmolStr};
use crate::{InlayHint, InlayHintPosition, InlayHintsConfig, InlayKind, LifetimeElisionHints};
@@ -80,7 +80,7 @@ pub(super) fn hints(
let mut gen_idx_name = {
let mut gen = (0u8..).map(|idx| match idx {
idx if idx < 10 => SmolStr::from_iter(['\'', (idx + 48) as char]),
- idx => format!("'{idx}").into(),
+ idx => format_smolstr!("'{idx}"),
});
move || gen.next().unwrap_or_default()
};
@@ -98,15 +98,13 @@ pub(super) fn hints(
};
{
let mut potential_lt_refs = potential_lt_refs.iter().filter(|&&(.., is_elided)| is_elided);
- if let Some(_) = &self_param {
- if let Some(_) = potential_lt_refs.next() {
- allocated_lifetimes.push(if config.param_names_for_lifetime_elision_hints {
- // self can't be used as a lifetime, so no need to check for collisions
- "'self".into()
- } else {
- gen_idx_name()
- });
- }
+ if self_param.is_some() && potential_lt_refs.next().is_some() {
+ allocated_lifetimes.push(if config.param_names_for_lifetime_elision_hints {
+ // self can't be used as a lifetime, so no need to check for collisions
+ "'self".into()
+ } else {
+ gen_idx_name()
+ });
}
potential_lt_refs.for_each(|(name, ..)| {
let name = match name {
@@ -130,11 +128,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,