-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
internal: Teach cargo about cfg(rust_analyzer)
#16257
Conversation
c3543a0
to
007c176
Compare
Is this so we can remove the cfg from bootstrap again? |
007c176
to
3a2ae64
Compare
Maybe, but I'm not too keen on trying it right now. See https://blog.rust-lang.org/inside-rust/2024/01/03/this-development-cycle-in-cargo-1-76.html#-zcheck-cfg, I don't know if it will be enabled by default in the future. |
I see, well fine with me either way. |
This is a bit annoying, I guess it will have to wait. |
This looks alright, but as noted it won't work if
The goal is to have it enable by default (and therefore remove |
Blocked on rust-lang/cargo#13571 |
Note that since rust-lang/cargo#13438, Cargo no longer emits a warning when using |
@bors r+ |
@@ -0,0 +1,5 @@ | |||
//! This teaches cargo about our cfg(rust_analyzer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why I added these, but.. 😅.
☀️ Test successful - checks-actions |
To double check, is If its the latter, that sounds like a "well known cfg" and should likely be defined in rustc along with miri and others or cargo along with docsrs. |
rust-analyzer sets this for workspace crates of a loaded project when doing its own analysis, but not when invoking cargo or any other tool. It's strictly contained to its analysis only. |
I was under the impression that the rust-analyzer/crates/project-model/src/workspace.rs Lines 1002 to 1006 in af1fd88
and also every "detached" Rust files
@Veykril Is my analysis right, that the EDIT: raced with |
Did that answer your question already? 😄 Effectively to cargo, the cfg will always be disabled (unless the user somehow passes it to cargo themselves), the cfgs linked in the code there are the ones that r-a sees, but not any invoked tooling. |
I think so. From what I understand during rust-analyzer analysis of the code r-a adds (an analysis-only) And then there is a second If my understanding is right, then every is good, |
It is not well known as it's fairly recent, and mainly an escape hatch to be able to cfg out things that are very slow for the ide (like the quote crate).
There it's also only used by analysis, its just that those crates are the only ones in the r-a codebase that actually have a |
My bad, I was referring to well-known in the sense of
This seems very similar to the So users can expect the |
Yes but only on workspace member crates (so not dependencies in the crates-io registry), to prevent libraries from special casing rust-analyzer for the time being. |
If you don't want users to "special case rust-analyzer for the time being", does that also mean that you don't want to advertise the cfg ? and if so, are fine with users having to expect the cfg in a More broadly the question is: should |
Having it be known is fine I think, it's not going away I'd say. The restriction is only there to deter people from doing weird r-a specific things in their libraries for now |
r? @Urgau is this a good idea?, CC @Veykril