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

Update SessionDiagnostic::into_diagnostic to take Handler instead of ParseSess #101434

Conversation

JhonnyBillM
Copy link
Contributor

Suggested by the team in this Zulip Topic.

Handler already has almost all the capabilities of ParseSess when it comes to diagnostic emission, in this migration we only needed to add the ability to access source_map from the emitter in order to get a Snippet and the start_point. Not sure if adding these two methods [span_to_snippet_from_emitter and span_start_point_from_emitter] is the best way to address this gap.

P.S. If this goes in the right direction, then we probably may want to move SessionDiagnostic to rustc_errors and rename it to DiagnosticHandler or something similar.

r? @davidtwco
r? @compiler-errors

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 5, 2022
@rustbot
Copy link
Collaborator

rustbot commented Sep 5, 2022

rustc_macros::diagnostics was changed

cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki

Some changes occurred in need_type_info.rs

cc @lcnr

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 5, 2022
@rust-log-analyzer

This comment has been minimized.

Suggested by the team in this Zulip Topic https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20SessionDiagnostic.20on.20Handler

Handler already has almost all the capabilities of ParseSess when it comes to diagnostic emission, in this migration we only needed to add the ability to access source_map from the emitter in order to get a Snippet and the start_point. Not sure if this is the best way to address this gap
@JhonnyBillM JhonnyBillM force-pushed the replace-session-for-handler-in-into-diagnostic branch from 64df415 to d14b3af Compare September 5, 2022 16:13
@JhonnyBillM JhonnyBillM requested review from davidtwco and compiler-errors and removed request for davidtwco September 5, 2022 16:17
@JhonnyBillM JhonnyBillM requested review from davidtwco and compiler-errors and removed request for davidtwco September 5, 2022 21:33
@davidtwco
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Sep 6, 2022

📌 Commit 46ba27d has been approved by davidtwco

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 Sep 6, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 6, 2022
…llaumeGomez

Rollup of 7 pull requests

Successful merges:

 - rust-lang#101357 (Include enum path in variant suggestion)
 - rust-lang#101434 (Update `SessionDiagnostic::into_diagnostic` to take `Handler` instead of `ParseSess`)
 - rust-lang#101445 (Suggest introducing an explicit lifetime if it does not exist)
 - rust-lang#101457 (Recover from using `;` as separator between fields)
 - rust-lang#101462 (Rustdoc-Json: Store Variant Fields as their own item.)
 - rust-lang#101471 (Report number of delayed bugs properly with `-Ztreat-err-as-bug`)
 - rust-lang#101473 (Add more size assertions for MIR types.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 4d830b7 into rust-lang:master Sep 6, 2022
@rustbot rustbot added this to the 1.65.0 milestone Sep 6, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 21, 2022
…agnostic-handler-refactor, r=davidtwco

Move and rename `SessionDiagnostic` & `SessionSubdiagnostic` traits and macros

After PR rust-lang#101434, we want to:
- [x] Move `SessionDiagnostic` to `rustc_errors`.
- [x] Add `emit_` methods that accept `impl SessionDiagnostic` to `Handler`.
- [x] _(optional)_ Rename trait `SessionDiagnostic` to `DiagnosticHandler`.
- [x] _(optional)_ Rename macro `SessionDiagnostic` to `DiagnosticHandler`.
- [x] Update Rustc Dev Guide and Docs to reflect these changes. rust-lang/rustc-dev-guide#1460

Now I am having build issues getting the compiler to build when trying to rename the macro.

<details>
  <summary>See diagnostics errors and context when building.</summary>

```
error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
  --> compiler/rustc_attr/src/session_diagnostics.rs:13:10
   |
13 |   #[derive(DiagnosticHandler)]
   |            ^^^^^^^^^^^^^^^^^ in this derive macro expansion
   |
  ::: /Users/jhonny/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/synstructure-0.12.6/src/macros.rs:94:9
   |
94 | /         pub fn $derives(
95 | |             i: $crate::macros::TokenStream
96 | |         ) -> $crate::macros::TokenStream {
   | |________________________________________- in this expansion of `#[derive(DiagnosticHandler)]`
   |
note: the lint level is defined here
  --> compiler/rustc_attr/src/lib.rs:10:9
   |
10 | #![deny(rustc::diagnostic_outside_of_impl)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

```

And also this one:

```
error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
   --> compiler/rustc_attr/src/session_diagnostics.rs:213:32
    |
213 |         let mut diag = handler.struct_span_err_with_code(
    |                                ^^^^^^^^^^^^^^^^^^^^^^^^^
```

> **Note**
> Can't find where this message is coming from, because you can see in [this experimental branch](https://github.com/JhonnyBillM/rust/tree/experimental/trying-to-rename-session-diagnostic-macro)  that I updated all errors and diags to say:
> error: diagnostics should only be created in **`DiagnosticHandler`**/`AddSubdiagnostic` impls
> and not:
> error: diagnostics should only be created in **`SessionDiagnostic`**/`AddSubdiagnostic` impls

</details>

I tried building the compiler in different ways (playing with the stages etc), but nothing worked.

## Question

**Do we need to build or do something different when renaming a macro and identifiers?**

For context, see experimental commit JhonnyBillM@f2193a9 where the macro and symbols are renamed, but it doesn't compile.
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) A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic 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.

7 participants