Stream: t-compiler/rust-analyzer

Topic: PR rust-analyzer#5993


Charles Lew (Sep 16 2020 at 03:53, on Zulip):

I'm seeking for some mentoring on rust-analyzer#5993 . I think there's something i need to do on lowering, but i'm not entirely sure.

Jonas Schievink [he/him] (Sep 16 2020 at 09:31, on Zulip):

I think you need to modify type_for_type_alias in hir_ty/src/lower.rs to check is_extern

Jonas Schievink [he/him] (Sep 16 2020 at 09:32, on Zulip):

Because right now that will just give you a TypeRef::Error when the = ExistingType part of the alias is missing

Charles Lew (Sep 16 2020 at 12:57, on Zulip):

Thanks for instruction! Updated.

Jonas Schievink [he/him] (Sep 16 2020 at 13:05, on Zulip):

Is it working now? Then the next step would be to add some inference tests, I think.

Charles Lew (Sep 16 2020 at 16:25, on Zulip):

It's not fully working, but definitely works better than without this PR. I've added a test.

Charles Lew (Sep 16 2020 at 16:25, on Zulip):
#[test]
fn method_resolution_foreign_opaque_type() {
    check_infer(
        r#"
        extern "C" {
            type S;
            fn f() -> &'static S;
        }
        impl S {
            fn foo(&self) -> bool {
                true
            }
        }
        fn test() {
            let s = unsafe { f() };
            s.foo();
        }
        "#,
        // FIXME: 's.foo()' should be `bool`.
        expect![[r#"
            75..79 'self': &S
            89..109 '{     ...     }': bool
            99..103 'true': bool
            123..167 '{     ...o(); }': ()
            133..134 's': &S
            137..151 'unsafe { f() }': &S
            144..151 '{ f() }': &S
            146..147 'f': fn f() -> &S
            146..149 'f()': &S
            157..158 's': &S
            157..164 's.foo()': {unknown}
        "#]],
    );
}
Charles Lew (Sep 16 2020 at 16:25, on Zulip):

There's still one {unknown}.

Charles Lew (Sep 16 2020 at 16:27, on Zulip):

without this PR everything is {unknown}:

75..79 'self': &{unknown}
89..109 '{     ...     }': bool
99..103 'true': bool
123..167 '{     ...o(); }': ()
133..134 's': &{unknown}
137..151 'unsafe { f() }': &{unknown}
144..151 '{ f() }': &{unknown}
146..147 'f': fn f() -> &{unknown}
146..149 'f()': &{unknown}
157..158 's': &{unknown}
157..164 's.foo()': {unknown}
Charles Lew (Sep 16 2020 at 16:51, on Zulip):

Found the problem with method resolution, fixed it~

Jonas Schievink [he/him] (Sep 16 2020 at 17:23, on Zulip):

Great!

Last update: Jul 24 2021 at 19:45UTC