diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-06-20 10:39:54 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2023-06-21 09:00:30 +0000 |
commit | 3a27f1e9058c67a153f5911af052ccbf253e7e58 (patch) | |
tree | 2740b9ff8dc9b8329ca0ee9eac97373aeed65094 /gcc | |
parent | dbf982cbd898adc581a28934f701acd6db27d5f8 (diff) | |
download | gcc-3a27f1e9058c67a153f5911af052ccbf253e7e58.zip gcc-3a27f1e9058c67a153f5911af052ccbf253e7e58.tar.gz gcc-3a27f1e9058c67a153f5911af052ccbf253e7e58.tar.bz2 |
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>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-trait-resolve.cc | 8 | ||||
-rw-r--r-- | 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 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<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 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) { |