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 + support for () fields #96853

Merged

Conversation

davidtwco
Copy link
Member

@davidtwco davidtwco commented May 9, 2022

  • 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 diagnostics: port more diagnostics to derive + add support for Vec fields #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

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 9, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 9, 2022
@rust-log-analyzer

This comment was marked as resolved.

@davidtwco
Copy link
Member Author

cc @Mark-Simulacrum for compiletest changes

@rust-log-analyzer

This comment was marked as resolved.

@davidtwco davidtwco force-pushed the diagnostic-translation-unit-and-more-porting branch from 4664552 to ecde2d9 Compare May 9, 2022 03:27
Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

r=me with manual diagnostic trait impl documented

Comment on lines +248 to +254
#[help]
pub is_nightly_build: Option<()>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if it could be useful to require the field name in the fluent file for spanless helps. Or generally for optional fields. It could be surprising to see some of them if you look at the entire fluent spec for an error, because you'd see all fields and they'd look "equal".

But considering I have zero fluent experience, that's just me guessing from the files.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe, I don't think it's worth changing this right now but it should be fairly easy to change down the line if we want to.

compiler/rustc_typeck/src/errors.rs Show resolved Hide resolved
@oli-obk oli-obk added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 10, 2022
Type attributes could previously be used to support spanless
subdiagnostics but these couldn't easily be made optional in the same
way that spanned subdiagnostics could by using a field attribute on a
field with an `Option<Span>` type. Spanless subdiagnostics can now be
specified on fields with `()` type or `Option<()>` type.

Signed-off-by: David Wood <david.wood@huawei.com>
Using new support for spanless subdiagnostics from `()` fields in the
diagnostic derive, simplify the "explicit generic args with impl trait"
diagnostic's struct.

Signed-off-by: David Wood <david.wood@huawei.com>
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.

Signed-off-by: David Wood <david.wood@huawei.com>
Manual implementors of translatable diagnostics will need to call
`set_arg`, not just the derive, so make this function a bit more
ergonomic by taking `IntoDiagnosticArg` rather than
`DiagnosticArgValue`.

Signed-off-by: David Wood <david.wood@huawei.com>
Port the "the type parameter `T` must be explicitly specified"
diagnostic to using a diagnostic struct.

Signed-off-by: David Wood <david.wood@huawei.com>
Port the "manual implementations of `X` are experimental" diagnostic to
use the diagnostic derive.

Signed-off-by: David Wood <david.wood@huawei.com>
Port "could not resolve substs on overridden impl" diagnostic to use the
diagnostic derive.

Signed-off-by: David Wood <david.wood@huawei.com>
@davidtwco davidtwco force-pushed the diagnostic-translation-unit-and-more-porting branch from ecde2d9 to 4758247 Compare May 12, 2022 06:38
@davidtwco davidtwco added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 12, 2022
@oli-obk
Copy link
Contributor

oli-obk commented May 12, 2022

@bors r+

@bors
Copy link
Contributor

bors commented May 12, 2022

📌 Commit 4758247 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 12, 2022
@bors
Copy link
Contributor

bors commented May 12, 2022

⌛ Testing commit 4758247 with merge 18bd2dd...

@bors
Copy link
Contributor

bors commented May 12, 2022

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 18bd2dd to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 12, 2022
@bors bors merged commit 18bd2dd into rust-lang:master May 12, 2022
@rustbot rustbot added this to the 1.62.0 milestone May 12, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (18bd2dd): comparison url.

Summary: This benchmark run did not return any relevant results.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

@davidtwco davidtwco deleted the diagnostic-translation-unit-and-more-porting branch May 12, 2022 14:11
@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 merged-by-bors This PR was explicitly merged by bors. 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.

10 participants