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

Unresolved import for platform specific modules #6038

Closed
GrayJack opened this issue Sep 19, 2020 · 50 comments · Fixed by rust-lang/rust#81969
Closed

Unresolved import for platform specific modules #6038

GrayJack opened this issue Sep 19, 2020 · 50 comments · Fixed by rust-lang/rust#81969
Labels
E-hard S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@GrayJack
Copy link
Contributor

I tried to search if it was reported but didn't found anything.

When importing the platform specific modules in std::os rust-analyzer gives me the following error:
unresolved import. Also those modules don't show up for auto-complete.

When the module is used outside use statement, there is no error, but the semantic token are of the type unresolvedReference.

RA version

Latest master branch

Example

use std::os::unix;
@jonas-schievink
Copy link
Contributor

We seem to have trouble finding/expanding the cfg_if! invocation

@jonas-schievink jonas-schievink added the A-macro macro expansion label Sep 19, 2020
@jonas-schievink
Copy link
Contributor

Oh, it's because we don't load the sysroot correctly. We just add a bunch of hard-coded path dependencies to libstd without looking at its Cargo.toml.

@jonas-schievink jonas-schievink removed the A-macro macro expansion label Sep 20, 2020
@jfcha
Copy link

jfcha commented Sep 21, 2020

I'm also seeing this issue for

use std::os::windows::ffi::{OsStrExt, OsStringExt};

in the 2020-09-21 release.

@ttzztztz
Copy link

Same issue.

@iulianR
Copy link

iulianR commented Sep 27, 2020

Hello, it's a bit spammy in VSCode (using Code Lens extension) because it looks like a hard error, making you think the code won't compile:
image
image
image

It is possible to change it somehow it so it shows in a similar way to an {unknown} error (when ra is unable to determine type for example)? I think that was the previous behaviour before the 21-09-2020 release.
Thanks!

@lnicola
Copy link
Member

lnicola commented Sep 27, 2020

@iulianR you can disable that warning in the preferences (the experimental diagnostics key).

EDIT: "rust-analyzer.diagnostics.disabled": ["unresolved-import"]

@leshow
Copy link

leshow commented Oct 4, 2020

I am running into this too, if I use the above disable though, won't that disable all unresolved import errors?

That doesn't seem to be desirable. Is there any other options? I assume it happens because rust-analyzer is set to build for all targets, and the import isn't available on some targets

@jonas-schievink
Copy link
Contributor

No, it happens because

we don't load the sysroot correctly. We just add a bunch of hard-coded path dependencies to libstd without looking at its Cargo.toml.

