]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Parse AttrInputMacro
authorOwen Avery <powerboat9.gamer@gmail.com>
Sun, 30 Apr 2023 06:57:15 +0000 (02:57 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:37:21 +0000 (18:37 +0100)
gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_attr_input): Parse AttrInputMacro.

gcc/testsuite/ChangeLog:

* rust/compile/doc_macro.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/parse/rust-parse-impl.h
gcc/testsuite/rust/compile/doc_macro.rs [new file with mode: 0644]

index 5d48ba637d7a3da38ae9d6d07d02a5a29e727816..3f2500660df61081e90c49054aec871c1e4682fc 100644 (file)
@@ -793,6 +793,21 @@ Parser<ManagedTokenSource>::parse_attr_input ()
 
        t = lexer.peek_token ();
 
+       // attempt to parse macro
+       // TODO: macros may/may not be allowed in attributes
+       // this is needed for "#[doc = include_str!(...)]"
+       if (is_simple_path_segment (t->get_id ()))
+         {
+           std::unique_ptr<AST::MacroInvocation> invoke
+             = parse_macro_invocation ({});
+
+           if (!invoke)
+             return nullptr;
+
+           return std::unique_ptr<AST::AttrInput> (
+             new AST::AttrInputMacro (std::move (invoke)));
+         }
+
        /* Ensure token is a "literal expression" (literally only a literal
         * token of any type) */
        if (!t->is_literal ())
diff --git a/gcc/testsuite/rust/compile/doc_macro.rs b/gcc/testsuite/rust/compile/doc_macro.rs
new file mode 100644 (file)
index 0000000..6d76910
--- /dev/null
@@ -0,0 +1 @@
+#![doc = concat!("AB")]