diff --git a/syntax/toposort.rs b/syntax/toposort.rs index 7c210f235..876f9ad11 100644 --- a/syntax/toposort.rs +++ b/syntax/toposort.rs @@ -34,16 +34,18 @@ fn visit<'a>( entry.insert(Mark::Visiting); } } + let mut result = Ok(()); for field in &strct.fields { if let Type::Ident(ident) = &field.ty { if let Some(inner) = types.structs.get(&ident.rust) { if visit(cx, inner, sorted, marks, types).is_err() { cx.error(field, "unsupported cyclic data structure"); + result = Err(()); } } } } marks.insert(strct, Mark::Visited); sorted.push(strct); - Ok(()) + result } diff --git a/tests/ui/struct_cycle.rs b/tests/ui/struct_cycle.rs index be5f553f1..e74c2b1ca 100644 --- a/tests/ui/struct_cycle.rs +++ b/tests/ui/struct_cycle.rs @@ -25,6 +25,10 @@ mod ffi { struct Node5 { node2: Node2, } + + struct Node6 { + node2: Node2, + } } fn main() {} diff --git a/tests/ui/struct_cycle.stderr b/tests/ui/struct_cycle.stderr index 7a64e2934..49bcb5f64 100644 --- a/tests/ui/struct_cycle.stderr +++ b/tests/ui/struct_cycle.stderr @@ -3,3 +3,21 @@ error: unsupported cyclic data structure | 26 | node2: Node2, | ^^^^^^^^^^^^ + +error: unsupported cyclic data structure + --> $DIR/struct_cycle.rs:22:9 + | +22 | node5: Node5, + | ^^^^^^^^^^^^ + +error: unsupported cyclic data structure + --> $DIR/struct_cycle.rs:13:9 + | +13 | node4: Node4, + | ^^^^^^^^^^^^ + +error: unsupported cyclic data structure + --> $DIR/struct_cycle.rs:8:9 + | +8 | node2: Node2, + | ^^^^^^^^^^^^