feat: allow renaming of elided lifetimes (Fixes #19260)#22178
Merged
ChayimFriedman2 merged 1 commit intoMay 2, 2026
Conversation
This comment has been minimized.
This comment has been minimized.
Amit5601
marked this pull request as draft
April 25, 2026 05:04
Amit5601
force-pushed
the
feat-rename-anonymous-lifetime
branch
from
April 25, 2026 05:28
11cb2e2 to
a1e47dc
Compare
Amit5601
marked this pull request as ready for review
April 25, 2026 05:35
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.
Amit5601
force-pushed
the
feat-rename-anonymous-lifetime
branch
2 times, most recently
from
April 27, 2026 13:58
a1e47dc to
0e81331
Compare
Amit5601
marked this pull request as draft
April 27, 2026 14:01
Amit5601
marked this pull request as draft
April 27, 2026 14:01
Amit5601
force-pushed
the
feat-rename-anonymous-lifetime
branch
from
April 27, 2026 14:05
0e81331 to
b7ce344
Compare
Amit5601
marked this pull request as ready for review
April 27, 2026 15:09
Amit5601
force-pushed
the
feat-rename-anonymous-lifetime
branch
from
April 28, 2026 12:22
b7ce344 to
85d5540
Compare
ChayimFriedman2
requested changes
Apr 30, 2026
Amit5601
marked this pull request as draft
May 1, 2026 04:11
Amit5601
force-pushed
the
feat-rename-anonymous-lifetime
branch
from
May 1, 2026 06:15
1200046 to
7813531
Compare
Amit5601
marked this pull request as ready for review
May 1, 2026 06:22
| if is_lifetime { | ||
| if let Some(last_lt) = last_lifetime { | ||
| let elements = vec![ | ||
| ast::make::token(SyntaxKind::COMMA).into(), |
Contributor
There was a problem hiding this comment.
Please replace all the make:: in this function with self.make() (you can of course cache self.make() in a variable, called make by convention).
Amit5601
force-pushed
the
feat-rename-anonymous-lifetime
branch
from
May 1, 2026 18:23
ef4d2d2 to
03ee216
Compare
ChayimFriedman2
approved these changes
May 2, 2026
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.