]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: fix unsafe lookup at zero index
authorPhilip Herron <herron.philip@googlemail.com>
Tue, 20 Jun 2023 09:39:54 +0000 (10:39 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:46:28 +0000 (18:46 +0100)
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>
gcc/rust/typecheck/rust-hir-trait-resolve.cc
gcc/rust/typecheck/rust-hir-type-check-path.cc

index 7c6ce4c7a2d79199c66fc36b6c743f5e50e72cd1..099c6729483f59d27889f205d226ec6735a790c4 100644 (file)
@@ -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;
index 6ae58cea631a50ac5b65c5338c95f49d4ba4aa6f..4bac75a63d9755d96f550b97a7fb93bb9c982dac 100644 (file)
@@ -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)
            {