Skip to content

Inlay hints cannot determine contained types for Self vs StructName #12968

@RuijieYu

Description

@RuijieYu

I am having an issue that the inlay hints cannot determine the types when destructuring a tuple-struct as &self while refering the type as Self. Destructuring with its type name has no problems. See the following code snippet. Please let me know if further information is needed.

#![allow(dead_code, unused_variables)]

use std::collections::HashSet;

struct Foo(Vec<()>, HashSet<()>);
impl Foo {
    fn validate(&self) {
        // let Foo(vec: &Vec<()>, set: &HashSet<()>) = self;
        let Foo(vec, set) = self;

        // let Self(vec: &{unknown}, set: &{unknown}) = self;
        let Self(vec, set) = self;

        // when I try to auto-complete here after "vec.", I still get methods
        // for IntoIterator, ExactSizeIterator, etc.
    }

    fn consume_foo(self) {
        // let Foo(vec: Vec<()>, set: HashSet<()>) = self;
        let Foo(vec, set) = self;
    }

    fn consume_self(self) {
        /* note that there is no inlay hints here, but hovering over "vec" and
         * "set" shows both are of type "{unknown}". */
        // let Self(vec, set) = self;
        let Self(vec, set) = self;
    }

    fn bar(this: &Self) {
        // let Foo(vec: &Vec<()>, set: &HashSet<()>) = this;
        let Foo(vec, set) = this;

        // let Self(vec: &{unknown}, set: &{unknown}) = this;
        let Self(vec, set) = this;
    }

    fn change(&mut self) {
        // let Foo(vec: &mut Vec<()>, set: &mut HashSet<()>) = self;
        let Foo(vec, set) = self;

        // let Self(vec: &mut {unknown}, set: &mut {unknown}) = self;
        let Self(vec, set) = self;
    }
}

The code compiles successfully -- only the inlay hints are lacking in this set of scenarios. As mentioned in the snippet, when I try to auto-complete on vec., I still get the methods that are supposed to match Vec<T>.


rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)

$ rust-analyzer --version
rust-analyzer 20220523

rustc version: (eg. output of rustc -V)

$ rustc -V
rustc 1.62.1 (e092d0b6b 2022-07-16)

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTUP_HOME or CARGO_HOME)

  • None that I can think of. I do have some settings in ~/.cargo/config for setting a shared target dir and controlling compilation options, but nothing else.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tytype system / type inference / traits / method resolutionC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions