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]>
---
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 30223a7b3d6..414171bae87 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 00000000000..fcc2cc3d5c5
--- /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
+}
--
2.50.1