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

Cargo.lock trailing newline removal in 1.38.0 #7254

Closed
est31 opened this issue Aug 16, 2019 · 5 comments · Fixed by #7262
Closed

Cargo.lock trailing newline removal in 1.38.0 #7254

est31 opened this issue Aug 16, 2019 · 5 comments · Fixed by #7262
Labels
C-bug Category: bug

Comments

@est31
Copy link
Member

est31 commented Aug 16, 2019

Consider this:

cargo +stable init --bin test_thing
cargo +stable check # to set Cargo.lock
git add . && git commit -m "Initial"
cargo +beta check
git diff

It will show you a difference! One line has been removed at the end of the file. Edit: Note that this only affects simple examples without dependencies. If there is a dependency, the newline behaviour is the same.

As time of writing, Rust beta is 1.38 and Rust stable is 1.37.

This bug may seem insignificant but it's the same "class" of change that #6180 was. In any environment where people use multiple versions of rustc to commit to the same codebase with a checked in Cargo.lock, you might run into situations where unrelated commits change Cargo.lock back and forth because the people just did cargo add. Environment with different versions of rustc can just mean that they haven't ran rustup in a while. #6180 at least had a phase in period.

I think the most likely culprit for this regression is #7070. I see some newline related changes there. cc @alexcrichton

I think that the old behaviour should be retained or at least the files with the trailing newline be kept so that there isn't jitter.

@est31 est31 added the C-bug Category: bug label Aug 16, 2019
@est31
Copy link
Member Author

est31 commented Aug 16, 2019

This bug wouldn't be so bad if a simple cargo check wouldn't trigger it. IMO cargo check, cargo build etc. should change Cargo.lock only if there is a good reason to, like when Cargo.toml added a dependency or when explicitly asked (I'd see cargo update as such). The code currently serializes Cargo.lock and compares it to the stored Cargo.lock. It would be much better if the code would compare the parsed toml Value's instead, then stuff like comments or newlines wouldn't matter. And even better if the code would compare higher level concepts like resolution graphs so that maybe even the upcoming Cargo.lock format wouldn't be introduced by an unrelated command like cargo build.

@est31
Copy link
Member Author

est31 commented Aug 16, 2019

cc @pietroalbini from release team as this is a beta regression.

@pietroalbini
Copy link
Member

Not sure if I would consider this a beta regression at the same level as the other ones: an old project still works, there is just a bit of churn in the lockfile. However, your suggestion of touching the lockfile only when needed is a good one, and could make this issue less of a problem.

Bringing in the loop the whole release team anyway, just to be sure. cc @rust-lang/release

@alexcrichton
Copy link
Member

This is a regression, not everyone can fix everything in 19 hours since this was reported. All Cargo contributors are very busy, we'll make sure this is fixed before the next release.

@est31
Copy link
Member Author

est31 commented Aug 16, 2019

This is a regression, not everyone can fix everything in 19 hours since this was reported. All Cargo contributors are very busy, we'll make sure this is fixed before the next release.

@alexcrichton I don't think that any of my statements can be interpreted as expectation of such a quick fix. Despite that, for the case you got such an impression, I'm deeply sorry for causing such an impression. Of course I don't expect that! I just wasn't sure whom to ping as you seemed busy (you still seem to be) and I tend to forget about bugs like this one myself so it's always best if it's in other people's trackers. Great respect for your work including that PR.

Thanks for your statement that the bug will be fixed until the next release.

bors added a commit that referenced this issue Aug 20, 2019
Fix old lockfile encoding wrt newlines

This commit fixes "old lockfile" encodings back to what they were prior
to #7070 with respect to newlines. The changes in #7070 accidentally
introduced a change where old lockfiles might have some extraneous
newlines removed unintentionally.

In #7070 it was attempted to clean up how newlines are emitted to ensure
a trailing blank newline never shows up at the end of the file, but this
acccidentally regressed cases where today we actually do have blank
newlines at the end of lock files. This commit instead restores all the
previous newline handling, and then scopes the "remove trailing
newlines" fix to specifically just the new encoding.

Closes #7254
@bors bors closed this as completed in b850342 Aug 20, 2019
alexcrichton added a commit to alexcrichton/cargo that referenced this issue Aug 20, 2019
This commit fixes "old lockfile" encodings back to what they were prior
to rust-lang#7070 with respect to newlines. The changes in rust-lang#7070 accidentally
introduced a change where old lockfiles might have some extraneous
newlines removed unintentionally.

In rust-lang#7070 it was attempted to clean up how newlines are emitted to ensure
a trailing blank newline never shows up at the end of the file, but this
acccidentally regressed cases where today we actually do have blank
newlines at the end of lock files. This commit instead restores all the
previous newline handling, and then scopes the "remove trailing
newlines" fix to specifically just the new encoding.

Closes rust-lang#7254
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants