-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Only bump error count when we are sure that the diagnostic is not a repetition #47146
Conversation
…epetition. This ensures that if we emit the same diagnostic twice, the error count will match the real number of errors shown to the user. Fixes #42106
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @eddyb (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@bors r+ |
📌 Commit 063607e has been approved by |
Only bump error count when we are sure that the diagnostic is not a repetition This ensures that if we emit the same diagnostic twice, the error count will match the real number of errors shown to the user. Fixes #42106 This is a followup of #45603 as stated in #42106 (comment). This program, for example: ```rust fn do_something<T>(collection: &mut Vec<T>) { let _a = &collection; collection.swap(1, 2); } fn main() {} ``` without this patch, produces: ``` error[E0502]: cannot borrow `*collection` as mutable because `collection` is also borrowed as immutable --> $DIR/issue-42106.rs:13:5 | 12 | let _a = &collection; | ---------- immutable borrow occurs here 13 | collection.swap(1, 2); //~ ERROR also borrowed as immutable | ^^^^^^^^^^ mutable borrow occurs here 14 | } | - immutable borrow ends here error: aborting due to 2 previous errors ``` The number of errors do not match the diagnostics reported. This PR fixes this problem. The output is now in this case: ``` error[E0502]: cannot borrow `*collection` as mutable because `collection` is also borrowed as immutable --> $DIR/issue-42106.rs:13:5 | 12 | let _a = &collection; | ---------- immutable borrow occurs here 13 | collection.swap(1, 2); //~ ERROR also borrowed as immutable | ^^^^^^^^^^ mutable borrow occurs here 14 | } | - immutable borrow ends here error: aborting due to previous error ``` Also, some other tests outputs have been adapted because their count didn't really match the number of diagnostics reported. As an aside, an outdated comment has been removed (`Handler::cancel` will only call to the `Diagnostic::cancel` method and will not decrease the count of errors). All tests are passing with this PR (`x.py test` is successful).
☀️ Test successful - status-appveyor, status-travis |
Tested on commit rust-lang/rust@0f4ebf9. 💔 rustfmt on windows: test-pass → test-fail (cc @nrc). 💔 rustfmt on linux: test-pass → test-fail (cc @nrc).
Clean emitted diagnostics when `reset_err_count` is called. When external tools like `rustfmt` calls to `reset_err_count` for handler reusing, it will set the error count on the handler to 0, but since #47146 the handler will contain status that will prevent the error count to be bumped if this handler is reused. This caused `rustfmt` idempotency tests to fail: rust-lang/rustfmt#2338 Fixes: rust-lang/rustfmt#2338
This ensures that if we emit the same diagnostic twice, the error count will
match the real number of errors shown to the user.
Fixes #42106
This is a followup of #45603 as stated in #42106 (comment).
This program, for example:
without this patch, produces:
The number of errors do not match the diagnostics reported. This PR fixes this problem. The output is now in this case:
Also, some other tests outputs have been adapted because their count didn't really match the number of diagnostics reported.
As an aside, an outdated comment has been removed (
Handler::cancel
will only call to theDiagnostic::cancel
method and will not decrease the count of errors).All tests are passing with this PR (
x.py test
is successful).