about summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-05-27 20:12:14 +0000
committerbors <bors@rust-lang.org>2019-05-27 20:12:14 +0000
commite70d5386d7abcf39adf54feb43a655c4f8a1bcb6 (patch)
tree78f07aa416883894265d017c06e0dd6adb7d1d30 /src/libsyntax/ext
parentfa40a111ff56c38590e83242e444e294093add07 (diff)
parent609ffa1a890fd6b8b0364cd7b35bf1d45abf82d0 (diff)
downloadrust-e70d5386d7abcf39adf54feb43a655c4f8a1bcb6.tar.gz
rust-e70d5386d7abcf39adf54feb43a655c4f8a1bcb6.zip
Auto merge of #61140 - estebank:attr-diagnostics, r=michaelwoerister
Reword malformed attribute input diagnostics

- Handle empty `cfg_attr` attribute
- Reword empty `derive` attribute error
- Use consistend error message: "malformed `attrname` attribute input"
- Provide suggestions when possible
- Move note/help to label/suggestion
- Use consistent wording "ill-formed" -> "malformed"
- Move diagnostic logic out of parser

Split up from https://github.com/rust-lang/rust/pull/61026, where there's prior conversation.
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/derive.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libsyntax/ext/derive.rs b/src/libsyntax/ext/derive.rs
index c47224ca0ce..a2cf4a2a82d 100644
--- a/src/libsyntax/ext/derive.rs
+++ b/src/libsyntax/ext/derive.rs
@@ -5,6 +5,7 @@ use crate::ext::base::ExtCtxt;
 use crate::ext::build::AstBuilder;
 use crate::parse::parser::PathStyle;
 use crate::symbol::{Symbol, sym};
+use crate::errors::Applicability;
 
 use syntax_pos::Span;
 
@@ -17,8 +18,13 @@ pub fn collect_derives(cx: &mut ExtCtxt<'_>, attrs: &mut Vec<ast::Attribute>) ->
             return true;
         }
         if !attr.is_meta_item_list() {
-            cx.span_err(attr.span,
-                        "attribute must be of the form `#[derive(Trait1, Trait2, ...)]`");
+            cx.struct_span_err(attr.span, "malformed `derive` attribute input")
+                .span_suggestion(
+                    attr.span,
+                    "missing traits to be derived",
+                    "#[derive(Trait1, Trait2, ...)]".to_owned(),
+                    Applicability::HasPlaceholders,
+                ).emit();
             return false;
         }