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

Cleanup things in and around Diagnostic #119763

Merged
merged 6 commits into from
Jan 11, 2024

Conversation

nnethercote
Copy link
Contributor

These changes all arose when I was looking closely at how to simplify DiagCtxtInner::emit_diagnostic.

r? @compiler-errors

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 9, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jan 9, 2024

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

The Miri subtree was changed

cc @rust-lang/miri

@nnethercote
Copy link
Contributor Author

I removed the last commit because I'm not sure if the TypeErrCtxt::drop change was legit.

@compiler-errors
Copy link
Member

r? oli-obk

@rustbot rustbot assigned oli-obk and unassigned compiler-errors Jan 10, 2024
Comment on lines 1307 to 1306
if diagnostic.has_future_breakage() {
(*TRACK_DIAGNOSTIC)(diagnostic, &mut |_| {});
}
return None;
}

if matches!(diagnostic.level, Expect(_) | Allow) {
(*TRACK_DIAGNOSTIC)(diagnostic, &mut |_| {});
return None;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please have a look at the PR that introduced them. I'm wary of removing them just because they have no effect on tests. This may be an incremental issue without tests. Alternatively verify from the source that this won't have an effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was #84762, sort of. @cjgillot, do you understand the purpose of these two (*TRACK_DIAGNOSTIC)(diagnostic, &mut |_| {}) calls? Removing them has no effect on test behaviour.

@oli-obk: I have removed this commit from the PR, all the other commits should be ok. Good to go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have done this TRACK_DIAGNOSTIC change by itself in #120699, I'm now fairly confident it's correct. Details in that PR.

Because the values put into it are functions named `track_diagnostic`
and `default_track_diagnostic`.
`is_force_warn` is only possible for diagnostics with `Level::Warning`,
but it is currently stored in `Diagnostic::code`, which every diagnostic
has.

This commit:
- removes the boolean `DiagnosticId::Lint::is_force_warn` field;
- adds a `ForceWarning` variant to `Level`.

Benefits:
- The common `Level::Warning` case now has no arguments, replacing
  lots of `Warning(None)` occurrences.
- `rustc_session::lint::Level` and `rustc_errors::Level` are more
  similar, both having `ForceWarning` and `Warning`.
It's missing but should obviously be included.
To put it next to a similar field.
There are four functions that adjust error and warning counts:
- `stash_diagnostic` (increment)
- `steal_diagnostic` (decrement)
- `emit_stashed_diagnostics) (decrement)
- `emit_diagnostic` (increment)

The first three all behave similarly, and only update `warn_count` for
forced warnings. But the last one updates `warn_count` for both forced
and non-forced warnings.

Seems like a bug. How should it be fixed? Well, `warn_count` is only
used in one place: `DiagCtxtInner::drop`, where it's part of the
condition relating to the printing of `good_path_delayed_bugs`. The
intention of that condition seems to be "have any errors been printed?"
so this commit replaces `warn_count` with `has_printed`, which is set
when printing occurs. This is simpler than all the ahead-of-time
incrementing and decrementing.
Of the error levels satisfying `is_error`, `Level::Error` is the only
one that can be a lint, so there's no need to check for it.

(And even if it wasn't, it would make more sense to include
non-`Error`-but-`is_error` lints under `lint_err_count` than under
`err_count`.)
@oli-obk
Copy link
Contributor

oli-obk commented Jan 10, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Jan 10, 2024

📌 Commit dd61eba has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 10, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 11, 2024
…iaskrgr

Rollup of 11 pull requests

Successful merges:

 - rust-lang#115046 (Use version-sorting for all sorting)
 - rust-lang#118915 (Add some comments, add `can_define_opaque_ty` check to `try_normalize_ty_recur`)
 - rust-lang#119006 (Fix is_global special address handling)
 - rust-lang#119637 (Pass LLVM error message back to pass wrapper.)
 - rust-lang#119715 (Exhaustiveness: abort on type error)
 - rust-lang#119763 (Cleanup things in and around `Diagnostic`)
 - rust-lang#119788 (change function name in comments)
 - rust-lang#119790 (Fix all_trait* methods to return all traits available in StableMIR)
 - rust-lang#119803 (Silence some follow-up errors [1/x])
 - rust-lang#119804 (Stabilize mutex_unpoison feature)
 - rust-lang#119832 (Meta: Add project const traits to triagebot config)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 88493fc into rust-lang:master Jan 11, 2024
11 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 11, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 11, 2024
Rollup merge of rust-lang#119763 - nnethercote:cleanup-Diagnostic, r=oli-obk

Cleanup things in and around `Diagnostic`

These changes all arose when I was looking closely at how to simplify `DiagCtxtInner::emit_diagnostic`.

r? `@compiler-errors`
@nnethercote nnethercote deleted the cleanup-Diagnostic branch January 11, 2024 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants