aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-10-13 10:10:37 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2023-02-21 12:36:33 +0100
commit59bee4d4663e7e285a41540e9378cb0f9f312ee1 (patch)
tree2283b25ed9a4f4eee89372c65af858a16dcfd47a /gcc/rust/resolve
parent2d7661e76e1276b3661502022ecee2861d040026 (diff)
downloadgcc-59bee4d4663e7e285a41540e9378cb0f9f312ee1.zip
gcc-59bee4d4663e7e285a41540e9378cb0f9f312ee1.tar.gz
gcc-59bee4d4663e7e285a41540e9378cb0f9f312ee1.tar.bz2
gccrs: Method resolution must support multiple candidates
This patch fixes bad method resolution in our operator_overload_9 case. When we have a &mut reference to something and we deref we must resolve to the mutable reference impl block. The interface we are using to resolve methods is the can_eq interface which allows for permissive mutability which means allowing for mutable reference being unified with an immutable one. This meant we actual match against both the immutable and mutable version leading to multiple candidate error. The fix here adds a method resolution flag to the can_eq interface so that we enforce mutability equality. The other hack is that we do not allow can_eq of ParamTypes to generic Slices. I think there is some subtle thing going on for that case. The Rustc method resolver actually filters the impl blocks for reference types based looking up the relevant lang items we need to do this as well but is a much larger refactor to our method resolver which should be done seperately. Fixes #1588 gcc/rust/ChangeLog: * typecheck/rust-autoderef.cc: Add support for multiple resolution candidates. * typecheck/rust-hir-dot-operator.cc (MethodResolver::MethodResolver): Edit `try_result` field and change constructor. (MethodResolver::Probe): Return set of candidates instead of singular candidate. (MethodResolver::select): Add better implementation to account for multiple candidates. * typecheck/rust-hir-dot-operator.h (struct MethodCandidate): Overload comparison operator in order to store them in `std::set`. * typecheck/rust-hir-inherent-impl-overlap.h: Do not fail assertion on missing type. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Adapt code to use multiple candidates. * typecheck/rust-tyty.cc (set_cmp_autoderef_mode): Add code to handle automatic derefs properly. (reset_cmp_autoderef_mode): Add helper function to reset said mode. * typecheck/rust-tyty.h (set_cmp_autoderef_mode): Declare function. (reset_cmp_autoderef_mode): Likewise. * typecheck/rust-tyty-cmp.h: Add handling of `autoderef_cmp_flag` gcc/testsuite/ChangeLog: * rust/compile/generics7.rs: Fix test with missing assertion. * rust/execute/torture/operator_overload_9.rs: Fix test assertion.
Diffstat (limited to 'gcc/rust/resolve')
0 files changed, 0 insertions, 0 deletions