https://gcc.gnu.org/g:d020cdb0d419806b24daf6376c7827809f23c24a
commit r17-3079-gd020cdb0d419806b24daf6376c7827809f23c24a Author: Owen Avery <[email protected]> Date: Fri Jul 3 15:52:33 2026 -0400 gccrs: Fix IdentifierPathPass on sub-patterns 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]> Diff: --- gcc/rust/resolve/rust-identifier-path.cc | 17 +++++++++----- gcc/testsuite/rust/execute/ident_pat_vs_path_3.rs | 27 +++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/gcc/rust/resolve/rust-identifier-path.cc b/gcc/rust/resolve/rust-identifier-path.cc index 30223a7b3d6c..414171bae879 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 000000000000..fcc2cc3d5c5d --- /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 +}
