From: Owen Avery <[email protected]>

gcc/rust/ChangeLog:

        * resolve/rust-identifier-path.cc
        (IdentifierPathPass::reseat (Pattern)): Remember to visit a
        pattern's sub-patterns, if we didn't convert it into a
        PathInExpression.

gcc/testsuite/ChangeLog:

        * rust/execute/ident_pat_vs_path_3.rs: New test.

Signed-off-by: Owen Avery <[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/f7a192fff40f141647752a7d5c8c0fae0c122d29

The commit has NOT been mentioned in any issue.

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

 gcc/rust/resolve/rust-identifier-path.cc      | 17 ++++++++----
 .../rust/execute/ident_pat_vs_path_3.rs       | 27 +++++++++++++++++++
 2 files changed, 39 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/rust/execute/ident_pat_vs_path_3.rs

diff --git a/gcc/rust/resolve/rust-identifier-path.cc 
b/gcc/rust/resolve/rust-identifier-path.cc
index 30223a7b3..414171bae 100644
--- a/gcc/rust/resolve/rust-identifier-path.cc
+++ b/gcc/rust/resolve/rust-identifier-path.cc
@@ -39,11 +39,14 @@ IdentifierPathPass::go (AST::Crate &crate, 
NameResolutionContext &ctx,
 void
 IdentifierPathPass::reseat (std::unique_ptr<AST::Pattern> &ptr)
 {
-  AST::IdentifierPattern *ident_pat;
-  if (ptr->get_pattern_kind () == AST::Pattern::Kind::Identifier)
-    ident_pat = static_cast<AST::IdentifierPattern *> (ptr.get ());
-  else
-    return;
+  if (ptr->get_pattern_kind () != AST::Pattern::Kind::Identifier)
+    {
+      // bail out, but make sure to still visit
+      visit (ptr);
+      return;
+    }
+
+  auto ident_pat = static_cast<AST::IdentifierPattern *> (ptr.get ());
 
   if (ident_path_to_convert.find (ident_pat->get_node_id ())
       != ident_path_to_convert.end ())
@@ -55,6 +58,10 @@ IdentifierPathPass::reseat (std::unique_ptr<AST::Pattern> 
&ptr)
        std::move (segments), std::vector<AST::Attribute> (),
        ident_pat->get_locus ());
     }
+  else
+    {
+      visit (ptr);
+    }
 }
 
 } // namespace Resolver2_0
diff --git a/gcc/testsuite/rust/execute/ident_pat_vs_path_3.rs 
b/gcc/testsuite/rust/execute/ident_pat_vs_path_3.rs
new file mode 100644
index 000000000..fcc2cc3d5
--- /dev/null
+++ b/gcc/testsuite/rust/execute/ident_pat_vs_path_3.rs
@@ -0,0 +1,27 @@
+// { dg-additional-options "-w" }
+#![feature(no_core)]
+#![no_core]
+
+enum E {
+    A,
+    B,
+    C
+}
+
+fn main() -> i32 {
+    use E::C;
+
+    let v1 = match (E::A,) {
+        (C,) => 1,
+        (E::A,) => 0,
+        (E::B,) => 1
+    };
+
+    let v2 = match (E::A,) {
+        (B,) => 0,
+        (E::A,) => 1,
+        (C,) => 1
+    };
+
+    v1 + v2
+}

base-commit: 1298319d8827ebdbc459587e2ef2e1142c4dd48b
-- 
2.54.0

Reply via email to