You can only disable the unresolved import diagnostic entirely (although check-on-save will still display rustc's unresolved import messages, regardless of how r-a diagnostics are configured)

@thomcc
Copy link
Member

thomcc commented Oct 5, 2020

This is (unsurprisingly) also broken for {core,std}::arch::*. I'm certain this used to work too... :(

@flodiebold
Copy link
Member

flodiebold commented Oct 5, 2020

It "used to work" in the sense that this diagnostic didn't show up, because the diagnostic wasn't implemented yet. You can make it not show up again with the setting mentioned above; you'll still get unresolved import errors from rustc. But at least we're now aware that rust-analyzer can't actually resolve these imports.

@jonas-schievink
Copy link
Contributor

The diagnostic is already marked as experimental fwiw, so unless you opt into the experimental ones this shouldn't show up.

@thomcc
Copy link
Member

thomcc commented Oct 6, 2020

It "used to work" in the sense that this diagnostic didn't show up

I guess I'll take your word for it that it never worked, but I was pretty sure I had autocomplete for some parts of core::arch in the past. Huh.

The diagnostic is already marked as experimental fwiw, so unless you opt into the experimental ones this shouldn't show up.

Hrm, I don't remember opting into experimental diagnostics anywhere.

@jonas-schievink
Copy link
Contributor

Oh, turns out the experimental ones are on by default

@cameron-rowe
Copy link

Oh, turns out the experimental ones are on by default

Disabling that caused the error to go away for me. This works as a temporary workaround. Thanks.

@blinsay
Copy link

blinsay commented Oct 14, 2020

Is there documentation on disabling diagnostics in editors that aren't VSCode? I can't tell from this thread if rust-analyzer.diagnostics.disabled is a VSCode option or a rust-analyzer option.

Thanks for rust-analyzer, it's wonderful.

@lnicola
Copy link
Member

lnicola commented Oct 14, 2020

It's a rust-analyzer option, but configuring it is client-dependant. If you're using coc.vim, you can use the same setting, otherwise it might be called diagnostics/enabled, without the program name.

If you figure it out and have the time, we'll probably accept client-specific documentation pull requests.

@matklad matklad added E-hard S-unactionable Issue requires feedback, design decisions or is blocked on other work labels Oct 15, 2020
matklad added a commit to matklad/rust-analyzer that referenced this issue Oct 20, 2020
The proper fix I think is:

* move rust-lang/rust library crates to a separate workspace
* when packaging rust-src component, vendor sources of external deps
bors bot added a commit that referenced this issue Oct 20, 2020
6294: Add a hacky remidy for #6038 r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
@matklad
Copy link
Member

matklad commented Oct 20, 2020

#6294 papers over this issue

bnjjj pushed a commit to bnjjj/rust-analyzer that referenced this issue Oct 20, 2020
The proper fix I think is:

* move rust-lang/rust library crates to a separate workspace
* when packaging rust-src component, vendor sources of external deps
@bjorn3
Copy link
Member

bjorn3 commented Feb 7, 2021

core::arch not resolving is a different issue. This one is due to #[path = "..."] mod arch; not working when the path is not part of any directory assumed to be part of a crate in the crate graph based on the output of cargo metadata.

@thomcc
Copy link
Member

thomcc commented Feb 9, 2021

core::arch not resolving is a different issue. This one is due to #[path = "..."] mod arch; not working when the path is not part of any directory assumed to be part of a crate in the crate graph based on the output of cargo metadata.

Oh. Well. Is there a separate bug for that? How tractable is it to fix in r-a?

If it's very hard to fix in r-a I could do a patch to change stdarch itself to not use #[path] in the name of simplifying things for tooling probably, since usually the alternative there is just a slightly more complex mod/use setup.

JohnTitor added a commit to JohnTitor/rust that referenced this issue Feb 21, 2021
…imulacrum

Avoid `cfg_if` in `std::os`

rust-analyzer cannot currently load the `cfg_if` crate, which means that rust-analyzer is unable to see `std::os::{unix, windows, linux}` here. This works around that by avoiding `cfg_if`; the `#[cfg]` expressions are simple enough to reasonably write by hand.

Fixes rust-lang/rust-analyzer#6038
JohnTitor added a commit to JohnTitor/rust that referenced this issue Feb 21, 2021
…imulacrum

Avoid `cfg_if` in `std::os`

rust-analyzer cannot currently load the `cfg_if` crate, which means that rust-analyzer is unable to see `std::os::{unix, windows, linux}` here. This works around that by avoiding `cfg_if`; the `#[cfg]` expressions are simple enough to reasonably write by hand.

Fixes rust-lang/rust-analyzer#6038
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 23, 2021
…imulacrum

Avoid `cfg_if` in `std::os`

rust-analyzer cannot currently load the `cfg_if` crate, which means that rust-analyzer is unable to see `std::os::{unix, windows, linux}` here. This works around that by avoiding `cfg_if`; the `#[cfg]` expressions are simple enough to reasonably write by hand.

Fixes rust-lang/rust-analyzer#6038
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 23, 2021
…imulacrum

Avoid `cfg_if` in `std::os`

rust-analyzer cannot currently load the `cfg_if` crate, which means that rust-analyzer is unable to see `std::os::{unix, windows, linux}` here. This works around that by avoiding `cfg_if`; the `#[cfg]` expressions are simple enough to reasonably write by hand.

Fixes rust-lang/rust-analyzer#6038
@lnicola
Copy link
Member

lnicola commented Feb 24, 2021

@jonas-schievink this doesn't seem to work for me even after rust-lang/rust#81969:

image

image

@lnicola
Copy link
Member

lnicola commented Feb 24, 2021

Oh, there's plenty more in lib/rustlib/src/rust/library/std/src/sys/mod.rs

@jonas-schievink
Copy link
Contributor

Ugh, how annoying

@elinorbgr
Copy link

Has something happened? I was successfully using the "add cfg-if in your dependency tree" method, but since today it no longer works, I again get unresolved import errors in vscode for std::os::unix::*.

Version 0.2.513 of the vscode rust-analyzer extension, and rustc 1.52.0-nightly (acca81892 2021-03-13)

@nico-abram
Copy link
Contributor

I'm encountering this issue when doing use std::os::windows::ffi::OsStrExt; (With no conditional compilation attributes, it's a toy project that will only run in my machine). I don't have cfg_if in my dep tree

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 25, 2021
Move all `sys::ext` modules to `os`

