Skip to content
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

Type inference not working for special associated type order. #13181

Closed
araraloren opened this issue Sep 3, 2022 · 0 comments · Fixed by #13192
Closed

Type inference not working for special associated type order. #13181

araraloren opened this issue Sep 3, 2022 · 0 comments · Fixed by #13192
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@araraloren
Copy link

araraloren commented Sep 3, 2022

Hi, the rust-analyzer display {unknown} with special associated type order.

    use std::fmt::Debug;

    pub trait Widget {}

    pub trait Windows {
        type W: Widget;
        type E: Debug;

        fn as_widget(&self) -> Result<&Self::W, Self::E>;
    }

    ///  !!! Pay attention to the order  Box<dyn Windows<E = E, W = W>> !!!
    impl<W: Widget, E: Debug> Windows for Box<dyn Windows<E = E, W = W>> {
        type W = W;
        type E = E;

        fn as_widget(&self) -> Result<&Self::W, Self::E> {
            todo!()
        }
    }

    pub struct Contain<W, WW>(Vec<WW>)
    where
        W: Widget,
        WW: Windows< W = W, E = String,>;

    impl<W, WW> Contain<W, WW>
    where
        W: Widget,
        WW: Windows< W = W, E = String,>,
    {
        pub fn new() -> Self {
            Self(vec![])
        }

        pub fn get_value(&self) -> bool {
            todo!()
        }
    }

    pub struct Dialog;

    impl Widget for Dialog {}

    let c = Contain::<Dialog, Box<dyn Windows<W = Dialog, E = String>>>::new();

    c.get_value(); /* display unknown */

When you enter point after c, it not display the get_value method in autocomplete list.

And point on the get_value , the RA display {unknown}.

If I changed the order of associated type order to

    impl<W: Widget, E: Debug> Windows for Box<dyn Windows<W = W, E = E>> {
        type W = W;
        type E = E;

        fn as_widget(&self) -> Result<&Self::W, Self::E> {
            todo!()
        }
    }

all the RA feature mentioned above working correctly.

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

rust-analyzer version: 0.3.1186-standalone (e8e598f 2022-08-28)

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

rustc 1.63.0 (4b91a6ea7 2022-08-08)

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

None

@Veykril Veykril added A-ty type system / type inference / traits / method resolution C-bug Category: bug labels Sep 3, 2022
@bors bors closed this as completed in 6dfd8ae Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants