diff options
author | Philip Herron <herron.philip@googlemail.com> | 2025-03-27 16:32:21 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2025-03-27 18:07:48 +0000 |
commit | 08bfb3550e76b14d6cb6e6eb1478bff79bacf091 (patch) | |
tree | ba3b873d37eee1fecd7d5f346d6fa1f66ef2cf98 /gcc/rust/backend | |
parent | ce8e35fc28ccc9ade61ff9c83fee55e2673acce8 (diff) | |
download | gcc-08bfb3550e76b14d6cb6e6eb1478bff79bacf091.zip gcc-08bfb3550e76b14d6cb6e6eb1478bff79bacf091.tar.gz gcc-08bfb3550e76b14d6cb6e6eb1478bff79bacf091.tar.bz2 |
gccrs: Fix ICE when compiling path which resolves to trait constant
Fixes Rust-GCC#3552
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): check for Expr trait
* hir/rust-hir-dump.cc (Dump::visit): expr is optional
gcc/testsuite/ChangeLog:
* rust/compile/issue-3552.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile-resolve-path.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index 9423951..d4901a4 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.cc +++ b/gcc/rust/backend/rust-compile-resolve-path.cc @@ -301,6 +301,27 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup, trait->get_mappings ().get_defid (), &trait_ref); rust_assert (ok); + if (trait_item.value ()->get_item_kind () + == HIR::TraitItem::TraitItemKind::CONST) + { + auto &c + = *static_cast<HIR::TraitItemConst *> (trait_item.value ()); + if (!c.has_expr ()) + { + rich_location r (line_table, expr_locus); + r.add_range (trait->get_locus ()); + r.add_range (c.get_locus ()); + rust_error_at (r, "no default expression on trait constant"); + return error_mark_node; + } + + return CompileExpr::Compile (c.get_expr (), ctx); + } + + if (trait_item.value ()->get_item_kind () + != HIR::TraitItem::TraitItemKind::FUNC) + return error_mark_node; + // the type resolver can only resolve type bounds to their trait // item so its up to us to figure out if this path should resolve // to an trait-impl-block-item or if it can be defaulted to the |