-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
try reading rust-version from Cargo.toml #8774
Conversation
r? @giraffate (rust-highfive has picked a reviewer for you, use r? to override) |
This sounds familiar. I think I also worked on that before 🤔 .... I did: rust-lang/cargo#9967 and I claimed #7765 back then. I probably forgot about finishing it 😄 I think one issue I couldn't resolve with this is that cc @matthiaskrgr Do you still have a way to run Clippy on rustc's test suite to test this branch and whether it brings back the issue linked above? |
I really tried searching for a duplicate, I'm sorry :D |
Yes, please. |
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.
I'm also not sure about the precedence. Should the rust-version
in the Cargo.toml
file be valued more or the one in the clippy.toml
file? Should we deprecate the msrv
conf option and point to the rust-version
instead?
clippy_lints/src/lib.rs
Outdated
Err(e) => { | ||
sess.struct_err(&format!("could not read cargo metadata: {}", e)).emit(); |
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.
I don't think this is a hard error. For example when using clippy-driver
outside of a cargo
project, no Cargo.toml
file can be found. I would just silently keep conf.msrv = None
here.
Good question. I thought, that the clippy.toml file should have a higher precedence, than the cargo.toml file. Deprecating it would be another idea, yes... But that's above my paygrade 😇 |
Let's talk about this in tomorrows meeting 👍 |
Shouldn't Cargo provide rust-version as an environment variable? They already provide a lot of other manifest data in that way - cargo docs. We already use CARGO_PRIMARY_PACKAGE in the driver. Line 338 in 95f8b26
|
We discussed this in today's meeting. We came to the agreement that:
I think the current implementation covers the first two points. Do you mind adding the warning? If you need help with that let me know. Also we should answer the perf question and if |
Thanks for the discussion on this topic. Currently, I only use the expensive MetadataCommand call if clippy.toml hasn't that I can open an issue/pr @ https://github.com/rust-lang/cargo to insert a |
Not really, because the issue only occurs if you check multiple single files, not a cargo project. But if you don't have a
For some reason I had in mind that a |
Checking this with flamegraph, the Looking at Without this patch: cargo uitest > /dev/null 75.74s user 26.33s system 886% cpu 11.511 total
cargo uitest > /dev/null 75.96s user 26.91s system 891% cpu 11.545 total
cargo uitest > /dev/null 76.83s user 26.69s system 879% cpu 11.768 total With this patch: cargo uitest > /dev/null 90.80s user 30.94s system 883% cpu 13.785 total
cargo uitest > /dev/null 91.13s user 30.94s system 880% cpu 13.864 total
cargo uitest > /dev/null 91.20s user 31.08s system 892% cpu 13.697 total (meassured on It isn't too bad, but definitely a noticable regression. I think creating an issue in cargo about the env var or (maybe better) asking on Zulip about it would be good. I'm open to merge this with |
Thanks for the measurement! |
If no such env var should get added we could just check if |
So I did things™. Instead of using What I wanted next, but couldn't achieve because of the way the |
2a8dc2f
to
56224e3
Compare
I really would like to add some tests, but I'm not really sure how to integrate them into the clippy testsuite. After all, I would like to have at least 7 different testcases and therefore 7 different cargo projects.
|
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.
But for this to work I either need to implement Deserialize directly for that struct (looking @flip1995 ;) ) or finding a clever workaround
I intentionally wrote the rustc-version
crate without deps. So adding serde
for this isn't really an option.
You can add tests for this in the tests/ui-toml
ortests/ui-cargo
dirs. See for example: https://github.com/rust-lang/rust-clippy/tree/master/tests/ui-cargo/cargo_common_metadata/pass which has both, a Cargo.toml and a clippy.toml file in the test.
Not sure if we should re-parse it by hand or just check for the |
I mean, in the end, the two options should be equal in their outcome. |
Yeah I guess this is only style preference in the end. I don't think the perf difference matters much when linting a whole crate with Let's keep the toml parsing code for now 👍 |
@flip1995 sorry, just randomly saw the mention (I'm getting like 30 github mails a day and don't check them all tbh 😓 ) |
56224e3
to
08ea04b
Compare
I did the suggested changes and rebased everything into one commit. Hope this is ready for merging :) |
08ea04b
to
3cebb1b
Compare
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.
LGTM. Do you want to add some tests to tests/ui-cargo
?
Hey @flip1995 I need your help again. I seem to be stuck to the same problem as last time, when I tried to parse Running Is there a way around this? Else I would have to use |
We may want to look at the UI-tests and if we can change something there to test it. We should definitely use the env var and not |
Would making a UI test with compiletest header to set the environment variable work? |
bab6b4a
to
7ce853d
Compare
I think I finally found the solution. It passes on my machine™. Problem is, that compiletest_rs does not parse the I know, this isn't a perfect solution, but this is the best I can do :) |
Using config file `$SRC_DIR/tests/ui-cargo/multiple_config_files/warn/.clippy.toml` | ||
Warning: `$SRC_DIR/tests/ui-cargo/multiple_config_files/warn/clippy.toml` will be ignored. | ||
Using config file `$SRC_DIR/.clippy.toml` | ||
Warning: `$SRC_DIR/clippy.toml` will be ignored. |
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.
This is a "fallout" by setting CARGO_MANIFEST_DIR
, but I think this is the proper way
7ce853d
to
d8e6c33
Compare
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.
Impl LGTM and also the solution to the tests. Only some minor things left.
@@ -0,0 +1,13 @@ | |||
#![feature(custom_inner_attributes)] | |||
#![clippy::msrv = "1.58.0"] |
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.
So, this doesn't produce a warning. That is not optimal, but I wouldn't try to address this in this PR.
Can you add a FIXME
, that this should produce some kind of warning, that it overrides the value from one of the toml files?
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.
Maybe abandon that attribute in the long run? ;)
5099e74
to
3d0f73e
Compare
Done |
4883039
to
f0a1cd5
Compare
Cargo.toml can contain a field `rust-version`, that acts like a MSRV of clippy.toml file: https://doc.rust-lang.org/cargo/reference/manifest.html#the-rust-version-field This will try to read that field and use it, if the clippy.toml config has no `msrv` entry
compiletest_rs is not meant to test full cargo projects, but instead only files. So we need to parse the `Cargo.toml` file ourself and set the corresponding environment variable. In this case we just set `CARGO_PKG_RUST_VERSION`, nothing more. But, of course, this can be extended.
CI is green and I think this is (finally) ready to merge |
Thanks so much for this and your patience with all the back and forth! @bors r+ |
📌 Commit f0a1cd5 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Clippy now respects the rust-version field in Cargo manifests: rust-lang/rust-clippy#8774
Cargo.toml can contain a field
rust-version
, that acts like a MSRV ofclippy.toml file: https://doc.rust-lang.org/cargo/reference/manifest.html#the-rust-version-field
This will try to read that field and use it, if the clippy.toml config
has no
msrv
entrychangelog: respect
rust-version
fromCargo.toml
closes #8746
closes #7765