[gcc r14-7680] gccrs: fix unsafe lookup at zero index
Arthur Cohen
cohenarthur@gcc.gnu.org
Tue Jan 16 17:53:11 GMT 2024
https://gcc.gnu.org/g:946af759bdc029c1bbd3d6349ad5f80098bc30e3
commit r14-7680-g946af759bdc029c1bbd3d6349ad5f80098bc30e3
Author: Philip Herron <herron.philip@googlemail.com>
Date: Tue Jun 20 10:39:54 2023 +0100
gccrs: fix unsafe lookup at zero index
Using lookup_predciate by DefId is the safe way to get the relevant
predicate.
Addresses #1893
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc: use lookup_predicate (DefID)
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): fix formatting
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diff:
---
gcc/rust/typecheck/rust-hir-trait-resolve.cc | 8 +++-----
gcc/rust/typecheck/rust-hir-type-check-path.cc | 4 +---
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 7c6ce4c7a2d..099c6729483 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -513,11 +513,9 @@ AssociatedImplTrait::setup_associated_types (
? SubstMapperInternal::Resolve (associated_self, infer_arguments)
: associated_self;
- // FIXME this needs to do a lookup for the trait-reference DefId instead of
- // assuming its the first one in the list
- rust_assert (associated_self->num_specified_bounds () > 0);
- TyTy::TypeBoundPredicate &impl_predicate
- = associated_self->get_specified_bounds ().at (0);
+ const TyTy::TypeBoundPredicate &impl_predicate
+ = associated_self->lookup_predicate (bound.get_id ());
+ rust_assert (!impl_predicate.is_error ());
// infer the arguments on the predicate
std::vector<TyTy::BaseType *> impl_trait_predicate_args;
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index 6ae58cea631..4bac75a63d9 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -427,9 +427,7 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id,
seg.get_locus ());
bool ok = prev_segment->get_kind () != TyTy::TypeKind::ERROR;
if (!ok)
- {
- return;
- }
+ return;
if (found_impl_trait)
{
More information about the Gcc-cvs
mailing list