rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.26k stars 1.61k forks source link

Incorrect elided lifetime shown #18094

Open theemathas opened 1 month ago

theemathas commented 1 month ago

rust-analyzer version: 0.3.2104-standalone (08c7bbc2d 2024-09-06)

rustc version: rustc 1.81.0 (eeb90cda1 2024-09-04)

editor or extension: VsCode, with rust-analyzer extension version v0.3.2104

relevant settings:

{
    "rust-analyzer.inlayHints.genericParameterHints.lifetime.enable": true,
    "rust-analyzer.inlayHints.lifetimeElisionHints.enable": "always",
}

code snippet to reproduce:

pub struct FooRef<'a>(pub &'a i32);

pub struct Foo(i32);

impl Foo {
    pub fn foo_as_ref(&self) -> FooRef<'_> {
        FooRef(&self.0)
    }
}
image

The elided lifetime for self and for FooRef should be shown as the same lifetime in the inlay hint. However, they're shown as different lifetimes.

Discovered by tionway on the rust community discord.

Veykril commented 1 month ago

That hint in FooRef is not an elided lifetime hint, its a generic parameter hint, rendering the name of the generic parameter that the arg is supplied for. 1) We don't have elision hints for path type generic args yet, 2) we wouldn't render them either way when there is a lifetime specified (as is the case with '_ here)

tionway commented 1 month ago

That hint in FooRef is not an elided lifetime hint, its a generic parameter hint, rendering the name of the generic parameter that the arg is supplied for. 1) We don't have elision hints for path type generic args yet, 2) we wouldn't render them either way when there is a lifetime specified (as is the case with '_ here)

is there a way to show the elided lifetime for path type generic like ordinary function with reference? Like the screenshot shows here

截屏2024-09-11 21 56 54