[gcc r14-7806] gccrs: proc macro: Detect malformed proc_macro_derive

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 18:00:09 GMT 2024


https://gcc.gnu.org/g:1b1f8d898857b69b98095fc26b4dd95bafffdc18

commit r14-7806-g1b1f8d898857b69b98095fc26b4dd95bafffdc18
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Tue Jul 18 13:37:03 2023 +0200

    gccrs: proc macro: Detect malformed proc_macro_derive
    
    A derive procedural macro declaration shall always have at least a trait
    to refer to. We should error out when it doesn't.
    
    gcc/rust/ChangeLog:
    
            * util/rust-attributes.cc (AttributeChecker::visit): Add
            attribute input check.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Diff:
---
 gcc/rust/util/rust-attributes.cc | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index a174edc625f..c8451def94e 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -561,6 +561,11 @@ AttributeChecker::visit (AST::Function &fun)
 
       if (result.name == "proc_macro_derive")
 	{
+	  if (!attribute.has_attr_input ())
+	    {
+	      rust_error_at (attribute.get_locus (),
+			     "malformed %<%s%> attribute input", name);
+	    }
 	  check_crate_type (name, attribute);
 	}
       else if (result.name == "proc_macro"


More information about the Gcc-cvs mailing list