about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDavid Wood <david.wood@huawei.com>2022-07-11 18:46:24 +0100
committerDavid Wood <david.wood@huawei.com>2022-07-15 16:13:49 +0100
commit81cf2294b4d912ec410696c5e2dec7659243d191 (patch)
tree6859d706f4be0d1bd9963d02681f12900a747b37 /src
parent88c11c5bfffea445c6cc49b62da17f172eb8f055 (diff)
downloadrust-81cf2294b4d912ec410696c5e2dec7659243d191.tar.gz
rust-81cf2294b4d912ec410696c5e2dec7659243d191.zip
macros: support adding warnings to diags
Both diagnostic and subdiagnostic derives were missing the ability to
add warnings to diagnostics - this is made more difficult by the `warn`
attribute already existing, so this name being unavailable for the
derives to use. `#[warn_]` is used instead, which requires
special-casing so that `{span_,}warn` is called instead of
`{span_,}warn_`.

Signed-off-by: David Wood <david.wood@huawei.com>
Diffstat (limited to 'src')
-rw-r--r--src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs9
-rw-r--r--src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr4
-rw-r--r--src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs12
3 files changed, 22 insertions, 3 deletions
diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs
index b343bcb7721..0a210cbdc94 100644
--- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs
+++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs
@@ -538,7 +538,7 @@ struct LabelWithTrailingList {
 
 #[derive(SessionDiagnostic)]
 #[lint(typeck::ambiguous_lifetime_bound)]
-//~^ ERROR only `#[error(..)]` and `#[warn(..)]` are supported
+//~^ ERROR only `#[error(..)]` and `#[warning(..)]` are supported
 struct LintsBad {
 }
 
@@ -559,3 +559,10 @@ struct ErrorWithMultiSpan {
     #[primary_span]
     span: MultiSpan,
 }
+
+#[derive(SessionDiagnostic)]
+#[error(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[warn_]
+struct ErrorWithWarn {
+    val: String,
+}
diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr
index e2580c6485a..c1080aa2452 100644
--- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr
+++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr
@@ -21,7 +21,7 @@ error: `#[nonsense(...)]` is not a valid attribute
 LL | #[nonsense(typeck::ambiguous_lifetime_bound, code = "E0123")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-   = help: only `error`, `warning`, `help` and `note` are valid attributes
+   = help: only `error`, `warning`, `help`, `note` and `warn_` are valid attributes
 
 error: diagnostic kind not specified
   --> $DIR/diagnostic-derive.rs:53:1
@@ -363,7 +363,7 @@ error: `#[label(...)]` is not a valid attribute
 LL |     #[label(typeck::label, foo("..."))]
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: only `#[error(..)]` and `#[warn(..)]` are supported
+error: only `#[error(..)]` and `#[warning(..)]` are supported
   --> $DIR/diagnostic-derive.rs:540:1
    |
 LL | / #[lint(typeck::ambiguous_lifetime_bound)]
diff --git a/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs
index cbb66c13c68..16da25c402b 100644
--- a/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs
+++ b/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs
@@ -508,3 +508,15 @@ enum AX {
         span: Span,
     }
 }
+
+#[derive(SessionSubdiagnostic)]
+#[warn_(parser::add_paren)]
+struct AY {
+}
+
+#[derive(SessionSubdiagnostic)]
+#[warn_(parser::add_paren)]
+struct AZ {
+    #[primary_span]
+    span: Span,
+}