rust/compiler
bors 683c582c1e Auto merge of #96468 - davidtwco:diagnostic-translation-subdiagnostic, r=oli-obk
macros: subdiagnostic derive

Add a new macro, `#[derive(SessionSubdiagnostic)]`, which can be applied to structs that represent subdiagnostics, such as labels, notes, helps or suggestions.

`#[derive(SessionSubdiagnostic)]` can be used with the existing `#[derive(SessionDiagnostic)]`. All diagnostics implemented using either derive are translatable, and this new derive should make it easier to port existing diagnostics to using these derives.

For example, consider the following subdiagnostic types...

```rust
#[derive(SessionSubdiagnostic)]
pub enum ExpectedIdentifierLabel<'tcx> {
    #[label(slug = "parser-expected-identifier")]
    WithoutFound {
        #[primary_span]
        span: Span,
    }
    #[label(slug = "parser-expected-identifier-found")]
    WithFound {
        #[primary_span]
        span: Span,
        found: String,
    }
}

#[derive(SessionSubdiagnostic)]
#[suggestion_verbose(slug = "parser-raw-identifier")]
pub struct RawIdentifierSuggestion<'tcx> {
    #[primary_span]
    span: Span,
    #[applicability]
    applicability: Applicability,
    ident: Ident,
}
```

...and the corresponding Fluent messages:

```fluent
parser-expected-identifier = expected identifier

parser-expected-identifier-found = expected identifier, found {$found}

parser-raw-identifier = escape `{$ident}` to use it as an identifier
```

These can be emitted using the new `subdiagnostic` function on `Diagnostic`...

```rust
diag.subdiagnostic(ExpectedIdentifierLabel::WithoutFound { span });
diag.subdiagnostic(RawIdentifierSuggestion { span, applicability, ident });
```

...or as part of a larger `#[derive(SessionDiagnostic)]`:

```rust
#[derive(SessionDiagnostic)]
#[error(slug = "parser-expected-identifier")]
pub struct ExpectedIdentifier {
    #[primary_span]
    span: Span,
    token_descr: String,
    #[subdiagnostic]
    label: ExpectedIdentifierLabel,
    #[subdiagnostic]
    raw_identifier_suggestion: Option<RawIdentifierSuggestion>,
}
```

```rust
sess.emit_err(ExpectedIdentifier { ... });
```

