Skip to content

Conversation

@philberty
Copy link
Member

Const generics bind values which can be accessed like a normal path but the difference is that they can be true expression values not just type paths. This patch adds support to resolving a method inference which passes a generic value into the method and fixes some missed bugs along the way. The tricky part was that there is a case where in the return position of a method returning a const param type vs the type of the method there is a special case in the unify rules so that we unify the specified type of the const param type not the const param itself.

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc: handle const param values
* typecheck/rust-hir-type-check-item.cc: generate const infer vars when required
* typecheck/rust-type-util.cc (unify_site_and): handle a null param cleanup
* typecheck/rust-tyty-util.cc (TyVar::get_implicit_const_infer_var): helper interface
* typecheck/rust-tyty-util.h: update header prototypes
* typecheck/rust-tyty.cc (BaseType::is_concrete): correctly handle const types
(ConstParamType::get_name): emit the specified type
(ConstParamType::is_equal): fix recursion loop
* typecheck/rust-unify.cc (UnifyRules::go): const infer vars need cleanup too
* typecheck/rust-unify.h: support base generics

gcc/testsuite/ChangeLog:

* rust/execute/torture/const-generics-2.rs: New test.

Const generics bind values which can be accessed like a normal path but the difference
is that they can be true expression values not just type paths. This patch adds support
to resolving a method inference which passes a generic value into the method and fixes
some missed bugs along the way. The tricky part was that there is a case where in the
return position of a method returning a const param type vs the type of the method
there is a special case in the unify rules so that we unify the specified type of the
const param type not the const param itself.

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc: handle const param values
	* typecheck/rust-hir-type-check-item.cc: generate const infer vars when required
	* typecheck/rust-type-util.cc (unify_site_and): handle a null param cleanup
	* typecheck/rust-tyty-util.cc (TyVar::get_implicit_const_infer_var): helper interface
	* typecheck/rust-tyty-util.h: update header prototypes
	* typecheck/rust-tyty.cc (BaseType::is_concrete): correctly handle const types
	(ConstParamType::get_name): emit the specified type
	(ConstParamType::is_equal): fix recursion loop
	* typecheck/rust-unify.cc (UnifyRules::go): const infer vars need cleanup too
	* typecheck/rust-unify.h: support base generics

gcc/testsuite/ChangeLog:

	* rust/execute/torture/const-generics-2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
@philberty philberty added this to the Deferred const inference milestone Nov 4, 2025
@philberty philberty added this pull request to the merge queue Nov 4, 2025
Merged via the queue into master with commit 7699f7f Nov 4, 2025
13 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in libcore 1.49 Nov 4, 2025
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.

2 participants