aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2024-11-12 12:16:40 +0000
committerPhilip Herron <philip.herron@embecosm.com>2024-11-12 14:53:02 +0000
commit680ad4625564f5f0ecf84a281e7b88c677421cbd (patch)
tree01c49b75f571af845643a02c10480d5c2b6fe8f3 /gcc/rust
parentb0d6abb923915451c6a90f1b328d8efbfdf22441 (diff)
downloadgcc-680ad4625564f5f0ecf84a281e7b88c677421cbd.zip
gcc-680ad4625564f5f0ecf84a281e7b88c677421cbd.tar.gz
gcc-680ad4625564f5f0ecf84a281e7b88c677421cbd.tar.bz2
gccrs: Fix bad handling for recursive type query
When resolving a type like this which is generic it causes the argument substitution to go through bounds checking which is expected. But this can call a type bounds probe which again calls a type query which will be on the Impl Type on an impl block which can result in a recursive type query which does eventually get caught and errors correctly. But this then triggers some old error diagnositcs which are not valid error codes but old error messages we used to catch simple errors very early on which do not apply for this senario. Fixes Rust-GCC#2905 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::resolve_impl_block_substitutions): dont check for unconstrained when the self is not resolved * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): remove bad debug error diagnostic * typecheck/rust-tyty-subst.cc: likewise gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle this * rust/compile/issue-2905-1.rs: New test. * rust/compile/issue-2905-2.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-item.cc8
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-type.cc7
-rw-r--r--gcc/rust/typecheck/rust-tyty-subst.cc3
3 files changed, 10 insertions, 8 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index 51ce827..ce8e759 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -724,6 +724,14 @@ TypeCheckItem::resolve_impl_block_substitutions (HIR::ImplBlock &impl_block,
}
TyTy::BaseType *self = TypeCheckType::Resolve (impl_block.get_type ().get ());
+ if (self->is<TyTy::ErrorType> ())
+ {
+ // we cannot check for unconstrained type arguments when the Self type is
+ // not resolved it will just add extra errors that dont help as well as
+ // the case where this could just be a recursive type query that should
+ // fail and will work later on anyway
+ return {substitutions, region_constraints};
+ }
// inherit the bounds
if (!specified_bound.is_error ())
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index f2e0405..f3aee8a 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -426,11 +426,8 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
if (!query_type (ref, &lookup))
{
if (is_root)
- {
- rust_error_at (seg->get_locus (),
- "failed to resolve root segment");
- return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
- }
+ return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
+
return root_tyty;
}
diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc
index 48dcd95..83d0e35 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.cc
+++ b/gcc/rust/typecheck/rust-tyty-subst.cc
@@ -634,8 +634,6 @@ SubstitutionRef::get_mappings_from_generic_args (
if (resolved == nullptr
|| resolved->get_kind () == TyTy::TypeKind::ERROR)
{
- rust_error_at (binding.get_locus (),
- "failed to resolve type arguments");
return SubstitutionArgumentMappings::error ();
}
@@ -701,7 +699,6 @@ SubstitutionRef::get_mappings_from_generic_args (
BaseType *resolved = Resolver::TypeCheckType::Resolve (arg.get ());
if (resolved == nullptr || resolved->get_kind () == TyTy::TypeKind::ERROR)
{
- rust_error_at (args.get_locus (), "failed to resolve type arguments");
return SubstitutionArgumentMappings::error ();
}