From 76d1de92eb4c5958842a4190ea1006e575bdcb9b Mon Sep 17 00:00:00 2001 From: jayant chauhan <0001jayant@gmail.com> Date: Fri, 13 Feb 2026 03:49:23 +0530 Subject: [PATCH] gccrs: ast: Fix missing location info in derive macros Fixes Rust-GCC#4433 gcc/rust/ChangeLog: * ast/rust-ast.cc (Attribute::get_traits_to_derive): Propagate location info from MetaWord to SimplePath. gcc/testsuite/ChangeLog: * rust/compile/issue-4433.rs: Update test to expect valid line numbers. Signed-off-by: Jayant Chauhan <0001jayant@gmail.com> --- gcc/rust/ast/rust-ast.cc | 5 +++-- gcc/testsuite/rust/compile/issue-4433.rs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/rust/compile/issue-4433.rs diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 30fb5f4d5d8..e571fc8ea0c 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -302,8 +302,9 @@ Attribute::get_traits_to_derive () auto word = static_cast (meta_item); // Convert current word to path current = std::make_unique ( - AST::MetaItemPath ( - AST::SimplePath (word->get_ident ()))); + AST::MetaItemPath (AST::SimplePath::from_str ( + word->get_ident ().as_string (), + word->get_locus ()))); auto path = static_cast (current.get ()); diff --git a/gcc/testsuite/rust/compile/issue-4433.rs b/gcc/testsuite/rust/compile/issue-4433.rs new file mode 100644 index 00000000000..37f829e0dcf --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-4433.rs @@ -0,0 +1,19 @@ +// { dg-options "-frust-incomplete-and-experimental-compiler-do-not-use" } +#![feature(no_core)] +#![no_core] + +#[derive(Toto)] // { dg-error "macro not found" } +// { dg-error "could not resolve trait" "" { target *-*-* } .-1 } +struct Test {} + +#[derive( + Happy, // { dg-error "macro not found" } + // { dg-error "could not resolve trait" "" { target *-*-* } .-1 } + Birthday // { dg-error "macro not found" } + // { dg-error "could not resolve trait" "" { target *-*-* } .-1 } +)] +struct MultiLine {} + +#[derive(One, Two)] // { dg-error "macro not found" } +// { dg-error "could not resolve trait" "" { target *-*-* } .-1 } +struct SingleLine {} \ No newline at end of file