This PR moves all `sys::ext` modules to `os`, centralizing the location of all `os` code and simplifying the dependencies between `os` and `sys`.

Because this also removes all uses `cfg_if!` on publicly exported items, where after rust-lang#81969 there were still a few left, this should properly work around rust-lang/rust-analyzer#6038.

`@rustbot` label: +T-libs-impl
bors added a commit to rust-lang-ci/rust that referenced this issue May 5, 2021
Move all `sys::ext` modules to `os`

This PR moves all `sys::ext` modules to `os`, centralizing the location of all `os` code and simplifying the dependencies between `os` and `sys`.

Because this also removes all uses `cfg_if!` on publicly exported items, where after rust-lang#81969 there were still a few left, this should properly work around rust-lang/rust-analyzer#6038.

`@rustbot` label: +T-libs-impl
@CDirkx
Copy link

CDirkx commented May 5, 2021

rust-lang/rust#84200 just got merged, which also removed more cfg_if in publicly exported items. I believe this should make everything in std::os usable, without needing to add cfg-if to your dependency tree. Can anyone confirm if this is the case?

@jonas-schievink
Copy link
Contributor

Looks like this block still causes problems with std::os::unix: https://github.com/rust-lang/rust/blob/bacf770f2983a52f31e3537db5f0fe1ef2eaa874/library/std/src/sys/mod.rs#L27-L50

However, std::os::linux seems to work fine now 🎉

flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue May 6, 2021
Move all `sys::ext` modules to `os`

This PR moves all `sys::ext` modules to `os`, centralizing the location of all `os` code and simplifying the dependencies between `os` and `sys`.

Because this also removes all uses `cfg_if!` on publicly exported items, where after #81969 there were still a few left, this should properly work around rust-lang/rust-analyzer#6038.

`@rustbot` label: +T-libs-impl
@noproto
Copy link

noproto commented Jun 18, 2021

I'm no longer seeing any errors! (latest toolchain Rust 1.53, nightly rust-analyzer) 🥳🥳🥳

@Meister1593
Copy link

Meister1593 commented Jun 20, 2021

Works for me only with git rust-analyzer (pretty much current nightly) and nightly rust 1.55 (nightly-x86_64-unknown-linux-gnu, 1.53 stable didn't work)
rustc 1.55.0-nightly (150fad30e 2021-06-19)
rust-analyzer 3843bd02a 2021-06-20 dev

@jonas-schievink
Copy link
Contributor

Cool, looks like we can close this then. The more general problem on the r-a side is tracked in #7637.

@xanderio
Copy link
Contributor

xanderio commented Aug 8, 2021

I'm still having this issue on my FreeBSD box with std::os::unix::ffi::OsStringExt.
rustc 1.54.0 (a178d0322 2021-07-26)
rust-analyzer bc084a6ee 2021-08-08 dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-hard S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

Successfully merging a pull request may close this issue.