diff options
| author | David Wood <david.wood@huawei.com> | 2022-06-23 16:12:52 +0100 |
|---|---|---|
| committer | David Wood <david.wood@huawei.com> | 2022-06-24 09:08:25 +0100 |
| commit | abd3467d47ad8f366239100334c31478f075a0de (patch) | |
| tree | ecd4d5078913f402480080b565b59796917f7315 /compiler/rustc_error_messages | |
| parent | 99bc97940314176bc6ed38cea11723cc1fd9ee3b (diff) | |
| download | rust-abd3467d47ad8f366239100334c31478f075a0de.tar.gz rust-abd3467d47ad8f366239100334c31478f075a0de.zip | |
macros: use typed identifiers in subdiag derive
As in the diagnostic derive, using typed identifiers in the subdiagnostic derive improves the diagnostics of using the subdiagnostic derive as Fluent messages will be confirmed to exist at compile-time. Signed-off-by: David Wood <david.wood@huawei.com>
Diffstat (limited to 'compiler/rustc_error_messages')
| -rw-r--r-- | compiler/rustc_error_messages/src/lib.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index 7211c054326..8d5ab1a4517 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -347,6 +347,27 @@ impl<S: Into<String>> From<S> for DiagnosticMessage { } } +/// Translating *into* a subdiagnostic message from a diagnostic message is a little strange - but +/// the subdiagnostic functions (e.g. `span_label`) take a `SubdiagnosticMessage` and the +/// subdiagnostic derive refers to typed identifiers that are `DiagnosticMessage`s, so need to be +/// able to convert between these, as much as they'll be converted back into `DiagnosticMessage` +/// using `with_subdiagnostic_message` eventually. Don't use this other than for the derive. +impl Into<SubdiagnosticMessage> for DiagnosticMessage { + fn into(self) -> SubdiagnosticMessage { + match self { + DiagnosticMessage::Str(s) => SubdiagnosticMessage::Str(s), + DiagnosticMessage::FluentIdentifier(id, None) => { + SubdiagnosticMessage::FluentIdentifier(id) + } + // There isn't really a sensible behaviour for this because it loses information but + // this is the most sensible of the behaviours. + DiagnosticMessage::FluentIdentifier(_, Some(attr)) => { + SubdiagnosticMessage::FluentAttr(attr) + } + } + } +} + /// A span together with some additional data. #[derive(Clone, Debug)] pub struct SpanLabel { |
