Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

gstreamer fails to build with RLS #1390

Closed
elomatreb opened this issue Mar 5, 2019 · 8 comments · Fixed by rust-lang/rust#59894
Closed

gstreamer fails to build with RLS #1390

elomatreb opened this issue Mar 5, 2019 · 8 comments · Fixed by rust-lang/rust#59894
Labels

Comments

@elomatreb
Copy link

Hi. I'm having a problem with the gstreamer crate. Adding it to my dependencies causes the RLS to emit build errors, while the regular cargo build from the command line works fine.

This happens even without any code of mine (simple demo).

The error in the Visual Studio Code console (formatted):

{
    "message": "cannot extract an associated type from a higher-ranked trait bound in this context",
    "code": {
        "code": "E0212",
        "explanation": null
    },
    "level": "error",
    "spans": [
        {
            "file_name": "/home/elomatreb/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/gstreamer-0.13.0/src/tags.rs",
            "byte_start": 20318,
            "byte_end": 20341,
            "line_start": 830,
            "line_end": 830,
            "column_start": 13,
            "column_end": 36,
            "is_primary": true,
            "text": [
                {
                    "text": "            T::TagType::static_type().to_glib(),",
                    "highlight_start": 13,
                    "highlight_end": 36
                }
            ],
            "label": null,
            "suggested_replacement": null,
            "suggestion_applicability": null,
            "expansion": null
        }
    ],
    "children": [],
    "rendered": "error[E0212]: cannot extract an associated type from a higher-ranked trait bound in this context\n   --> /home/elomatreb/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/gstreamer-0.13.0/src/tags.rs:830:13\n    |\n830 |             T::TagType::static_type().to_glib(),\n    |             ^^^^^^^^^^^^^^^^^^^^^^^\n\n"
}
{
    "message": "aborting due to previous error",
    "code": null,
    "level": "error",
    "spans": [],
    "children": [],
    "rendered": "error: aborting due to previous error\n\n"
}
{
    "message": "For more information about this error, try `rustc --explain E0212`.",
    "code": null,
    "level": "",
    "spans": [],
    "children": [],
    "rendered": "For more information about this error, try `rustc --explain E0212`.\n"
}

This is the line the error reports, but the level of Rust I feel like is necessary to understand the error is a little beyond me.

I'm sorry if this is a user error, I'm still fairly new to Rust in general.

@jshrake
Copy link

jshrake commented Mar 10, 2019

I can reproduce the same issue from the command-line RUST_LOG=rls=debug rls --cli with both the stable-x86_64-pc-windows-gnu and nightly-x86_64-pc-windows-gnu toolchains. I'm building against gstreamer="0.13.0".

$ rustup show
Default host: x86_64-pc-windows-msvc

installed toolchains
--------------------

stable-x86_64-pc-windows-gnu (default)
nightly-x86_64-pc-windows-gnu

active toolchain
----------------

stable-x86_64-pc-windows-gnu (default)
rustc 1.33.0 (2aa4c46cf 2019-02-28)

@Xanewok Xanewok added the bug label Mar 10, 2019
@jshrake
Copy link

jshrake commented Mar 10, 2019

@Xanewok
Copy link
Member

Xanewok commented Mar 13, 2019

I can confirm the error with:

$ rustc --version
rustc 1.35.0-nightly (7c19e1eed 2019-03-12)
$ rls --version
rls 1.34.0 (6840dd6 2019-03-10)

Interestingly enough, the RLS rustc shim seems to be at fault here somehow (:man_shrugging: )

RLS_RUSTC_SHIM=1 /home/xanewok/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rls --crate-name gstreamer /home/xanewok/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/gstreamer-0.13.0/src/lib.rs --color never --crate-type lib --emit=dep-info,metadata -C debuginfo=2 --cfg 'feature="default"' -C metadata=9bbfe699423328b2 -C extra-filename=-9bbfe699423328b2 --out-dir /home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps -L dependency=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps --extern bitflags=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/libbitflags-11d0722d0adf4c3c.rmeta --extern cfg_if=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/libcfg_if-e9ff40315488b035.rmeta --extern glib=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/libglib-68c2bf5d05cf3859.rmeta --extern glib_sys=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/libglib_sys-997ed6c170759744.rmeta --extern gobject_sys=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/libgobject_sys-9236f8dfc67a5fb8.rmeta --extern gstreamer_sys=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/libgstreamer_sys-67fc9f3d8e2f03e4.rmeta --extern lazy_static=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/liblazy_static-6d811268429bebf1.rmeta --extern libc=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/liblibc-950ceab466e2e16c.rmeta --extern muldiv=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/libmuldiv-b4a30e4439349381.rmeta --extern num_rational=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/libnum_rational-2a4d6475597a98b0.rmeta --cap-lints allow --error-format=json --sysroot /home/xanewok/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu

