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

BREAKING CHANGE fix running path/to/cargo-clippy --fix #9461

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

matthiaskrgr
Copy link
Member

@matthiaskrgr matthiaskrgr commented Sep 10, 2022

Previously, we would assume clippy is called as "cargo clippy --arg1 --arg2" so we stripped the first two items and parsed "--arg1" and "--arg2" as cmdline args.
The problem is when we run cargo-clippy binary directly as "target/debug/cargo-clippy --arg1 --arg2", we would still remove the first two args which would be "..cargo-clippy" and "--arg1" in this case which is wrong.

Fix this by checking if we run clippy via "cargo clippy" or "../path/to/cargo-clippy" and for the latter, only skip the first arg instead of two.

Spotted by Kraktus because lintcheck --fix was no longer working

This is potentially a breaking change because the "target/debug/cargo-clippy clippy --fix" will no longer work!
Use "target/debug/cargo-clippy --fix" directly instead.


changelog: Important change: cargo-clippy will now no longer ignore the first argument. cargo-clippy clippy will still work as documented (the second clippy is ignored). However, arguments like --fix will issue a warning for now and will no longer be ignored in a few releases. cargo clippy (without -!) is unaffected by this change.
#9461

@rust-highfive
Copy link

r? @giraffate

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 10, 2022
src/main.rs Outdated
// if we run "cargo clippy" (as cargo subcommand), we have to strip "cargo clippy" (first 2 args)
// but if we are run via "..../target/debug/cargo-clippy", only ommit the first arg, the second one
// might be a normal cmdline arg already (which we don't want to ommit)
let args = if let Some(first_arg) = env::args().next() && (first_arg.ends_with("cargo-clippy") || first_arg.ends_with("cargo-clippy.exe")) {
Copy link
Member

@Alexendoo Alexendoo Sep 10, 2022

Choose a reason for hiding this comment

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

We can avoid a breaking change by checking if the 2nd arg is clippy, rather than the first being an invocation of cargo-clippy[.exe]

Copy link
Member Author

Choose a reason for hiding this comment

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

ah so that cargo clippy but also cargo-clippy clippy still works? clever! :D

I'll revisit this tomorrow after a good portion of sleep :)

Copy link
Contributor

Choose a reason for hiding this comment

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

That doesn't avoid the breaking change. Anything that uses cargo-clippy -- would break. Or anything else for that matter.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is what is happening for lintcheck for example

Copy link
Member

Choose a reason for hiding this comment

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

Ah right since any arg can currently be used as the separator

Copy link
Member

Choose a reason for hiding this comment

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

cargo clippy does execute with the first arg as .../cargo-clippy though, so we'd still need a different approach

execve("/home/alex/.cargo/bin/cargo", ["cargo", "clippy"], 0xffffd242db68 /* 49 vars */) = 0
execve("/home/alex/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/bin/cargo", ["/home/alex/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/bin/cargo", "clippy"], 0xaaaae39b8940 /* 54 vars */) = 0
execve("/home/alex/.cargo/bin/cargo-clippy", ["/home/alex/.cargo/bin/cargo-clippy", "clippy"], 0xaaab0d612f40 /* 57 vars */) = 0
execve("/home/alex/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/bin/cargo-clippy", ["/home/alex/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/bin/cargo-clippy", "clippy"], 0xaaaafea6a490 /* 57 vars */) = 0```

Copy link
Member Author

Choose a reason for hiding this comment

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

I just checked clippy 1.50 which was the lastest version when I wrote lintcheck 2 years ago and it looks like

RUSTC_BOOTSTRAP=1 ~/.rustup/toolchains/1.50-x86_64-unknown-linux-gnu/bin/cargo-clippy --fix -Zunstable-options

actually never worked as intended 😶 😅 😅

@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Sep 11, 2022

so to recap, on current master:
path/to/cargo-clippy --fix // this doesn't work but I would like it to
cargo clippy --fix // this works
cargo-clippy clippy --fix // this works but its super weird imo, I personally have no objections to dropping support but its probably better to keep backwards compatibility here 🙃
path/to/cargo-clippy -- --fix // this also works
cargo clippy -- --fix this does not work but I don't really care
cargo-clippy -- --fix this works

@Jarcho
Copy link
Contributor

Jarcho commented Oct 5, 2022

I think the least breaking change we could do here is to check if the first argument is one of clippy's argument (currently
--no-deps, --fix, -h, --help, -V, --version, --explain). This does leave an inconsistency with -- being ignored if it's the first argument, so it only half fixes the problem. cargo-clippy -- -W some-lint would still not work.

Alternatively, we could just treat anything with a leading dash as an argument. This will break some scripts, but it will make any direct use of cargo-clippy just work. I think this will make everything fail with an invalid argument error, rather than silently running with the wrong arguments.

@flip1995
Copy link
Member

flip1995 commented Oct 15, 2022

Doing a GitHub search I mostly find cargo-clippy clippy things. Or cargo-clippy --version, which works as expected. Also --help and --explain work as the first argument. I would say, as long as we keep supporting cargo-clippy clippy, we can just break every other usage of cargo-clippy where the second argument is used as a separator. I nominate the breakage discussion for the next meeting.

We also see cargo-clippy --all, which we should test if it works.

@flip1995 flip1995 added the I-nominated Issue: Nominated to be discussed at the next Clippy meeting label Oct 15, 2022
@flip1995
Copy link
Member

Clippy meeting result:

  • We don't want to hard break this now.
  • We want to keep cargo-clippy clippy as it works now
  • We want to emit warnings for all flags that are affected by this bug
    • --fix
    • --no-deps (not sure if this is affected)
    • Find out if other flags are affected
    • Emit a warning if cargo-clippy is followed by one of those flags, but don't change behavior yet
  • After 1-3 release cycles, change the behavior and remove the warnings
    • doesn't have to happen in the same release cycle
    • We can remove the warnings a release cycle later

@xFrednet
Copy link
Member

Oh, and we should probably add a big disclaimer to the changelog :)

kraktus added a commit to kraktus/rust-clippy that referenced this pull request Oct 27, 2022
There were several issues:
- `--fix` was ignored as part of rust-lang#9461
-  `--filter` in conjunction to `--fix` was broken due to rust-lang#9703

After `lintcheck --fix` is used, crates will be re-extracted since their content has been modified
kraktus added a commit to kraktus/rust-clippy that referenced this pull request Oct 27, 2022
There were several issues:
- `--fix` was ignored as part of rust-lang#9461
-  `--filter` in conjunction to `--fix` was broken due to rust-lang#9703

After `lintcheck --fix` is used, crates will be re-extracted since their content has been modified
kraktus added a commit to kraktus/rust-clippy that referenced this pull request Oct 27, 2022
There were several issues:
- `--fix` was ignored as part of rust-lang#9461
-  `--filter` in conjunction to `--fix` was broken due to rust-lang#9703

After `lintcheck --fix` is used, crates will be re-extracted since their content has been modified
kraktus added a commit to kraktus/rust-clippy that referenced this pull request Oct 27, 2022
There were several issues:
- `--fix` was ignored as part of rust-lang#9461
-  `--filter` in conjunction to `--fix` was broken due to rust-lang#9703

After `lintcheck --fix` is used, crates will be re-extracted since their content has been modified
@Alexendoo Alexendoo mentioned this pull request Oct 28, 2022
@flip1995 flip1995 removed the I-nominated Issue: Nominated to be discussed at the next Clippy meeting label Nov 1, 2022
@xFrednet
Copy link
Member

I've now updated the changelog entry according to the meeting results listed above :)

@xFrednet
Copy link
Member

xFrednet commented Dec 17, 2022

I'm marking this as waiting on author, until the discussed changes have been implemented. (Correct me, if I'm wrong with my assessment)

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Dec 17, 2022
@xFrednet
Copy link
Member

Hey @matthiaskrgr, I'd like to announce this change one or two changelogs, before the version that puts this into effect. Can you address the comments and make this PR ready to be merged? Then I could include it in the 1.67 changelog to be added in 1.69 🙃

@flip1995
Copy link
Member

flip1995 commented Jan 31, 2023

cargo-clippy now expects clippy to be the first argument.

This is not correct. I was unclear / ambiguous in my summary.

The warning we want to emit for cargo-clippy --*s that exist today is that those flags will have an effect in the future. Currently they don't, because you need something (usually clippy) before the first flag.

We want to keep supporting cargo-clippy clippy as a special case to be backwards compatible. Currently cargo-clippy foo-bar-baz ... and cargo-clippy clippy ... are exactly the same. So what we want to change here is to only remove the first arg after cargo-clippy, if it is actually clippy.

@xFrednet
Copy link
Member

xFrednet commented Feb 1, 2023

That makes a lot of sense, I had the feeling my understanding was not quite correct. Could you take a second look at the suggested changelog entry?

@flip1995
Copy link
Member

flip1995 commented Feb 1, 2023

Updated the changelog.

@xFrednet
Copy link
Member

I'll mark this as beta-accepted to make sure, that I include the deprecation message in the next changelog. It seems like I'm the one blocking this rn (Sorry 😅 )

@rustbot label +I-blocked -S-waiting-on-author +beta-accepted

@Alexendoo Alexendoo added S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work beta-accepted Accepted for backporting to the compiler in the beta channel. and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Mar 22, 2024
@xFrednet xFrednet removed the beta-accepted Accepted for backporting to the compiler in the beta channel. label Apr 29, 2024
@xFrednet xFrednet added S-final-comment-period Status: final comment period it will be merged unless new objections are raised (~1 week) S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Apr 29, 2024
@xFrednet
Copy link
Member

xFrednet commented Apr 29, 2024

Hey @matthiaskrgr, I'll mention this change in the next changelog, which unblocks this PR from being merged. Can you get this up to speed, with a rebase?

@matthiaskrgr
Copy link
Member Author

Uuh i may need a bit to wrap my head around this again after 1.5 years I fear 😅

@xFrednet
Copy link
Member

Very understandable ^^ (Sorry for the delay). The changelog doesn't mention a specific date or release, so there is no pressure from that side.

@flip1995 flip1995 added the I-nominated Issue: Nominated to be discussed at the next Clippy meeting label May 2, 2024
@flip1995
Copy link
Member

In the last meeting we decided to not emit a warning, but rather break the behavior on a edition boundary.

@flip1995 flip1995 removed the I-nominated Issue: Nominated to be discussed at the next Clippy meeting label May 15, 2024
@xFrednet
Copy link
Member

Is there already a date for the edition? And what is the best way to find out when it's scheduled to be released?

@flip1995
Copy link
Member

I don't think there's a date for the edition. Not sure who's the edition manager though.

Previously, we would assume clippy is called as "cargo clippy --arg1 --arg2" so we stripped the first two items and parsed "--arg1" and "--arg2" as cmdline args.
The problem is when we run cargo-clippy binary directly as "target/debug/cargo-clippy --arg1 --arg2", we would still remove the first two args which would be "..cargo-clippy" and "--arg1" in this case which is wrong.

Fix this by checking if we run clippy via "cargo clippy" or "../path/to/cargo-clippy" and for the latter, only skip the first arg instead of two.

Spotted by Kraktus because lintcheck --fix was no longer working

This is potentially a breaking change because the "target/debug/cargo-clippy clippy --fix" will no longer work!
Use "target/debug/cargo-clippy --fix" directly instead.

changelog: fix "cargo-clippy --foo" omitting the first flag, break "../cargo-clippy clippy --foo" which will now complain about the "clippy" arg.
Comment on lines -46 to +63
if let Err(code) = process(env::args().skip(2)) {
// if we run "cargo clippy" (as cargo subcommand), we have to strip "cargo clippy" (first 2 args)
// but if we are run via "..../target/debug/cargo-clippy", only ommit the first arg, the second one
// might be a normal cmdline arg already (which we don't want to ommit)
let args = if let Some(first_arg) = env::args().next()
&& (first_arg.ends_with("cargo-clippy") || first_arg.ends_with("cargo-clippy.exe"))
{
// turn this of during the migration
// env::args().skip(1)
eprintln!(
"WARNING: potentially breaking change: 'cargo-clippy arg1 arg2...' will no longer ignore 'arg1' after edition=2024"
);
env::args().skip(2)
} else {
env::args().skip(2)
};

if let Err(code) = process(args) {
Copy link
Member Author

Choose a reason for hiding this comment

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

🤔

@bors
Copy link
Collaborator

bors commented Aug 6, 2024

☔ The latest upstream changes (presumably #13225) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work S-final-comment-period Status: final comment period it will be merged unless new objections are raised (~1 week) S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants