Skip to content

Go to definition (but skip generic intermediaries) #15315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
not-my-profile opened this issue Jul 20, 2023 · 3 comments · Fixed by #18934
Closed

Go to definition (but skip generic intermediaries) #15315

not-my-profile opened this issue Jul 20, 2023 · 3 comments · Fixed by #18934
Labels
A-ide general IDE features C-feature Category: feature request

Comments

@not-my-profile
Copy link

not-my-profile commented Jul 20, 2023

Take the following code as an example:

struct A;
struct B;

impl From<B> for A {
    fn from(value: B) -> Self {
        Self
    }
}

fn main() {
    let a: A = B.into();
}

If you go to definition on .into() you probably want to get to the implementation of the From trait but rust-analyzer will just take you to the following blanket implementation of the standard library:

impl<T, U> const Into<U> for T
where
    U: ~const From<T>,
{
    /// Calls `U::from(self)`.
    ///
    /// That is, this conversion is whatever the implementation of
    /// <code>[From]&lt;T&gt; for U</code> chooses to do.
    #[inline]
    fn into(self) -> U {
        U::from(self)
    }
}

which is technically correct ... but not very helpful when you're trying to get to the definition of the actual conversion code. Especially in large code bases it can be hard to manually find where a trait is implemented.

So it would be great if rust-analyzer could offer an alternative "Go to definition (but skip generic intermediaries)" option.

(This would of course not just apply to Into but to TryInto and str::parse as well.)

@not-my-profile not-my-profile added the C-feature Category: feature request label Jul 20, 2023
@not-my-profile not-my-profile changed the title Go to definition (but skip blanket implementations) Go to definition (but skip generic intermediaries) Jul 20, 2023
@Veykril Veykril added the A-ide general IDE features label Jul 30, 2023
@Veykril
Copy link
Member

Veykril commented Jul 30, 2023

Ye this would be really nice to have, the main question is the UX. It feels like we'd want something akin to a call hierarchy but for implementations that we can walk (iirc this isn't currently possible with chalk, but it might with the next trait solver if my memory serves right)

@flodiebold
Copy link
Member

Related: "Monomorphized" go to definition where we remember the type arguments; I mentioned this in #7890 but I think we still don't have a separate issue for it. I don't think this is limited by Chalk; we know the type arguments and just have to substitute them in.

@Veykril
Copy link
Member

Veykril commented Aug 1, 2023

Ah, that was it. I thought we had an issue for that and went looking but didn't find anything either. Ye that seems doable then, the only problem to solve is how to keep the temporary knowledge about the type arguments for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ide general IDE features C-feature Category: feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants