gccrs: Fix higher ranked trait bounds computation of self
commit9754a60623c5a3a8df0d32600345dd310812bec1
authorPhilip Herron <herron.philip@googlemail.com>
Tue, 31 Jan 2023 18:52:33 +0000 (31 18:52 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 6 Apr 2023 08:47:21 +0000 (6 10:47 +0200)
tree1931b375e10bba12ee9f396ac50e45f7467a8922
parentf62dcf2c65a66615321acdf73f0f4c8a9ce679f9
gccrs: Fix higher ranked trait bounds computation of self

This updates the higher ranked trait bounds computation to handle ambigious
cases. When we have a slice for example:

  let slice = &a[1..3];

This works by reusing the Index operator overload from libcore, so when the
index range of 1..3 is computed, the type system needs to compute what the
types of index are; this works by integer inference variables
Range<<integer>> that need to be unified with the impl Index for
Range<Usize> which computes the real type of usize for the index. This is
fine but what happens when we have the Copy and Clone traits bounds which
have implementations for all the primitive types i8, i16, i32, i64...
which is valid for any integer inference variable so the code prior to this
patch would have grabbed the first impl it would have found and used it
which is incorrect. When we have integer or float inference variables we
need to look for their respective defaults or emit an ambigious type bound
error.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.h: add const infterface
* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::get_generic_param): make const
(SubstitutionRef::monomorphize): fix issue
* typecheck/rust-tyty-subst.h: constify interface
gcc/rust/typecheck/rust-hir-trait-reference.h
gcc/rust/typecheck/rust-tyty-subst.cc
gcc/rust/typecheck/rust-tyty-subst.h