Skip to content

feat: allow renaming of elided lifetimes (Fixes #19260)#22178

Open
Amit5601 wants to merge 1 commit intorust-lang:masterfrom
Amit5601:feat-rename-anonymous-lifetime
Open

feat: allow renaming of elided lifetimes (Fixes #19260)#22178
Amit5601 wants to merge 1 commit intorust-lang:masterfrom
Amit5601:feat-rename-anonymous-lifetime

Conversation

@Amit5601
Copy link
Copy Markdown
Contributor

@Amit5601 Amit5601 commented Apr 25, 2026

Fixes #19260.
Bypasses the standard definition search to allow renaming elided lifetimes ('_'), automatically uneliding and injecting the newly named lifetime into the parent's generic parameters.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 25, 2026
@rustbot

This comment has been minimized.

@Amit5601 Amit5601 marked this pull request as draft April 25, 2026 05:04
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 25, 2026
@Amit5601 Amit5601 force-pushed the feat-rename-anonymous-lifetime branch from 11cb2e2 to a1e47dc Compare April 25, 2026 05:28
@Amit5601 Amit5601 marked this pull request as ready for review April 25, 2026 05:35
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 25, 2026
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test.

View changes since this review

Comment thread crates/ide/src/rename.rs
}

#[test]
fn rename_constructor_locals() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo the removal of this test.

Comment thread crates/ide/src/rename.rs
lifetime_token: syntax::SyntaxToken,
new_name: &str,
) -> RenameResult<SourceChange> {
use syntax::ast::{self, AstNode, HasGenericParams, HasName};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go at the top.

Comment thread crates/ide/src/rename.rs
edit.replace(lifetime_token.text_range(), new_name.to_owned());

let parent = lifetime_token.parent().unwrap();
if let Some(fn_def) = parent.ancestors().find_map(ast::Fn::cast) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if let Some(fn_def) = parent.ancestors().find_map(ast::Fn::cast) {
if let Some(fn_def) = lifetime_token.parent_ancestors().find_map(ast::Fn::cast) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole thing is also better done with SyntaxEditor and add_generic_param().

Comment thread crates/ide/src/rename.rs
} else if let Some(name) = fn_def.name() {
edit.insert(name.syntax().text_range().end(), format!("<{}>", new_name));
}
} else if let Some(impl_def) = parent.ancestors().find_map(ast::Impl::cast) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use AnyHasGenericParams instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Renaming '_ should unelide the lifetime

3 participants