Stream: t-compiler/rust-analyzer

Topic: possible typo?


kev (Dec 11 2020 at 15:25, on Zulip):

On this line of text: https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/base_db/src/input.rs#L59

Should it say, as in the rustc compiler instead of as in the rust-lang proper ?

kev (Dec 11 2020 at 15:26, on Zulip):

Or maybe I'm parsing the sentence incorrectly. I believe it is trying to say that packages have names, to which we pass to the rustc compiler

Jonas Schievink [he/him] (Dec 11 2020 at 15:27, on Zulip):

Hmm, I think that comment might be wrong

Jonas Schievink [he/him] (Dec 11 2020 at 15:27, on Zulip):

But no, we don't pass anything to rustc

kev (Dec 11 2020 at 15:28, on Zulip):

Oh, I thought cargo passed the package name to rustc? via the --extern flag?

Jonas Schievink [he/him] (Dec 11 2020 at 15:29, on Zulip):

Yeah, and r-a's model tries to match that, which is what the comment is trying to say

Jonas Schievink [he/him] (Dec 11 2020 at 15:30, on Zulip):

Jonas Schievink said:

Hmm, I think that comment might be wrong

The reason I think it's wrong is because Cargo sets CARGO_CRATE_NAME for every crate it is compiling (https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates), so there is a canonical name for every crate. They just can be arbitrarily renamed when depended on, and that name is usually more important to rust-analyzer.

kev (Dec 11 2020 at 15:35, on Zulip):

IIUC, so if I have a workspace with a local crate called "foo" and I download an external dependency crate from cargo called "foo". They will both have unique names?

Jonas Schievink [he/him] (Dec 11 2020 at 15:37, on Zulip):

I don't know. I think they only have to have unique names if a crate depends on both of them.

kev (Dec 11 2020 at 15:38, on Zulip):

Maybe the name is derived as {CRATE_TYPE}{PACKAGE_NAME}_{CHECKSUM}, since in 'target/deps' I see the usually see names as libfoo-94e80d872615fc96

Jonas Schievink [he/him] (Dec 11 2020 at 15:39, on Zulip):

yes, the will get unique file name hashes and lockfile entries

Jonas Schievink [he/him] (Dec 11 2020 at 15:39, on Zulip):

but that isn't the crate name

kev (Dec 11 2020 at 15:40, on Zulip):

Ahh right, my mistake

kev (Dec 11 2020 at 15:41, on Zulip):

I'll leave a note on the comment and come back, as cargo is a bit out of scope right now :D

bjorn3 (Dec 11 2020 at 15:42, on Zulip):

Thar hash part is passed to rustc using -Cextra-filename. The full filename is derived as <file prefix><package name><extra-filename><file postfix>. File prefix and postfix are dependent on the crate type and target. For example windows doesn't use the lib prefix.

Last update: Jul 26 2021 at 14:15UTC