From 3a27f1e9058c67a153f5911af052ccbf253e7e58 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Tue, 20 Jun 2023 10:39:54 +0100 Subject: 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 --- 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(-) (limited to 'gcc') diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index d7eb16d..f6c748b 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 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 a62ebcb..dcdf17d 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) { -- cgit v1.1