use rustc_hash::FxHashSet;
use syntax::{
- ast::{self, edit_in_place::GenericParamsOwnerEdit, make, GenericParamsOwner},
+ ast::{self, edit_in_place::GenericParamsOwnerEdit, make, HasGenericParams},
ted::{self, Position},
AstNode, TextRange,
};
// }
// }
// ```
-// FIXME: How can we handle renaming any one of multiple anonymous lifetimes?
-// FIXME: should also add support for the case fun(f: &Foo) -> &$0Foo
pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
+ // FIXME: How can we handle renaming any one of multiple anonymous lifetimes?
+ // FIXME: should also add support for the case fun(f: &Foo) -> &$0Foo
let lifetime =
ctx.find_node_at_offset::<ast::Lifetime>().filter(|lifetime| lifetime.text() == "'_")?;
let lifetime_loc = lifetime.lifetime_ident_token()?.text_range();
})
.collect();
match fn_params_without_lifetime.len() {
- 1 => Some(fn_params_without_lifetime.into_iter().nth(0)?),
+ 1 => Some(fn_params_without_lifetime.into_iter().next()?),
0 => None,
// multiple unnnamed is invalid. assist is not applicable
_ => return None,
}
};
acc.add(AssistId(ASSIST_NAME, AssistKind::Refactor), ASSIST_LABEL, lifetime_loc, |builder| {
- let fn_def = builder.make_ast_mut(fn_def);
- let lifetime = builder.make_ast_mut(lifetime);
+ let fn_def = builder.make_mut(fn_def);
+ let lifetime = builder.make_mut(lifetime);
let loc_needing_lifetime =
loc_needing_lifetime.and_then(|it| it.make_mut(builder).to_position());
make::lifetime_param(new_lifetime_param.clone()).clone_for_update().into(),
);
ted::replace(lifetime.syntax(), new_lifetime_param.clone_for_update().syntax());
- loc_needing_lifetime
- .map(|position| ted::insert(position, new_lifetime_param.clone_for_update().syntax()));
+ if let Some(position) = loc_needing_lifetime {
+ ted::insert(position, new_lifetime_param.clone_for_update().syntax());
+ }
})
}
) -> Option<()> {
let new_lifetime_param = generate_unique_lifetime_param_name(impl_def.generic_param_list())?;
acc.add(AssistId(ASSIST_NAME, AssistKind::Refactor), ASSIST_LABEL, lifetime_loc, |builder| {
- let impl_def = builder.make_ast_mut(impl_def);
- let lifetime = builder.make_ast_mut(lifetime);
+ let impl_def = builder.make_mut(impl_def);
+ let lifetime = builder.make_mut(lifetime);
impl_def.get_or_create_generic_param_list().add_generic_param(
make::lifetime_param(new_lifetime_param.clone()).clone_for_update().into(),
impl NeedsLifetime {
fn make_mut(self, builder: &mut AssistBuilder) -> Self {
match self {
- Self::SelfParam(it) => Self::SelfParam(builder.make_ast_mut(it)),
- Self::RefType(it) => Self::RefType(builder.make_ast_mut(it)),
+ Self::SelfParam(it) => Self::SelfParam(builder.make_mut(it)),
+ Self::RefType(it) => Self::RefType(builder.make_mut(it)),
}
}