Skip to content

fix: offer on path_type for add_lifetime_to_type#22332

Open
A4-Tacks wants to merge 2 commits into
rust-lang:masterfrom
A4-Tacks:add-lifetime-path-type
Open

fix: offer on path_type for add_lifetime_to_type#22332
A4-Tacks wants to merge 2 commits into
rust-lang:masterfrom
A4-Tacks:add-lifetime-path-type

Conversation

@A4-Tacks
Copy link
Copy Markdown
Member

Example

struct Foo {
    a: &'_ i32,
    b: Foo<'_$0>,
}

Before this PR

Assist not applicable

After this PR

struct Foo<'a> {
    a: &'a i32,
    b: Foo<'a>,
}

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

fn trigger_assist(ctx: &AssistContext<'_, '_>) -> bool {
ctx.find_node_at_offset::<ast::RefType>()
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 May 15, 2026

Choose a reason for hiding this comment

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

I think it's better to check either for ast::Lifetime or for a without-lifetime ast::RefType. Technically it will be nice if the assist will also trigger for missing lifetime params in ADTs, but I think this is better done by having a diagnostic for this with a quickfix (that can supersede this assist).

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it's better to check either for ast::Lifetime or for a without-lifetime ast::RefType.

The text range of '_ is too small, which may not be conducive to user use

but I think this is better done by having a diagnostic for this with a quickfix (that can supersede this assist).

After the diagnostics stabilize, consider migration

Technically it will be nice if the assist will also trigger for missing lifetime params in ADTs

Good idea

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.

The text range of '_ is too small, which may not be conducive to user use

IMO it's confusing if we offer this on unrelated parts of the path.

@A4-Tacks
Copy link
Copy Markdown
Member Author

A4-Tacks commented May 15, 2026

This assist always needs to be applied or not triggered because it is unlikely to have a false positive

Perhaps it's a good idea for the entire Adt application, what do you think?

@ChayimFriedman2
Copy link
Copy Markdown
Contributor

This assist always needs to be applied or not triggered because it is unlikely to have a false positive

What do you mean?

@A4-Tacks
Copy link
Copy Markdown
Member Author

For an Adt in development, exists a missing lifetime argument:

  • When exists a lifetime parameter: assist not applicable
  • When non-exists a lifetime parameter: you always need to add lifetime parameters and arguments
    • uses this assist: At most, it's just an additional renaming
    • not uses this assist:
      • add a lifetime parameter: assist not applicable because exists a lifetime parameter
      • add a lifetime arguments: assist not applicable because not-exists missing lifetime

@A4-Tacks
Copy link
Copy Markdown
Member Author

Anyway, let's implement it this way first. I have placed an XXX comment

Example
---
```rust
struct Foo {
    a: &'_ i32,
    b: Foo<'_$0>,
}
```

**Before this PR**

Assist not applicable

**After this PR**

```rust
struct Foo<'a> {
    a: &'a i32,
    b: Foo<'a>,
}
```
@A4-Tacks A4-Tacks force-pushed the add-lifetime-path-type branch from 850c4ef to 9331224 Compare May 15, 2026 04:57
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 15, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@A4-Tacks A4-Tacks force-pushed the add-lifetime-path-type branch from 9331224 to dae20ce Compare May 15, 2026 05:16
@A4-Tacks A4-Tacks requested a review from ChayimFriedman2 May 15, 2026 05:24
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.

3 participants