diff options
author | Philip Herron <herron.philip@googlemail.com> | 2024-12-02 16:17:54 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2024-12-02 17:30:59 +0000 |
commit | db3d8fb22c8d10a3687742a85de85242a96ac1ba (patch) | |
tree | f3d403738882a75b3eb48a8aa6d58eee60eeb890 /gcc/rust/backend/rust-compile-base.h | |
parent | fa93e280ed1c11d9775cb9c3211e13853d39c51c (diff) | |
download | gcc-db3d8fb22c8d10a3687742a85de85242a96ac1ba.zip gcc-db3d8fb22c8d10a3687742a85de85242a96ac1ba.tar.gz gcc-db3d8fb22c8d10a3687742a85de85242a96ac1ba.tar.bz2 |
gccrs: constant evaluation like these are coercion sites
The code here was wrongly assuming the decl type from the folding of the
expression would be the type of the constant decl. This is not the case for
unsized coercions for slices, where the expression here is a reference to
an array then we require the coercion to fix the result up to the expected
type.
Fixes Rust-GCC#1525
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc: apply coercion site to result
* backend/rust-compile-base.h: update prototype
* backend/rust-compile-implitem.cc (CompileTraitItem::visit): send in coercion info
* backend/rust-compile-item.cc (CompileItem::visit): likewise
gcc/testsuite/ChangeLog:
* rust/compile/issue-1525.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-base.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-base.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h index bf175d7..3c50535 100644 --- a/gcc/rust/backend/rust-compile-base.h +++ b/gcc/rust/backend/rust-compile-base.h @@ -90,9 +90,11 @@ protected: void compile_function_body (tree fndecl, HIR::BlockExpr &function_body, TyTy::BaseType *fn_return_ty); - tree compile_constant_item (TyTy::BaseType *resolved_type, + tree compile_constant_item (HirId coercion_id, TyTy::BaseType *resolved_type, + TyTy::BaseType *expected_type, const Resolver::CanonicalPath &canonical_path, - HIR::Expr &const_value_expr, location_t locus); + HIR::Expr &const_value_expr, location_t locus, + location_t expr_locus); tree compile_function (const std::string &fn_name, HIR::SelfParam &self_param, std::vector<HIR::FunctionParam> &function_params, |