Skip to content

Commit

Permalink
Merge pull request dtolnay#414 from dtolnay/sort
Browse files Browse the repository at this point in the history
Point out every field involved in the cycle
  • Loading branch information
dtolnay authored Nov 4, 2020
2 parents 36b0ae8 + 35b662d commit 818004f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion syntax/toposort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions tests/ui/struct_cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ mod ffi {
struct Node5 {
node2: Node2,
}

struct Node6 {
node2: Node2,
}
}

fn main() {}
18 changes: 18 additions & 0 deletions tests/ui/struct_cycle.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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,
| ^^^^^^^^^^^^

0 comments on commit 818004f

Please sign in to comment.