exits with the aforementioned message and exit code 130, meanwhile regular rustc call: (only executable and RLS_RUSTC_SHIM=1 changed)

/home/xanewok/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name gstreamer /home/xanewok/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/gstreamer-0.13.0/src/lib.rs --color never --crate-type lib --emit=dep-info,metadata -C debuginfo=2 --cfg 'feature="default"' -C metadata=9bbfe699423328b2 -C extra-filename=-9bbfe699423328b2 --out-dir /home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps -L dependency=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps --extern bitflags=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/libbitflags-11d0722d0adf4c3c.rmeta --extern cfg_if=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/libcfg_if-e9ff40315488b035.rmeta --extern glib=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/libglib-68c2bf5d05cf3859.rmeta --extern glib_sys=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/libglib_sys-997ed6c170759744.rmeta --extern gobject_sys=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/libgobject_sys-9236f8dfc67a5fb8.rmeta --extern gstreamer_sys=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/libgstreamer_sys-67fc9f3d8e2f03e4.rmeta --extern lazy_static=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/liblazy_static-6d811268429bebf1.rmeta --extern libc=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/liblibc-950ceab466e2e16c.rmeta --extern muldiv=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/libmuldiv-b4a30e4439349381.rmeta --extern num_rational=/home/xanewok/repos/rls-gstreamer-error-demo/target/rls/debug/deps/libnum_rational-2a4d6475597a98b0.rmeta --cap-lints allow --error-format=json --sysroot /home/xanewok/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu

succeeds.

I'll poke around and see if I can fix this

@compiaffe
Copy link

compiaffe commented Apr 2, 2019

Same issue here with

$ rls --version
rls-preview 1.33.0 (9f3c906 2019-01-20)
$ rustc --version
rustc 1.33.0 (2aa4c46cf 2019-02-28)

@Xanewok did you find out anything?

I've created a matching bug report over at the gstreamer-rs repo: https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/194

@Thinkofname
Copy link

I'm having the same error with one of my own crates. Reduced the code down to an small test case.

trait Test<'a> {
    type Thing: Test2;
}

trait Test2 {
    fn print();
}

#[allow(unused)]
fn example<T>(t: T)
    where T: for<'a> Test<'a>
{
    T::Thing::print();
}

@Xanewok
Copy link
Member

Xanewok commented Apr 11, 2019

Sorry it took so long, managed to come back to this issue today. Hopefully I found the culprit; the issue seems to be in the save-analysis lib in the Rust compiler. Things seem to work as expected with the fix applied, so - fingers crossed 🤞

Centril added a commit to Centril/rust that referenced this issue Apr 12, 2019
save-analysis: Pull associated type definition using `qpath_def`

Closes rust-lang/rls#1390

This (probably?) fixes the case where we run the save-analysis code on the following snippet:
```rust
trait Test<'a> {
    type Thing: Test2;
}

trait Test2 {
    fn print();
}

#[allow(unused)]
fn example<T>(t: T)
    where T: for<'a> Test<'a>
{
    T::Thing::print(); //~ ERROR cannot extract an associated type from a higher-ranked trait bound in this context
    // ^ only errors in save-analysis mode
}
```

The chain is as follows:
- culprit is `hir_ty_to_ty`
- which calls `ast_ty_to_ty` in the `ItemCtxt`
- which calls `associated_path_to_ty`
- which finally fails on `projected_ty_from_poly_trait_ref`
https://github.com/rust-lang/rust/blob/3de0106789468b211bcc3a25c09c0cf07119186d/src/librustc_typeck/collect.rs#L212-L224

I'm not exactly sure why `hir_ty_to_ty` fails - is it because it needs more setup from typeck to work correctly? I'm guessing the fix is okay since we just pull the already typeck'd data (we run save-analysis after all the analysis passes are complete) from the tables.

With this change we can 'go to def' on all segments in the `T::Thing::print()` path.
@BrainBlasted
Copy link

Is there a chance of this being backported to 1.34, in e.g. 1.34.1?

@compiaffe
Copy link

@Xanewok Any idea when this will hit stable?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants