about summary refs log tree commit diff
path: root/compiler/rustc_attr_parsing/src/attributes/test_attrs.rs
diff options
context:
space:
mode:
authorJonathan Brouwer <jonathantbrouwer@gmail.com>2025-06-30 16:09:01 +0200
committerJonathan Brouwer <jonathantbrouwer@gmail.com>2025-07-05 21:23:09 +0200
commit2d8ffff10ae22cbe0effb7fb6f5561c8a859279e (patch)
treed4cf13c84b00b42b5520bddb9f79d0c7d27ffd96 /compiler/rustc_attr_parsing/src/attributes/test_attrs.rs
parent733b47ea4b1b86216f14ef56e49440c33933f230 (diff)
downloadrust-2d8ffff10ae22cbe0effb7fb6f5561c8a859279e.tar.gz
rust-2d8ffff10ae22cbe0effb7fb6f5561c8a859279e.zip
Port `#[ignore]` to the new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
Diffstat (limited to 'compiler/rustc_attr_parsing/src/attributes/test_attrs.rs')
-rw-r--r--compiler/rustc_attr_parsing/src/attributes/test_attrs.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/compiler/rustc_attr_parsing/src/attributes/test_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/test_attrs.rs
new file mode 100644
index 00000000000..cea3ee52ff4
--- /dev/null
+++ b/compiler/rustc_attr_parsing/src/attributes/test_attrs.rs
@@ -0,0 +1,46 @@
+use rustc_attr_data_structures::AttributeKind;
+use rustc_attr_data_structures::lints::AttributeLintKind;
+use rustc_feature::{AttributeTemplate, template};
+use rustc_span::{Symbol, sym};
+
+use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
+use crate::context::{AcceptContext, Stage};
+use crate::parser::ArgParser;
+
+pub(crate) struct IgnoreParser;
+
+impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
+    const PATH: &[Symbol] = &[sym::ignore];
+    const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
+    const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
+    const TEMPLATE: AttributeTemplate = template!(Word, NameValueStr: "reason");
+
+    fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
+        Some(AttributeKind::Ignore {
+            span: cx.attr_span,
+            reason: match args {
+                ArgParser::NoArgs => None,
+                ArgParser::NameValue(name_value) => {
+                    let Some(str_value) = name_value.value_as_str() else {
+                        let suggestions = <Self as SingleAttributeParser<S>>::TEMPLATE
+                            .suggestions(false, "ignore");
+                        let span = cx.attr_span;
+                        cx.emit_lint(
+                            AttributeLintKind::IllFormedAttributeInput { suggestions },
+                            span,
+                        );
+                        return None;
+                    };
+                    Some(str_value)
+                }
+                ArgParser::List(_) => {
+                    let suggestions =
+                        <Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "ignore");
+                    let span = cx.attr_span;
+                    cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
+                    return None;
+                }
+            },
+        })
+    }
+}