Skip to content

feat: implement a simple hover auto traits in rpit - #23240

Open
A4-Tacks wants to merge 3 commits into
rust-lang:masterfrom
A4-Tacks:hover-rpit-auto-traits
Open

feat: implement a simple hover auto traits in rpit#23240
A4-Tacks wants to merge 3 commits into
rust-lang:masterfrom
A4-Tacks:hover-rpit-auto-traits

Conversation

@A4-Tacks

@A4-Tacks A4-Tacks commented Aug 26, 2026

Copy link
Copy Markdown
Member

Partial implement of #23237

Example

//- minicore: send, unpin
fn foo() -> $0impl Trait {
    &raw const ()
}

->

impl Trait + Unpin
impl Trait = *const ()

impl

keyword docs

Example
---
```rust
//- minicore: send, unpin
fn foo() -> $0impl Trait {
    &raw const ()
}
```

->

> ```rust
> impl Trait + Unpin
> impl Trait = *const ()
> ```
>
> ---
>
> ```rust
> impl
> ```
>
> ---
>
> keyword docs
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 26, 2026
if traits.is_empty() { None } else { Some(traits.into_iter().collect()) }
}

#[salsa::tracked(returns(as_deref))]

@ChayimFriedman2 ChayimFriedman2 Aug 26, 2026

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.

Should IMO be the same query with crate_notable_traits(). Also both should check the presence of the unsafe feature like we do for crate_lang_items().

View changes since the review

Some(HoverResult { markup, actions })
}

pub(super) fn rpit(

@ChayimFriedman2 ChayimFriedman2 Aug 26, 2026

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.

IMO this is the wrong way to fix. We should instead do that in display infra, for every printed opaque.

Granted, it'll need more work because we don't currently carry the Option<GenericDefId> required for trait solving (to get trait_environment()) in display.

View changes since the review

@A4-Tacks A4-Tacks Aug 28, 2026

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.

IMO this is the wrong way to fix. We should instead do that in display infra, for every printed opaque.

I think these are two different features, regarding RPIT and any expressions

fn foo() -> Cell<impl Trait> { Cell::new(2) }
               //^^^^ impl Trait + Send + Sync + ...
               //     impl Trait = i32
fn foo() -> Cell<impl Trait> { Cell::new(2) }
                             //^^^^^^^^^^^^ Cell<i32>
                             //             implement auto traits: Send + ...
fn foo() -> Cell<impl Trait> { Cell::new(2) }
                                       //^ i32
                                       //  implement auto traits: Send + Sync + ...

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.

No. I'm not saying to add a clause "implements auto traits" similar to "implements notable traits", only to add this information when displaying opaques.

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 this is a feature that is bound to the function return, and the opaque semantics in other places are different, such as in the impl Trait of the function parameter

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 is a feature that is relevant to any opqaue - RPIT, ATPIT, ....

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.

Hmmm…, On the other hand, the current implementation is simple and very practical (in the stable version)

@Veykril

Veykril commented Aug 29, 2026

Copy link
Copy Markdown
Member

I feel like we should also generally render these for function hovers? Given auto trait leakage is here to stay showing them in all relevant places where we render the rpit feels appropriate, or at least for Send and Sync (more unconditionally is probably too much)

@A4-Tacks

Copy link
Copy Markdown
Member Author

I feel like we should also generally render these for function hovers?

I hope it's an expression. The last time the functions displayed 'notable traits', it caused me a lot of pain

Given auto trait leakage is here to stay showing them in all relevant places where we render the rpit feels appropriate

These places should render 'auto traits' instead of 'rpit'

For expressions, they should be simple, but for types (especially generics), I don't think we're ready yet

[2].iter();
         Iter<'_, i32>
         ─────────────────────────────────────────────────
         Implements notable traits: Iterator<Item = &i32>
         ─────────────────────────────────────────────────
         Implements auto traits:    Send + Sync + Unpin +
         RefUnwindSafe + UnwindSafe + Freeze + UnsafeUnpin

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

I argue we should only show Send and Sync. The rest auto traits are just not interesting (Send and Sync could also be not interesting, but at least they sometimes are).

@A4-Tacks

Copy link
Copy Markdown
Member Author

I think we should show all, but we can do some heuristic sorting or hard coding to put more useful results at the forefront

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

What other auto traits you consider interesting?

  • Freeze and UnsafeUnpin are unstable implementation details.
  • UnwindSafe and RefUnwindSafe might only be interesting when calling catch_unwind(), and easy to fix by adding AssertUnwindSafe.
  • Unpin, maybe.

@A4-Tacks

Copy link
Copy Markdown
Member Author

I sometimes notice Freeze, but the main reason is that I believe this feature should not hide the output, or at least use a blacklist instead of a whitelist

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

Given auto traits are perma-unstable feature, I absolutely think this should be a whitelist.

@A4-Tacks

Copy link
Copy Markdown
Member Author

Considering unstable rust users, won't they feel confused about r-a when using unstable features?

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

Auto traits are perma-unstable. They will not be stabilized. If someone is using them, that's on them.

@A4-Tacks

Copy link
Copy Markdown
Member Author

Maybe, when someone complains, consider whether to improve or not

  • Freeze and UnsafeUnpin are unstable implementation details.

Although Freeze is unstable, it is a useful reference for me when using some libraries

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.

4 participants