feat: allow renaming of elided lifetimes (Fixes #19260)#22178
Open
Amit5601 wants to merge 1 commit intorust-lang:masterfrom
Open
feat: allow renaming of elided lifetimes (Fixes #19260)#22178Amit5601 wants to merge 1 commit intorust-lang:masterfrom
Amit5601 wants to merge 1 commit intorust-lang:masterfrom
Conversation
This comment has been minimized.
This comment has been minimized.
11cb2e2 to
a1e47dc
Compare
ChayimFriedman2
requested changes
Apr 26, 2026
| } | ||
|
|
||
| #[test] | ||
| fn rename_constructor_locals() { |
Contributor
There was a problem hiding this comment.
Please undo the removal of this test.
| lifetime_token: syntax::SyntaxToken, | ||
| new_name: &str, | ||
| ) -> RenameResult<SourceChange> { | ||
| use syntax::ast::{self, AstNode, HasGenericParams, HasName}; |
Contributor
There was a problem hiding this comment.
This should go at the top.
| 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) { |
Contributor
There was a problem hiding this comment.
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) { |
Contributor
There was a problem hiding this comment.
This whole thing is also better done with SyntaxEditor and add_generic_param().
| } 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) { |
Contributor
There was a problem hiding this comment.
Use AnyHasGenericParams instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.