gccrs: Add missing bounds checks on the associated impl - #4787
Merged
Conversation
philberty
force-pushed
the
phil/trait-bounds
branch
from
August 16, 2026 21:08
bfe364d to
1e72531
Compare
Before this require_b<T: B> (T) only checked for S<Bad> implement B and it early accepted the impl<T: A> B for S<T> But we need to validate the impl's bound after we bind the arguments being used on the generic impl. So when we do a call-expr/method-call expr we are binding to that impl and we need to validate. When we do that we know that impl T = Bad and we walk the impl generic params T: A apply the subst for Bad: A where its is not implemented and we fail and return. Fixes #4678 gcc/rust/ChangeLog: * typecheck/rust-hir-trait-reference.h: add emit_errors option * typecheck/rust-hir-trait-resolve.cc (AssociatedImplTrait::bind_impl_for_projection): new (AssociatedImplTrait::bind_impl_for_bound): call new validate function * typecheck/rust-type-util.cc (lookup_associated_impl_block): make this more generic * typecheck/rust-tyty-call.cc (validate_call_argument_associated_impl_bounds): new (TypeCheckCallExpr::visit): for each call arg validate and bind (TypeCheckMethodCallExpr::check): likewise gcc/testsuite/ChangeLog: * rust/compile/issue-4678.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
philberty
force-pushed
the
phil/trait-bounds
branch
from
August 16, 2026 21:15
1e72531 to
1e5540a
Compare
philberty
enabled auto-merge
August 16, 2026 21:42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before this require_b<T: B> (T) only checked for S implement B and it early accepted the
impl<T: A> B for S
But we need to validate the impl's bound after we bind the arguments being used on the generic impl. So when we do a call-expr/method-call expr we are binding to that impl and we need to validate. When we do that we know that impl T = Bad and we walk the impl generic params T: A apply the subst for Bad: A where its is not implemented and we fail and return.
Fixes #4678
gcc/rust/ChangeLog:
gcc/testsuite/ChangeLog: