Skip to content

Conversation

A4-Tacks
Copy link
Contributor

@A4-Tacks A4-Tacks commented Jul 23, 2025

And add &self lifetime support

Fixes #17366

Example

struct Foo<T>(T);
impl Foo<i32> {
    fn foo(&'static self$0) {}
}

Old:

struct Foo<T>(T);
impl Foo<i32> {
    fn foo(this: &Foo) {}
}

Fixes:

struct Foo<T>(T);
impl Foo<i32> {
    fn foo(this: &'static Self) {}
}

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 23, 2025
And add `&self` lifetime support

Example
===

Rename to `this`

```rust
struct Foo<T>(T);
impl Foo<i32> {
    fn foo(&'static self$0) {}
}
```

Old:

```rust
struct Foo<T>(T);
impl Foo<i32> {
    fn foo(this: &Foo) {}
}
```

Fixes:

```rust
struct Foo<T>(T);
impl Foo<i32> {
    fn foo(this: &'static Self) {}
}
```
Copy link
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.

Seems reasonable to me, just one request.

replacement_text.push_str(": _");
Some(TextEdit::replace(self_param.syntax().text_range(), replacement_text))
}
if self_param.syntax().ancestors().find_map(ast::Impl::cast).is_some() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should also include ast::Trait (although this wasn't in the original code). Also this check will be incorrect in case of a nested function inside impl, but I guess it's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What does "include ast::Trait" mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant methods in traits should also use Self, but I see you changed it to always use Self, that's also good.

@A4-Tacks A4-Tacks requested a review from ChayimFriedman2 July 23, 2025 14:21
Copy link
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.

Thanks!

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Jul 23, 2025
Merged via the queue into rust-lang:master with commit 1bf93c3 Jul 23, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 23, 2025
@A4-Tacks A4-Tacks deleted the fix-rename-self branch July 23, 2025 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename self param will no generic params
3 participants