diff options
author | Philip Herron <herron.philip@googlemail.com> | 2024-12-02 14:10:11 +0000 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-21 12:33:07 +0100 |
commit | 02bdd68e7daf59a0081ad9b05b5a17624d620dc3 (patch) | |
tree | bdfa0f8f8aff55728f1dd0e77add6574c1df3b69 /gcc/rust | |
parent | a6ad5cdc87c9c7f023351d1c3fa0ac12198928b2 (diff) | |
download | gcc-02bdd68e7daf59a0081ad9b05b5a17624d620dc3.zip gcc-02bdd68e7daf59a0081ad9b05b5a17624d620dc3.tar.gz gcc-02bdd68e7daf59a0081ad9b05b5a17624d620dc3.tar.bz2 |
gccrs: Remove bad assertion in name resolution
This was a handy debug assertion but only works for valid rust code. This
needs to handle the case where the type is not resolved which is a valid
case.
Fixes Rust-GCC#2423
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): remove assertions
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: nr2 can't handle this
* rust/compile/issue-2423.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.cc | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 2861fb9..245523a 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -582,7 +582,14 @@ ResolveItem::visit (AST::InherentImpl &impl_block) // Setup paths CanonicalPath self_cpath = CanonicalPath::create_empty (); bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_type (), self_cpath); - rust_assert (ok); + if (!ok) + { + resolver->get_name_scope ().pop (); + resolver->get_type_scope ().pop (); + resolver->get_label_scope ().pop (); + return; + } + rust_debug ("AST::InherentImpl resolve Self: {%s}", self_cpath.get ().c_str ()); @@ -671,12 +678,17 @@ ResolveItem::visit (AST::TraitImpl &impl_block) return; } - bool ok; // setup paths CanonicalPath canonical_trait_type = CanonicalPath::create_empty (); - ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path (), - canonical_trait_type); - rust_assert (ok); + bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path (), + canonical_trait_type); + if (!ok) + { + resolver->get_name_scope ().pop (); + resolver->get_type_scope ().pop (); + resolver->get_label_scope ().pop (); + return; + } rust_debug ("AST::TraitImpl resolve trait type: {%s}", canonical_trait_type.get ().c_str ()); @@ -684,7 +696,13 @@ ResolveItem::visit (AST::TraitImpl &impl_block) CanonicalPath canonical_impl_type = CanonicalPath::create_empty (); ok = ResolveTypeToCanonicalPath::go (impl_block.get_type (), canonical_impl_type); - rust_assert (ok); + if (!ok) + { + resolver->get_name_scope ().pop (); + resolver->get_type_scope ().pop (); + resolver->get_label_scope ().pop (); + return; + } rust_debug ("AST::TraitImpl resolve self: {%s}", canonical_impl_type.get ().c_str ()); |