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

Add a config setting to disable the 'test' cfg in specified crates #9227

Merged
merged 2 commits into from
Jun 21, 2021

Conversation

lf-
Copy link
Contributor

@lf- lf- commented Jun 12, 2021

If you are opening libcore from rust-lang/rust as opposed to e.g.
goto definition from some other crate which would use the sysroot
instance of libcore, a #![cfg(not(test))] would previously have made
all the code excluded from the module tree, breaking the editor
experience.

Core does not need to ever be edited with #[cfg(test)] enabled,
as the tests are in another crate.

This PR puts in a slight hack that checks for the crate name "core" and
turns off #[cfg(test)] for that crate.

Fixes #9203
Fixes #9226

@lf- lf- marked this pull request as draft June 12, 2021 12:59
@lf-
Copy link
Contributor Author

lf- commented Jun 12, 2021

Actually marking this as a draft because per feedback from @flodiebold, it should probably be a config setting we can set per workspace.

@matklad
Copy link
Member

matklad commented Jun 12, 2021

Curious, what breaks if we comment out that cfg(not(test)) in rust-lang/rust? Due to this line, this cfg shouldn't have any effect I would think?

https://github.com/rust-lang/rust/blob/d59b80d588368cdcfcc1d54e119374a3d78169ff/library/core/Cargo.toml#L13

Can we use this info from cargo.toml to not apply test?

@flodiebold
Copy link
Member

Can we use this info from cargo.toml to not apply test?

I think we should be able to, there's a "test": false in the target info in the metadata.

@jonas-schievink
Copy link
Contributor

This would also be fixed if we correctly created all dependencies without cfg(test) set (since crates only have that set when they're compiled into a test executable)

@lf-
Copy link
Contributor Author

lf- commented Jun 13, 2021

This would also be fixed if we correctly created all dependencies without cfg(test) set (since crates only have that set when they're compiled into a test executable)

The thing I'm concerned about with this is that it would have unintended side effects: currently you can work in a workspace with r-a and work on tests of arbitrary crates within it. I think (?) if we were to do this, it would disable tests in some/all of those crates, breaking this use case. The compiler's behaviour is not necessarily the most user friendly in an IDE context. Setting cfg(test) in workspace crates only wouldn't work either, because sometimes you are working in a workspace with a cfg(test) bomb.

I concur with @flodiebold that probably the only way to do this properly is to analyze multiple times or to add a config option that overrides cfgs per crate to allow us to fix the ones that are broken by the current strategy.

@lf- lf- marked this pull request as ready for review June 14, 2021 06:21
@lf- lf- changed the title Fix libcore not being included in rust-lang/rust module tree Add a config setting to disable the 'test' cfg in specified crates Jun 14, 2021
@lf-
Copy link
Contributor Author

lf- commented Jun 14, 2021

Made it a config option, which conveniently also fixes some other bugs on the tracker about other crates that were doing this.

@lf-
Copy link
Contributor Author

lf- commented Jun 14, 2021

Cannot reproduce the CI failure, guessing it's spurious. :/

@lnicola
Copy link
Member

lnicola commented Jun 14, 2021

Uh, that looks bad.

bors try

bors bot added a commit that referenced this pull request Jun 14, 2021
@bors
Copy link
Contributor

bors bot commented Jun 14, 2021

@lnicola
Copy link
Member

lnicola commented Jun 14, 2021

bors try

bors bot added a commit that referenced this pull request Jun 14, 2021
@bors
Copy link
Contributor

bors bot commented Jun 14, 2021

try

Build succeeded:

lf- added 2 commits June 19, 2021 01:09
If you are opening libcore from rust-lang/rust as opposed to e.g.
goto definition from some other crate which would use the sysroot
instance of libcore, a `#![cfg(not(test))]` would previously have made
all the code excluded from the module tree, breaking the editor
experience.

This puts in a slight hack that checks for the crate name "core" and
turns off `#[cfg(test)]`.
Fixes crates which vanish when the 'test' cfg atom is set.

Fix rust-lang#7243.
Fix rust-lang#9203.
Fix rust-lang#7225.
@lf-
Copy link
Contributor Author

lf- commented Jun 19, 2021

Rebased for the 1.53 fix. Good to go.

Copy link
Member

@matklad matklad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r+

Observation: workspace.rs seem to acquire more and more special cases, and the code there is pretty horrible. What's concerning is that this functionality is essentially untested. I fear that one day we'll have to split it into IOing and data wrangling parts, and write unit-tests for data wrangling...

@bors
Copy link
Contributor

bors bot commented Jun 21, 2021

@bors bors bot merged commit b48aba0 into rust-lang:master Jun 21, 2021
@flodiebold
Copy link
Member

Observation: workspace.rs seem to acquire more and more special cases, and the code there is pretty horrible. What's concerning is that this functionality is essentially untested. I fear that one day we'll have to split it into IOing and data wrangling parts, and write unit-tests for data wrangling...

Ideally we'd want to do this on the VFS anyway, right? That should make it more testable as well...

@matklad
Copy link
Member

matklad commented Jun 21, 2021

Yeah, VFS is in a similar situation, although it's more stable in practice!

@matklad
Copy link
Member

matklad commented Jul 20, 2021

and write unit-tests for data wrangling...

This took some time, but now we have 1 (one) tests for this:

#9644

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants