]> git.ipfire.org Git - thirdparty/gcc.git/commit
gccrs: Fix bad bounds checking for PartialOrd
authorPhilip Herron <herron.philip@googlemail.com>
Fri, 27 Jun 2025 16:13:29 +0000 (17:13 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:54 +0000 (16:36 +0200)
commitd8d02332bccefdd449c938e93afc78ef7e295337
treea245504024c07a36751de60f2145af0a81f26109
parenta887f69e96b7507173771526e20715c31c8f844f
gccrs: Fix bad bounds checking for PartialOrd

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 Rust-GCC#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>
14 files changed:
gcc/rust/typecheck/rust-hir-trait-resolve.cc
gcc/rust/typecheck/rust-hir-type-bounds.h
gcc/rust/typecheck/rust-hir-type-check-base.h
gcc/rust/typecheck/rust-hir-type-check-expr.cc
gcc/rust/typecheck/rust-tyty-bounds.cc
gcc/rust/typecheck/rust-tyty-subst.cc
gcc/rust/typecheck/rust-tyty-subst.h
gcc/rust/typecheck/rust-tyty.h
gcc/testsuite/rust/compile/derive_partial_ord1.rs
gcc/testsuite/rust/compile/issue-3836.rs [new file with mode: 0644]
gcc/testsuite/rust/execute/torture/basic_partial_ord1.rs
gcc/testsuite/rust/execute/torture/basic_partial_ord2.rs
gcc/testsuite/rust/execute/torture/issue-3836.rs [new file with mode: 0644]
gcc/testsuite/rust/execute/torture/partial-ord-6.rs [new file with mode: 0644]