Stream: t-compiler/wg-rls-2.0

Topic: rust-project.json and the core and alloc crates


Paul Faria (Jul 28 2020 at 01:18, on Zulip):

Hi @matklad , I'm looking into adding better support for the core and alloc traits when analyzing a project that uses rust-project.json. core is especially tricky because its extern crate core; statement is added by #![no_std].

We can solve this outside of RA by just including core and alloc as automatic dependencies in all roots, even if unused. Though it is adding unnecessary dependencies for the vast majority of crates.

I was wondering if it would make sense to have them specialized in rust-project.json since they're not included in the list of externs passed to rustc. Either through some kind of flag or matching by name.

matklad (Jul 28 2020 at 06:50, on Zulip):

So, it’s not „them“, it’s „sysrroot crate don‘t have to be explicitly specified on he command line“. rust-analyzer deliberately lacks the concept of sysroot and requires every dependency to be explicit. So, just adding them to all te crates is how this should work

Paul Faria (Jul 28 2020 at 14:00, on Zulip):

Ok, and I assume that means there's no harm in leaving in, for example, std in a no_std context. Is that a safe assumption to make?

matklad (Jul 28 2020 at 14:02, on Zulip):

Yup, that is a safe assumption

Paul Faria (Jul 28 2020 at 14:14, on Zulip):

Thanks!

Florian Diebold (Jul 28 2020 at 14:33, on Zulip):

hmm, couldn't it influence import path generation?

matklad (Jul 28 2020 at 14:35, on Zulip):

I think you can extern crate std in an otherwise ![no_std] crate?
`

bjorn3 (Jul 28 2020 at 14:37, on Zulip):

Yes, you can explicitly import any sysroot crate. #![no_std] just disables the implicit extern crate std and changes the prelude to refer to libcore instead of libstd.

Jonas Schievink (Jul 28 2020 at 14:37, on Zulip):

the import path code looks at presence of #![no_std] to decide which crate to prefer

Jonas Schievink (Jul 28 2020 at 14:38, on Zulip):

On embedded targets libstd literally is not present though

woody77 (Jul 28 2020 at 17:30, on Zulip):

Ok, so our assumption that we can just directly provide core and std as deps for all crates in rust-project.json is the correct path forward?

Last update: Sep 27 2020 at 14:15UTC