Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gccrs: constant evaluation like these are coercion sites #3281

Merged
merged 1 commit into from
Dec 2, 2024

Conversation

philberty
Copy link
Member

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 #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.

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 #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 <[email protected]>
@philberty philberty added this pull request to the merge queue Dec 2, 2024
Merged via the queue into master with commit db3d8fb Dec 2, 2024
13 checks passed
@philberty philberty deleted the phil/const-expr branch December 12, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Letting a slice variable from a constant slice throws error.
1 participant