gccrs: Fix compilation of trait-items which map to impl items #3414
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.
When we have paths such as Try::from_error the Try references the Trait and then from_error references the from_error trait item. So this resolves directly to a trait implementation which has the type:
fn (v: placeholder) -> Self
Remember that a path such as: Try::from_error gets handled by doing a
clever substitution: <T? as Try>::from_error
The main piece here is that we resolve this function type and for monomoprhization we know this is a trait call but we know that all trait's have an implicit Self type param which in this case is Result<i32, i32> so when it comes to knowing which impl block this is we got rid of the old bad insert/lookup receiver hack and use the specified type to know which impl block we are talking about to generate the function.
The hard part here is inside rust-compil-item.cc, where we have the 'concete' type which is the trait item fntype of:
fn <Result<i32, i32>> (v : i32) -> Result<i32,i32>
This does not really match the signiture of the impl item for Result which is:
fn <T, E> (v: i32) -> Result<T, E>
So what we need to do is actually infer this by inputing inference variables on the impl fntype then unify'ing the trait object to this to compute the types of this to monomorphize this.
Fixes #3381
gcc/rust/ChangeLog:
gcc/testsuite/ChangeLog: