From: jayant chauhan <[email protected]>

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 <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/461ab85753c6eadfd16565ba3422f44fc80b0190

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4435

 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 30fb5f4d5..e571fc8ea 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<AST::MetaWord *> (meta_item);
                        // Convert current word to path
                        current = std::make_unique<AST::MetaItemPath> (
-                         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<AST::MetaItemPath *> (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 000000000..37f829e0d
--- /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

base-commit: 308bc94241b95066f12818dc63b9f7b26c0b07f8
-- 
2.52.0

Reply via email to