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

Merged
merged 1 commit into from Jan 3, 2018

Conversation

Projects
None yet
5 participants
@ereslibre
Contributor

ereslibre commented Jan 2, 2018

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:

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).

Only bump error count when we are sure that the diagnostic is not a r…
…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
@rust-highfive

This comment has been minimized.

Show comment
Hide comment
@rust-highfive

rust-highfive Jan 2, 2018

Collaborator

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.

Collaborator

rust-highfive commented Jan 2, 2018

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.

@estebank

This comment has been minimized.

Show comment
Hide comment
@estebank

estebank Jan 3, 2018

Contributor

@bors r+

Contributor

estebank commented Jan 3, 2018

@bors r+

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Jan 3, 2018

Contributor

📌 Commit 063607e has been approved by estebank

Contributor

bors commented Jan 3, 2018

📌 Commit 063607e has been approved by estebank

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Jan 3, 2018

Contributor

⌛️ Testing commit 063607e with merge 0f4ebf9...

Contributor

bors commented Jan 3, 2018

⌛️ Testing commit 063607e with merge 0f4ebf9...

bors added a commit that referenced this pull request Jan 3, 2018

Auto merge of #47146 - ereslibre:issue-42106, r=estebank
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).
@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Jan 3, 2018

Contributor

☀️ Test successful - status-appveyor, status-travis
Approved by: estebank
Pushing 0f4ebf9 to master...

Contributor

bors commented Jan 3, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: estebank
Pushing 0f4ebf9 to master...

@bors bors merged commit 063607e into rust-lang:master Jan 3, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

kennytm-githubbot added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Jan 3, 2018

📣 Toolstate changed by rust-lang/rust#47146!
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).

@ereslibre ereslibre deleted the ereslibre:issue-42106 branch Jan 3, 2018

ereslibre added a commit to ereslibre/rust that referenced this pull request Jan 6, 2018

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
rust-lang#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-nursery/rustfmt#2338

Fixes: rust-lang-nursery/rustfmt#2338

ereslibre added a commit to ereslibre/rust that referenced this pull request Jan 8, 2018

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
rust-lang#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-nursery/rustfmt#2338

Fixes: rust-lang-nursery/rustfmt#2338

ereslibre added a commit to ereslibre/rust that referenced this pull request Jan 8, 2018

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
rust-lang#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-nursery/rustfmt#2338

Fixes: rust-lang-nursery/rustfmt#2338

bors added a commit that referenced this pull request Jan 9, 2018

Auto merge of #47231 - ereslibre:clean-emitted-diagnostics, r=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-nursery/rustfmt#2338

Fixes: rust-lang-nursery/rustfmt#2338
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment