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

diagnostics: port more diagnostics to derive + add support for Vec fields #96760

Merged
merged 4 commits into from
May 7, 2022

Conversation

davidtwco
Copy link
Member

  • Port "unconstrained opaque type" diagnostic to using the derive.
  • Allow Vec fields in diagnostic derive - enables support for diagnostics that have multiple primary spans, or have subdiagnostics repeated at multiple locations. Vec<..> fields in the diagnostic derive become loops in the generated code.
  • Add create_{err,warning} - there wasn't a way to create a diagnostic from a struct and not emit it straight away.
  • Port "explicit generic args w/ impl trait" diagnostic to using the derive.

r? @oli-obk
cc @pvdrz

Port the "unconstrained opaque type" diagnostic to using the diagnostic
derive.

Signed-off-by: David Wood <david.wood@huawei.com>
Diagnostics can have multiple primary spans, or have subdiagnostics
repeated at multiple locations, so support `Vec<..>` fields in the
diagnostic derive which become loops in the generated code.

Signed-off-by: David Wood <david.wood@huawei.com>
Currently, the only API for creating errors from a diagnostic derive
will emit it immediately. This makes it difficult to add subdiagnostics
to diagnostics from the derive, so add `create_{err,warning}` functions
that return the diagnostic without emitting it.

Signed-off-by: David Wood <david.wood@huawei.com>
Port the "explicit generic arguments with impl trait" diagnostic to
using the diagnostic derive.

Signed-off-by: David Wood <david.wood@huawei.com>
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 6, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 6, 2022
pub(crate) fn option_inner_ty(ty: &Type) -> Option<&Type> {
if type_matches_path(ty, &["std", "option", "Option"]) {
/// Inner type of a field and type of wrapper.
pub(crate) enum FieldInnerTy<'ty> {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is ok for now, it's just inside rustc after all, but in the future we should probably invent a new trait that we can auto-impl for all subdiagnostics and manually impl for vec and option. The problem with the current approach is that it's dependent on exact names in the source, without actually tying them to the type we expect.

@oli-obk
Copy link
Contributor

oli-obk commented May 6, 2022

@bors r+

@bors
Copy link
Contributor

bors commented May 6, 2022

📌 Commit af47257 has been approved by oli-obk

@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 May 6, 2022
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 6, 2022
…c, r=oli-obk

diagnostics: port more diagnostics to derive + add support for `Vec` fields

- Port "unconstrained opaque type" diagnostic to using the derive.
- Allow `Vec` fields in diagnostic derive - enables support for diagnostics that have multiple primary spans, or have subdiagnostics repeated at multiple locations. `Vec<..>` fields in the diagnostic derive become loops in the generated code.
- Add `create_{err,warning}` - there wasn't a way to create a diagnostic from a struct and not emit it straight away.
- Port "explicit generic args w/ impl trait" diagnostic to using the derive.

r? `@oli-obk`
cc `@pvdrz`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 6, 2022
…c, r=oli-obk

diagnostics: port more diagnostics to derive + add support for `Vec` fields

- Port "unconstrained opaque type" diagnostic to using the derive.
- Allow `Vec` fields in diagnostic derive - enables support for diagnostics that have multiple primary spans, or have subdiagnostics repeated at multiple locations. `Vec<..>` fields in the diagnostic derive become loops in the generated code.
- Add `create_{err,warning}` - there wasn't a way to create a diagnostic from a struct and not emit it straight away.
- Port "explicit generic args w/ impl trait" diagnostic to using the derive.

r? ``@oli-obk``
cc ``@pvdrz``
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 6, 2022
…c, r=oli-obk

diagnostics: port more diagnostics to derive + add support for `Vec` fields

- Port "unconstrained opaque type" diagnostic to using the derive.
- Allow `Vec` fields in diagnostic derive - enables support for diagnostics that have multiple primary spans, or have subdiagnostics repeated at multiple locations. `Vec<..>` fields in the diagnostic derive become loops in the generated code.
- Add `create_{err,warning}` - there wasn't a way to create a diagnostic from a struct and not emit it straight away.
- Port "explicit generic args w/ impl trait" diagnostic to using the derive.

r? ```@oli-obk```
cc ```@pvdrz```
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 7, 2022
…c, r=oli-obk

diagnostics: port more diagnostics to derive + add support for `Vec` fields

- Port "unconstrained opaque type" diagnostic to using the derive.
- Allow `Vec` fields in diagnostic derive - enables support for diagnostics that have multiple primary spans, or have subdiagnostics repeated at multiple locations. `Vec<..>` fields in the diagnostic derive become loops in the generated code.
- Add `create_{err,warning}` - there wasn't a way to create a diagnostic from a struct and not emit it straight away.
- Port "explicit generic args w/ impl trait" diagnostic to using the derive.

r? ````@oli-obk````
cc ````@pvdrz````
bors added a commit to rust-lang-ci/rust that referenced this pull request May 7, 2022
…laumeGomez

Rollup of 7 pull requests

Successful merges:

 - rust-lang#96581 (make Size and Align debug-printing a bit more compact)
 - rust-lang#96636 (Fix jump to def regression)
 - rust-lang#96760 (diagnostics: port more diagnostics to derive + add support for `Vec` fields)
 - rust-lang#96788 (Improve validator around field projections and checked bin ops)
 - rust-lang#96805 (Change eslint rules from configuration comments to configuration file)
 - rust-lang#96807 (update Miri)
 - rust-lang#96811 (Fix a minor typo in the description of Formatter)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a644197 into rust-lang:master May 7, 2022
@rustbot rustbot added this to the 1.62.0 milestone May 7, 2022
@davidtwco davidtwco deleted the diagnostic-translation-vec branch May 9, 2022 01:20
bors added a commit to rust-lang-ci/rust that referenced this pull request May 12, 2022
…-and-more-porting, r=oli-obk

diagnostics: port more diagnostics to derive + support for `()` fields

- Extend diagnostic derive so that spanless subdiagnostics (e.g. some uses of `help`/`note`) can be applied via attributes to fields of type `()` (currently spanless subdiagnostics are applied via attributes on the diagnostic struct itself). A consequence of this is that `Option<()>` fields can be used to represent optional spanless subdiagnostics, which are sometimes useful (e.g. for a `help` that should only show on nightly builds).
- Simplify the "explicit generic args with impl trait" diagnostic struct (from rust-lang#96760) using support for `Option<()>` spanless subdiagnostics.
- Change `DiagnosticBuilder::set_arg`, used to provide context for Fluent messages, so that it takes anything that implements `IntoDiagnosticArg`, rather than `DiagnosticArgValue` - this improves the ergonomics of manual implementations of `SessionDiagnostic` which are translatable.
- Port "the type parameter `T` must be explicitly specified", "manual implementations of `X` are experimental", "could not resolve substs on overridden impl" diagnostics to diagnostic structs.
- When testing macros from `rustc_macros` in `ui-fulldeps` tests, sometimes paths from the compiler source tree can be shown in error messages - these need to be normalized in `compiletest`.

r? `@oli-obk`
cc `@pvdrz`
@compiler-errors compiler-errors added the A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic label Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants