]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: [E0391] Detected type dependency cycle
authorMuhammad Mahad <mahadtxt@gmail.com>
Tue, 15 Aug 2023 16:29:03 +0000 (21:29 +0500)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:00:32 +0000 (19:00 +0100)
This errorcode & message emits when cycle
detected when computing the super predicates
of `x` which requires computing the super
predicates of `y`, which again requires
computing the super predicates of `x`,
completing the cycle.

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait):
Updated errorcode & more userfriendly message.

gcc/testsuite/ChangeLog:

* rust/compile/issue-1589.rs: Updated comment for dejagnu.
* rust/compile/trait-cycle.rs: New relevant test.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
gcc/rust/typecheck/rust-hir-trait-resolve.cc
gcc/testsuite/rust/compile/issue-1589.rs
gcc/testsuite/rust/compile/trait-cycle.rs [new file with mode: 0644]

index b99fe2341af5ed10a65d07d5e4b91487cfbd8d93..1d6a9fbdd37e82ac060b920cf8f7393a45f3e90f 100644 (file)
@@ -156,7 +156,10 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference)
   DefId trait_id = trait_reference->get_mappings ().get_defid ();
   if (context->trait_query_in_progress (trait_id))
     {
-      rust_error_at (trait_reference->get_locus (), "trait cycle detected");
+      rust_error_at (
+       trait_reference->get_locus (), ErrorCode::E0391,
+       "cycle detected when computing the super predicates of %qs",
+       trait_reference->get_name ().as_string ().c_str ());
       return &TraitReference::error_node ();
     }
 
index 45f2415a81316da4c832fa9f78e70f51a58bcd4b..1dd7a45286c47d0106e00cdeaa950185384f6ee2 100644 (file)
@@ -2,7 +2,7 @@
 pub trait Sized {}
 
 pub trait A: B {}
-// { dg-error "trait cycle detected" "" { target *-*-* } .-1 }
+// { dg-error "cycle detected when computing the super predicates of .A." "" { target *-*-* } .-1 }
 
 pub trait B: A {}
-// { dg-error "trait cycle detected" "" { target *-*-* } .-1 }
+// { dg-error "cycle detected when computing the super predicates of .B." "" { target *-*-* } .-1 }
diff --git a/gcc/testsuite/rust/compile/trait-cycle.rs b/gcc/testsuite/rust/compile/trait-cycle.rs
new file mode 100644 (file)
index 0000000..3bcadbb
--- /dev/null
@@ -0,0 +1,4 @@
+pub trait FirstTrait: SecondTrait {}
+// { dg-error "cycle detected when computing the super predicates of .FirstTrait." "" { target *-*-* } .-1 }
+pub trait SecondTrait: FirstTrait {}
+// { dg-error "cycle detected when computing the super predicates of .SecondTrait." "" { target *-*-* } .-1 }