-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
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>
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> { |
There was a problem hiding this comment.
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.
@bors r+ |
📌 Commit af47257 has been approved by |
…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`
…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``
…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```
…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````
…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
…-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`
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.create_{err,warning}
- there wasn't a way to create a diagnostic from a struct and not emit it straight away.r? @oli-obk
cc @pvdrz