Skip to content

Commit

Permalink
gccrs: [E0391] Detected type dependency cycle
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
MahadMuhammad authored and CohenArthur committed Aug 18, 2023
1 parent 8ac2e43 commit 879a62f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion gcc/rust/typecheck/rust-hir-trait-resolve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
}

Expand Down
4 changes: 2 additions & 2 deletions gcc/testsuite/rust/compile/issue-1589.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
4 changes: 4 additions & 0 deletions gcc/testsuite/rust/compile/trait-cycle.rs
Original file line number Diff line number Diff line change
@@ -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 }

0 comments on commit 879a62f

Please sign in to comment.