Skip to content

gccrs: Fix bad bounds checking for PartialOrd#3899

Merged
philberty merged 1 commit into
masterfrom
phil/dev
Jul 10, 2025
Merged

gccrs: Fix bad bounds checking for PartialOrd#3899
philberty merged 1 commit into
masterfrom
phil/dev

Conversation

@philberty

Copy link
Copy Markdown
Member

This was a nasty issue to debug, the issue was very eager type bounds checking. So for example:

pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq

The super trait of PartialEq is a generic substitution and we reuse our bounds code here for normal generic bounds and generics an invalid bounds check was occuring when PartialEq was getting substituted becase this is a trait doing proper bounds checking is not valid here because this is telling us about the bounds in this case.

Fixes #3836

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): track is super trait
* typecheck/rust-hir-type-bounds.h: refactor bounds scan
* typecheck/rust-hir-type-check-base.h: track from super trait
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::is_bound_satisfied_for_type): refactor
(TypeBoundsProbe::scan): likewise
(TypeBoundPredicate::apply_generic_arguments): likewise
* typecheck/rust-tyty-subst.cc: optional bounds checking on parm subst
* typecheck/rust-tyty-subst.h: likewise
* typecheck/rust-tyty.h: likewise

gcc/testsuite/ChangeLog:

* rust/compile/derive_partial_ord1.rs: this is now fully supported
* rust/execute/torture/basic_partial_ord1.rs: add missing i32 impl
* rust/execute/torture/basic_partial_ord2.rs: likewise
* rust/compile/issue-3836.rs: New test.
* rust/execute/torture/issue-3836.rs: New test.
* rust/execute/torture/partial-ord-6.rs: New test.

This was a nasty issue to debug, the issue was very eager type bounds
checking. So for example:

  pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs>

The super trait of PartialEq<Rhs> is a generic substitution and we reuse
our bounds code here for normal generic bounds and generics an invalid
bounds check was occuring when PartialEq<Rhs> was getting substituted becase
this is a trait doing proper bounds checking is not valid here because this
is telling us about the bounds in this case.

Fixes #3836

gcc/rust/ChangeLog:

	* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): track is super trait
	* typecheck/rust-hir-type-bounds.h: refactor bounds scan
	* typecheck/rust-hir-type-check-base.h: track from super trait
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise
	* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::is_bound_satisfied_for_type): refactor
	(TypeBoundsProbe::scan): likewise
	(TypeBoundPredicate::apply_generic_arguments): likewise
	* typecheck/rust-tyty-subst.cc: optional bounds checking on parm subst
	* typecheck/rust-tyty-subst.h: likewise
	* typecheck/rust-tyty.h: likewise

gcc/testsuite/ChangeLog:

	* rust/compile/derive_partial_ord1.rs: this is now fully supported
	* rust/execute/torture/basic_partial_ord1.rs: add missing i32 impl
	* rust/execute/torture/basic_partial_ord2.rs: likewise
	* rust/compile/issue-3836.rs: New test.
	* rust/execute/torture/issue-3836.rs: New test.
	* rust/execute/torture/partial-ord-6.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
@philberty philberty added this to the Typecheck issues 16.1 milestone Jul 10, 2025
@philberty philberty added the bug label Jul 10, 2025
@philberty philberty added this pull request to the merge queue Jul 10, 2025
Merged via the queue into master with commit 4b6b389 Jul 10, 2025
13 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in libcore 1.49 Jul 10, 2025
@philberty philberty deleted the phil/dev branch July 11, 2025 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Bad trait bounds checking stopping derive PartialOrd

1 participant