r? `@oli-obk`
cc `@pvdrz`
2022-04-29 11:58:24 +00:00
..
rustc Propagate parallel_compiler feature through rustc crates. Turned off feature gives change of builded crates: 238 -> 224. 2022-03-28 08:41:12 +03:00
rustc_apfloat Addressed comments by @compiler-errors and @bjorn3 2022-03-30 17:04:46 -04:00
rustc_arena mark FIXMES for all the places found that are probably offset_from 2022-03-29 20:18:28 -04:00
rustc_ast rustc_ast: Harmonize delimiter naming with proc_macro::Delimiter 2022-04-28 10:04:29 +03:00
rustc_ast_lowering rustc_ast: Harmonize delimiter naming with proc_macro::Delimiter 2022-04-28 10:04:29 +03:00
rustc_ast_passes rename to BoundKind and add comments 2022-04-21 10:09:32 +08:00
rustc_ast_pretty rustc_ast: Harmonize delimiter naming with proc_macro::Delimiter 2022-04-28 10:04:29 +03:00
rustc_attr Rollup merge of #94948 - jhpratt:rustc_deprecated, r=Dylan-DPC 2022-03-20 09:14:59 +01:00
rustc_borrowck errors: span_suggestion takes impl ToString 2022-04-29 02:05:20 +01:00
rustc_builtin_macros errors: span_suggestion takes impl ToString 2022-04-29 02:05:20 +01:00
rustc_codegen_cranelift Merge commit 'f2cdd4a78d89c009342197cf5844a21f8aa813df' into sync_cg_clif-2022-04-22 2022-04-22 21:11:38 +02:00
rustc_codegen_gcc Rollup merge of #95740 - Amanieu:kreg0, r=nagisa 2022-04-19 22:57:39 +02:00
rustc_codegen_llvm Rollup merge of #96432 - SparrowLii:dbg_scope, r=davidtwco 2022-04-28 02:40:34 +02:00
rustc_codegen_ssa Rollup merge of #96523 - nbdd0121:windows, r=petrochenkov 2022-04-29 11:23:16 +02:00
rustc_const_eval Auto merge of #95976 - b-naber:valtree-constval-conversion, r=oli-obk 2022-04-28 13:18:22 +00:00
rustc_data_structures incr. comp.: Don't export impl_stable_hash_via_hash!() and warn about using it. 2022-04-19 10:43:20 +02:00
rustc_driver errors: lazily load fallback fluent bundle 2022-04-13 02:44:59 +01:00
rustc_error_codes rework error messages for incorrect inherent impls 2022-03-30 11:23:58 +02:00
rustc_error_messages macros: subdiagnostic derive 2022-04-29 02:05:20 +01:00
rustc_errors macros: subdiagnostic derive 2022-04-29 02:05:20 +01:00
rustc_expand errors: span_suggestion takes impl ToString 2022-04-29 02:05:20 +01:00
rustc_feature Rollup merge of #94457 - jhpratt:stabilize-derive_default_enum, r=davidtwco 2022-04-15 20:50:43 +02:00
rustc_fs_util
rustc_graphviz
rustc_hir Auto merge of #91557 - cjgillot:ast-lifetimes-named, r=petrochenkov 2022-04-27 23:13:28 +00:00
rustc_hir_pretty Stop pretty-printing HIR visibility. 2022-04-23 09:55:25 +02:00
rustc_incremental Rollup merge of #95434 - cjgillot:dump-dep-kind, r=oli-obk 2022-04-21 20:55:18 +02:00
rustc_index tut tut tut 2022-04-27 08:51:33 +01:00
rustc_infer errors: span_suggestion takes impl ToString 2022-04-29 02:05:20 +01:00
rustc_interface Rollup merge of #96090 - JakobDegen:mir-tests, r=nagisa 2022-04-25 00:10:59 +02:00
rustc_lexer Reduce max hash in raw strings from u16 to u8 2022-03-23 22:13:55 +01:00
rustc_lint errors: span_suggestion takes impl ToString 2022-04-29 02:05:20 +01:00
rustc_lint_defs Plumb through rustc_lint_defs::Level as enum rather than string. 2022-04-27 10:04:25 -07:00
rustc_llvm Stub out more PassManagerBuilder functions 2022-04-20 09:36:02 +02:00
rustc_log
rustc_macros macros: add interop between diagnostic derives 2022-04-29 02:12:10 +01:00
rustc_metadata Add --json unused-externs-silent with original behaviour 2022-04-27 10:04:25 -07:00
rustc_middle Auto merge of #95976 - b-naber:valtree-constval-conversion, r=oli-obk 2022-04-28 13:18:22 +00:00
rustc_mir_build only show a simple description in E0133 span label 2022-04-24 18:33:07 +02:00
rustc_mir_dataflow Add new MutatatingUseContexts for deinit and SetDiscriminant 2022-04-11 09:26:26 -04:00
rustc_mir_transform Rollup merge of #96471 - BoxyUwU:let_else_considered_harmful, r=lcnr 2022-04-28 02:40:36 +02:00
rustc_monomorphize Auto merge of #95604 - nbdd0121:used2, r=petrochenkov 2022-04-25 16:14:54 +00:00
rustc_parse errors: span_suggestion takes impl ToString 2022-04-29 02:05:20 +01:00
rustc_parse_format Spellchecking compiler comments 2022-03-30 15:14:15 -04:00
rustc_passes Auto merge of #95604 - nbdd0121:used2, r=petrochenkov 2022-04-25 16:14:54 +00:00
rustc_plugin_impl
rustc_privacy Compute has_pub_restricted in the resolver. 2022-04-23 23:03:18 +02:00
rustc_query_impl implement (as of now still unused) query for valtree -> constvalue conversion 2022-04-21 16:37:24 +02:00
rustc_query_system Remove NodeIdHashingMode. 2022-04-12 19:59:32 +02:00
rustc_resolve errors: span_suggestion takes impl ToString 2022-04-29 02:05:20 +01:00
rustc_save_analysis Drop vis in ImplItem. 2022-04-23 09:57:00 +02:00
rustc_serialize Remove unused macro rules 2022-04-18 23:28:06 +02:00
rustc_session Rollup merge of #96433 - petrochenkov:delim, r=nnethercote 2022-04-28 20:13:02 +02:00
rustc_span extend EventArgRecorder into span-aware SpannedEventArgRecorder 2022-04-22 18:06:21 +02:00
rustc_symbol_mangling Auto merge of #95655 - kckeiks:create-hir-crate-items-query, r=cjgillot 2022-04-17 08:06:53 +00:00
rustc_target Update data layout string for wasm64-unknown-unknown 2022-04-27 07:29:44 -07:00
rustc_trait_selection Auto merge of #95976 - b-naber:valtree-constval-conversion, r=oli-obk 2022-04-28 13:18:22 +00:00
rustc_traits Remove opaque type obligation and just register opaque types as they are encountered. 2022-03-28 16:57:45 +00:00
rustc_ty_utils Avoid accessing HIR from MIR queries. 2022-04-10 13:08:36 +02:00
rustc_type_ir Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk" 2022-03-28 16:27:14 +00:00
rustc_typeck Auto merge of #96468 - davidtwco:diagnostic-translation-subdiagnostic, r=oli-obk 2022-04-29 11:58:24 +00:00