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

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
Merged

Only bump error count when we are sure that the diagnostic is not a repetition #47146

merged 1 commit into from
Jan 3, 2018

Conversation

ereslibre
Copy link
Contributor

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

…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
Copy link
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.

@estebank
Copy link
Contributor

estebank commented Jan 3, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Jan 3, 2018

📌 Commit 063607e has been approved by estebank

@estebank estebank added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 3, 2018
@bors
Copy link
Contributor

bors commented Jan 3, 2018

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

bors added a commit that referenced this pull request Jan 3, 2018
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
Copy link
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
kennytm-githubbot added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Jan 3, 2018
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 issue-42106 branch January 3, 2018 09:28
bors added a commit that referenced this pull request Jan 9, 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
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Repeated "mutable/immutable borrow" error messages
5 participants